diff --git a/api/src/com/cloud/network/router/VirtualRouter.java b/api/src/com/cloud/network/router/VirtualRouter.java index 32009620c88..49c8d5eda96 100755 --- a/api/src/com/cloud/network/router/VirtualRouter.java +++ b/api/src/com/cloud/network/router/VirtualRouter.java @@ -29,4 +29,9 @@ public interface VirtualRouter extends VirtualMachine { DHCP_USERDATA } Role getRole(); + public enum RedundantState { + MASTER, + BACKUP, + UNKNOWN + } } diff --git a/core/src/com/cloud/vm/DomainRouterVO.java b/core/src/com/cloud/vm/DomainRouterVO.java index 0e04c7588bb..fca4475d921 100755 --- a/core/src/com/cloud/vm/DomainRouterVO.java +++ b/core/src/com/cloud/vm/DomainRouterVO.java @@ -57,8 +57,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { @Column(name="priority") int priority; - @Column(name="is_master") - boolean isMaster; + @Column(name="redundant_state") + @Enumerated(EnumType.STRING) + private RedundantState redundantState; @Column(name="role") @Enumerated(EnumType.STRING) @@ -75,13 +76,13 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { long networkId, boolean isRedundantRouter, int priority, - boolean isMaster, + RedundantState redundantState, boolean haEnabled) { super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled); this.networkId = networkId; this.isRedundantRouter = isRedundantRouter; this.priority = priority; - this.isMaster = isMaster; + this.redundantState = redundantState; } public void setPublicIpAddress(String publicIpAddress) { @@ -159,12 +160,12 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter { this.priority = priority; } - public boolean getIsMaster() { - return this.isMaster; + public RedundantState getRedundantState() { + return this.redundantState; } - public void setIsMaster(boolean isMaster) { - this.isMaster = isMaster; + public void setRedundantState(RedundantState redundantState) { + this.redundantState = redundantState; } public void setServiceOfferingId(long serviceOfferingId) { diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 1a5cd9f5538..09c9c1327aa 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -122,6 +122,7 @@ import com.cloud.network.dao.VpnUserDao; import com.cloud.network.lb.LoadBalancingRule; import com.cloud.network.lb.LoadBalancingRule.LbDestination; import com.cloud.network.lb.LoadBalancingRulesManager; +import com.cloud.network.router.VirtualRouter.RedundantState; import com.cloud.network.router.VirtualRouter.Role; import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule.Purpose; @@ -730,12 +731,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian final CheckRouterAnswer answer = (CheckRouterAnswer) _agentMgr.easySend(router.getHostId(), command); if (answer != null) { if (answer.getResult()) { - router.setIsMaster(answer.getIsMaster()); + if (answer.getIsMaster()) { + router.setRedundantState(RedundantState.MASTER); + } else { + router.setRedundantState(RedundantState.BACKUP); + } } else { - router.setIsMaster(false); + router.setRedundantState(RedundantState.UNKNOWN); } } else { - router.setIsMaster(false); + router.setRedundantState(RedundantState.UNKNOWN); } Transaction txn = Transaction.open(Transaction.CLOUD_DB); try { @@ -849,7 +854,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian priority = 100 - routers.size() * 20; } router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(), - owner.getDomainId(), owner.getId(), guestNetwork.getId(), offering.isRedundantRouterEnabled(), priority, false, _offering.getOfferHA()); + owner.getDomainId(), owner.getId(), guestNetwork.getId(), offering.isRedundantRouterEnabled(), priority, RedundantState.UNKNOWN, _offering.getOfferHA()); router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner); routers.add(router); } @@ -943,7 +948,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian VMTemplateVO template = _templateDao.findRoutingTemplate(dest.getCluster().getHypervisorType()); router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(), - owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, _offering.getOfferHA()); + owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, RedundantState.UNKNOWN, _offering.getOfferHA()); router.setRole(Role.DHCP_USERDATA); router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index a5d127ff064..56133da9a29 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -896,7 +896,7 @@ CREATE TABLE `cloud`.`domain_router` ( `network_id` bigint unsigned NOT NULL COMMENT 'network configuration that this domain router belongs to', `is_redundant_router` int(1) unsigned NOT NULL COMMENT 'if in redundant router mode', `priority` int(4) unsigned COMMENT 'priority of router in the redundant router mode', - `is_master` int(1) unsigned DEFAULT 0 COMMENT 'if the router is master in redundant router mode', + `redundant_state` varchar(64) NOT NULL COMMENT 'the state of redundant virtual router', `role` varchar(64) NOT NULL COMMENT 'type of role played by this router', PRIMARY KEY (`id`), CONSTRAINT `fk_domain_router__id` FOREIGN KEY `fk_domain_router__id` (`id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE