refactor test plan in database, and add a column named "failTimes" for

task queue
This commit is contained in:
Tienan Chen 2013-11-05 10:30:41 +08:00
parent 0bc53295b5
commit 427f4780a8
4 changed files with 48 additions and 21 deletions

View File

@ -24,7 +24,7 @@ public class TestPlan {
private String testPlanRunId;
private String testPlanModelContent;
private Byte currentStatus;
private int priority;
private int failTimes;
private boolean reportCreated;
@Id
@ -97,13 +97,13 @@ public class TestPlan {
this.currentStatus = currentStatus;
}
@Column(name = "priority", nullable = false)
public int getPriority() {
return priority;
@Column(name = "failTimes", nullable = false)
public int getFailTimes() {
return failTimes;
}
public void setPriority(int priority) {
this.priority = priority;
public void setFailTimes(int failTimes) {
this.failTimes = failTimes;
}
@Column(name = "reportCreated", nullable = false)

View File

@ -36,7 +36,8 @@ public class TestPlanService {
public static final Byte TEST_PLAN_STATUS_NOT_START = 1;
public static final Byte TEST_PLAN_STATUS_COMPLETE = 2;
public static final Byte TEST_PLAN_STATUS_ERROR = 3;
public static final int LOWEST_REPEAT_PRIORITY = 0;
public static final Byte TEST_PLAN_STATUS_ERROR_NO_ENOUGH_MAXLOAD = 4;
public static final Byte TEST_PLAN_STATUS_PENDING_NO_ENOUGH_CURRENT_LOAD = 5;
public SessionHelper getSessionHelper() {
return sessionHelper;
@ -91,7 +92,7 @@ public class TestPlanService {
testPlan.setUser(user);
testPlan.setTestPlanRunId(testPlanRunId.toString());
testPlan.setCurrentStatus(TEST_PLAN_STATUS_NOT_START);
testPlan.setPriority(LOWEST_REPEAT_PRIORITY);
testPlan.setFailTimes(0);
testPlan.setTestPlanModelContent(marshalTestPlanModel(testPlanModel));
result = (TestPlan) session.merge(testPlan);
return result;

View File

@ -24,4 +24,11 @@ public class AgentRunBlotter {
this.testPlanId = testPlanId;
}
public AgentRunBlotter() {
}
public AgentRunBlotter(UUID testPlanID, RunningAgentModel runningAgentModel) {
this.setTestPlanId(testPlanID);
this.setRunningAgentModel(runningAgentModel);
}
}

View File

@ -10,8 +10,11 @@ import org.bench4q.master.communication.agent.StopTestModel;
import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.service.AgentService;
import org.bench4q.master.service.TestPlanService;
import org.bench4q.master.testPlan.AgentRunBlotter;
import org.bench4q.master.testPlan.TestPlanContainer;
import org.bench4q.master.testPlan.TestPlanContext;
import org.bench4q.master.testPlan.highavailable.HighAvailablePool;
import org.bench4q.master.testPlan.highavailable.StopAgentFault;
public class ExecutionOverTask extends TimerTask {
private AgentService agentService;
@ -84,20 +87,43 @@ public class ExecutionOverTask extends TimerTask {
runningAgentModel.getAgent(),
runningAgentModel.getAgentRunId());
if (resultModel == null || !resultModel.isSuccess()) {
logger.error("when stop agent with hostName "
+ runningAgentModel.getAgent().getHostName()
+ " returns null!");
// TODO:give this runningAgentModel to HA, let it do it
doFaultTolerance(runningAgentModel);
continue;
}
backLoadAndCleanUp(runningAgentModel);
}
this.getRunningScriptModel().setFinish(true);
cleanUpTestPlan();
System.out.println("execute ExecutionOverTask");
}
private void doFaultTolerance(RunningAgentModel runningAgentModel) {
logger.error("when stop agent with hostName "
+ runningAgentModel.getAgent().getHostName() + " returns null!");
StopAgentFault stopAgentFault = new StopAgentFault(
new AgentRunBlotter(this.getRunningScriptModel()
.getTestPlanID(), runningAgentModel));
stopAgentFault.doTolerance();
}
private void cleanUpTestPlan() {
UUID testPlanID = this.getRunningScriptModel().getTestPlanID();
if (this.getTestPlanContainer().verifyTestPlanFinish(testPlanID)) {
clearUpAndUpdateComplete(testPlanID);
TestPlanContext context = this.getTestPlanContainer()
.getRunningTestPlans().get(testPlanID);
// TODO: remove the testPlan's other info in HA
for (RunningScriptModel runningScriptModel : context
.getRunningScriptMap().values()) {
for (RunningAgentModel runningAgentModel : runningScriptModel
.getRunningAgents()) {
this.getHighAvailablePool().getAgentRunBlotters()
.remove(runningAgentModel.getAgentRunId());
}
}
this.getTestPlanContainer().getRunningTestPlans()
.remove(testPlanID);
this.getTestPlanService().handleTestPlanComplete(testPlanID);
}
System.out.println("execute ExecutionOverTask");
}
private void backLoadAndCleanUp(RunningAgentModel runningAgentModel) {
@ -108,11 +134,4 @@ public class ExecutionOverTask extends TimerTask {
this.getHighAvailablePool().getAgentRunBlotters()
.remove(runningAgentModel.getAgentRunId());
}
private void clearUpAndUpdateComplete(UUID testPlanId) {
this.getTestPlanContainer().getRunningTestPlans().remove(testPlanId);
this.getTestPlanService().handleTestPlanComplete(testPlanId);
// TODO: remove the testPlan's other info in HA
// eg. agentRunBlotters
}
}