add limit flag to MonitorMain

add Observer to testplan for stopping
This commit is contained in:
hmm 2014-09-22 10:35:59 +08:00
parent 743e71c969
commit d186075beb
7 changed files with 62 additions and 19 deletions

View File

@ -131,7 +131,7 @@ public class Monitor {
hostName, port);
System.out.println(MarshalHelper.tryMarshal(monitorMain));
//tell test plan has to stop itself
testPlan.setHasToStop(monitorMain.isFinished());
testPlan.setHasToStop(monitorMain.isTouchLimit());
List<MonitorResult> monitorResults = this.getTestPlanFactory()
.createMonitorResultListWithOutId(monitorMain, testPlan,
this, sampeTime);

View File

@ -1,5 +1,6 @@
package org.bench4q.master.domain.entity;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@ -25,8 +26,8 @@ import javax.persistence.Transient;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.IAggregate;
import org.bench4q.master.domain.repository.TestPlanRepository;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.domain.service.TestResultSave;
import org.bench4q.master.domain.valueobject.limitation.TestPlanObserver;
import org.bench4q.master.domain.valueobject.transaction.impl.TestPlanLoadApplication;
import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.helper.MarshalHelper;
@ -49,9 +50,9 @@ public class TestPlan implements IAggregate {
private Set<Monitor> monitors;
private TestResultSave testResultSave;
private TestPlanRepository repository;
private TestPlanEngine testPlanEngine;
private boolean hasToStop;
private LimitModel limitModel;
private List<TestPlanObserver> observers = new ArrayList<TestPlanObserver>();
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -288,7 +289,7 @@ public class TestPlan implements IAggregate {
getTestResultSave().update(TestPlan.this,
collectResult(new Date()));
if(isHasToStop()){
testPlanEngine.stop(UUID.fromString(testPlanRunId));
submitToObserver();
}
}
}, 0, this.getSampleCycleInSeconds(), TimeUnit.SECONDS);
@ -348,22 +349,23 @@ public class TestPlan implements IAggregate {
this.hasToStop = hasToStop;
}
@Transient
public TestPlanEngine getTestPlanEngine() {
return testPlanEngine;
}
public void setTestPlanEngine(TestPlanEngine testPlanEngine) {
this.testPlanEngine = testPlanEngine;
}
@Transient
public LimitModel getLimitModel() {
return limitModel;
}
public void setLimitModel(LimitModel limitModel) {
limitModel = limitModel;
this.limitModel = limitModel;
}
public void addObserver(TestPlanObserver testPlanObserver){
observers.add(testPlanObserver);
}
private void submitToObserver(){
UUID testPlanIdUuid = UUID.fromString(testPlanRunId);
for(TestPlanObserver testPlanObserver: observers){
testPlanObserver.processStop(testPlanIdUuid);
}
}
}

View File

@ -25,7 +25,6 @@ import org.bench4q.master.domain.entity.TestPlanScriptResult;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.repository.TestPlanRepository;
import org.bench4q.master.domain.service.ScriptService;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.domain.service.TestResultSave;
import org.bench4q.master.domain.valueobject.transaction.TransactionFactory;
import org.bench4q.master.exception.ExceptionLog;
@ -103,7 +102,7 @@ public class TestPlanFactory {
}
public TestPlan createATestPlanWithoutId(TestPlanModel testPlanModel,
User user, UUID runId, TestPlanEngine testPlanEngine) throws IllegalParameterException {
User user, UUID runId) throws IllegalParameterException {
this.logger.info("testPlanName:" + testPlanModel.getName());
TestPlan result = new TestPlan();
result.setCreateDateTime(new Date());
@ -143,7 +142,6 @@ public class TestPlanFactory {
monitors.add(monitorInBusiness);
}
result.setMonitors(monitors);
result.setTestPlanEngine(testPlanEngine);
result.setLimitModel(testPlanModel.getLimitModel());
return result;
}
@ -283,7 +281,9 @@ public class TestPlanFactory {
List<MonitorResult> monitorResults = new LinkedList<MonitorResult>();
Field[] fields = monitorMain.getClass().getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
if(fields[i].getAnnotation(MonitorMain.Transient.class) != null) continue;
MonitorResult monitorResult = new MonitorResult();
monitorResult.setTestPlanDB(testPlan);
monitorResult.setMonitor(monitor);

View File

@ -16,6 +16,7 @@ import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.entity.User;
import org.bench4q.master.domain.factory.TestPlanFactory;
import org.bench4q.master.domain.repository.TestPlanRepository;
import org.bench4q.master.domain.valueobject.limitation.TestPlanObserver;
import org.bench4q.master.domain.valueobject.schedulscript.TaskCompleteCallback;
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
import org.bench4q.master.infrastructure.highavailable.CurrentLoadObserver;
@ -30,7 +31,7 @@ import org.springframework.stereotype.Component;
@Component
public class TestPlanEngine implements TaskCompleteCallback,
CurrentLoadObserver {
CurrentLoadObserver, TestPlanObserver {
private HighAvailablePool haPool;
private TestPlanRepository testPlanRepository;
private TestPlanFactory testPlanFactory;
@ -126,7 +127,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
final User user, final UUID testPlanRunId)
throws IllegalParameterException {
TestPlan testPlan = this.getTestPlanFactory().createATestPlanWithoutId(
testPlanBusinessModel, user, testPlanRunId, this);
testPlanBusinessModel, user, testPlanRunId);
Logger.getLogger(TestPlanService.class).info(
"test plan name:" + testPlan.getName());
return this.getTestPlanRepository().attach(testPlan);
@ -198,4 +199,8 @@ public class TestPlanEngine implements TaskCompleteCallback,
public void executePendingTestPlan() {
pickATestPlan();
}
public void processStop(final UUID testPlanId) {
this.stop(testPlanId);
}
}

View File

@ -0,0 +1,9 @@
package org.bench4q.master.domain.valueobject.limitation;
import java.util.UUID;
public interface TestPlanObserver{
public abstract void processStop(final UUID testPlanId);
}

View File

@ -29,6 +29,9 @@ public class MonitorMain extends SampleModel {
private NetworkInterfaceModel networkInterfaceModel;
@XmlElement(name = "process_info")
private ProcessModel processModel;
@XmlElement(name = "touch_limit")
private boolean isTouchLimit;
private SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd-HH-mm-ss");
@ -76,4 +79,12 @@ public class MonitorMain extends SampleModel {
NetworkInterfaceModel networkInterfaceModel) {
this.networkInterfaceModel = networkInterfaceModel;
}
public boolean isTouchLimit() {
return isTouchLimit;
}
public void setTouchLimit(boolean isTouchLimit) {
this.isTouchLimit = isTouchLimit;
}
}

View File

@ -1,5 +1,7 @@
package org.bench4q.share.models.monitor;
import java.beans.Transient;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@ -19,6 +21,8 @@ public class MonitorMain extends SampleModel{
private NetworkInterfaceModel networkInterfaceModel;
private ProcessModel processModel;
private boolean isTouchLimit;
public MonitorMain() {
@ -63,4 +67,16 @@ public class MonitorMain extends SampleModel{
public void setProcessModel(ProcessModel processModel) {
this.processModel = processModel;
}
@MonitorMain.Transient
@XmlElement(name = "touch_limit")
public boolean isTouchLimit() {
return isTouchLimit;
}
public void setTouchLimit(boolean isTouchLimit) {
this.isTouchLimit = isTouchLimit;
}
public @interface Transient{}
}