cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [05/50] git commit: updated refs/heads/feature/systemvm-persistent-config to 921f6e2
Date Mon, 16 Feb 2015 16:39:56 GMT
Fixing guest network interfaces on redundant routers

- The interfaces were messed up because part of the code was still taking inot account a non-redundant
path.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3aaab4cc
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3aaab4cc
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3aaab4cc

Branch: refs/heads/feature/systemvm-persistent-config
Commit: 3aaab4cc92026138993a24892dd50250d42bbfb9
Parents: ee868a0
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Tue Jan 20 11:04:39 2015 +0100
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Wed Feb 4 18:47:07 2015 +0100

----------------------------------------------------------------------
 .../cloud/network/router/NetworkHelperImpl.java |   5 +-
 .../VpcVirtualNetworkApplianceManagerImpl.java  | 403 +++++++++----------
 .../topology/AdvancedNetworkTopology.java       |  35 +-
 3 files changed, 212 insertions(+), 231 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3aaab4cc/server/src/com/cloud/network/router/NetworkHelperImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/NetworkHelperImpl.java b/server/src/com/cloud/network/router/NetworkHelperImpl.java
index cfbaf52..8ca7615 100644
--- a/server/src/com/cloud/network/router/NetworkHelperImpl.java
+++ b/server/src/com/cloud/network/router/NetworkHelperImpl.java
@@ -392,10 +392,7 @@ public class NetworkHelperImpl implements NetworkHelper {
         DomainRouterVO result = null;
         assert router.getIsRedundantRouter();
         final List<Long> networkIds = _routerDao.getRouterNetworks(router.getId());
-        // Not support VPC now
-        if (networkIds.size() > 1) {
-            throw new ResourceUnavailableException("Unable to support more than one guest
network for redundant router now!", DataCenter.class, router.getDataCenterId());
-        }
+
         DomainRouterVO routerToBeAvoid = null;
         if (networkIds.size() != 0) {
             final List<DomainRouterVO> routerList = _routerDao.findByNetwork(networkIds.get(0));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3aaab4cc/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
index e74f022..f06b1ba 100644
--- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java
@@ -234,39 +234,35 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
 
     @Override
     public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile, final
DeployDestination dest, final ReservationContext context) {
-        final DomainRouterVO vr = _routerDao.findById(profile.getId());
-
-        if (vr.getVpcId() != null) {
-            final List<DomainRouterVO> routers = getVpcRouters(vr.getVpcId());
-            for (final DomainRouterVO domainRouterVO : routers) {
-
-                if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState()
== State.Running) {
-                    String defaultDns1 = null;
-                    String defaultDns2 = null;
-                    // remove public and guest nics as we will plug them later
-                    final Iterator<NicProfile> it = profile.getNics().iterator();
-                    while (it.hasNext()) {
-                        final NicProfile nic = it.next();
-                        if (nic.getTrafficType() == TrafficType.Public || nic.getTrafficType()
== TrafficType.Guest) {
-                            // save dns information
-                            if (nic.getTrafficType() == TrafficType.Public) {
-                                defaultDns1 = nic.getDns1();
-                                defaultDns2 = nic.getDns2();
-                            }
-                            s_logger.debug("Removing nic " + nic + " of type " + nic.getTrafficType()
+ " from the nics passed on vm start. " + "The nic will be plugged later");
-                            it.remove();
+        final DomainRouterVO domainRouterVO = _routerDao.findById(profile.getId());
+
+        if (domainRouterVO.getVpcId() != null) {
+            if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState()
== State.Running) {
+                String defaultDns1 = null;
+                String defaultDns2 = null;
+                // remove public and guest nics as we will plug them later
+                final Iterator<NicProfile> it = profile.getNics().iterator();
+                while (it.hasNext()) {
+                    final NicProfile nic = it.next();
+                    if (nic.getTrafficType() == TrafficType.Public || nic.getTrafficType()
== TrafficType.Guest) {
+                        // save dns information
+                        if (nic.getTrafficType() == TrafficType.Public) {
+                            defaultDns1 = nic.getDns1();
+                            defaultDns2 = nic.getDns2();
                         }
+                        s_logger.debug("Removing nic " + nic + " of type " + nic.getTrafficType()
+ " from the nics passed on vm start. " + "The nic will be plugged later");
+                        it.remove();
                     }
+                }
 
-                    // add vpc cidr/dns/networkdomain to the boot load args
-                    final StringBuilder buf = profile.getBootArgsBuilder();
-                    final Vpc vpc = _entityMgr.findById(Vpc.class, domainRouterVO.getVpcId());
-                    buf.append(" vpccidr=" + vpc.getCidr() + " domain=" + vpc.getNetworkDomain());
+                // add vpc cidr/dns/networkdomain to the boot load args
+                final StringBuilder buf = profile.getBootArgsBuilder();
+                final Vpc vpc = _entityMgr.findById(Vpc.class, domainRouterVO.getVpcId());
+                buf.append(" vpccidr=" + vpc.getCidr() + " domain=" + vpc.getNetworkDomain());
 
-                    buf.append(" dns1=").append(defaultDns1);
-                    if (defaultDns2 != null) {
-                        buf.append(" dns2=").append(defaultDns2);
-                    }
+                buf.append(" dns1=").append(defaultDns1);
+                if (defaultDns2 != null) {
+                    buf.append(" dns2=").append(defaultDns2);
                 }
             }
         }
@@ -276,208 +272,201 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
 
     @Override
     public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile
profile) {
-        final DomainRouterVO router = _routerDao.findById(profile.getId());
+        final DomainRouterVO domainRouterVO = _routerDao.findById(profile.getId());
 
-        final boolean isVpc = router.getVpcId() != null;
+        final boolean isVpc = domainRouterVO.getVpcId() != null;
         if (!isVpc) {
             return super.finalizeCommandsOnStart(cmds, profile);
         }
 
-        final List<DomainRouterVO> routers = getVpcRouters(router.getVpcId());
-        for (final DomainRouterVO domainRouterVO : routers) {
+        if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState() == State.Running)
{
+            // 1) FORM SSH CHECK COMMAND
+            final NicProfile controlNic = getControlNic(profile);
+            if (controlNic == null) {
+                s_logger.error("Control network doesn't exist for the router " + domainRouterVO);
+                return false;
+            }
 
-            if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState()
== State.Running) {
-                // 1) FORM SSH CHECK COMMAND
-                final NicProfile controlNic = getControlNic(profile);
-                if (controlNic == null) {
-                    s_logger.error("Control network doesn't exist for the router " + domainRouterVO);
-                    return false;
+            finalizeSshAndVersionAndNetworkUsageOnStart(cmds, profile, domainRouterVO, controlNic);
+
+            // 2) FORM PLUG NIC COMMANDS
+            final List<Pair<Nic, Network>> guestNics = new ArrayList<Pair<Nic,
Network>>();
+            final List<Pair<Nic, Network>> publicNics = new ArrayList<Pair<Nic,
Network>>();
+            final Map<String, String> vlanMacAddress = new HashMap<String, String>();
+
+            final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
+            for (final Nic routerNic : routerNics) {
+                final Network network = _networkModel.getNetwork(routerNic.getNetworkId());
+                if (network.getTrafficType() == TrafficType.Guest) {
+                    final Pair<Nic, Network> guestNic = new Pair<Nic, Network>(routerNic,
network);
+                    guestNics.add(guestNic);
+                } else if (network.getTrafficType() == TrafficType.Public) {
+                    final Pair<Nic, Network> publicNic = new Pair<Nic, Network>(routerNic,
network);
+                    publicNics.add(publicNic);
+                    final String vlanTag = BroadcastDomainType.getValue(routerNic.getBroadcastUri());
+                    vlanMacAddress.put(vlanTag, routerNic.getMacAddress());
                 }
+            }
 
-                finalizeSshAndVersionAndNetworkUsageOnStart(cmds, profile, domainRouterVO,
controlNic);
-
-                // 2) FORM PLUG NIC COMMANDS
-                final List<Pair<Nic, Network>> guestNics = new ArrayList<Pair<Nic,
Network>>();
-                final List<Pair<Nic, Network>> publicNics = new ArrayList<Pair<Nic,
Network>>();
-                final Map<String, String> vlanMacAddress = new HashMap<String, String>();
-
-                final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
-                for (final Nic routerNic : routerNics) {
-                    final Network network = _networkModel.getNetwork(routerNic.getNetworkId());
-                    if (network.getTrafficType() == TrafficType.Guest) {
-                        final Pair<Nic, Network> guestNic = new Pair<Nic, Network>(routerNic,
network);
-                        guestNics.add(guestNic);
-                    } else if (network.getTrafficType() == TrafficType.Public) {
-                        final Pair<Nic, Network> publicNic = new Pair<Nic, Network>(routerNic,
network);
-                        publicNics.add(publicNic);
-                        final String vlanTag = BroadcastDomainType.getValue(routerNic.getBroadcastUri());
-                        vlanMacAddress.put(vlanTag, routerNic.getMacAddress());
-                    }
-                }
+            final List<Command> usageCmds = new ArrayList<Command>();
 
-                final List<Command> usageCmds = new ArrayList<Command>();
-
-                // 3) PREPARE PLUG NIC COMMANDS
-                try {
-                    // add VPC router to public networks
-                    final List<PublicIp> sourceNat = new ArrayList<PublicIp>(1);
-                    for (final Pair<Nic, Network> nicNtwk : publicNics) {
-                        final Nic publicNic = nicNtwk.first();
-                        final Network publicNtwk = nicNtwk.second();
-                        final IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(),
publicNic.getIp4Address());
-
-                        if (userIp.isSourceNat()) {
-                            final PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp,
_vlanDao.findById(userIp.getVlanId()));
-                            sourceNat.add(publicIp);
-
-                            if (domainRouterVO.getPublicIpAddress() == null) {
-                                final DomainRouterVO routerVO = _routerDao.findById(domainRouterVO.getId());
-                                routerVO.setPublicIpAddress(publicNic.getIp4Address());
-                                routerVO.setPublicNetmask(publicNic.getNetmask());
-                                routerVO.setPublicMacAddress(publicNic.getMacAddress());
-                                _routerDao.update(routerVO.getId(), routerVO);
-                            }
-                        }
-                        final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO,
publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()),
-                                domainRouterVO.getInstanceName(), domainRouterVO.getType());
-                        cmds.addCommand(plugNicCmd);
-                        final VpcVO vpc = _vpcDao.findById(domainRouterVO.getVpcId());
-                        final NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(domainRouterVO.getPrivateIpAddress(),
domainRouterVO.getInstanceName(), true, publicNic.getIp4Address(), vpc.getCidr());
-                        usageCmds.add(netUsageCmd);
-                        UserStatisticsVO stats = _userStatsDao.findBy(domainRouterVO.getAccountId(),
domainRouterVO.getDataCenterId(), publicNtwk.getId(), publicNic.getIp4Address(), domainRouterVO.getId(),
-                                domainRouterVO.getType().toString());
-                        if (stats == null) {
-                            stats = new UserStatisticsVO(domainRouterVO.getAccountId(), domainRouterVO.getDataCenterId(),
publicNic.getIp4Address(), domainRouterVO.getId(), domainRouterVO.getType().toString(),
-                                    publicNtwk.getId());
-                            _userStatsDao.persist(stats);
+            // 3) PREPARE PLUG NIC COMMANDS
+            try {
+                // add VPC router to public networks
+                final List<PublicIp> sourceNat = new ArrayList<PublicIp>(1);
+                for (final Pair<Nic, Network> nicNtwk : publicNics) {
+                    final Nic publicNic = nicNtwk.first();
+                    final Network publicNtwk = nicNtwk.second();
+                    final IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(),
publicNic.getIp4Address());
+
+                    if (userIp.isSourceNat()) {
+                        final PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp,
_vlanDao.findById(userIp.getVlanId()));
+                        sourceNat.add(publicIp);
+
+                        if (domainRouterVO.getPublicIpAddress() == null) {
+                            final DomainRouterVO routerVO = _routerDao.findById(domainRouterVO.getId());
+                            routerVO.setPublicIpAddress(publicNic.getIp4Address());
+                            routerVO.setPublicNetmask(publicNic.getNetmask());
+                            routerVO.setPublicMacAddress(publicNic.getMacAddress());
+                            _routerDao.update(routerVO.getId(), routerVO);
                         }
                     }
-
-                    // create ip assoc for source nat
-                    if (!sourceNat.isEmpty()) {
-                        _commandSetupHelper.createVpcAssociatePublicIPCommands(domainRouterVO,
sourceNat, cmds, vlanMacAddress);
+                    final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO,
publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()),
+                            domainRouterVO.getInstanceName(), domainRouterVO.getType());
+                    cmds.addCommand(plugNicCmd);
+                    final VpcVO vpc = _vpcDao.findById(domainRouterVO.getVpcId());
+                    final NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(domainRouterVO.getPrivateIpAddress(),
domainRouterVO.getInstanceName(), true, publicNic.getIp4Address(), vpc.getCidr());
+                    usageCmds.add(netUsageCmd);
+                    UserStatisticsVO stats = _userStatsDao.findBy(domainRouterVO.getAccountId(),
domainRouterVO.getDataCenterId(), publicNtwk.getId(), publicNic.getIp4Address(), domainRouterVO.getId(),
+                            domainRouterVO.getType().toString());
+                    if (stats == null) {
+                        stats = new UserStatisticsVO(domainRouterVO.getAccountId(), domainRouterVO.getDataCenterId(),
publicNic.getIp4Address(), domainRouterVO.getId(), domainRouterVO.getType().toString(),
+                                publicNtwk.getId());
+                        _userStatsDao.persist(stats);
                     }
+                }
 
-                    // add VPC router to guest networks
-                    for (final Pair<Nic, Network> nicNtwk : guestNics) {
-                        final Nic guestNic = nicNtwk.first();
-                        // plug guest nic
-                        final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO,
guestNic.getNetworkId(), null), domainRouterVO.getInstanceName(), domainRouterVO.getType());
-                        cmds.addCommand(plugNicCmd);
-                        if (!_networkModel.isPrivateGateway(guestNic.getNetworkId())) {
-                            // set guest network
-                            final VirtualMachine vm = _vmDao.findById(domainRouterVO.getId());
-                            final NicProfile nicProfile = _networkModel.getNicProfile(vm,
guestNic.getNetworkId(), null);
-                            final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand(domainRouterVO,
true, nicProfile);
-                            cmds.addCommand(setupCmd);
-                        } else {
-
-                            // set private network
-                            final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(guestNic.getNetworkId(),
guestNic.getIp4Address());
-                            final Network network = _networkDao.findById(guestNic.getNetworkId());
-                            BroadcastDomainType.getValue(network.getBroadcastUri());
-                            final String netmask = NetUtils.getCidrNetmask(network.getCidr());
-                            final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(),
network.getGateway(), netmask, guestNic.getMacAddress());
-
-                            final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
-                            privateIps.add(ip);
-                            _commandSetupHelper.createVpcAssociatePrivateIPCommands(domainRouterVO,
privateIps, cmds, true);
-
-                            final Long privateGwAclId = _vpcGatewayDao.getNetworkAclIdForPrivateIp(ipVO.getVpcId(),
ipVO.getNetworkId(), ipVO.getIpAddress());
-
-                            if (privateGwAclId != null) {
-                                // set network acl on private gateway
-                                final List<NetworkACLItemVO> networkACLs = _networkACLItemDao.listByACL(privateGwAclId);
-                                s_logger.debug("Found " + networkACLs.size() + " network
ACLs to apply as a part of VPC VR " + domainRouterVO + " start for private gateway ip = "
-                                        + ipVO.getIpAddress());
-
-                                _commandSetupHelper.createNetworkACLsCommands(networkACLs,
domainRouterVO, cmds, ipVO.getNetworkId(), true);
-                            }
-                        }
-                    }
-                } catch (final Exception ex) {
-                    s_logger.warn("Failed to add router " + domainRouterVO + " to network
due to exception ", ex);
-                    return false;
+                // create ip assoc for source nat
+                if (!sourceNat.isEmpty()) {
+                    _commandSetupHelper.createVpcAssociatePublicIPCommands(domainRouterVO,
sourceNat, cmds, vlanMacAddress);
                 }
 
-                // 4) RE-APPLY ALL STATIC ROUTE RULES
-                final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(domainRouterVO.getVpcId());
-                final List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
-                final Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
-                for (final StaticRoute route : routes) {
-                    VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId());
-                    if (gateway == null) {
-                        gateway = _entityMgr.findById(VpcGateway.class, route.getVpcGatewayId());
-                        gatewayMap.put(gateway.getId(), gateway);
+                // add VPC router to guest networks
+                for (final Pair<Nic, Network> nicNtwk : guestNics) {
+                    final Nic guestNic = nicNtwk.first();
+                    // plug guest nic
+                    final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO,
guestNic.getNetworkId(), null), domainRouterVO.getInstanceName(), domainRouterVO.getType());
+                    cmds.addCommand(plugNicCmd);
+                    if (!_networkModel.isPrivateGateway(guestNic.getNetworkId())) {
+                        // set guest network
+                        final VirtualMachine vm = _vmDao.findById(domainRouterVO.getId());
+                        final NicProfile nicProfile = _networkModel.getNicProfile(vm, guestNic.getNetworkId(),
null);
+                        final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand(domainRouterVO,
true, nicProfile);
+                        cmds.addCommand(setupCmd);
+                    } else {
+
+                        // set private network
+                        final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(guestNic.getNetworkId(),
guestNic.getIp4Address());
+                        final Network network = _networkDao.findById(guestNic.getNetworkId());
+                        BroadcastDomainType.getValue(network.getBroadcastUri());
+                        final String netmask = NetUtils.getCidrNetmask(network.getCidr());
+                        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(),
network.getGateway(), netmask, guestNic.getMacAddress());
+
+                        final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
+                        privateIps.add(ip);
+                        _commandSetupHelper.createVpcAssociatePrivateIPCommands(domainRouterVO,
privateIps, cmds, true);
+
+                        final Long privateGwAclId = _vpcGatewayDao.getNetworkAclIdForPrivateIp(ipVO.getVpcId(),
ipVO.getNetworkId(), ipVO.getIpAddress());
+
+                        if (privateGwAclId != null) {
+                            // set network acl on private gateway
+                            final List<NetworkACLItemVO> networkACLs = _networkACLItemDao.listByACL(privateGwAclId);
+                            s_logger.debug("Found " + networkACLs.size() + " network ACLs
to apply as a part of VPC VR " + domainRouterVO + " start for private gateway ip = "
+                                    + ipVO.getIpAddress());
+
+                            _commandSetupHelper.createNetworkACLsCommands(networkACLs, domainRouterVO,
cmds, ipVO.getNetworkId(), true);
+                        }
                     }
-                    staticRouteProfiles.add(new StaticRouteProfile(route, gateway));
                 }
+            } catch (final Exception ex) {
+                s_logger.warn("Failed to add router " + domainRouterVO + " to network due
to exception ", ex);
+                return false;
+            }
 
-                s_logger.debug("Found " + staticRouteProfiles.size() + " static routes to
apply as a part of vpc route " + domainRouterVO + " start");
-                if (!staticRouteProfiles.isEmpty()) {
-                    _commandSetupHelper.createStaticRouteCommands(staticRouteProfiles, domainRouterVO,
cmds);
+            // 4) RE-APPLY ALL STATIC ROUTE RULES
+            final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(domainRouterVO.getVpcId());
+            final List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
+            final Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
+            for (final StaticRoute route : routes) {
+                VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId());
+                if (gateway == null) {
+                    gateway = _entityMgr.findById(VpcGateway.class, route.getVpcGatewayId());
+                    gatewayMap.put(gateway.getId(), gateway);
                 }
+                staticRouteProfiles.add(new StaticRouteProfile(route, gateway));
+            }
 
-                // 5) RE-APPLY ALL REMOTE ACCESS VPNs
-                final RemoteAccessVpnVO vpn = _vpnDao.findByAccountAndVpc(domainRouterVO.getAccountId(),
domainRouterVO.getVpcId());
-                if (vpn != null) {
-                    _commandSetupHelper.createApplyVpnCommands(true, vpn, domainRouterVO,
cmds);
-                }
+            s_logger.debug("Found " + staticRouteProfiles.size() + " static routes to apply
as a part of vpc route " + domainRouterVO + " start");
+            if (!staticRouteProfiles.isEmpty()) {
+                _commandSetupHelper.createStaticRouteCommands(staticRouteProfiles, domainRouterVO,
cmds);
+            }
 
-                // 6) REPROGRAM GUEST NETWORK
-                boolean reprogramGuestNtwks = true;
-                if (profile.getParameter(Param.ReProgramGuestNetworks) != null &&
(Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
-                    reprogramGuestNtwks = false;
-                }
+            // 5) RE-APPLY ALL REMOTE ACCESS VPNs
+            final RemoteAccessVpnVO vpn = _vpnDao.findByAccountAndVpc(domainRouterVO.getAccountId(),
domainRouterVO.getVpcId());
+            if (vpn != null) {
+                _commandSetupHelper.createApplyVpnCommands(true, vpn, domainRouterVO, cmds);
+            }
 
-                final VirtualRouterProvider vrProvider = _vrProviderDao.findById(domainRouterVO.getElementId());
-                if (vrProvider == null) {
-                    throw new CloudRuntimeException("Cannot find related virtual router provider
of router: " + domainRouterVO.getHostName());
-                }
-                final Provider provider = Network.Provider.getProvider(vrProvider.getType().toString());
-                if (provider == null) {
-                    throw new CloudRuntimeException("Cannot find related provider of virtual
router provider: " + vrProvider.getType().toString());
-                }
+            // 6) REPROGRAM GUEST NETWORK
+            boolean reprogramGuestNtwks = true;
+            if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean)
profile.getParameter(Param.ReProgramGuestNetworks) == false) {
+                reprogramGuestNtwks = false;
+            }
 
-                for (final Pair<Nic, Network> nicNtwk : guestNics) {
-                    final Nic guestNic = nicNtwk.first();
-                    final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start,
domainRouterVO.getInstanceName(), controlNic.getIp4Address(), _routerControlHelper.getRouterIpInNetwork(
-                            guestNic.getNetworkId(), domainRouterVO.getId()));
-                    cmds.addCommand(startCmd);
-                    if (reprogramGuestNtwks) {
-                        finalizeIpAssocForNetwork(cmds, domainRouterVO, provider, guestNic.getNetworkId(),
vlanMacAddress);
-                        finalizeNetworkRulesForNetwork(cmds, domainRouterVO, provider, guestNic.getNetworkId());
-                    }
+            final VirtualRouterProvider vrProvider = _vrProviderDao.findById(domainRouterVO.getElementId());
+            if (vrProvider == null) {
+                throw new CloudRuntimeException("Cannot find related virtual router provider
of router: " + domainRouterVO.getHostName());
+            }
+            final Provider provider = Network.Provider.getProvider(vrProvider.getType().toString());
+            if (provider == null) {
+                throw new CloudRuntimeException("Cannot find related provider of virtual
router provider: " + vrProvider.getType().toString());
+            }
 
-                    finalizeUserDataAndDhcpOnStart(cmds, domainRouterVO, provider, guestNic.getNetworkId());
-                    final AggregationControlCommand finishCmd = new AggregationControlCommand(Action.Finish,
domainRouterVO.getInstanceName(), controlNic.getIp4Address(), _routerControlHelper.getRouterIpInNetwork(
-                            guestNic.getNetworkId(), domainRouterVO.getId()));
-                    cmds.addCommand(finishCmd);
+            for (final Pair<Nic, Network> nicNtwk : guestNics) {
+                final Nic guestNic = nicNtwk.first();
+                final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start,
domainRouterVO.getInstanceName(), controlNic.getIp4Address(), _routerControlHelper.getRouterIpInNetwork(
+                        guestNic.getNetworkId(), domainRouterVO.getId()));
+                cmds.addCommand(startCmd);
+                if (reprogramGuestNtwks) {
+                    finalizeIpAssocForNetwork(cmds, domainRouterVO, provider, guestNic.getNetworkId(),
vlanMacAddress);
+                    finalizeNetworkRulesForNetwork(cmds, domainRouterVO, provider, guestNic.getNetworkId());
                 }
 
-                // Add network usage commands
-                cmds.addCommands(usageCmds);
+                finalizeUserDataAndDhcpOnStart(cmds, domainRouterVO, provider, guestNic.getNetworkId());
+                final AggregationControlCommand finishCmd = new AggregationControlCommand(Action.Finish,
domainRouterVO.getInstanceName(), controlNic.getIp4Address(), _routerControlHelper.getRouterIpInNetwork(
+                        guestNic.getNetworkId(), domainRouterVO.getId()));
+                cmds.addCommand(finishCmd);
             }
+
+            // Add network usage commands
+            cmds.addCommands(usageCmds);
         }
         return true;
     }
 
     @Override
-    protected void finalizeNetworkRulesForNetwork(final Commands cmds, final DomainRouterVO
router, final Provider provider, final Long guestNetworkId) {
+    protected void finalizeNetworkRulesForNetwork(final Commands cmds, final DomainRouterVO
domainRouterVO, final Provider provider, final Long guestNetworkId) {
 
-        super.finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId);
+        super.finalizeNetworkRulesForNetwork(cmds, domainRouterVO, provider, guestNetworkId);
 
-        if (router.getVpcId() != null) {
-            final List<DomainRouterVO> routers = getVpcRouters(router.getVpcId());
-            for (final DomainRouterVO domainRouterVO : routers) {
+        if (domainRouterVO.getVpcId() != null) {
 
-                if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState()
== State.Running) {
-                    if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.NetworkACL,
Provider.VPCVirtualRouter)) {
-                        final List<NetworkACLItemVO> networkACLs = _networkACLMgr.listNetworkACLItems(guestNetworkId);
-                        if (networkACLs != null && !networkACLs.isEmpty()) {
-                            s_logger.debug("Found " + networkACLs.size() + " network ACLs
to apply as a part of VPC VR " + domainRouterVO + " start for guest network id=" + guestNetworkId);
-                            _commandSetupHelper.createNetworkACLsCommands(networkACLs, domainRouterVO,
cmds, guestNetworkId, false);
-                        }
+            if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState()
== State.Running) {
+                if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.NetworkACL,
Provider.VPCVirtualRouter)) {
+                    final List<NetworkACLItemVO> networkACLs = _networkACLMgr.listNetworkACLItems(guestNetworkId);
+                    if (networkACLs != null && !networkACLs.isEmpty()) {
+                        s_logger.debug("Found " + networkACLs.size() + " network ACLs to
apply as a part of VPC VR " + domainRouterVO + " start for guest network id=" + guestNetworkId);
+                        _commandSetupHelper.createNetworkACLsCommands(networkACLs, domainRouterVO,
cmds, guestNetworkId, false);
                     }
                 }
             }
@@ -574,25 +563,21 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
     }
 
     @Override
-    protected void finalizeIpAssocForNetwork(final Commands cmds, final VirtualRouter router,
final Provider provider, final Long guestNetworkId,
+    protected void finalizeIpAssocForNetwork(final Commands cmds, final VirtualRouter domainRouterVO,
final Provider provider, final Long guestNetworkId,
             final Map<String, String> vlanMacAddress) {
 
-        if (router.getVpcId() == null) {
-            super.finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId, vlanMacAddress);
+        if (domainRouterVO.getVpcId() == null) {
+            super.finalizeIpAssocForNetwork(cmds, domainRouterVO, provider, guestNetworkId,
vlanMacAddress);
             return;
         }
 
-        final List<DomainRouterVO> routers = getVpcRouters(router.getVpcId());
-        for (final DomainRouterVO domainRouterVO : routers) {
+        if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState() == State.Running)
{
+            final ArrayList<? extends PublicIpAddress> publicIps = getPublicIpsToApply(domainRouterVO,
provider, guestNetworkId, IpAddress.State.Releasing);
 
-            if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState()
== State.Running) {
-                final ArrayList<? extends PublicIpAddress> publicIps = getPublicIpsToApply(domainRouterVO,
provider, guestNetworkId, IpAddress.State.Releasing);
-
-                if (publicIps != null && !publicIps.isEmpty()) {
-                    s_logger.debug("Found " + publicIps.size() + " ip(s) to apply as a part
of domR " + domainRouterVO + " start.");
-                    // Re-apply public ip addresses - should come before PF/LB/VPN
-                    _commandSetupHelper.createVpcAssociatePublicIPCommands(domainRouterVO,
publicIps, cmds, vlanMacAddress);
-                }
+            if (publicIps != null && !publicIps.isEmpty()) {
+                s_logger.debug("Found " + publicIps.size() + " ip(s) to apply as a part of
domR " + domainRouterVO + " start.");
+                // Re-apply public ip addresses - should come before PF/LB/VPN
+                _commandSetupHelper.createVpcAssociatePublicIPCommands(domainRouterVO, publicIps,
cmds, vlanMacAddress);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3aaab4cc/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
index f35af42..fffac04 100644
--- a/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
+++ b/server/src/org/apache/cloudstack/network/topology/AdvancedNetworkTopology.java
@@ -71,11 +71,11 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
 
         s_logger.debug("APPLYING ADVANCED VPN USERS RULES");
 
-        AdvancedVpnRules routesRules = new AdvancedVpnRules(remoteAccessVpn, users);
+        final AdvancedVpnRules routesRules = new AdvancedVpnRules(remoteAccessVpn, users);
 
-        boolean agentResult = routesRules.accept(_advancedVisitor, router);
+        final boolean agentResult = routesRules.accept(_advancedVisitor, router);
 
-        String[] result = new String[users.size()];
+        final String[] result = new String[users.size()];
         for (int i = 0; i < result.length; i++) {
             if (agentResult) {
                 result[i] = null;
@@ -97,10 +97,10 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
             return true;
         }
 
-        StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);
+        final StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);
 
         boolean result = true;
-        for (VirtualRouter router : routers) {
+        for (final VirtualRouter router : routers) {
             if (router.getState() == State.Running) {
 
                 result = result && routesRules.accept(_advancedVisitor, router);
@@ -126,7 +126,7 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
             return false;
         }
 
-        DhcpPvlanRules pvlanRules = new DhcpPvlanRules(isAddPvlan, nic);
+        final DhcpPvlanRules pvlanRules = new DhcpPvlanRules(isAddPvlan, nic);
 
         return pvlanRules.accept(_advancedVisitor, router);
     }
@@ -135,7 +135,7 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
     public boolean setupPrivateGateway(final PrivateGateway gateway, final VirtualRouter
router) throws ConcurrentOperationException, ResourceUnavailableException {
         s_logger.debug("SETUP PRIVATE GATEWAY RULES");
 
-        PrivateGatewayRules routesRules = new PrivateGatewayRules(gateway);
+        final PrivateGatewayRules routesRules = new PrivateGatewayRules(gateway);
 
         return routesRules.accept(_advancedVisitor, router);
     }
@@ -151,7 +151,7 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
         final boolean failWhenDisconnect = false;
         final Long podId = null;
 
-        UserdataPwdRules pwdRules = new UserdataPwdRules(network, nic, profile, dest);
+        final UserdataPwdRules pwdRules = new UserdataPwdRules(network, nic, profile, dest);
 
         return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect,
new RuleApplierWrapper<RuleApplier>(pwdRules));
     }
@@ -167,7 +167,7 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
         final boolean isPodLevelException = false;
         final boolean failWhenDisconnect = false;
 
-        DhcpEntryRules dhcpRules = new DhcpEntryRules(network, nic, profile, dest);
+        final DhcpEntryRules dhcpRules = new DhcpEntryRules(network, nic, profile, dest);
 
         return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect,
new RuleApplierWrapper<RuleApplier>(dhcpRules));
     }
@@ -181,10 +181,7 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
             return true;
         }
 
-        // only one router is supported in VPC for now
-        VirtualRouter router = routers.get(0);
-
-        if (router.getVpcId() == null) {
+        if (network.getVpcId() == null) {
             return super.associatePublicIP(network, ipAddresses, routers);
         }
 
@@ -195,11 +192,13 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
         final boolean failWhenDisconnect = false;
         final Long podId = null;
 
-        NicPlugInOutRules nicPlugInOutRules = new NicPlugInOutRules(network, ipAddresses);
-        nicPlugInOutRules.accept(_advancedVisitor, router);
+        final NicPlugInOutRules nicPlugInOutRules = new NicPlugInOutRules(network, ipAddresses);
+        for (final VirtualRouter router : routers) {
+            nicPlugInOutRules.accept(_advancedVisitor, router);
+        }
 
-        VpcIpAssociationRules ipAssociationRules = new VpcIpAssociationRules(network, ipAddresses);
-        boolean result = applyRules(network, routers, typeString, isPodLevelException, podId,
failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(ipAssociationRules));
+        final VpcIpAssociationRules ipAssociationRules = new VpcIpAssociationRules(network,
ipAddresses);
+        final boolean result = applyRules(network, routers, typeString, isPodLevelException,
podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(ipAssociationRules));
 
         if (result) {
             _advancedVisitor.visit(nicPlugInOutRules);
@@ -224,7 +223,7 @@ public class AdvancedNetworkTopology extends BasicNetworkTopology {
         final boolean failWhenDisconnect = false;
         final Long podId = null;
 
-        NetworkAclsRules aclsRules = new NetworkAclsRules(network, rules, isPrivateGateway);
+        final NetworkAclsRules aclsRules = new NetworkAclsRules(network, rules, isPrivateGateway);
 
         return applyRules(network, routers, typeString, isPodLevelException, podId, failWhenDisconnect,
new RuleApplierWrapper<RuleApplier>(aclsRules));
     }


Mime
View raw message