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);
}
public InsufficientVirtualNetworkCapcityException(String msg, long id) {
this(msg, Pod.class, id);
public InsufficientVirtualNetworkCapcityException(String msg, long podId) {
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 destination where were deploying to.
* @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.

View File

@ -151,7 +151,7 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
}
@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;
return config;
}

View File

@ -200,7 +200,7 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
}
@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;
}

View File

@ -59,14 +59,19 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
@Local(value=NetworkGuru.class)
@Local(value = NetworkGuru.class)
public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(GuestNetworkGuru.class);
@Inject protected NetworkManager _networkMgr;
@Inject protected DataCenterDao _dcDao;
@Inject protected VlanDao _vlanDao;
@Inject protected NicDao _nicDao;
@Inject protected NetworkDao _networkDao;
@Inject
protected NetworkManager _networkMgr;
@Inject
protected DataCenterDao _dcDao;
@Inject
protected VlanDao _vlanDao;
@Inject
protected NicDao _nicDao;
@Inject
protected NetworkDao _networkDao;
String _defaultGateway;
String _defaultCidr;
@ -77,7 +82,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
}
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()) {
return true;
} else {
@ -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);
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
(userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
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());
} else {
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) {
String[] cidrTuple = guestNetworkCidr.split("\\/");
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[] cidrTuple = guestNetworkCidr.split("\\/");
network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
network.setCidr(guestNetworkCidr);;
network.setCidr(guestNetworkCidr);
;
}
return network;
@ -136,16 +141,19 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
}
@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;
long dcId = dest.getDataCenter().getId();
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), network.getDataCenterId(), State.Allocated);
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(),
network.getDataCenterId(), State.Allocated);
if (network.getBroadcastUri() == null) {
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));
} else {
implemented.setBroadcastUri(network.getBroadcastUri());
@ -163,8 +171,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
}
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
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());
if (nic.getIp4Address() == null){
if (nic.getIp4Address() == null) {
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
nic.setGateway(network.getGateway());
@ -212,7 +220,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
String[] cidr = network.getCidr().split("/");
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) {
usedIps.add(NetUtils.ip2Long(ip));
}
@ -227,8 +235,8 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
}
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
nic.setBroadcastUri(network.getBroadcastUri());

View File

@ -22,6 +22,7 @@ import javax.ejb.Local;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
@ -58,7 +59,7 @@ public class OvsGuestNetworkGuru extends GuestNetworkGuru {
}
@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;
if (!_ovsNetworkMgr.isOvsNetworkEnabled()&& !_ovsTunnelMgr.isOvsTunnelEnabled()) {
return null;

View File

@ -137,7 +137,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
}
@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;
}

View File

@ -165,7 +165,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
}
@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;
}