127127
128128@ Component
129129@ Local (value = {NetworkElement .class , ConnectivityProvider .class , SourceNatServiceProvider .class , StaticNatServiceProvider .class , PortForwardingServiceProvider .class ,
130- IpDeployer .class })
130+ IpDeployer .class })
131131public class NiciraNvpElement extends AdapterBase implements ConnectivityProvider , SourceNatServiceProvider , PortForwardingServiceProvider , StaticNatServiceProvider ,
132- NiciraNvpElementService , ResourceStateAdapter , IpDeployer {
132+ NiciraNvpElementService , ResourceStateAdapter , IpDeployer {
133133
134134 private static final int MAX_PORT = 65535 ;
135135 private static final int MIN_PORT = 0 ;
@@ -211,7 +211,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
211211
212212 @ Override
213213 public boolean implement (Network network , NetworkOffering offering , DeployDestination dest , ReservationContext context ) throws ConcurrentOperationException ,
214- ResourceUnavailableException , InsufficientCapacityException {
214+ ResourceUnavailableException , InsufficientCapacityException {
215215 s_logger .debug ("entering NiciraNvpElement implement function for network " + network .getDisplayText () + " (state " + network .getState () + ")" );
216216
217217 if (!canHandle (network , Service .Connectivity )) {
@@ -262,9 +262,9 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
262262 long vlanid = (Vlan .UNTAGGED .equals (vtag )) ? 0 : Long .parseLong (vtag );
263263
264264 CreateLogicalRouterCommand cmd =
265- new CreateLogicalRouterCommand (niciraNvpHost .getDetail ("l3gatewayserviceuuid" ), vlanid , BroadcastDomainType .getValue (network .getBroadcastUri ()),
266- "router-" + network .getDisplayText (), publicCidr , sourceNatIp .getGateway (), internalCidr , context .getDomain ().getName () + "-" +
267- context .getAccount ().getAccountName ());
265+ new CreateLogicalRouterCommand (niciraNvpHost .getDetail ("l3gatewayserviceuuid" ), vlanid , BroadcastDomainType .getValue (network .getBroadcastUri ()),
266+ "router-" + network .getDisplayText (), publicCidr , sourceNatIp .getGateway (), internalCidr , context .getDomain ().getName () + "-" +
267+ context .getAccount ().getAccountName ());
268268 CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer )agentMgr .easySend (niciraNvpHost .getId (), cmd );
269269 if (answer .getResult () == false ) {
270270 s_logger .error ("Failed to create Logical Router for network " + network .getDisplayText ());
@@ -281,7 +281,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
281281
282282 @ Override
283283 public boolean prepare (Network network , NicProfile nic , VirtualMachineProfile vm , DeployDestination dest , ReservationContext context )
284- throws ConcurrentOperationException , ResourceUnavailableException , InsufficientCapacityException {
284+ throws ConcurrentOperationException , ResourceUnavailableException , InsufficientCapacityException {
285285
286286 if (!canHandle (network , Service .Connectivity )) {
287287 return false ;
@@ -310,8 +310,8 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm
310310 if (answer .getResult ()) {
311311 s_logger .warn ("Existing Logical Switchport found for nic " + nic .getName () + " with uuid " + existingNicMap .getLogicalSwitchPortUuid ());
312312 UpdateLogicalSwitchPortCommand cmd =
313- new UpdateLogicalSwitchPortCommand (existingNicMap .getLogicalSwitchPortUuid (), BroadcastDomainType .getValue (network .getBroadcastUri ()),
314- nicVO .getUuid (), context .getDomain ().getName () + "-" + context .getAccount ().getAccountName (), nic .getName ());
313+ new UpdateLogicalSwitchPortCommand (existingNicMap .getLogicalSwitchPortUuid (), BroadcastDomainType .getValue (network .getBroadcastUri ()),
314+ nicVO .getUuid (), context .getDomain ().getName () + "-" + context .getAccount ().getAccountName (), nic .getName ());
315315 agentMgr .easySend (niciraNvpHost .getId (), cmd );
316316 return true ;
317317 } else {
@@ -321,8 +321,8 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm
321321 }
322322
323323 CreateLogicalSwitchPortCommand cmd =
324- new CreateLogicalSwitchPortCommand (BroadcastDomainType .getValue (network .getBroadcastUri ()), nicVO .getUuid (), context .getDomain ().getName () + "-" +
325- context .getAccount ().getAccountName (), nic .getName ());
324+ new CreateLogicalSwitchPortCommand (BroadcastDomainType .getValue (network .getBroadcastUri ()), nicVO .getUuid (), context .getDomain ().getName () + "-" +
325+ context .getAccount ().getAccountName (), nic .getName ());
326326 CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer )agentMgr .easySend (niciraNvpHost .getId (), cmd );
327327
328328 if (answer == null || !answer .getResult ()) {
@@ -331,15 +331,15 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm
331331 }
332332
333333 NiciraNvpNicMappingVO nicMap =
334- new NiciraNvpNicMappingVO (BroadcastDomainType .getValue (network .getBroadcastUri ()), answer .getLogicalSwitchPortUuid (), nicVO .getUuid ());
334+ new NiciraNvpNicMappingVO (BroadcastDomainType .getValue (network .getBroadcastUri ()), answer .getLogicalSwitchPortUuid (), nicVO .getUuid ());
335335 niciraNvpNicMappingDao .persist (nicMap );
336336
337337 return true ;
338338 }
339339
340340 @ Override
341341 public boolean release (Network network , NicProfile nic , VirtualMachineProfile vm , ReservationContext context ) throws ConcurrentOperationException ,
342- ResourceUnavailableException {
342+ ResourceUnavailableException {
343343
344344 if (!canHandle (network , Service .Connectivity )) {
345345 return false ;
@@ -434,7 +434,7 @@ public boolean isReady(PhysicalNetworkServiceProvider provider) {
434434
435435 @ Override
436436 public boolean shutdownProviderInstances (PhysicalNetworkServiceProvider provider , ReservationContext context ) throws ConcurrentOperationException ,
437- ResourceUnavailableException {
437+ ResourceUnavailableException {
438438 // Nothing to do here.
439439 return true ;
440440 }
@@ -499,6 +499,9 @@ public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
499499 ServerResource resource = new NiciraNvpResource ();
500500 final String deviceName = Network .Provider .NiciraNvp .getName ();
501501 NetworkDevice networkDevice = NetworkDevice .getNetworkDevice (deviceName );
502+ if (networkDevice == null ) {
503+ throw new CloudRuntimeException ("No network device found for " + deviceName );
504+ }
502505 final Long physicalNetworkId = cmd .getPhysicalNetworkId ();
503506 PhysicalNetworkVO physicalNetwork = physicalNetworkDao .findById (physicalNetworkId );
504507 if (physicalNetwork == null ) {
@@ -507,13 +510,13 @@ public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
507510 long zoneId = physicalNetwork .getDataCenterId ();
508511
509512 final PhysicalNetworkServiceProviderVO ntwkSvcProvider =
510- physicalNetworkServiceProviderDao .findByServiceProvider (physicalNetwork .getId (), networkDevice .getNetworkServiceProvder ());
513+ physicalNetworkServiceProviderDao .findByServiceProvider (physicalNetwork .getId (), networkDevice .getNetworkServiceProvder ());
511514 if (ntwkSvcProvider == null ) {
512515 throw new CloudRuntimeException ("Network Service Provider: " + networkDevice .getNetworkServiceProvder () + " is not enabled in the physical network: " +
513- physicalNetworkId + "to add this device" );
516+ physicalNetworkId + "to add this device" );
514517 } else if (ntwkSvcProvider .getState () == PhysicalNetworkServiceProvider .State .Shutdown ) {
515518 throw new CloudRuntimeException ("Network Service Provider: " + ntwkSvcProvider .getProviderName () + " is in shutdown state in the physical network: " +
516- physicalNetworkId + "to add this device" );
519+ physicalNetworkId + "to add this device" );
517520 }
518521
519522 if (niciraNvpDao .listByPhysicalNetwork (physicalNetworkId ).size () != 0 ) {
@@ -598,12 +601,13 @@ public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
598601 // Lets see if there are networks that use us
599602 // Find the nicira networks on this physical network
600603 List <NetworkVO > networkList = networkDao .listByPhysicalNetwork (physicalNetworkId );
601-
602- // Networks with broadcast type lswitch are ours
603- for (NetworkVO network : networkList ) {
604- if (network .getBroadcastDomainType () == Networks .BroadcastDomainType .Lswitch ) {
605- if ((network .getState () != Network .State .Shutdown ) && (network .getState () != Network .State .Destroy )) {
606- throw new CloudRuntimeException ("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack." );
604+ if (networkList != null ) {
605+ // Networks with broadcast type lswitch are ours
606+ for (NetworkVO network : networkList ) {
607+ if (network .getBroadcastDomainType () == Networks .BroadcastDomainType .Lswitch ) {
608+ if ((network .getState () != Network .State .Shutdown ) && (network .getState () != Network .State .Destroy )) {
609+ throw new CloudRuntimeException ("This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack." );
610+ }
607611 }
608612 }
609613 }
@@ -665,6 +669,9 @@ public List<? extends Network> listNiciraNvpDeviceNetworks(ListNiciraNvpDeviceNe
665669
666670 // Find the nicira networks on this physical network
667671 List <NetworkVO > networkList = networkDao .listByPhysicalNetwork (physicalNetworkId );
672+ if (networkList == null ) {
673+ return Collections .emptyList ();
674+ }
668675
669676 // Networks with broadcast type lswitch are ours
670677 List <NetworkVO > responseList = new ArrayList <NetworkVO >();
@@ -747,7 +754,7 @@ public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddre
747754 cidrs .add (ip .getAddress ().addr () + "/" + NetUtils .getCidrSize (ip .getNetmask ()));
748755 }
749756 ConfigurePublicIpsOnLogicalRouterCommand cmd =
750- new ConfigurePublicIpsOnLogicalRouterCommand (routermapping .getLogicalRouterUuid (), niciraNvpHost .getDetail ("l3gatewayserviceuuid" ), cidrs );
757+ new ConfigurePublicIpsOnLogicalRouterCommand (routermapping .getLogicalRouterUuid (), niciraNvpHost .getDetail ("l3gatewayserviceuuid" ), cidrs );
751758 ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer )agentMgr .easySend (niciraNvpHost .getId (), cmd );
752759 //FIXME answer can be null if the host is down
753760 return answer .getResult ();
@@ -788,7 +795,7 @@ public boolean applyStaticNats(Network network, List<? extends StaticNat> rules)
788795 // we only need the source and destination ip. Unfortunately no mention if a rule
789796 // is new.
790797 StaticNatRuleTO ruleTO =
791- new StaticNatRuleTO (1 , sourceIp .getAddress ().addr (), MIN_PORT , MAX_PORT , rule .getDestIpAddress (), MIN_PORT , MAX_PORT , "any" , rule .isForRevoke (), false );
798+ new StaticNatRuleTO (1 , sourceIp .getAddress ().addr (), MIN_PORT , MAX_PORT , rule .getDestIpAddress (), MIN_PORT , MAX_PORT , "any" , rule .isForRevoke (), false );
792799 staticNatRules .add (ruleTO );
793800 }
794801
@@ -830,7 +837,7 @@ public boolean applyPFRules(Network network, List<PortForwardingRule> rules) thr
830837 }
831838
832839 ConfigurePortForwardingRulesOnLogicalRouterCommand cmd =
833- new ConfigurePortForwardingRulesOnLogicalRouterCommand (routermapping .getLogicalRouterUuid (), portForwardingRules );
840+ new ConfigurePortForwardingRulesOnLogicalRouterCommand (routermapping .getLogicalRouterUuid (), portForwardingRules );
834841 ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer )agentMgr .easySend (niciraNvpHost .getId (), cmd );
835842
836843 return answer .getResult ();
0 commit comments