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