Skip to content

Commit 64c61c7

Browse files
committed
Fix two NPE exceptions in the Contrail Plugin when contrail is not providing any services on the network.
1 parent cbbe3e0 commit 64c61c7

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

  • plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management

‎plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/management/ContrailGuru.java‎

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.net.URI;
2222
import java.util.List;
2323

24-
import javax.inject.Inject;
2524
import javax.ejb.Local;
25+
import javax.inject.Inject;
2626

2727
import net.juniper.contrail.api.types.MacAddressesType;
2828
import net.juniper.contrail.api.types.VirtualMachineInterface;
@@ -34,40 +34,40 @@
3434
import org.apache.cloudstack.network.contrail.model.VirtualMachineModel;
3535
import org.apache.cloudstack.network.contrail.model.VirtualNetworkModel;
3636

37+
import com.cloud.dc.DataCenter;
38+
import com.cloud.dc.DataCenter.NetworkType;
39+
import com.cloud.dc.dao.DataCenterDao;
3740
import com.cloud.deploy.DeployDestination;
3841
import com.cloud.deploy.DeploymentPlan;
3942
import com.cloud.exception.ConcurrentOperationException;
4043
import com.cloud.exception.InsufficientAddressCapacityException;
4144
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
42-
import com.cloud.dc.DataCenter;
43-
import com.cloud.dc.DataCenter.NetworkType;
44-
import com.cloud.dc.dao.DataCenterDao;
45+
import com.cloud.network.IpAddressManager;
4546
import com.cloud.network.Network;
4647
import com.cloud.network.Network.State;
4748
import com.cloud.network.NetworkProfile;
4849
import com.cloud.network.Networks.AddressFormat;
4950
import com.cloud.network.Networks.BroadcastDomainType;
5051
import com.cloud.network.Networks.Mode;
5152
import com.cloud.network.Networks.TrafficType;
53+
import com.cloud.network.PhysicalNetwork;
54+
import com.cloud.network.addr.PublicIp;
55+
import com.cloud.network.dao.IPAddressDao;
56+
import com.cloud.network.dao.IPAddressVO;
5257
import com.cloud.network.dao.NetworkDao;
5358
import com.cloud.network.dao.NetworkVO;
54-
import com.cloud.network.guru.NetworkGuru;
55-
import com.cloud.network.PhysicalNetwork;
5659
import com.cloud.network.dao.PhysicalNetworkDao;
5760
import com.cloud.network.dao.PhysicalNetworkVO;
58-
import com.cloud.network.dao.IPAddressVO;
59-
import com.cloud.network.addr.PublicIp;
61+
import com.cloud.network.guru.NetworkGuru;
6062
import com.cloud.offering.NetworkOffering;
6163
import com.cloud.user.Account;
64+
import com.cloud.user.AccountManager;
6265
import com.cloud.utils.component.AdapterBase;
6366
import com.cloud.utils.exception.CloudRuntimeException;
6467
import com.cloud.utils.net.NetUtils;
6568
import com.cloud.vm.Nic.ReservationStrategy;
6669
import com.cloud.vm.NicProfile;
6770
import com.cloud.vm.NicVO;
68-
import com.cloud.network.dao.IPAddressDao;
69-
import com.cloud.user.AccountManager;
70-
import com.cloud.network.IpAddressManager;
7171
import com.cloud.vm.ReservationContext;
7272
import com.cloud.vm.VMInstanceVO;
7373
import com.cloud.vm.VirtualMachineProfile;
@@ -96,6 +96,16 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru {
9696
private static final TrafficType[] TrafficTypes = {TrafficType.Guest};
9797

9898
private boolean canHandle(NetworkOffering offering, NetworkType networkType, PhysicalNetwork physicalNetwork) {
99+
if (physicalNetwork == null) {
100+
// Physical network can be false for system network during initial setup of CloudStack
101+
return false;
102+
}
103+
104+
if (_manager.getRouterOffering() == null || _manager.getVpcRouterOffering() == null) {
105+
// FIXME The resource is apparently not configured, we need another way to check this.
106+
return false;
107+
}
108+
99109
if (networkType == NetworkType.Advanced
100110
&& (offering.getId() == _manager.getRouterOffering().getId() || offering.getId() == _manager.getVpcRouterOffering().getId())
101111
&& isMyTrafficType(offering.getTrafficType())
@@ -121,8 +131,8 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
121131
return null;
122132
}
123133
NetworkVO network =
124-
new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Lswitch, offering.getId(), State.Allocated, plan.getDataCenterId(),
125-
plan.getPhysicalNetworkId());
134+
new NetworkVO(offering.getTrafficType(), Mode.Dhcp, BroadcastDomainType.Lswitch, offering.getId(), State.Allocated, plan.getDataCenterId(),
135+
plan.getPhysicalNetworkId());
126136
if (userSpecified.getCidr() != null) {
127137
network.setCidr(userSpecified.getCidr());
128138
network.setGateway(userSpecified.getGateway());
@@ -133,7 +143,7 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
133143

134144
@Override
135145
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context)
136-
throws InsufficientVirtualNetworkCapcityException {
146+
throws InsufficientVirtualNetworkCapcityException {
137147
s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType());
138148

139149
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
@@ -180,7 +190,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
180190
*/
181191
@Override
182192
public NicProfile allocate(Network network, NicProfile profile, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapcityException,
183-
InsufficientAddressCapacityException, ConcurrentOperationException {
193+
InsufficientAddressCapacityException, ConcurrentOperationException {
184194
s_logger.debug("allocate NicProfile on " + network.getName());
185195

186196
if (profile != null && profile.getRequestedIpv4() != null) {
@@ -207,7 +217,7 @@ public NicProfile allocate(Network network, NicProfile profile, VirtualMachinePr
207217
*/
208218
@Override
209219
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
210-
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
220+
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
211221
s_logger.debug("reserve NicProfile on network id: " + network.getId() + " " + network.getName());
212222
s_logger.debug("deviceId: " + nic.getDeviceId());
213223

0 commit comments

Comments
 (0)