refactor, remove total count from agent's testbriefresult
This commit is contained in:
parent
a0ec495df1
commit
4fa7c211d1
|
@ -13,7 +13,6 @@ public class TestBriefStatusModel {
|
|||
private int successCount;
|
||||
private int failCount;
|
||||
private int finishedCount;
|
||||
private int totalCount;
|
||||
private int scenarioBehaviorCount;
|
||||
private double averageResponseTime;
|
||||
private boolean finished;
|
||||
|
@ -72,15 +71,6 @@ public class TestBriefStatusModel {
|
|||
this.finishedCount = finishedCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public void setTotalCount(int totalCount) {
|
||||
this.totalCount = totalCount;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public double getAverageResponseTime() {
|
||||
return averageResponseTime;
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.bench4q.master.testPlan;
|
|||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -30,21 +29,11 @@ public class LoadBallancer {
|
|||
private AgentService agentService;
|
||||
private HighAvailableAgentPool highAvailableAgentPool;
|
||||
|
||||
private boolean monopolizeByUserSet = true;
|
||||
|
||||
@Autowired
|
||||
public void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
private boolean isMonopolizeByUserSet() {
|
||||
return monopolizeByUserSet;
|
||||
}
|
||||
|
||||
public void setMonopolizeByUserSet(boolean monopolize) {
|
||||
this.monopolizeByUserSet = monopolize;
|
||||
}
|
||||
|
||||
private AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
@ -58,6 +47,10 @@ public class LoadBallancer {
|
|||
public void setHttpRequester(HttpRequester httpRequester) {
|
||||
}
|
||||
|
||||
public HighAvailableAgentPool getHighAvailableAgentPool() {
|
||||
return highAvailableAgentPool;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setHighAvailableAgentPool(
|
||||
HighAvailableAgentPool highAvailableAgentPool) {
|
||||
|
@ -115,49 +108,57 @@ public class LoadBallancer {
|
|||
}
|
||||
|
||||
private RunningScriptModel runAgentsWithScenario(
|
||||
RunScenarioModel runScenarioModel, int requireLoad, int scriptId,
|
||||
UUID testPlanId) throws JAXBException {
|
||||
Iterator<Agent> iterator;
|
||||
Agent agent;
|
||||
RunScenarioModel runScenarioModel, int totalRequireLoad,
|
||||
int scriptId, UUID testPlanId) throws JAXBException {
|
||||
RunningAgentModel runningAgentModel = new RunningAgentModel();
|
||||
RunScenarioResultModel runScenarioResultModel = new RunScenarioResultModel();
|
||||
List<RunningAgentModel> runningAgentModelList = new ArrayList<RunningAgentModel>();
|
||||
int min;
|
||||
int loadForRunCurrent;
|
||||
|
||||
for (iterator = this.highAvailableAgentPool.getHighAvailablePool()
|
||||
.iterator(); iterator.hasNext() && requireLoad > 0;) {
|
||||
agent = iterator.next();
|
||||
if (this.highAvailableAgentPool.queryAgentStatus(agent) == null) {
|
||||
for (Agent agent : this.getHighAvailableAgentPool()
|
||||
.getHighAvailablePool()) {
|
||||
if (allocationFinish(totalRequireLoad)) {
|
||||
break;
|
||||
}
|
||||
if (this.highAvailableAgentPool.queryAgentStatus(agent) == null
|
||||
|| inUse(agent)) {
|
||||
continue;
|
||||
}
|
||||
if (isMonopolized(agent)) {
|
||||
continue;
|
||||
}
|
||||
min = getMin(requireLoad, agent.getRemainLoad());
|
||||
|
||||
runScenarioModel.setPoolSize(min);
|
||||
runScenarioModel.setTotalCount(min);
|
||||
loadForRunCurrent = getMin(totalRequireLoad, agent.getRemainLoad());
|
||||
|
||||
runScenarioModel.setPoolSize(loadForRunCurrent);
|
||||
runScenarioModel.setTotalCount(loadForRunCurrent);
|
||||
runScenarioResultModel = runAgentWithScenario(runScenarioModel,
|
||||
agent, min);
|
||||
agent);
|
||||
if (runScenarioResultModel == null) {
|
||||
continue;
|
||||
}
|
||||
runningAgentModel = buildRunningAgentModel(agent, min, scriptId,
|
||||
runningAgentModel = buildRunningAgentModel(agent,
|
||||
loadForRunCurrent, scriptId,
|
||||
runScenarioResultModel.getRunId());
|
||||
runningAgentModelList.add(runningAgentModel);
|
||||
|
||||
this.highAvailableAgentPool.getAgentRunBlotters().put(
|
||||
runScenarioResultModel.getRunId(),
|
||||
buildAgentRunBlotter(runningAgentModel, testPlanId));
|
||||
requireLoad -= min;
|
||||
totalRequireLoad -= loadForRunCurrent;
|
||||
}
|
||||
// this means that the allocation of this script fails.
|
||||
if (requireLoad > 0) {
|
||||
stopAgentsRunningThisScript(runningAgentModelList);
|
||||
runningAgentModelList = null;
|
||||
|
||||
if (!allocationFinish(totalRequireLoad)) {
|
||||
runningAgentModelList = rollbackForUnfinishedAllocation(runningAgentModelList);
|
||||
}
|
||||
return _buildRunningScriptModel(runningAgentModelList, scriptId);
|
||||
return buildRunningScriptModel(runningAgentModelList, scriptId);
|
||||
}
|
||||
|
||||
private List<RunningAgentModel> rollbackForUnfinishedAllocation(
|
||||
List<RunningAgentModel> runningAgentModelList) {
|
||||
stopAgentsRunningThisScript(runningAgentModelList);
|
||||
runningAgentModelList = null;
|
||||
return runningAgentModelList;
|
||||
}
|
||||
|
||||
private boolean allocationFinish(int requireLoad) {
|
||||
return requireLoad <= 0;
|
||||
}
|
||||
|
||||
private void stopAgentsRunningThisScript(
|
||||
|
@ -169,10 +170,13 @@ public class LoadBallancer {
|
|||
}
|
||||
|
||||
private RunScenarioResultModel runAgentWithScenario(
|
||||
RunScenarioModel runScenarioModel, Agent agent, int min)
|
||||
RunScenarioModel runScenarioModel, Agent agent)
|
||||
throws JAXBException {
|
||||
try {
|
||||
this.getAgentService().getLoadFromAgent(agent.getHostName(), min);
|
||||
if (!this.getAgentService().getLoadFromAgent(agent.getHostName(),
|
||||
runScenarioModel.getPoolSize())) {
|
||||
return null;
|
||||
}
|
||||
return this.getAgentService().run(agent,
|
||||
this._marshalRunScenarioModelToString(runScenarioModel));
|
||||
|
||||
|
@ -200,9 +204,8 @@ public class LoadBallancer {
|
|||
return result;
|
||||
}
|
||||
|
||||
private boolean isMonopolized(Agent agent) {
|
||||
return agent.getRemainLoad() < agent.getMaxLoad()
|
||||
&& this.isMonopolizeByUserSet();
|
||||
private boolean inUse(Agent agent) {
|
||||
return agent.getRemainLoad() < agent.getMaxLoad();
|
||||
}
|
||||
|
||||
private int getMin(int requireLoad, int remainLoadByStart) {
|
||||
|
@ -220,7 +223,7 @@ public class LoadBallancer {
|
|||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
private RunningScriptModel _buildRunningScriptModel(
|
||||
private RunningScriptModel buildRunningScriptModel(
|
||||
List<RunningAgentModel> runningAgentModels, int scriptId) {
|
||||
RunningScriptModel result = new RunningScriptModel();
|
||||
result.setScriptId(scriptId);
|
||||
|
|
Loading…
Reference in New Issue