bug 9488: throw InsufficientVirtualNetworkCapcityException when fail to allocate guest vnet as a part of network implement() call

status 9488: resolved fixed
This commit is contained in:
alena 2011-04-21 11:48:59 -07:00
parent 3d33fd7f92
commit c844655825
8 changed files with 70 additions and 60 deletions

View File

@ -27,7 +27,7 @@ public class InsufficientVirtualNetworkCapcityException extends InsufficientNetw
super(msg, scope, id); super(msg, scope, id);
} }
public InsufficientVirtualNetworkCapcityException(String msg, long id) { public InsufficientVirtualNetworkCapcityException(String msg, long podId) {
this(msg, Pod.class, id); this(msg, Pod.class, podId);
} }
} }

View File

@ -71,8 +71,9 @@ public interface NetworkGuru extends Adapter {
* @param offering offering that the network configuration was based on. * @param offering offering that the network configuration was based on.
* @param destination where were deploying to. * @param destination where were deploying to.
* @return a fully implemented NetworkConfiguration. * @return a fully implemented NetworkConfiguration.
* @throws InsufficientVirtualNetworkCapcityException TODO
*/ */
Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context); Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException;
/** /**
* reserve a nic for this VM in this network. * reserve a nic for this VM in this network.

View File

@ -151,7 +151,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
} }
@Override @Override
public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) { public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
assert config.getTrafficType() == TrafficType.Control : "Why are you sending this configuration to me " + config; assert config.getTrafficType() == TrafficType.Control : "Why are you sending this configuration to me " + config;
return config; return config;
} }

View File

@ -200,7 +200,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
} }
@Override @Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) { public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
return network; return network;
} }

View File

@ -62,11 +62,16 @@ import com.cloud.vm.dao.NicDao;
@Local(value = NetworkGuru.class) @Local(value = NetworkGuru.class)
public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(GuestNetworkGuru.class); private static final Logger s_logger = Logger.getLogger(GuestNetworkGuru.class);
@Inject protected NetworkManager _networkMgr; @Inject
@Inject protected DataCenterDao _dcDao; protected NetworkManager _networkMgr;
@Inject protected VlanDao _vlanDao; @Inject
@Inject protected NicDao _nicDao; protected DataCenterDao _dcDao;
@Inject protected NetworkDao _networkDao; @Inject
protected VlanDao _vlanDao;
@Inject
protected NicDao _nicDao;
@Inject
protected NetworkDao _networkDao;
String _defaultGateway; String _defaultGateway;
String _defaultCidr; String _defaultCidr;
@ -95,8 +100,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
NetworkVO network = new NetworkVO(offering.getTrafficType(), offering.getGuestType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), State.Allocated); NetworkVO network = new NetworkVO(offering.getTrafficType(), offering.getGuestType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), State.Allocated);
if (userSpecified != null) { if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
(userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
throw new InvalidParameterValueException("cidr and gateway must be specified together."); throw new InvalidParameterValueException("cidr and gateway must be specified together.");
} }
@ -125,7 +129,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
String guestNetworkCidr = dc.getGuestNetworkCidr(); String guestNetworkCidr = dc.getGuestNetworkCidr();
String[] cidrTuple = guestNetworkCidr.split("\\/"); String[] cidrTuple = guestNetworkCidr.split("\\/");
network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]))); network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
network.setCidr(guestNetworkCidr);; network.setCidr(guestNetworkCidr);
;
} }
return network; return network;
@ -136,16 +141,19 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
} }
@Override @Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) { public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network; assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
long dcId = dest.getDataCenter().getId(); long dcId = dest.getDataCenter().getId();
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(),
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), network.getDataCenterId(), State.Allocated); network.getDataCenterId(), State.Allocated);
if (network.getBroadcastUri() == null) { if (network.getBroadcastUri() == null) {
String vnet = _dcDao.allocateVnet(dcId, network.getAccountId(), context.getReservationId()); String vnet = _dcDao.allocateVnet(dcId, network.getAccountId(), context.getReservationId());
if (vnet == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId);
}
implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnet)); implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnet));
} else { } else {
implemented.setBroadcastUri(network.getBroadcastUri()); implemented.setBroadcastUri(network.getBroadcastUri());
@ -163,8 +171,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
} }
@Override @Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException { InsufficientAddressCapacityException {
assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name! Why are you calling me when the traffic type is : " + network.getTrafficType(); assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name! Why are you calling me when the traffic type is : " + network.getTrafficType();
@ -227,8 +235,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
} }
@Override @Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
InsufficientAddressCapacityException { throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? "; assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
nic.setBroadcastUri(network.getBroadcastUri()); nic.setBroadcastUri(network.getBroadcastUri());

View File

@ -22,6 +22,7 @@ import javax.ejb.Local;
import com.cloud.deploy.DeployDestination; import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network; import com.cloud.network.Network;
import com.cloud.network.NetworkManager; import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO; import com.cloud.network.NetworkVO;
@ -58,7 +59,7 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru {
} }
@Override @Override
public Network implement(Network config, NetworkOffering offering, DeployDestination dest, ReservationContext context) { public Network implement(Network config, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
assert (config.getState() == State.Implementing) : "Why are we implementing " + config; assert (config.getState() == State.Implementing) : "Why are we implementing " + config;
if (!_ovsNetworkMgr.isOvsNetworkEnabled()&& !_ovsTunnelMgr.isOvsTunnelEnabled()) { if (!_ovsNetworkMgr.isOvsNetworkEnabled()&& !_ovsTunnelMgr.isOvsTunnelEnabled()) {
return null; return null;

View File

@ -137,7 +137,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
} }
@Override @Override
public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) { public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
return config; return config;
} }

View File

@ -165,7 +165,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
} }
@Override @Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) { public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
return network; return network;
} }