little refa
This commit is contained in:
parent
afc70a74f6
commit
2488a32971
|
@ -66,29 +66,43 @@ public class BusinessModelMapFactory {
|
|||
}
|
||||
|
||||
public static RunningScript toBusiness(RunningScriptModel runningScriptModel) {
|
||||
RunningScript result = new RunningScript();
|
||||
result.setConfig(runningScriptModel.getConfig());
|
||||
result.setFinished(runningScriptModel.isFinished());
|
||||
result.setRequireLoad(runningScriptModel.getRequireLoad());
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
for (RunningAgentModel runningAgentModel : runningScriptModel
|
||||
.getRunningAgentModels()) {
|
||||
runningAgents.add(BusinessModelMapFactory
|
||||
.toBusiness(runningAgentModel));
|
||||
}
|
||||
result.setRunningAgents(runningAgents);
|
||||
result.setScriptId(runningScriptModel.getScriptId());
|
||||
result.setTestPlanID(runningScriptModel.getTestPlanID());
|
||||
RunningScript result = new RunningScript(
|
||||
runningScriptModel.getConfig(),
|
||||
runningScriptModel.getRequireLoad(),
|
||||
runningScriptModel.getScriptId(),
|
||||
runningScriptModel.getTestPlanID(),
|
||||
toBusiness(runningScriptModel.getRunningAgentModels()));
|
||||
// result.setConfig(runningScriptModel.getConfig());
|
||||
// result.setFinished(runningScriptModel.isFinished());
|
||||
// result.setRequireLoad(runningScriptModel.getRequireLoad());
|
||||
// List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
// for (RunningAgentModel runningAgentModel : runningScriptModel
|
||||
// .getRunningAgentModels()) {
|
||||
// runningAgents.add(BusinessModelMapFactory
|
||||
// .toBusiness(runningAgentModel));
|
||||
// }
|
||||
// result.setRunningAgents(runningAgents);
|
||||
// result.setScriptId(runningScriptModel.getScriptId());
|
||||
// result.setTestPlanID(runningScriptModel.getTestPlanID());
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<RunningAgent> toBusiness(
|
||||
List<RunningAgentModel> runningAgentModels) {
|
||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||
for (RunningAgentModel runningAgentModel : runningAgentModels) {
|
||||
runningAgents.add(toBusiness(runningAgentModel));
|
||||
}
|
||||
return runningAgents;
|
||||
}
|
||||
|
||||
public static RunningScriptModel toModel(RunningScript runningScript) {
|
||||
RunningScriptModel ret = new RunningScriptModel();
|
||||
ret.setConfig(runningScript.getConfig());
|
||||
ret.setFinished(runningScript.isFinished());
|
||||
ret.setRequireLoad(runningScript.getRequireLoad());
|
||||
List<RunningAgentModel> runningAgentModels = new ArrayList<RunningAgentModel>();
|
||||
for (RunningAgent runningAgent : runningScript.getRunningAgents()) {
|
||||
for (RunningAgent runningAgent : runningScript.queryRunningAgentsUnModifiable()) {
|
||||
runningAgentModels.add(BusinessModelMapFactory
|
||||
.toModel(runningAgent));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.bench4q.master.domain;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
@ -46,7 +47,7 @@ public class RunningScript {
|
|||
return scriptId;
|
||||
}
|
||||
|
||||
public void setScriptId(int scriptId) {
|
||||
private void setScriptId(int scriptId) {
|
||||
this.scriptId = scriptId;
|
||||
}
|
||||
|
||||
|
@ -54,7 +55,7 @@ public class RunningScript {
|
|||
return requireLoad;
|
||||
}
|
||||
|
||||
public void setRequireLoad(int requireLoad) {
|
||||
private void setRequireLoad(int requireLoad) {
|
||||
this.requireLoad = requireLoad;
|
||||
}
|
||||
|
||||
|
@ -62,7 +63,7 @@ public class RunningScript {
|
|||
return config;
|
||||
}
|
||||
|
||||
public void setConfig(TestScriptConfig config) {
|
||||
private void setConfig(TestScriptConfig config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
|
@ -70,15 +71,15 @@ public class RunningScript {
|
|||
return finished;
|
||||
}
|
||||
|
||||
public void setFinished(boolean finish) {
|
||||
private void setFinished(boolean finish) {
|
||||
this.finished = finish;
|
||||
}
|
||||
|
||||
public List<RunningAgent> getRunningAgents() {
|
||||
return runningAgents;
|
||||
private List<RunningAgent> getRunningAgents() {
|
||||
return this.runningAgents;
|
||||
}
|
||||
|
||||
public void setRunningAgents(List<RunningAgent> runningAgents) {
|
||||
private void setRunningAgents(List<RunningAgent> runningAgents) {
|
||||
this.runningAgents = runningAgents;
|
||||
}
|
||||
|
||||
|
@ -114,7 +115,7 @@ public class RunningScript {
|
|||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
public RunningScript() {
|
||||
private RunningScript() {
|
||||
this.setRunningAgents(new ArrayList<RunningAgent>());
|
||||
this.setDataStatisticsList(new ArrayList<DataStatistics>());
|
||||
this.getDataStatisticsList().add(new ScriptBriefStatistics());
|
||||
|
@ -126,10 +127,25 @@ public class RunningScript {
|
|||
AgentService.class));
|
||||
}
|
||||
|
||||
public RunningScript(TestScriptConfig config, int requireLoad,
|
||||
int scriptId, UUID testPlanId, List<RunningAgent> runningAgents) {
|
||||
this();
|
||||
this.setConfig(config);
|
||||
this.setFinished(false);
|
||||
this.setRequireLoad(requireLoad);
|
||||
this.setTestPlanID(testPlanId);
|
||||
this.setScriptId(scriptId);
|
||||
this.runningAgents.addAll(runningAgents);
|
||||
}
|
||||
|
||||
public static boolean notValidScript(RunningScript input) {
|
||||
return input == null || input.getRunningAgents() == null;
|
||||
}
|
||||
|
||||
public List<RunningAgent> queryRunningAgentsUnModifiable() {
|
||||
return Collections.unmodifiableList(this.runningAgents);
|
||||
}
|
||||
|
||||
private DataStatistics getScriptBriefStatistics() {
|
||||
return getSpecificStaitstics(ScriptBriefStatistics.class);
|
||||
}
|
||||
|
@ -240,10 +256,15 @@ public class RunningScript {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void doAfterDistributeLoad(List<RunningAgent> agentsAfterDistribute) {
|
||||
this.getRunningAgents().addAll(agentsAfterDistribute);
|
||||
// TODO: start to cyclic brief
|
||||
|
||||
}
|
||||
|
||||
public void doForComplete() {
|
||||
for (RunningAgent runningAgent : this.getRunningAgents()) {
|
||||
if (runningAgent == null
|
||||
|| runningAgent.getAgent().getCurrentStatus() == AgentService.AGENT_STATUS_BreakDown) {
|
||||
for (RunningAgent runningAgent : this.runningAgents) {
|
||||
if (runningAgent == null) {
|
||||
continue;
|
||||
}
|
||||
StopTestModel resultModel = this.getRunningAgentService().stop(
|
||||
|
@ -254,7 +275,7 @@ public class RunningScript {
|
|||
}
|
||||
backLoadAndCleanUp(runningAgent);
|
||||
}
|
||||
this.getRunningAgents().clear();
|
||||
this.runningAgents.clear();
|
||||
this.setFinished(true);
|
||||
}
|
||||
|
||||
|
@ -272,4 +293,7 @@ public class RunningScript {
|
|||
runningAgent.getLoadInUse());
|
||||
}
|
||||
|
||||
public void addAgentToScriptForTest(RunningAgent runningAgent) {
|
||||
this.getRunningAgents().add(runningAgent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package org.bench4q.master.testplan;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgent;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanContext;
|
||||
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
|
||||
import org.bench4q.master.testplan.transaction.Transaction;
|
||||
import org.bench4q.master.testplan.transaction.script.ScriptLoadCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -41,16 +42,16 @@ public class LoadDistribute {
|
|||
|
||||
try {
|
||||
for (RunningScript scriptInput : testPlanContext.getAllScript()) {
|
||||
Transaction scriptLoadCommand = new ScriptLoadCommand(
|
||||
ScriptLoadCommand scriptLoadCommand = new ScriptLoadCommand(
|
||||
scriptInput, testPlanId);
|
||||
// TODO: there is a problem
|
||||
RunningScript scriptOutput = (RunningScript) scriptLoadCommand
|
||||
List<RunningAgent> runningAgents = scriptLoadCommand
|
||||
.execute();
|
||||
if (scriptOutput == null) {
|
||||
if (runningAgents == null) {
|
||||
logger.error("distribute load error, the runningAgents is null");
|
||||
scriptLoadCommand.rollBack();
|
||||
return false;
|
||||
}
|
||||
testPlanContext.addToScriptMap(scriptOutput);
|
||||
doAfterDistributeLoadSuccess(scriptInput, runningAgents);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
|
@ -59,6 +60,11 @@ public class LoadDistribute {
|
|||
}
|
||||
}
|
||||
|
||||
private void doAfterDistributeLoadSuccess(RunningScript scriptInput,
|
||||
List<RunningAgent> runningAgents) {
|
||||
scriptInput.doAfterDistributeLoad(runningAgents);
|
||||
}
|
||||
|
||||
private boolean hasEnoughCurrentLoad(TestPlanContext testPlanContext) {
|
||||
return this.highAvailableAgentPool.getCurrentAvailableLoad() >= testPlanContext
|
||||
.getTotalLoad();
|
||||
|
|
|
@ -175,7 +175,8 @@ public class HighAvailablePool extends CurrentLoadSubject {
|
|||
deadAgentBlotter.getRunningAgent().getScriptId()));
|
||||
ScriptLoadBase loadCommand = new ScriptLoadSubstitute(runningScript,
|
||||
deadAgentBlotter);
|
||||
loadCommand.execute();
|
||||
List<RunningAgent> agentsAfterDistribute = loadCommand.execute();
|
||||
runningScript.doAfterDistributeLoad(agentsAfterDistribute);
|
||||
}
|
||||
|
||||
private void _doForHealth(ServerStatusModel newModel, Agent agent) {
|
||||
|
@ -214,7 +215,7 @@ public class HighAvailablePool extends CurrentLoadSubject {
|
|||
public void doForTestPlanComplete(final TestPlanContext context) {
|
||||
|
||||
for (RunningScript runningScript : context.getAllScript()) {
|
||||
for (RunningAgent runningAgent : runningScript.getRunningAgents()) {
|
||||
for (RunningAgent runningAgent : runningScript.queryRunningAgentsUnModifiable()) {
|
||||
this.getAgentRunBlotters().remove(runningAgent.getAgentRunId());
|
||||
logger.info("see the agentBlotter after run : "
|
||||
+ this.getAgentRunBlotters().get(
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.bench4q.master.domain.RunningScript;
|
|||
import org.bench4q.master.entity.Agent;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.service.infrastructure.AgentService;
|
||||
import org.bench4q.master.service.infrastructure.RunningAgentService;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
|
||||
|
@ -106,7 +105,7 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
this.setAgentListThisTime(new ArrayList<RunningAgent>());
|
||||
}
|
||||
|
||||
public Object execute() {
|
||||
public List<RunningAgent> execute() {
|
||||
logger.info(this.getRunningScript().getScriptId());
|
||||
RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
.getRunSceniroModelByScriptId(
|
||||
|
@ -129,9 +128,7 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
+ this.getRunningScript().getScriptId());
|
||||
return null;
|
||||
}
|
||||
this.getRunningScript().getRunningAgents()
|
||||
.addAll(this.getAgentListThisTime());
|
||||
return this.getRunningScript();
|
||||
return this.getAgentListThisTime();
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getExceptionStackTrace(e).toString()
|
||||
+ " whose scriptID is "
|
||||
|
@ -223,23 +220,21 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
}
|
||||
|
||||
public void rollBack() {
|
||||
stopAgentsRunningThisScript(this.getAgentListThisTime());
|
||||
if (this.getRunningScript().getRunningAgents().size() > 0) {
|
||||
|
||||
}
|
||||
stopAgentsRunningThisScript();
|
||||
}
|
||||
|
||||
private void stopAgentsRunningThisScript(List<RunningAgent> runningAgents) {
|
||||
if (runningAgents == null) {
|
||||
private void stopAgentsRunningThisScript() {
|
||||
if (this.getAgentListThisTime() == null) {
|
||||
return;
|
||||
}
|
||||
for (RunningAgent runningAgent : runningAgents) {
|
||||
if (runningAgent.getAgent().getCurrentStatus() == AgentService.AGENT_STATUS_BreakDown) {
|
||||
runningAgents.remove(runningAgent);
|
||||
continue;
|
||||
for (RunningAgent runningAgent : this.getAgentListThisTime()) {
|
||||
// TODO: there's a problem
|
||||
AgentRunBlotter agentRunBlotter = this.getHighAvailableAgentPool()
|
||||
.getAgentRunBlotters().get(runningAgent.getAgentRunId());
|
||||
if (agentRunBlotter.getRunningAgent().isBreakDown()) {
|
||||
} else if (stopAgentSuccess(runningAgent)) {
|
||||
runningAgents.remove(runningAgent);
|
||||
}
|
||||
this.getAgentListThisTime().remove(runningAgent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,15 +36,17 @@ public class Test_RunningScript extends TestBase_MakeUpTestPlan {
|
|||
runningAgent.setLoadInUse(40);
|
||||
runningAgent.setScriptId(this.getScriptId());
|
||||
runningAgent.setAgent(new Agent());
|
||||
this.getRunningScript().getRunningAgents().add(runningAgent);
|
||||
this.getRunningScript().addAgentToScriptForTest(runningAgent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoForComplete() {
|
||||
assertEquals(false, this.getRunningScript().isFinished());
|
||||
assertEquals(1, this.getRunningScript().getRunningAgents().size());
|
||||
assertEquals(1, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
this.getRunningScript().doForComplete();
|
||||
assertEquals(0, this.getRunningScript().getRunningAgents().size());
|
||||
assertEquals(0, this.getRunningScript()
|
||||
.queryRunningAgentsUnModifiable().size());
|
||||
assertEquals(true, this.getRunningScript().isFinished());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue