add support for schedule

add support for schedule
This commit is contained in:
coderfengyun 2014-09-04 09:17:04 +08:00
parent e8378b6476
commit b00cc44785
10 changed files with 102 additions and 72 deletions

View File

@ -11,9 +11,8 @@ import javax.persistence.Table;
@Table(name = "planedConfig") @Table(name = "planedConfig")
public class PlanedConfig { public class PlanedConfig {
private int id; private int id;
private long warmUp;
private long executeRange; private long executeRange;
private long coolDown; private String scheduleContent;
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@ -26,16 +25,7 @@ public class PlanedConfig {
this.id = id; this.id = id;
} }
@Column(name = "warmUp", nullable = false) @Column(name = "executeRange", nullable = false)
public long getWarmUp() {
return warmUp;
}
public void setWarmUp(long warmUp) {
this.warmUp = warmUp;
}
@Column(name = "excuteRange", nullable = false)
public long getExecuteRange() { public long getExecuteRange() {
return executeRange; return executeRange;
} }
@ -44,13 +34,13 @@ public class PlanedConfig {
this.executeRange = executeRange; this.executeRange = executeRange;
} }
@Column(name = "coolDown", nullable = false) @Column(name = "scheduleContent", columnDefinition = "LONGTEXT", nullable = false)
public long getCoolDown() { public String getScheduleContent() {
return coolDown; return scheduleContent;
} }
public void setCoolDown(long coolDown) { public void setScheduleContent(String scheduleContent) {
this.coolDown = coolDown; this.scheduleContent = scheduleContent;
} }
} }

View File

@ -5,7 +5,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID; import java.util.UUID;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@ -28,7 +27,6 @@ import org.bench4q.master.domain.RunningScriptInterface;
import org.bench4q.master.domain.factory.TestPlanFactory; import org.bench4q.master.domain.factory.TestPlanFactory;
import org.bench4q.master.domain.valueobject.datastatistics.RunningScriptSampler; import org.bench4q.master.domain.valueobject.datastatistics.RunningScriptSampler;
import org.bench4q.master.domain.valueobject.schedulscript.ExecutionOverTask; import org.bench4q.master.domain.valueobject.schedulscript.ExecutionOverTask;
import org.bench4q.master.domain.valueobject.schedulscript.WarmUpOverTask;
import org.bench4q.master.domain.valueobject.transaction.Transaction; import org.bench4q.master.domain.valueobject.transaction.Transaction;
import org.bench4q.master.domain.valueobject.transaction.TransactionFactory; import org.bench4q.master.domain.valueobject.transaction.TransactionFactory;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
@ -197,25 +195,10 @@ public class TestPlanScript implements RunningScriptInterface {
return false; return false;
} }
Timer timer = new Timer(); Timer timer = new Timer();
timer.schedule(new WarmUpOverTask(), testScriptConfig.getWarmUp() ExecutionOverTask executionOverTask = new ExecutionOverTask(this);
timer.schedule(executionOverTask, (testScriptConfig.getExecuteRange())
* SECOND_MILISECOND_UNIT_CONVERSION); * SECOND_MILISECOND_UNIT_CONVERSION);
ExecutionOverTask executionOverTask = new ExecutionOverTask(this);
timer.schedule(
executionOverTask,
(testScriptConfig.getWarmUp() + testScriptConfig
.getExecuteRange()) * SECOND_MILISECOND_UNIT_CONVERSION);
timer.schedule(
new TimerTask() {
@Override
public void run() {
System.out.println("cool down over!");
}
},
(testScriptConfig.getWarmUp()
+ testScriptConfig.getExecuteRange() + testScriptConfig
.getCoolDown()) * SECOND_MILISECOND_UNIT_CONVERSION);
return true; return true;
} }

View File

@ -3,7 +3,6 @@ package org.bench4q.master.domain.factory;
import org.bench4q.master.domain.RunningAgentInterface; import org.bench4q.master.domain.RunningAgentInterface;
import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.domain.entity.Monitor; import org.bench4q.master.domain.entity.Monitor;
import org.bench4q.master.domain.entity.PlanedConfig;
import org.bench4q.master.domain.entity.Port; import org.bench4q.master.domain.entity.Port;
import org.bench4q.master.domain.entity.Script; import org.bench4q.master.domain.entity.Script;
import org.bench4q.master.domain.entity.TestPlan; import org.bench4q.master.domain.entity.TestPlan;
@ -14,7 +13,6 @@ import org.bench4q.share.models.master.PortModel;
import org.bench4q.share.models.master.RunningAgentModel; import org.bench4q.share.models.master.RunningAgentModel;
import org.bench4q.share.models.master.ScriptModel; import org.bench4q.share.models.master.ScriptModel;
import org.bench4q.share.models.master.TestPlanDBModel; import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestScriptConfig;
import org.bench4q.share.models.master.UserModel; import org.bench4q.share.models.master.UserModel;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -46,14 +44,6 @@ public class BusinessModelMapFactory {
return ret; return ret;
} }
public TestScriptConfig toModel(PlanedConfig config) {
TestScriptConfig result = new TestScriptConfig();
result.setWarmUp(config.getWarmUp());
result.setExecuteRange(config.getExecuteRange());
result.setCoolDown(config.getCoolDown());
return result;
}
public static Monitor toBusiness(MonitorModel monitorModel) { public static Monitor toBusiness(MonitorModel monitorModel) {
Monitor monitor = new Monitor(); Monitor monitor = new Monitor();
monitor.setHostName(monitorModel.getHostName()); monitor.setHostName(monitorModel.getHostName());

View File

@ -36,11 +36,11 @@ import org.bench4q.share.models.agent.ScriptFilterOptionsModel;
import org.bench4q.share.models.agent.scriptrecord.BatchModel; import org.bench4q.share.models.agent.scriptrecord.BatchModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel; import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.scriptrecord.PageModel; import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel; import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanModel;
import org.bench4q.share.models.master.TestScriptConfig;
import org.bench4q.share.models.master.statistics.ScriptResultModel; import org.bench4q.share.models.master.statistics.ScriptResultModel;
import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.MonitorMain;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -126,7 +126,7 @@ public class TestPlanFactory {
testPlanScripts.add(createATestPlanScriptWithoutId( testPlanScripts.add(createATestPlanScriptWithoutId(
runningScriptModel.getRequireLoad(), runningScriptModel.getRequireLoad(),
runningScriptModel.getScriptId(), runningScriptModel.getScriptId(),
runningScriptModel.getConfig(), result, runningScriptModel.getScheduleModel(), result,
runningScriptModel.getScriptFilterOptionsModel())); runningScriptModel.getScriptFilterOptionsModel()));
} }
result.setRequiredLoad(requiredLoad); result.setRequiredLoad(requiredLoad);
@ -150,7 +150,7 @@ public class TestPlanFactory {
} }
public TestPlanScript createATestPlanScriptWithoutId(int requireLoad, public TestPlanScript createATestPlanScriptWithoutId(int requireLoad,
int scriptId, TestScriptConfig config, TestPlan testPlanDB, int scriptId, ScheduleModel config, TestPlan testPlanDB,
ScriptFilterOptionsModel scriptFilterOptionsModel) { ScriptFilterOptionsModel scriptFilterOptionsModel) {
TestPlanScript testPlanScript = new TestPlanScript(); TestPlanScript testPlanScript = new TestPlanScript();
testPlanScript.setRequireLoad(requireLoad); testPlanScript.setRequireLoad(requireLoad);
@ -214,12 +214,10 @@ public class TestPlanFactory {
} }
private PlanedConfig createAPlanedConfigWithoutId(TestScriptConfig config) { private PlanedConfig createAPlanedConfigWithoutId(ScheduleModel schedule) {
PlanedConfig planedConfig = new PlanedConfig(); PlanedConfig result = new PlanedConfig();
planedConfig.setWarmUp(config.getWarmUp()); result.setScheduleContent(MarshalHelper.tryMarshal(schedule));
planedConfig.setExecuteRange(config.getExecuteRange()); return result;
planedConfig.setCoolDown(config.getCoolDown());
return planedConfig;
} }
public TestPlanScriptResult createScriptResultWithoutId(Object model, public TestPlanScriptResult createScriptResultWithoutId(Object model,

View File

@ -25,10 +25,11 @@ import org.bench4q.master.infrastructure.communication.AgentMessenger;
import org.bench4q.master.infrastructure.highavailable.HighAvailablePool; import org.bench4q.master.infrastructure.highavailable.HighAvailablePool;
import org.bench4q.master.unitTest.controller.TestBase; import org.bench4q.master.unitTest.controller.TestBase;
import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel.PointModel;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanModel;
import org.bench4q.share.models.master.TestScriptConfig;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -374,11 +375,11 @@ public class TestBase_MakeUpTestPlan extends TestBase {
RunningScriptModel model = new RunningScriptModel(); RunningScriptModel model = new RunningScriptModel();
model.setScriptId(scriptID); model.setScriptId(scriptID);
model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE); model.setRequireLoad(EACH_SCRIPT_LOAD_SMALLSCALE);
TestScriptConfig config = new TestScriptConfig(); ScheduleModel config = new ScheduleModel();
config.setWarmUp(20); config.getPoints().add(new PointModel(0, 0));
config.setExecuteRange(60); config.getPoints().add(new PointModel(20, 10));
config.setCoolDown(10); config.getPoints().add(new PointModel(60, 10));
model.setConfig(config); model.setScheduleModel(config);
return model; return model;
} }

View File

@ -67,7 +67,7 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan {
assertEquals(1, testPlan.getMonitors().size()); assertEquals(1, testPlan.getMonitors().size());
for (TestPlanScript testPlanScript : testPlanScripts) { for (TestPlanScript testPlanScript : testPlanScripts) {
assertEquals(getScriptId(), testPlanScript.getScript().getId()); assertEquals(getScriptId(), testPlanScript.getScript().getId());
assertEquals(20, testPlanScript.getPlanedConfig().getWarmUp()); assertEquals(20, testPlanScript.getPlanedConfig().getExecuteRange());
} }
assertTrue(this.getTestPlanRepository().detach(testPlan.getId())); assertTrue(this.getTestPlanRepository().detach(testPlan.getId()));
} }

View File

@ -25,6 +25,18 @@ public class ScheduleModel {
this.points = new LinkedList<PointModel>(); this.points = new LinkedList<PointModel>();
} }
public long getExecuteRange() {
if (this.points.size() == 0) {
return 0;
}
long startTime = this.points.get(0).getTime(), endTime = startTime;
for (PointModel point : this.getPoints()) {
startTime = Math.min(point.getTime(), startTime);
endTime = Math.max(point.getTime(), endTime);
}
return endTime - startTime;
}
@XmlRootElement @XmlRootElement
public static class PointModel { public static class PointModel {
private long time; private long time;
@ -48,8 +60,10 @@ public class ScheduleModel {
this.load = load; this.load = load;
} }
public PointModel(){} public PointModel() {
public PointModel(long time, int load){ }
public PointModel(long time, int load) {
this.time = time; this.time = time;
this.load = load; this.load = load;
} }

View File

@ -10,12 +10,13 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.ScriptFilterOptionsModel; import org.bench4q.share.models.agent.ScriptFilterOptionsModel;
import org.bench4q.share.models.agent.scriptrecord.ScheduleModel;
@XmlRootElement(name = "runningScripModel") @XmlRootElement(name = "runningScripModel")
public class RunningScriptModel { public class RunningScriptModel {
private int scriptId; private int scriptId;
private int requireLoad; private int requireLoad;
private TestScriptConfig config; private ScheduleModel scheduleModel;
private ScriptFilterOptionsModel scriptFilterOptionsModel; private ScriptFilterOptionsModel scriptFilterOptionsModel;
private RunScenarioModel scenarioModel; private RunScenarioModel scenarioModel;
private String scriptName; private String scriptName;
@ -42,12 +43,12 @@ public class RunningScriptModel {
} }
@XmlElement @XmlElement
public TestScriptConfig getConfig() { public ScheduleModel getScheduleModel() {
return config; return scheduleModel;
} }
public void setConfig(TestScriptConfig config) { public void setScheduleModel(ScheduleModel scheduleModel) {
this.config = config; this.scheduleModel = scheduleModel;
} }
@XmlElement @XmlElement
@ -100,7 +101,8 @@ public class RunningScriptModel {
return scriptFilterOptionsModel; return scriptFilterOptionsModel;
} }
public void setScriptFilterOptionsModel(ScriptFilterOptionsModel scriptFilterOptionsModel) { public void setScriptFilterOptionsModel(
ScriptFilterOptionsModel scriptFilterOptionsModel) {
this.scriptFilterOptionsModel = scriptFilterOptionsModel; this.scriptFilterOptionsModel = scriptFilterOptionsModel;
} }
} }

View File

@ -0,0 +1,52 @@
package org.bench4q.share.models.master;
import java.util.LinkedList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class TestScriptConfigModel {
private List<PointModel> points;
@XmlElementWrapper(name = "points")
@XmlElement(name = "point")
public List<PointModel> getPoints() {
return points;
}
private void setPoints(List<PointModel> points) {
this.points = points;
}
public TestScriptConfigModel() {
this.setPoints(new LinkedList<PointModel>());
}
@XmlRootElement
public static class PointModel {
private int load;
private long relativeTime;
@XmlElement
public int getLoad() {
return load;
}
public void setLoad(int load) {
this.load = load;
}
@XmlElement
public long getRelativeTime() {
return relativeTime;
}
public void setRelativeTime(long relativeTime) {
this.relativeTime = relativeTime;
}
}
}

View File

@ -18,7 +18,7 @@ import org.bench4q.share.models.master.ScriptHandleModel;
import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanModel;
import org.bench4q.share.models.master.TestPlanResultModel; import org.bench4q.share.models.master.TestPlanResultModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.TestScriptConfig; import org.bench4q.share.models.master.TestScriptConfigModel;
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel; import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
import org.bench4q.share.models.master.statistics.ScriptBriefResultModel; import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
import org.bench4q.web.masterMessager.TestPlanMessager; import org.bench4q.web.masterMessager.TestPlanMessager;
@ -73,7 +73,7 @@ public class TestPlanService {
scriptFilterOptionsModel.setFilterTypeMatches(scriptModel.getFilterTypeMatches()); scriptFilterOptionsModel.setFilterTypeMatches(scriptModel.getFilterTypeMatches());
scriptFilterOptionsModel.setFilterTimer(scriptModel.isFilterTimer()); scriptFilterOptionsModel.setFilterTimer(scriptModel.isFilterTimer());
TestScriptConfig testScriptConfig = new TestScriptConfig(); TestScriptConfigModel testScriptConfig = new TestScriptConfigModel();
testScriptConfig.setCoolDown(scriptModel.getCooldown()); testScriptConfig.setCoolDown(scriptModel.getCooldown());
testScriptConfig.setExecuteRange(scriptModel.getExecuteRange()); testScriptConfig.setExecuteRange(scriptModel.getExecuteRange());
testScriptConfig.setWarmUp(scriptModel.getWarmup()); testScriptConfig.setWarmUp(scriptModel.getWarmup());