bug 11463: Simulator: try to put security rule into db again, but only put seq/signature into db. Hope it will be faster.

This commit is contained in:
Edison Su 2011-10-05 14:46:24 -07:00
parent 0f76c1fa24
commit 4fa95df837
4 changed files with 32 additions and 18 deletions

View File

@ -357,7 +357,7 @@ public class MockVmManagerImpl implements MockVmManager {
if (!info.isEnabled()) {
return new SecurityIngressRuleAnswer(cmd, false, "Disabled", SecurityIngressRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL);
}
/*
Map<String, Ternary<String,Long, Long>> rules = _securityRules.get(info.getHostUuid());
if (rules == null) {
@ -368,16 +368,34 @@ public class MockVmManagerImpl implements MockVmManager {
} else {
logSecurityGroupAction(cmd, rules.get(cmd.getVmName()));
rules.put(cmd.getVmName(), new Ternary<String, Long,Long>(cmd.getSignature(), cmd.getVmId(), cmd.getSeqNum()));
}
}*/
MockSecurityRulesVO rule = _mockSecurityDao.findByVmId(cmd.getVmId());
if (rule == null) {
logSecurityGroupAction(cmd, null);
rule = new MockSecurityRulesVO();
rule.setSeqNum(cmd.getSeqNum());
rule.setSignature(cmd.getSignature());
rule.setVmId(cmd.getVmId());
rule.setVmName(cmd.getVmName());
rule.setHostId(info.getHostUuid());
rule = _mockSecurityDao.persist(rule);
} else {
boolean update = logSecurityGroupAction(cmd, rule);
if (update) {
rule.setSeqNum(cmd.getSeqNum());
rule.setSignature(cmd.getSignature());
_mockSecurityDao.update(rule.getId(), rule);
}
}
return new SecurityIngressRuleAnswer(cmd);
}
private boolean logSecurityGroupAction(SecurityIngressRulesCmd cmd, Ternary<String,Long, Long> rule) {
private boolean logSecurityGroupAction(SecurityIngressRulesCmd cmd, MockSecurityRulesVO rule) {
String action = ", do nothing";
String reason = ", reason=";
Long currSeqnum = rule == null? null: rule.third();
String currSig = rule == null? null: rule.first();
Long currSeqnum = rule == null? null: rule.getSeqNum();
String currSig = rule == null? null: rule.getSignature();
boolean updateSeqnoAndSig = false;
if (currSeqnum != null) {
if (cmd.getSeqNum() > currSeqnum) {
@ -430,13 +448,18 @@ public class MockVmManagerImpl implements MockVmManager {
@Override
public HashMap<String, Pair<Long, Long>> syncNetworkGroups(SimulatorInfo info) {
HashMap<String, Pair<Long, Long>> maps = new HashMap<String, Pair<Long, Long>>();
/*
Map<String, Ternary<String, Long, Long>> rules = _securityRules.get(info.getHostUuid());
if (rules == null) {
return maps;
}
for (Map.Entry<String,Ternary<String, Long, Long>> rule : rules.entrySet()) {
maps.put(rule.getKey(), new Pair<Long, Long>(rule.getValue().second(), rule.getValue().third()));
}*/
List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(info.getHostUuid());
for (MockSecurityRulesVO rule: rules) {
maps.put(rule.getVmName(), new Pair<Long, Long>(rule.getVmId(), rule.getSeqNum()));
}
return maps;
}

View File

@ -208,6 +208,7 @@ public class AgentResourceBase implements ServerResource {
@Override
public boolean stop() {
s_logger.debug("anget is stopped");
this.stopped = true;
return true;
}

View File

@ -25,9 +25,6 @@ public class MockSecurityRulesVO {
@Column(name="seqnum")
private Long seqNum;
@Column(name="ruleset")
private String ruleSet;
@Column(name="hostid")
private String hostId;
@ -77,12 +74,4 @@ public class MockSecurityRulesVO {
public void setSeqNum(Long seqNum) {
this.seqNum = seqNum;
}
public String getRuleSet() {
return this.ruleSet;
}
public void setRuleSet(String ruleset) {
this.ruleSet = ruleset;
}
}

View File

@ -95,11 +95,12 @@ CREATE TABLE `cloud`.`mocksecurityrules` (
`id` bigint unsigned NOT NULL auto_increment,
`vmid` bigint unsigned,
`signature` varchar(255),
`ruleset` varchar(4095),
`hostid` varchar(255),
`seqnum` bigint unsigned,
`vmname` varchar(255),
PRIMARY KEY (`id`),
INDEX `i_mocksecurityrules__vmid`(`vmid`),
INDEX `i_mocksecurityrules__seqnum`(`seqnum`),
INDEX `i_mocksecurityrules__signature`(`signature`),
INDEX `i_mocksecurityrules__hostid`(`hostid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;