Skip to content

Commit c844655

Browse files
committed
bug 9488: throw InsufficientVirtualNetworkCapcityException when fail to allocate guest vnet as a part of network implement() call
status 9488: resolved fixed
1 parent 3d33fd7 commit c844655

8 files changed

Lines changed: 70 additions & 60 deletions

File tree

‎api/src/com/cloud/exception/InsufficientVirtualNetworkCapcityException.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public InsufficientVirtualNetworkCapcityException(String msg, Class<?> scope, Lo
2727
super(msg, scope, id);
2828
}
2929

30-
public InsufficientVirtualNetworkCapcityException(String msg, long id) {
31-
this(msg, Pod.class, id);
30+
public InsufficientVirtualNetworkCapcityException(String msg, long podId) {
31+
this(msg, Pod.class, podId);
3232
}
3333
}

‎api/src/com/cloud/network/guru/NetworkGuru.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ public interface NetworkGuru extends Adapter {
7171
* @param offering offering that the network configuration was based on.
7272
* @param destination where were deploying to.
7373
* @return a fully implemented NetworkConfiguration.
74+
* @throws InsufficientVirtualNetworkCapcityException TODO
7475
*/
75-
Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context);
76+
Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException;
7677

7778
/**
7879
* reserve a nic for this VM in this network.

‎server/src/com/cloud/network/guru/ControlNetworkGuru.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMa
151151
}
152152

153153
@Override
154-
public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
154+
public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
155155
assert config.getTrafficType() == TrafficType.Control : "Why are you sending this configuration to me " + config;
156156
return config;
157157
}

‎server/src/com/cloud/network/guru/DirectNetworkGuru.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMa
200200
}
201201

202202
@Override
203-
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
203+
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
204204
return network;
205205
}
206206

‎server/src/com/cloud/network/guru/GuestNetworkGuru.java‎

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,38 @@
5959
import com.cloud.vm.VirtualMachineProfile;
6060
import com.cloud.vm.dao.NicDao;
6161

62-
@Local(value=NetworkGuru.class)
62+
@Local(value = NetworkGuru.class)
6363
public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
6464
private static final Logger s_logger = Logger.getLogger(GuestNetworkGuru.class);
65-
@Inject protected NetworkManager _networkMgr;
66-
@Inject protected DataCenterDao _dcDao;
67-
@Inject protected VlanDao _vlanDao;
68-
@Inject protected NicDao _nicDao;
69-
@Inject protected NetworkDao _networkDao;
70-
65+
@Inject
66+
protected NetworkManager _networkMgr;
67+
@Inject
68+
protected DataCenterDao _dcDao;
69+
@Inject
70+
protected VlanDao _vlanDao;
71+
@Inject
72+
protected NicDao _nicDao;
73+
@Inject
74+
protected NetworkDao _networkDao;
75+
7176
String _defaultGateway;
7277
String _defaultCidr;
7378
Random _rand = new Random(System.currentTimeMillis());
74-
79+
7580
protected GuestNetworkGuru() {
7681
super();
77-
}
78-
82+
}
83+
7984
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
80-
//This guru handles only non-system Guest network
81-
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == GuestIpType.Virtual && !offering.isSystemOnly()) {
85+
// This guru handles only non-system Guest network
86+
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == GuestIpType.Virtual && !offering.isSystemOnly()) {
8287
return true;
8388
} else {
8489
s_logger.trace("We only take care of Guest Virtual networks in zone of type " + NetworkType.Advanced);
8590
return false;
8691
}
8792
}
88-
93+
8994
@Override
9095
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
9196
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
@@ -95,124 +100,127 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
95100

96101
NetworkVO network = new NetworkVO(offering.getTrafficType(), offering.getGuestType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), State.Allocated);
97102
if (userSpecified != null) {
98-
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
99-
(userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
103+
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
100104
throw new InvalidParameterValueException("cidr and gateway must be specified together.");
101105
}
102-
106+
103107
if (userSpecified.getCidr() != null) {
104108
network.setCidr(userSpecified.getCidr());
105109
network.setGateway(userSpecified.getGateway());
106110
} else {
107111
String guestNetworkCidr = dc.getGuestNetworkCidr();
108-
//guest network cidr can be null for Basic zone
112+
// guest network cidr can be null for Basic zone
109113
if (guestNetworkCidr != null) {
110114
String[] cidrTuple = guestNetworkCidr.split("\\/");
111115
network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
112-
network.setCidr(guestNetworkCidr);
116+
network.setCidr(guestNetworkCidr);
113117
}
114118
}
115-
119+
116120
if (userSpecified.getBroadcastUri() != null) {
117121
network.setBroadcastUri(userSpecified.getBroadcastUri());
118122
network.setState(State.Setup);
119123
}
120124
if (userSpecified.getNetworkDomain() != null) {
121125
network.setNetworkDomain(userSpecified.getNetworkDomain());
122126
}
123-
127+
124128
} else {
125129
String guestNetworkCidr = dc.getGuestNetworkCidr();
126130
String[] cidrTuple = guestNetworkCidr.split("\\/");
127131
network.setGateway(NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1])));
128-
network.setCidr(guestNetworkCidr);;
132+
network.setCidr(guestNetworkCidr);
133+
;
129134
}
130-
135+
131136
return network;
132137
}
133138

134139
@Override
135140
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) {
136141
}
137-
142+
138143
@Override
139-
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) {
144+
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
140145
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
141-
146+
142147
long dcId = dest.getDataCenter().getId();
143-
144-
145-
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), network.getDataCenterId(), State.Allocated);
146-
148+
149+
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(),
150+
network.getDataCenterId(), State.Allocated);
151+
147152
if (network.getBroadcastUri() == null) {
148153
String vnet = _dcDao.allocateVnet(dcId, network.getAccountId(), context.getReservationId());
154+
if (vnet == null) {
155+
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId);
156+
}
149157
implemented.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vnet));
150158
} else {
151159
implemented.setBroadcastUri(network.getBroadcastUri());
152160
}
153-
161+
154162
if (network.getGateway() != null) {
155163
implemented.setGateway(network.getGateway());
156164
}
157-
165+
158166
if (network.getCidr() != null) {
159167
implemented.setCidr(network.getCidr());
160168
}
161-
169+
162170
return implemented;
163171
}
164172

165173
@Override
166-
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm)
167-
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
168-
174+
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
175+
InsufficientAddressCapacityException {
176+
169177
assert (network.getTrafficType() == TrafficType.Guest) : "Look at my name! Why are you calling me when the traffic type is : " + network.getTrafficType();
170-
178+
171179
if (nic == null) {
172180
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
173-
}
174-
181+
}
182+
175183
DataCenter dc = _dcDao.findById(network.getDataCenterId());
176-
177-
if (nic.getIp4Address() == null){
184+
185+
if (nic.getIp4Address() == null) {
178186
nic.setBroadcastUri(network.getBroadcastUri());
179187
nic.setIsolationUri(network.getBroadcastUri());
180188
nic.setGateway(network.getGateway());
181189
nic.setIp4Address(acquireGuestIpAddress(network));
182190
nic.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
183191
nic.setFormat(AddressFormat.Ip4);
184-
192+
185193
nic.setDns1(dc.getDns1());
186194
nic.setDns2(dc.getDns2());
187195
}
188-
196+
189197
nic.setStrategy(ReservationStrategy.Start);
190-
198+
191199
if (nic.getMacAddress() == null) {
192200
nic.setMacAddress(_networkMgr.getNextAvailableMacAddressInNetwork(network.getId()));
193201
if (nic.getMacAddress() == null) {
194202
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
195203
}
196204
}
197-
205+
198206
return nic;
199207
}
200-
208+
201209
@Override
202210
public void updateNicProfile(NicProfile profile, Network network) {
203211
DataCenter dc = _dcDao.findById(network.getDataCenterId());
204212
if (profile != null) {
205213
profile.setDns1(dc.getDns1());
206214
profile.setDns2(dc.getDns2());
207-
}
215+
}
208216
}
209-
217+
210218
@DB
211219
protected String acquireGuestIpAddress(Network network) {
212220
List<String> ips = _nicDao.listIpAddressInNetwork(network.getId());
213221
String[] cidr = network.getCidr().split("/");
214222
Set<Long> allPossibleIps = NetUtils.getAllIpsFromCidr(cidr[0], Integer.parseInt(cidr[1]));
215-
Set<Long> usedIps = new TreeSet<Long> ();
223+
Set<Long> usedIps = new TreeSet<Long>();
216224
for (String ip : ips) {
217225
usedIps.add(NetUtils.ip2Long(ip));
218226
}
@@ -224,11 +232,11 @@ protected String acquireGuestIpAddress(Network network) {
224232
}
225233
Long[] array = allPossibleIps.toArray(new Long[allPossibleIps.size()]);
226234
return NetUtils.long2Ip(array[_rand.nextInt(array.length)]);
227-
}
235+
}
228236

229237
@Override
230-
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
231-
InsufficientAddressCapacityException {
238+
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context)
239+
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
232240
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
233241

234242
nic.setBroadcastUri(network.getBroadcastUri());
@@ -253,7 +261,7 @@ public void shutdown(NetworkProfile profile, NetworkOffering offering) {
253261
public boolean trash(Network network, NetworkOffering offering, Account owner) {
254262
return true;
255263
}
256-
264+
257265
@Override
258266
public void updateNetworkProfile(NetworkProfile networkProfile) {
259267
DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId());

‎server/src/com/cloud/network/guru/OvsGuestNetworkGuru.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.cloud.deploy.DeployDestination;
2424
import com.cloud.deploy.DeploymentPlan;
25+
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
2526
import com.cloud.network.Network;
2627
import com.cloud.network.NetworkManager;
2728
import com.cloud.network.NetworkVO;
@@ -58,7 +59,7 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
5859
}
5960

6061
@Override
61-
public Network implement(Network config, NetworkOffering offering, DeployDestination dest, ReservationContext context) {
62+
public Network implement(Network config, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
6263
assert (config.getState() == State.Implementing) : "Why are we implementing " + config;
6364
if (!_ovsNetworkMgr.isOvsNetworkEnabled()&& !_ovsTunnelMgr.isOvsTunnelEnabled()) {
6465
return null;

‎server/src/com/cloud/network/guru/PodBasedNetworkGuru.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMa
137137
}
138138

139139
@Override
140-
public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
140+
public Network implement(Network config, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
141141
return config;
142142
}
143143

‎server/src/com/cloud/network/guru/PublicNetworkGuru.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMa
165165
}
166166

167167
@Override
168-
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
168+
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapcityException {
169169
return network;
170170
}
171171

0 commit comments

Comments
 (0)