Skip to content

Commit aef562c

Browse files
author
Sheng Yang
committed
bug 9154: Replace domain_router.is_master with domain_router.redundant_state in DB
Then we can distingush BACKUP state from UNKNOWN state(which means we didn't get valid answer from CheckRouterCommand).
1 parent 770c5cd commit aef562c

4 files changed

Lines changed: 25 additions & 14 deletions

File tree

‎api/src/com/cloud/network/router/VirtualRouter.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public enum Role {
2929
DHCP_USERDATA
3030
}
3131
Role getRole();
32+
public enum RedundantState {
33+
MASTER,
34+
BACKUP,
35+
UNKNOWN
36+
}
3237
}

‎core/src/com/cloud/vm/DomainRouterVO.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
5757
@Column(name="priority")
5858
int priority;
5959

60-
@Column(name="is_master")
61-
boolean isMaster;
60+
@Column(name="redundant_state")
61+
@Enumerated(EnumType.STRING)
62+
private RedundantState redundantState;
6263

6364
@Column(name="role")
6465
@Enumerated(EnumType.STRING)
@@ -75,13 +76,13 @@ public DomainRouterVO(long id,
7576
long networkId,
7677
boolean isRedundantRouter,
7778
int priority,
78-
boolean isMaster,
79+
RedundantState redundantState,
7980
boolean haEnabled) {
8081
super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
8182
this.networkId = networkId;
8283
this.isRedundantRouter = isRedundantRouter;
8384
this.priority = priority;
84-
this.isMaster = isMaster;
85+
this.redundantState = redundantState;
8586
}
8687

8788
public void setPublicIpAddress(String publicIpAddress) {
@@ -159,12 +160,12 @@ public void setPriority(int priority) {
159160
this.priority = priority;
160161
}
161162

162-
public boolean getIsMaster() {
163-
return this.isMaster;
163+
public RedundantState getRedundantState() {
164+
return this.redundantState;
164165
}
165166

166-
public void setIsMaster(boolean isMaster) {
167-
this.isMaster = isMaster;
167+
public void setRedundantState(RedundantState redundantState) {
168+
this.redundantState = redundantState;
168169
}
169170

170171
public void setServiceOfferingId(long serviceOfferingId) {

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import com.cloud.network.lb.LoadBalancingRule;
123123
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
124124
import com.cloud.network.lb.LoadBalancingRulesManager;
125+
import com.cloud.network.router.VirtualRouter.RedundantState;
125126
import com.cloud.network.router.VirtualRouter.Role;
126127
import com.cloud.network.rules.FirewallRule;
127128
import com.cloud.network.rules.FirewallRule.Purpose;
@@ -730,12 +731,16 @@ public void run() {
730731
final CheckRouterAnswer answer = (CheckRouterAnswer) _agentMgr.easySend(router.getHostId(), command);
731732
if (answer != null) {
732733
if (answer.getResult()) {
733-
router.setIsMaster(answer.getIsMaster());
734+
if (answer.getIsMaster()) {
735+
router.setRedundantState(RedundantState.MASTER);
736+
} else {
737+
router.setRedundantState(RedundantState.BACKUP);
738+
}
734739
} else {
735-
router.setIsMaster(false);
740+
router.setRedundantState(RedundantState.UNKNOWN);
736741
}
737742
} else {
738-
router.setIsMaster(false);
743+
router.setRedundantState(RedundantState.UNKNOWN);
739744
}
740745
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
741746
try {
@@ -849,7 +854,7 @@ public List<DomainRouterVO> deployVirtualRouter(Network guestNetwork, DeployDest
849854
priority = 100 - routers.size() * 20;
850855
}
851856
router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(),
852-
owner.getDomainId(), owner.getId(), guestNetwork.getId(), offering.isRedundantRouterEnabled(), priority, false, _offering.getOfferHA());
857+
owner.getDomainId(), owner.getId(), guestNetwork.getId(), offering.isRedundantRouterEnabled(), priority, RedundantState.UNKNOWN, _offering.getOfferHA());
853858
router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner);
854859
routers.add(router);
855860
}
@@ -943,7 +948,7 @@ public List<DomainRouterVO> deployDhcp(Network guestNetwork, DeployDestination d
943948
VMTemplateVO template = _templateDao.findRoutingTemplate(dest.getCluster().getHypervisorType());
944949

945950
router = new DomainRouterVO(id, _offering.getId(), VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(), template.getGuestOSId(),
946-
owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, false, _offering.getOfferHA());
951+
owner.getDomainId(), owner.getId(), guestNetwork.getId(), false, 0, RedundantState.UNKNOWN, _offering.getOfferHA());
947952
router.setRole(Role.DHCP_USERDATA);
948953
router = _itMgr.allocate(router, template, _offering, networks, plan, null, owner);
949954
}

‎setup/db/create-schema.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ CREATE TABLE `cloud`.`domain_router` (
896896
`network_id` bigint unsigned NOT NULL COMMENT 'network configuration that this domain router belongs to',
897897
`is_redundant_router` int(1) unsigned NOT NULL COMMENT 'if in redundant router mode',
898898
`priority` int(4) unsigned COMMENT 'priority of router in the redundant router mode',
899-
`is_master` int(1) unsigned DEFAULT 0 COMMENT 'if the router is master in redundant router mode',
899+
`redundant_state` varchar(64) NOT NULL COMMENT 'the state of redundant virtual router',
900900
`role` varchar(64) NOT NULL COMMENT 'type of role played by this router',
901901
PRIMARY KEY (`id`),
902902
CONSTRAINT `fk_domain_router__id` FOREIGN KEY `fk_domain_router__id` (`id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE

0 commit comments

Comments
 (0)