add maxAvailableLoad and currentAvailableLoad to HA, and let it can do

the task queue matter and can return enough message if it can't execute
it
This commit is contained in:
Tienan Chen 2013-11-05 11:09:04 +08:00
parent 427f4780a8
commit 37b0afa18c
4 changed files with 30 additions and 22 deletions

View File

@ -144,7 +144,8 @@ public class TestPlanService {
}
TestPlanScript testPlanScript = (TestPlanScript) session
.createCriteria(TestPlanScript.class)
.add(Restrictions.eq("testPlan", testPlan)).uniqueResult();
.add(Restrictions.eq("testPlan", testPlan))
.add(Restrictions.eq("scriptId", scriptId)).uniqueResult();
if (testPlanScript == null) {
return -1;
}

View File

@ -50,8 +50,7 @@ public class LoadDistribute {
}
private boolean hasEnoughLoad(TestPlanContext testPlanContext) {
return this.highAvailableAgentPool.getMaxLoadOfHAPool() >= testPlanContext
return this.highAvailableAgentPool.getCurrentAvailableLoad() >= testPlanContext
.getTotalLoad();
}
}

View File

@ -30,7 +30,8 @@ public class HighAvailablePool {
private TestPlanContainer testPlanContainer;
private Map<String, ServerStatusModel> agentStatusOfPreviousBeatMap;
private Map<UUID, AgentRunBlotter> agentRunBlotters;
private long maxLoadOfHAPool;
private long maxAvailableLoad;
private long currentAvailableLoad;
private static Logger logger = Logger.getLogger(HighAvailablePool.class);
public Map<String, Agent> getPool() {
@ -60,12 +61,20 @@ public class HighAvailablePool {
this.testPlanContainer = testPlanContainer;
}
public Long getMaxLoadOfHAPool() {
return maxLoadOfHAPool;
public Long getMaxAvailableLoad() {
return maxAvailableLoad;
}
private void setMaxLoadOfHAPool(Long maxLoadOfHAPool) {
this.maxLoadOfHAPool = maxLoadOfHAPool;
private void setMaxAvailableLoad(Long maxAvailableLoad) {
this.maxAvailableLoad = maxAvailableLoad;
}
public long getCurrentAvailableLoad() {
return currentAvailableLoad;
}
public void setCurrentAvailableLoad(long currentAvailableLoad) {
this.currentAvailableLoad = currentAvailableLoad;
}
public ScriptService getScriptService() {
@ -94,7 +103,7 @@ public class HighAvailablePool {
this.setPool(new HashMap<String, Agent>());
this.setAgentRunBlotters(new HashMap<UUID, AgentRunBlotter>());
this.setAgentStatusOfPreviousBeatMap(new HashMap<String, ServerStatusModel>());
this.setMaxLoadOfHAPool((long) 0);
this.setCurrentAvailableLoad((long) 0);
}
@Scheduled(cron = "0,30 */1 * * * *")
@ -111,7 +120,8 @@ public class HighAvailablePool {
this.pool.clear();
List<Agent> agents = this.agentService.loadAgentPoolFromDB();
ServerStatusModel model = new ServerStatusModel();
this.setMaxLoadOfHAPool((long) 0);
this.setCurrentAvailableLoad((long) 0);
this.setMaxAvailableLoad((long) 0);
for (int i = 0; i < agents.size(); i++) {
this.getPool().put(agents.get(i).getHostName(), agents.get(i));
model = queryAgentStatus(agents.get(i));
@ -121,6 +131,10 @@ public class HighAvailablePool {
}
_doForHealth(model, agents.get(i));
}
logger.info("Current Available load in pool is "
+ this.getCurrentAvailableLoad());
logger.info("Max available load in pool is "
+ this.getMaxAvailableLoad());
}
public ServerStatusModel queryAgentStatus(Agent agent) {
@ -176,16 +190,15 @@ public class HighAvailablePool {
}
private void _doForHealth(ServerStatusModel newModel, Agent agent) {
_arrageUnfinishedTest(newModel, agent);
if (agent.getCurrentStatus() == AgentService.AGENT_STATUS_Idel) {
this.setMaxLoadOfHAPool(this.getMaxLoadOfHAPool()
+ (long) agent.getRemainLoad());
}
arrageUnfinishedTest(newModel, agent);
this.setCurrentAvailableLoad(this.getCurrentAvailableLoad()
+ (long) agent.getRemainLoad());
this.setMaxAvailableLoad(this.getMaxAvailableLoad()
+ (long) agent.getMaxLoad());
this.agentStatusOfPreviousBeatMap.put(agent.getHostName(), newModel);
}
private void _arrageUnfinishedTest(ServerStatusModel newModel, Agent agent) {
private void arrageUnfinishedTest(ServerStatusModel newModel, Agent agent) {
List<UUID> agentUnfinishedRunIds = queryUnfinishedTest(newModel,
agent.getHostName());
if (agentUnfinishedRunIds == null || agentUnfinishedRunIds.size() == 0) {

View File

@ -1,5 +0,0 @@
package org.bench4q.master.testPlan.schedulscript;
public class ScheduleScript {
}