diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index a3f56c6b94e..f0730f5bd82 100644 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -1060,8 +1060,8 @@ Configurable, StateListener { /* * In order to make fail-over works well at any time, we have to ensure: - * 1. Backup router's priority = Master's priority - DELTA + 1 2. Backup - * router's priority hasn't been bumped up. + * 1. Backup router's priority = Master's priority - DELTA + 1 + * 2. Backup router's priority hasn't been bumped up. */ private void checkSanity(final List routers) { final Set checkedNetwork = new HashSet(); @@ -1137,15 +1137,8 @@ Configurable, StateListener { protected void runInContext() { while (true) { try { - final Long networkId = _vrUpdateQueue.take(); // This is a - // blocking - // call so - // this thread - // won't run - // all the - // time if no - // work item - // in queue. + final Long networkId = _vrUpdateQueue.take(); + // This is a blocking call so this thread won't run all the time if no work item in queue. final List routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER); if (routers.size() != 2) { @@ -1159,7 +1152,7 @@ Configurable, StateListener { final DomainRouterVO router0 = routers.get(0); final DomainRouterVO router1 = routers.get(1); DomainRouterVO router = router0; - if (router0.getId() < router1.getId() && router0.getHostId() != null) { + if (router0.getId() < router1.getId()) { router = router0; } else { router = router1; @@ -1596,7 +1589,28 @@ Configurable, StateListener { final boolean isRedundant = router.getIsRedundantRouter(); if (isRedundant) { buf.append(" redundant_router=1"); - final List routers = _routerDao.listByNetworkAndRole(nic.getNetworkId(), Role.VIRTUAL_ROUTER); + + final Long vpcId = router.getVpcId(); + final List routers; + if (vpcId != null) { + routers = _routerDao.listByVpcId(vpcId); + } else { + routers = _routerDao.listByNetworkAndRole(nic.getNetworkId(), Role.VIRTUAL_ROUTER); + } + + String redundantState = RedundantState.BACKUP.toString(); + if (routers.size() == 0) { + redundantState = RedundantState.MASTER.toString(); + } else { + final DomainRouterVO router0 = routers.get(0); + + if (router.getId() == router0.getId()) { + redundantState = RedundantState.MASTER.toString(); + } + } + + buf.append(" redundant_state=").append(redundantState); + try { final int priority = getUpdatedPriority(network, routers, router); router.setPriority(priority); diff --git a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java index f06b1bad02c..77cc0deacfb 100644 --- a/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java @@ -236,7 +236,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) { final DomainRouterVO domainRouterVO = _routerDao.findById(profile.getId()); - if (domainRouterVO.getVpcId() != null) { + final Long vpcId = domainRouterVO.getVpcId(); + + if (vpcId != null) { if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState() == State.Running) { String defaultDns1 = null; String defaultDns2 = null; @@ -257,7 +259,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian // add vpc cidr/dns/networkdomain to the boot load args final StringBuilder buf = profile.getBootArgsBuilder(); - final Vpc vpc = _entityMgr.findById(Vpc.class, domainRouterVO.getVpcId()); + final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); buf.append(" vpccidr=" + vpc.getCidr() + " domain=" + vpc.getNetworkDomain()); buf.append(" dns1=").append(defaultDns1); @@ -688,16 +690,6 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian return _routerDao.listByVpcId(vpcId); } - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - return true; - } - @Override public boolean startRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException { if (router.getState() != State.Running) { diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py index fbafad220cf..d1d899b37df 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsDatabag.py @@ -125,3 +125,8 @@ class CsCmdLine(CsDataBag): if "redundant_master" in self.idata(): return self.idata()['redundant_master'] == "true" return False + + def get_state(self): + if "redundant_state" in self.idata(): + return self.idata()['redundant_state'] + return "MASTER" \ No newline at end of file diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py index d9d36e25853..267cc1c840b 100644 --- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py +++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsRedundant.py @@ -101,6 +101,7 @@ class CsRedundant(object): file.search(" router_id ", " router_id %s" % self.cl.get_name()) file.search(" priority ", " priority %s" % self.cl.get_priority()) file.search(" weight ", " weight %s" % 2) + file.search(" state ", " state %s" % self.cl.get_state()) file.greplace("[RROUTER_BIN_PATH]", self.CS_ROUTER_DIR) file.section("virtual_ipaddress {", "}", self._collect_ips()) file.commit() @@ -121,7 +122,7 @@ class CsRedundant(object): if connt.is_changed(): CsHelper.service("conntrackd", "restart") - if file.is_changed(): + if file.is_changed() and self.cl.get_state() == 'MASTER': CsHelper.service("keepalived", "restart") # FIXME