refactor, and move the datastatistics to runningScript
This commit is contained in:
parent
4483838010
commit
df43f8734c
|
@ -13,7 +13,6 @@ import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||||
import org.bench4q.master.datastatistics.BehaviorsBriefStatistics;
|
import org.bench4q.master.datastatistics.BehaviorsBriefStatistics;
|
||||||
import org.bench4q.master.datastatistics.PageBriefStatistics;
|
|
||||||
import org.bench4q.master.datastatistics.ScriptBriefStatistics;
|
import org.bench4q.master.datastatistics.ScriptBriefStatistics;
|
||||||
import org.bench4q.master.entity.db.TestPlanDB;
|
import org.bench4q.master.entity.db.TestPlanDB;
|
||||||
import org.bench4q.master.exception.Bench4QException;
|
import org.bench4q.master.exception.Bench4QException;
|
||||||
|
@ -188,8 +187,7 @@ public class TestPlanController extends BaseController {
|
||||||
this.getLogger().info("testPlanContext exists!");
|
this.getLogger().info("testPlanContext exists!");
|
||||||
|
|
||||||
List<RunningScriptModel> runningScriptModels = new ArrayList<RunningScriptModel>();
|
List<RunningScriptModel> runningScriptModels = new ArrayList<RunningScriptModel>();
|
||||||
for (RunningScript runningScript : testPlanContext
|
for (RunningScript runningScript : testPlanContext.getAllScript()) {
|
||||||
.getRunningScriptMap().values()) {
|
|
||||||
runningScriptModels.add(BusinessModelMapFactory
|
runningScriptModels.add(BusinessModelMapFactory
|
||||||
.toModel(runningScript));
|
.toModel(runningScript));
|
||||||
}
|
}
|
||||||
|
@ -227,13 +225,12 @@ public class TestPlanController extends BaseController {
|
||||||
ret.setFinished(true);
|
ret.setFinished(true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
RunningScript runningScript = context.getRunningScriptMap().get(
|
RunningScript runningScript = context.queryRunningScript(scriptId);
|
||||||
new Integer(scriptId));
|
|
||||||
if (runningScript == null || runningScript.isFinished()) {
|
if (runningScript == null || runningScript.isFinished()) {
|
||||||
ret.setFinished(true);
|
ret.setFinished(true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = this.getRunningScriptService().getRunningScriptBrief(testPlanId,
|
ret = this.getRunningScriptService().getScriptBrief(testPlanId,
|
||||||
runningScript, new ScriptBriefStatistics());
|
runningScript, new ScriptBriefStatistics());
|
||||||
ret.setPlanedRunningTime(runningScript.getConfig().getExecuteRange());
|
ret.setPlanedRunningTime(runningScript.getConfig().getExecuteRange());
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -337,13 +334,11 @@ public class TestPlanController extends BaseController {
|
||||||
ScriptBehaviorsBriefModel ret = new ScriptBehaviorsBriefModel();
|
ScriptBehaviorsBriefModel ret = new ScriptBehaviorsBriefModel();
|
||||||
TestPlanContext context = this.getTestPlanContainer()
|
TestPlanContext context = this.getTestPlanContainer()
|
||||||
.getRunningTestPlans().get(testPlanRunID);
|
.getRunningTestPlans().get(testPlanRunID);
|
||||||
if (context.isFinish()
|
if (context.isFinish() || !context.isContains(scriptId)) {
|
||||||
|| !context.getRunningScriptMap().containsKey(scriptId)) {
|
|
||||||
ret.setFinished(true);
|
ret.setFinished(true);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
RunningScript runningScript = context.getRunningScriptMap().get(
|
RunningScript runningScript = context.queryRunningScript(scriptId);
|
||||||
scriptId);
|
|
||||||
if (runningScript == null || runningScript.isFinished()) {
|
if (runningScript == null || runningScript.isFinished()) {
|
||||||
ret.setFinished(true);
|
ret.setFinished(true);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -372,9 +367,8 @@ public class TestPlanController extends BaseController {
|
||||||
guardForTestPlan(testPlanRunId);
|
guardForTestPlan(testPlanRunId);
|
||||||
TestPlanContext context = this.getTestPlanContainer()
|
TestPlanContext context = this.getTestPlanContainer()
|
||||||
.getRunningTestPlans().get(testPlanRunId);
|
.getRunningTestPlans().get(testPlanRunId);
|
||||||
RunningScript runningScript = context.getRunningScriptMap().get(
|
RunningScript runningScript = context.queryRunningScript(scriptId);
|
||||||
scriptId);
|
|
||||||
return this.getRunningScriptService().getPageBriefModel(testPlanRunId,
|
return this.getRunningScriptService().getPageBriefModel(testPlanRunId,
|
||||||
runningScript, pageId, new PageBriefStatistics());
|
runningScript, pageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,20 +66,20 @@ public class BusinessModelMapFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RunningScript toBusiness(RunningScriptModel runningScriptModel) {
|
public static RunningScript toBusiness(RunningScriptModel runningScriptModel) {
|
||||||
RunningScript runningScript = new RunningScript();
|
RunningScript result = new RunningScript();
|
||||||
runningScript.setConfig(runningScriptModel.getConfig());
|
result.setConfig(runningScriptModel.getConfig());
|
||||||
runningScript.setFinished(runningScriptModel.isFinished());
|
result.setFinished(runningScriptModel.isFinished());
|
||||||
runningScript.setRequireLoad(runningScriptModel.getRequireLoad());
|
result.setRequireLoad(runningScriptModel.getRequireLoad());
|
||||||
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||||
for (RunningAgentModel runningAgentModel : runningScriptModel
|
for (RunningAgentModel runningAgentModel : runningScriptModel
|
||||||
.getRunningAgentModels()) {
|
.getRunningAgentModels()) {
|
||||||
runningAgents.add(BusinessModelMapFactory
|
runningAgents.add(BusinessModelMapFactory
|
||||||
.toBusiness(runningAgentModel));
|
.toBusiness(runningAgentModel));
|
||||||
}
|
}
|
||||||
runningScript.setRunningAgents(runningAgents);
|
result.setRunningAgents(runningAgents);
|
||||||
runningScript.setScriptId(runningScriptModel.getScriptId());
|
result.setScriptId(runningScriptModel.getScriptId());
|
||||||
runningScript.setTestPlanID(runningScriptModel.getTestPlanID());
|
result.setTestPlanID(runningScriptModel.getTestPlanID());
|
||||||
return runningScript;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RunningScriptModel toModel(RunningScript runningScript) {
|
public static RunningScriptModel toModel(RunningScript runningScript) {
|
||||||
|
|
|
@ -6,4 +6,14 @@ public interface DataStatistics {
|
||||||
public void add(DataStatisticsModel dataUnit);
|
public void add(DataStatisticsModel dataUnit);
|
||||||
|
|
||||||
public Object getStatistics();
|
public Object getStatistics();
|
||||||
|
|
||||||
|
public class DefaultStatistics implements DataStatistics {
|
||||||
|
public void add(DataStatisticsModel dataUnit) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getStatistics() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class RunningScriptService {
|
||||||
this.testPlanScriptService = testPlanScriptService;
|
this.testPlanScriptService = testPlanScriptService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptBriefResultModel getRunningScriptBrief(UUID testPlanId,
|
public ScriptBriefResultModel getScriptBrief(UUID testPlanId,
|
||||||
RunningScript runningScript, DataStatistics briefStatistics) {
|
RunningScript runningScript, DataStatistics briefStatistics) {
|
||||||
if (RunningScript.notValidScript(runningScript)) {
|
if (RunningScript.notValidScript(runningScript)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -82,19 +82,19 @@ public class RunningScriptService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptPageBriefModel getPageBriefModel(UUID testPlanID,
|
public ScriptPageBriefModel getPageBriefModel(UUID testPlanID,
|
||||||
RunningScript runningScript, int pageId,
|
RunningScript runningScript, int pageId) {
|
||||||
DataStatistics dataStatistics) {
|
|
||||||
if (RunningScript.notValidScript(runningScript)) {
|
if (RunningScript.notValidScript(runningScript)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (RunningAgent runningAgent : runningScript.getRunningAgents()) {
|
for (RunningAgent runningAgent : runningScript.getRunningAgents()) {
|
||||||
dataStatistics.add(this.getRunningAgentService().pageBrief(
|
runningScript.getPageBriefStatistics().add(
|
||||||
runningAgent.getAgent(), runningAgent.getAgentRunId(),
|
this.getRunningAgentService().pageBrief(
|
||||||
pageId));
|
runningAgent.getAgent(),
|
||||||
|
runningAgent.getAgentRunId(), pageId));
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptPageBriefModel result = (ScriptPageBriefModel) dataStatistics
|
ScriptPageBriefModel result = (ScriptPageBriefModel) runningScript
|
||||||
.getStatistics();
|
.getPageBriefStatistics().getStatistics();
|
||||||
result.setFinished(runningScript.isFinished());
|
result.setFinished(runningScript.isFinished());
|
||||||
// TODO:save it in the database
|
// TODO:save it in the database
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -38,8 +38,7 @@ public class LoadDistribute {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
for (RunningScript scriptInput : testPlanContext
|
for (RunningScript scriptInput : testPlanContext.getAllScript()) {
|
||||||
.getRunningScriptMap().values()) {
|
|
||||||
Transaction scriptLoadCommand = new ScriptLoadCommand(
|
Transaction scriptLoadCommand = new ScriptLoadCommand(
|
||||||
scriptInput, testPlanId);
|
scriptInput, testPlanId);
|
||||||
RunningScript scriptOutput = (RunningScript) scriptLoadCommand
|
RunningScript scriptOutput = (RunningScript) scriptLoadCommand
|
||||||
|
|
|
@ -43,15 +43,13 @@ public class TestPlanContainer {
|
||||||
public boolean isTestPlanFinished(UUID testPlanId) {
|
public boolean isTestPlanFinished(UUID testPlanId) {
|
||||||
TestPlanContext testPlanContext = this.queryTestPlanContext(testPlanId);
|
TestPlanContext testPlanContext = this.queryTestPlanContext(testPlanId);
|
||||||
boolean finish = true;
|
boolean finish = true;
|
||||||
if (testPlanContext == null
|
if (testPlanContext == null || testPlanContext.getScriptCount() == 0) {
|
||||||
|| testPlanContext.getRunningScriptMap().size() == 0) {
|
|
||||||
logger.error("testPlanContext is null or scriptMap size is 0, where the testPlanID is"
|
logger.error("testPlanContext is null or scriptMap size is 0, where the testPlanID is"
|
||||||
+ testPlanId);
|
+ testPlanId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
for (RunningScript runningScript : testPlanContext
|
for (RunningScript runningScript : testPlanContext.getAllScript()) {
|
||||||
.getRunningScriptMap().values()) {
|
|
||||||
if (!runningScript.isFinished()) {
|
if (!runningScript.isFinished()) {
|
||||||
finish = false;
|
finish = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.bench4q.master.testplan;
|
package org.bench4q.master.testplan;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -21,7 +23,7 @@ public class TestPlanContext {
|
||||||
this.testPlan = testPlan;
|
this.testPlan = testPlan;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, RunningScript> getRunningScriptMap() {
|
private Map<Integer, RunningScript> getRunningScriptMap() {
|
||||||
return runningScriptMap;
|
return runningScriptMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +71,22 @@ public class TestPlanContext {
|
||||||
return this.runningScriptMap.get(new Integer(scriptId));
|
return this.runningScriptMap.get(new Integer(scriptId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<RunningScript> getAllScript() {
|
||||||
|
return Collections.unmodifiableCollection(this.getRunningScriptMap()
|
||||||
|
.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScriptCount() {
|
||||||
|
return this.getRunningScriptMap().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isContains(int scriptId) {
|
||||||
|
return this.getRunningScriptMap().containsKey(scriptId);
|
||||||
|
}
|
||||||
|
|
||||||
int getTotalLoad() {
|
int getTotalLoad() {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (RunningScript runningScript : this.getRunningScriptMap().values()) {
|
for (RunningScript runningScript : getAllScript()) {
|
||||||
result += runningScript.getRequireLoad();
|
result += runningScript.getRequireLoad();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
||||||
final TestPlanContext testPlanContext = new TestPlanContext(testPlan,
|
final TestPlanContext testPlanContext = new TestPlanContext(testPlan,
|
||||||
testPlanId);
|
testPlanId);
|
||||||
if (!this.testPlanService.saveTestPlanToDB(testPlan, user, testPlanId,
|
if (!this.testPlanService.saveTestPlanToDB(testPlan, user, testPlanId,
|
||||||
testPlanContext.getRunningScriptMap().values())) {
|
testPlanContext.getAllScript())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,9 +105,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
||||||
|
|
||||||
private boolean schedulePlanConfig(TestPlanContext testPlanContext,
|
private boolean schedulePlanConfig(TestPlanContext testPlanContext,
|
||||||
UUID testPlanId) {
|
UUID testPlanId) {
|
||||||
for (RunningScript runningScript : testPlanContext
|
for (RunningScript runningScript : testPlanContext.getAllScript()) {
|
||||||
.getRunningScriptMap().values()) {
|
|
||||||
|
|
||||||
scheduleScriptConfig(runningScript, testPlanId);
|
scheduleScriptConfig(runningScript, testPlanId);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -154,8 +152,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
||||||
+ testPlanID.toString() + " is null!");
|
+ testPlanID.toString() + " is null!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (RunningScript runningScript : context.getRunningScriptMap()
|
for (RunningScript runningScript : context.getAllScript()) {
|
||||||
.values()) {
|
|
||||||
for (RunningAgent runningAgent : runningScript.getRunningAgents()) {
|
for (RunningAgent runningAgent : runningScript.getRunningAgents()) {
|
||||||
this.getHaPool().getAgentRunBlotters()
|
this.getHaPool().getAgentRunBlotters()
|
||||||
.remove(runningAgent.getAgentRunId());
|
.remove(runningAgent.getAgentRunId());
|
||||||
|
|
|
@ -4,15 +4,20 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bench4q.master.datastatistics.BehaviorsBriefStatistics;
|
||||||
|
import org.bench4q.master.datastatistics.DataStatistics;
|
||||||
|
import org.bench4q.master.datastatistics.PageBriefStatistics;
|
||||||
|
import org.bench4q.master.datastatistics.ScriptBriefStatistics;
|
||||||
import org.bench4q.share.models.master.TestScriptConfig;
|
import org.bench4q.share.models.master.TestScriptConfig;
|
||||||
|
|
||||||
public class RunningScript {
|
public class RunningScript {
|
||||||
private int scriptId;
|
private int scriptId;
|
||||||
private int requireLoad;
|
|
||||||
private TestScriptConfig config;
|
|
||||||
private boolean finished;
|
|
||||||
private List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
|
||||||
private UUID testPlanID;
|
private UUID testPlanID;
|
||||||
|
private int requireLoad;
|
||||||
|
private boolean finished;
|
||||||
|
private TestScriptConfig config;
|
||||||
|
private List<DataStatistics> dataStatisticsList;
|
||||||
|
private List<RunningAgent> runningAgents = new ArrayList<RunningAgent>();
|
||||||
|
|
||||||
public int getScriptId() {
|
public int getScriptId() {
|
||||||
return scriptId;
|
return scriptId;
|
||||||
|
@ -62,6 +67,53 @@ public class RunningScript {
|
||||||
this.testPlanID = testPlanID;
|
this.testPlanID = testPlanID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<DataStatistics> getDataStatisticsList() {
|
||||||
|
return dataStatisticsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDataStatisticsList(List<DataStatistics> dataStatisticsList) {
|
||||||
|
this.dataStatisticsList = dataStatisticsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RunningScript() {
|
||||||
|
this.setRunningAgents(new ArrayList<RunningAgent>());
|
||||||
|
this.setDataStatisticsList(new ArrayList<DataStatistics>());
|
||||||
|
this.getDataStatisticsList().add(new ScriptBriefStatistics());
|
||||||
|
this.getDataStatisticsList().add(new PageBriefStatistics());
|
||||||
|
this.getDataStatisticsList().add(new BehaviorsBriefStatistics());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataStatistics getScriptBriefStatistics() {
|
||||||
|
return getSpecificStaitstics(ScriptBriefStatistics.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataStatistics getPageBriefStatistics() {
|
||||||
|
return getSpecificStaitstics(PageBriefStatistics.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataStatistics getBehaviorsBriefStatistics() {
|
||||||
|
return getSpecificStaitstics(BehaviorsBriefStatistics.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DataStatistics getSpecificStaitstics(
|
||||||
|
Class<?> specificStatisticsClass) {
|
||||||
|
for (DataStatistics dataStatistics : this.getDataStatisticsList()) {
|
||||||
|
if (specificStatisticsClass.equals(ScriptBriefStatistics.class)
|
||||||
|
&& (dataStatistics instanceof ScriptBriefStatistics)) {
|
||||||
|
return dataStatistics;
|
||||||
|
}
|
||||||
|
if (specificStatisticsClass.equals(BehaviorsBriefStatistics.class)
|
||||||
|
&& (dataStatistics instanceof BehaviorsBriefStatistics)) {
|
||||||
|
return dataStatistics;
|
||||||
|
}
|
||||||
|
if (specificStatisticsClass.equals(PageBriefStatistics.class)
|
||||||
|
&& (dataStatistics instanceof PageBriefStatistics)) {
|
||||||
|
return dataStatistics;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new DataStatistics.DefaultStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean notValidScript(RunningScript input) {
|
public static boolean notValidScript(RunningScript input) {
|
||||||
return input == null || input.getRunningAgents() == null;
|
return input == null || input.getRunningAgents() == null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,8 +170,8 @@ public class HighAvailablePool extends CurrentLoadSubject {
|
||||||
logger.info("The testPlan has finished or not started, so no need to substitute!");
|
logger.info("The testPlan has finished or not started, so no need to substitute!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RunningScript runningScript = context.getRunningScriptMap().get(
|
RunningScript runningScript = context.queryRunningScript(new Integer(
|
||||||
new Integer(deadAgentBlotter.getRunningAgent().getScriptId()));
|
deadAgentBlotter.getRunningAgent().getScriptId()));
|
||||||
ScriptLoadBase loadCommand = new ScriptLoadSubstitute(runningScript,
|
ScriptLoadBase loadCommand = new ScriptLoadSubstitute(runningScript,
|
||||||
deadAgentBlotter);
|
deadAgentBlotter);
|
||||||
loadCommand.execute();
|
loadCommand.execute();
|
||||||
|
|
Loading…
Reference in New Issue