@@ -178,7 +178,7 @@ public boolean sendCommandsToRouter(final VirtualRouter router, final Commands c
178178 throw new AgentUnavailableException ("Unable to send commands to virtual router " , router .getHostId (), e );
179179 }
180180
181- if (( answers == null ) || ( answers .length != cmds .size () )) {
181+ if (answers == null || answers .length != cmds .size ()) {
182182 return false ;
183183 }
184184
@@ -199,7 +199,7 @@ public void handleSingleWorkingRedundantRouter(final List<? extends VirtualRoute
199199 if (connectedRouters .isEmpty () || disconnectedRouters .isEmpty ()) {
200200 return ;
201201 }
202- if (( connectedRouters .size () != 1 ) || ( disconnectedRouters .size () != 1 ) ) {
202+ if (connectedRouters .size () != 1 || disconnectedRouters .size () != 1 ) {
203203 s_logger .warn ("How many redundant routers do we have?? " );
204204 return ;
205205 }
@@ -255,7 +255,7 @@ public int getRealPriority(final DomainRouterVO router) {
255255
256256 @ Override
257257 public NicTO getNicTO (final VirtualRouter router , final Long networkId , final String broadcastUri ) {
258- NicProfile nicProfile = _networkModel .getNicProfile (router , networkId , broadcastUri );
258+ final NicProfile nicProfile = _networkModel .getNicProfile (router , networkId , broadcastUri );
259259
260260 return _itMgr .toNicTO (nicProfile , router .getHypervisorType ());
261261 }
@@ -325,7 +325,7 @@ protected DomainRouterVO waitRouter(final DomainRouterVO router) {
325325 while (vm .getState () == State .Starting ) {
326326 try {
327327 Thread .sleep (1000 );
328- } catch (InterruptedException e ) {
328+ } catch (final InterruptedException e ) {
329329 }
330330
331331 // reload to get the latest state info
@@ -348,14 +348,14 @@ protected DomainRouterVO waitRouter(final DomainRouterVO router) {
348348 public List <DomainRouterVO > startRouters (final RouterDeploymentDefinition routerDeploymentDefinition ) throws StorageUnavailableException , InsufficientCapacityException ,
349349 ConcurrentOperationException , ResourceUnavailableException {
350350
351- List <DomainRouterVO > runningRouters = new ArrayList <DomainRouterVO >();
351+ final List <DomainRouterVO > runningRouters = new ArrayList <DomainRouterVO >();
352352
353353 for (DomainRouterVO router : routerDeploymentDefinition .getRouters ()) {
354354 boolean skip = false ;
355355 final State state = router .getState ();
356- if (( router .getHostId () != null ) && ( state != State .Running ) ) {
356+ if (router .getHostId () != null && state != State .Running ) {
357357 final HostVO host = _hostDao .findById (router .getHostId ());
358- if (( host == null ) || ( host .getState () != Status .Up ) ) {
358+ if (host == null || host .getState () != Status .Up ) {
359359 skip = true ;
360360 }
361361 }
@@ -375,7 +375,7 @@ public List<DomainRouterVO> startRouters(final RouterDeploymentDefinition router
375375 public DomainRouterVO startVirtualRouter (final DomainRouterVO router , final User user , final Account caller , final Map <Param , Object > params )
376376 throws StorageUnavailableException , InsufficientCapacityException , ConcurrentOperationException , ResourceUnavailableException {
377377
378- if (( router .getRole () != Role .VIRTUAL_ROUTER ) || !router .getIsRedundantRouter ()) {
378+ if (router .getRole () != Role .VIRTUAL_ROUTER || !router .getIsRedundantRouter ()) {
379379 return start (router , user , caller , params , null );
380380 }
381381
@@ -393,7 +393,7 @@ public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User
393393 return waitRouter (router );
394394 }
395395
396- DataCenterDeployment plan = new DataCenterDeployment (0 , null , null , null , null , null );
396+ final DataCenterDeployment plan = new DataCenterDeployment (0 , null , null , null , null , null );
397397 DomainRouterVO result = null ;
398398 assert router .getIsRedundantRouter ();
399399 final List <Long > networkIds = _routerDao .getRouterNetworks (router .getId ());
@@ -405,7 +405,7 @@ public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User
405405 if (networkIds .size () != 0 ) {
406406 final List <DomainRouterVO > routerList = _routerDao .findByNetwork (networkIds .get (0 ));
407407 for (final DomainRouterVO rrouter : routerList ) {
408- if (( rrouter .getHostId () != null ) && rrouter .getIsRedundantRouter () && ( rrouter .getState () == State .Running ) ) {
408+ if (rrouter .getHostId () != null && rrouter .getIsRedundantRouter () && rrouter .getState () == State .Running ) {
409409 if (routerToBeAvoid != null ) {
410410 throw new ResourceUnavailableException ("Try to start router " + router .getInstanceName () + "(" + router .getId () + ")"
411411 + ", but there are already two redundant routers with IP " + router .getPublicIpAddress () + ", they are " + rrouter .getInstanceName () + "("
@@ -428,7 +428,7 @@ public DomainRouterVO startVirtualRouter(final DomainRouterVO router, final User
428428 avoids [1 ].addCluster (_hostDao .findById (routerToBeAvoid .getHostId ()).getClusterId ());
429429 avoids [2 ] = new ExcludeList ();
430430 final List <VolumeVO > volumes = _volumeDao .findByInstanceAndType (routerToBeAvoid .getId (), Volume .Type .ROOT );
431- if (( volumes != null ) && ( volumes .size () != 0 ) ) {
431+ if (volumes != null && volumes .size () != 0 ) {
432432 avoids [2 ].addPool (volumes .get (0 ).getPoolId ());
433433 }
434434 avoids [2 ].addHost (routerToBeAvoid .getHostId ());
@@ -457,13 +457,13 @@ protected String retrieveTemplateName(final HypervisorType hType, final long dat
457457 String templateName = null ;
458458
459459 if (hType == HypervisorType .BareMetal ) {
460- ConfigKey <String > hypervisorConfigKey = hypervisorsMap .get (HypervisorType .VMware );
460+ final ConfigKey <String > hypervisorConfigKey = hypervisorsMap .get (HypervisorType .VMware );
461461 templateName = hypervisorConfigKey .valueIn (datacenterId );
462462 } else {
463463 // Returning NULL is fine because the simulator will need it when
464464 // being used instead of a real hypervisor.
465465 // The hypervisorsMap contains only real hypervisors.
466- ConfigKey <String > hypervisorConfigKey = hypervisorsMap .get (hType );
466+ final ConfigKey <String > hypervisorConfigKey = hypervisorsMap .get (hType );
467467
468468 if (hypervisorConfigKey != null ) {
469469 templateName = hypervisorConfigKey .valueIn (datacenterId );
@@ -497,7 +497,7 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
497497 .getDataCenter (), hType ));
498498 }
499499
500- String templateName = retrieveTemplateName (hType , routerDeploymentDefinition .getDest ().getDataCenter ().getId ());
500+ final String templateName = retrieveTemplateName (hType , routerDeploymentDefinition .getDest ().getDataCenter ().getId ());
501501 final VMTemplateVO template = _templateDao .findRoutingTemplate (hType , templateName );
502502
503503 if (template == null ) {
@@ -516,7 +516,7 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
516516
517517 // routerDeploymentDefinition.getVpc().getId() ==> do not use
518518 // VPC because it is not a VPC offering.
519- Long vpcId = routerDeploymentDefinition .getVpc () != null ? routerDeploymentDefinition .getVpc ().getId () : null ;
519+ final Long vpcId = routerDeploymentDefinition .getVpc () != null ? routerDeploymentDefinition .getVpc ().getId () : null ;
520520
521521 long userId = CallContext .current ().getCallingUserId ();
522522 if (CallContext .current ().getCallingAccount ().getId () != owner .getId ()) {
@@ -530,11 +530,11 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
530530 router .setDynamicallyScalable (template .isDynamicallyScalable ());
531531 router .setRole (Role .VIRTUAL_ROUTER );
532532 router = _routerDao .persist (router );
533- LinkedHashMap <Network , List <? extends NicProfile >> networks = createRouterNetworks (routerDeploymentDefinition );
533+ final LinkedHashMap <Network , List <? extends NicProfile >> networks = createRouterNetworks (routerDeploymentDefinition );
534534 _itMgr .allocate (router .getInstanceName (), template , routerOffering , networks , routerDeploymentDefinition .getPlan (), null );
535535 router = _routerDao .findById (router .getId ());
536536 } catch (final InsufficientCapacityException ex ) {
537- if (( allocateRetry < 2 ) && iter .hasNext ()) {
537+ if (allocateRetry < 2 && iter .hasNext ()) {
538538 s_logger .debug ("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time" );
539539 continue ;
540540 } else {
@@ -549,7 +549,7 @@ public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploy
549549 router = startVirtualRouter (router , _accountMgr .getSystemUser (), _accountMgr .getSystemAccount (), routerDeploymentDefinition .getParams ());
550550 break ;
551551 } catch (final InsufficientCapacityException ex ) {
552- if (( startRetry < 2 ) && iter .hasNext ()) {
552+ if (startRetry < 2 && iter .hasNext ()) {
553553 s_logger .debug ("Failed to start the VR " + router + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time" );
554554 // destroy the router
555555 destroyRouter (router .getId (), _accountMgr .getAccount (Account .ACCOUNT_ID_SYSTEM ), User .UID_SYSTEM );
@@ -618,12 +618,12 @@ protected List<HypervisorType> getHypervisors(final RouterDeploymentDefinition r
618618 protected HypervisorType getClusterToStartDomainRouterForOvm (final long podId ) {
619619 final List <ClusterVO > clusters = _clusterDao .listByPodId (podId );
620620 for (final ClusterVO cv : clusters ) {
621- if (( cv .getHypervisorType () == HypervisorType .Ovm ) || ( cv .getHypervisorType () == HypervisorType .BareMetal ) ) {
621+ if (cv .getHypervisorType () == HypervisorType .Ovm || cv .getHypervisorType () == HypervisorType .BareMetal ) {
622622 continue ;
623623 }
624624
625625 final List <HostVO > hosts = _resourceMgr .listAllHostsInCluster (cv .getId ());
626- if (( hosts == null ) || hosts .isEmpty ()) {
626+ if (hosts == null || hosts .isEmpty ()) {
627627 continue ;
628628 }
629629
@@ -646,42 +646,44 @@ public LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks(f
646646 throws ConcurrentOperationException , InsufficientAddressCapacityException {
647647
648648 // Form networks
649- LinkedHashMap <Network , List <? extends NicProfile >> networks = new LinkedHashMap <Network , List <? extends NicProfile >>(3 );
649+ final LinkedHashMap <Network , List <? extends NicProfile >> networks = new LinkedHashMap <Network , List <? extends NicProfile >>(3 );
650650 // 1) Guest network
651651 boolean hasGuestNetwork = false ;
652- if (routerDeploymentDefinition .getGuestNetwork () != null ) {
653- s_logger .debug ("Adding nic for Virtual Router in Guest network " + routerDeploymentDefinition .getGuestNetwork ());
652+ final Network guestNetwork = routerDeploymentDefinition .getGuestNetwork ();
653+
654+ if (guestNetwork != null ) {
655+ s_logger .debug ("Adding nic for Virtual Router in Guest network " + guestNetwork );
654656 String defaultNetworkStartIp = null , defaultNetworkStartIpv6 = null ;
655657 if (!routerDeploymentDefinition .isPublicNetwork ()) {
656- final Nic placeholder = _networkModel .getPlaceholderNicForRouter (routerDeploymentDefinition . getGuestNetwork () , routerDeploymentDefinition .getPodId ());
657- if (routerDeploymentDefinition . getGuestNetwork () .getCidr () != null ) {
658- if (( placeholder != null ) && ( placeholder .getIp4Address () != null ) ) {
658+ final Nic placeholder = _networkModel .getPlaceholderNicForRouter (guestNetwork , routerDeploymentDefinition .getPodId ());
659+ if (guestNetwork .getCidr () != null ) {
660+ if (placeholder != null && placeholder .getIp4Address () != null ) {
659661 s_logger .debug ("Requesting ipv4 address " + placeholder .getIp4Address () + " stored in placeholder nic for the network "
660- + routerDeploymentDefinition . getGuestNetwork () );
662+ + guestNetwork );
661663 defaultNetworkStartIp = placeholder .getIp4Address ();
662664 } else {
663- final String startIp = _networkModel .getStartIpAddress (routerDeploymentDefinition . getGuestNetwork () .getId ());
664- if (( startIp != null )
665- && ( _ipAddressDao .findByIpAndSourceNetworkId (routerDeploymentDefinition . getGuestNetwork (). getId (), startIp ).getAllocatedTime () == null ) ) {
665+ final String startIp = _networkModel .getStartIpAddress (guestNetwork .getId ());
666+ if (startIp != null
667+ && _ipAddressDao .findByIpAndSourceNetworkId (guestNetwork . getId (), startIp ).getAllocatedTime () == null ) {
666668 defaultNetworkStartIp = startIp ;
667669 } else if (s_logger .isDebugEnabled ()) {
668- s_logger .debug ("First ipv4 " + startIp + " in network id=" + routerDeploymentDefinition . getGuestNetwork () .getId ()
670+ s_logger .debug ("First ipv4 " + startIp + " in network id=" + guestNetwork .getId ()
669671 + " is already allocated, can't use it for domain router; will get random ip address from the range" );
670672 }
671673 }
672674 }
673675
674- if (routerDeploymentDefinition . getGuestNetwork () .getIp6Cidr () != null ) {
675- if (( placeholder != null ) && ( placeholder .getIp6Address () != null ) ) {
676+ if (guestNetwork .getIp6Cidr () != null ) {
677+ if (placeholder != null && placeholder .getIp6Address () != null ) {
676678 s_logger .debug ("Requesting ipv6 address " + placeholder .getIp6Address () + " stored in placeholder nic for the network "
677- + routerDeploymentDefinition . getGuestNetwork () );
679+ + guestNetwork );
678680 defaultNetworkStartIpv6 = placeholder .getIp6Address ();
679681 } else {
680- final String startIpv6 = _networkModel .getStartIpv6Address (routerDeploymentDefinition . getGuestNetwork () .getId ());
681- if (( startIpv6 != null ) && ( _ipv6Dao .findByNetworkIdAndIp (routerDeploymentDefinition . getGuestNetwork (). getId (), startIpv6 ) == null ) ) {
682+ final String startIpv6 = _networkModel .getStartIpv6Address (guestNetwork .getId ());
683+ if (startIpv6 != null && _ipv6Dao .findByNetworkIdAndIp (guestNetwork . getId (), startIpv6 ) == null ) {
682684 defaultNetworkStartIpv6 = startIpv6 ;
683685 } else if (s_logger .isDebugEnabled ()) {
684- s_logger .debug ("First ipv6 " + startIpv6 + " in network id=" + routerDeploymentDefinition . getGuestNetwork () .getId ()
686+ s_logger .debug ("First ipv6 " + startIpv6 + " in network id=" + guestNetwork .getId ()
685687 + " is already allocated, can't use it for domain router; will get random ipv6 address from the range" );
686688 }
687689 }
@@ -691,29 +693,29 @@ public LinkedHashMap<Network, List<? extends NicProfile>> createRouterNetworks(f
691693 final NicProfile gatewayNic = new NicProfile (defaultNetworkStartIp , defaultNetworkStartIpv6 );
692694 if (routerDeploymentDefinition .isPublicNetwork ()) {
693695 if (routerDeploymentDefinition .isRedundant ()) {
694- gatewayNic .setIp4Address (_ipAddrMgr .acquireGuestIpAddress (routerDeploymentDefinition . getGuestNetwork () , null ));
696+ gatewayNic .setIp4Address (_ipAddrMgr .acquireGuestIpAddress (guestNetwork , null ));
695697 } else {
696- gatewayNic .setIp4Address (routerDeploymentDefinition . getGuestNetwork () .getGateway ());
698+ gatewayNic .setIp4Address (guestNetwork .getGateway ());
697699 }
698- gatewayNic .setBroadcastUri (routerDeploymentDefinition . getGuestNetwork () .getBroadcastUri ());
699- gatewayNic .setBroadcastType (routerDeploymentDefinition . getGuestNetwork () .getBroadcastDomainType ());
700- gatewayNic .setIsolationUri (routerDeploymentDefinition . getGuestNetwork () .getBroadcastUri ());
701- gatewayNic .setMode (routerDeploymentDefinition . getGuestNetwork () .getMode ());
702- final String gatewayCidr = routerDeploymentDefinition . getGuestNetwork () .getCidr ();
700+ gatewayNic .setBroadcastUri (guestNetwork .getBroadcastUri ());
701+ gatewayNic .setBroadcastType (guestNetwork .getBroadcastDomainType ());
702+ gatewayNic .setIsolationUri (guestNetwork .getBroadcastUri ());
703+ gatewayNic .setMode (guestNetwork .getMode ());
704+ final String gatewayCidr = guestNetwork .getCidr ();
703705 gatewayNic .setNetmask (NetUtils .getCidrNetmask (gatewayCidr ));
704706 } else {
705707 gatewayNic .setDefaultNic (true );
706708 }
707709
708- networks .put (routerDeploymentDefinition . getGuestNetwork () , new ArrayList <NicProfile >(Arrays .asList (gatewayNic )));
710+ networks .put (guestNetwork , new ArrayList <NicProfile >(Arrays .asList (gatewayNic )));
709711 hasGuestNetwork = true ;
710712 }
711713
712714 // 2) Control network
713715 s_logger .debug ("Adding nic for Virtual Router in Control network " );
714- List <? extends NetworkOffering > offerings = _networkModel .getSystemAccountNetworkOfferings (NetworkOffering .SystemControlNetwork );
715- NetworkOffering controlOffering = offerings .get (0 );
716- Network controlConfig = _networkMgr .setupNetwork (s_systemAccount , controlOffering , routerDeploymentDefinition .getPlan (), null , null , false ).get (0 );
716+ final List <? extends NetworkOffering > offerings = _networkModel .getSystemAccountNetworkOfferings (NetworkOffering .SystemControlNetwork );
717+ final NetworkOffering controlOffering = offerings .get (0 );
718+ final Network controlConfig = _networkMgr .setupNetwork (s_systemAccount , controlOffering , routerDeploymentDefinition .getPlan (), null , null , false ).get (0 );
717719 networks .put (controlConfig , new ArrayList <NicProfile >());
718720 // 3) Public network
719721 if (routerDeploymentDefinition .isPublicNetwork ()) {
0 commit comments