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

@ -59,14 +59,19 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile; import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao; 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;
@ -77,8 +82,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
} }
protected boolean canHandle(NetworkOffering offering, DataCenter dc) { protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
//This guru handles only non-system Guest network // This guru handles only non-system Guest network
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == GuestIpType.Virtual && !offering.isSystemOnly()) { if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == GuestIpType.Virtual && !offering.isSystemOnly()) {
return true; return true;
} else { } else {
s_logger.trace("We only take care of Guest Virtual networks in zone of type " + NetworkType.Advanced); s_logger.trace("We only take care of Guest Virtual networks in zone of type " + NetworkType.Advanced);
@ -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.");
} }
@ -105,7 +109,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
network.setGateway(userSpecified.getGateway()); network.setGateway(userSpecified.getGateway());
} else { } else {
String guestNetworkCidr = dc.getGuestNetworkCidr(); String guestNetworkCidr = dc.getGuestNetworkCidr();
//guest network cidr can be null for Basic zone // guest network cidr can be null for Basic zone
if (guestNetworkCidr != null) { if (guestNetworkCidr != null) {
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])));
@ -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();
@ -174,7 +182,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
DataCenter dc = _dcDao.findById(network.getDataCenterId()); DataCenter dc = _dcDao.findById(network.getDataCenterId());
if (nic.getIp4Address() == null){ if (nic.getIp4Address() == null) {
nic.setBroadcastUri(network.getBroadcastUri()); nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri()); nic.setIsolationUri(network.getBroadcastUri());
nic.setGateway(network.getGateway()); nic.setGateway(network.getGateway());
@ -212,7 +220,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
List<String> ips = _nicDao.listIpAddressInNetwork(network.getId()); List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
String[] cidr = network.getCidr().split("/"); String[] cidr = network.getCidr().split("/");
Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1])); Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1]));
Set<Long> usedIps = new TreeSet<Long> (); Set<Long> usedIps = new TreeSet<Long>();
for (String ip : ips) { for (String ip : ips) {
usedIps.add(NetUtils.ip2Long(ip)); usedIps.add(NetUtils.ip2Long(ip));
} }
@ -224,11 +232,11 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
} }
Long[] array = allPossibleIps.toArray(new Long[allPossibleIps.size()]); Long[] array = allPossibleIps.toArray(new Long[allPossibleIps.size()]);
return NetUtils.long2Ip(array[_rand.nextInt(array.length)]); return NetUtils.long2Ip(array[_rand.nextInt(array.length)]);
} }
@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;
} }