monitor tell the testplan to stop itself by TestPlanEngine, changes in

master
This commit is contained in:
hmm 2014-09-19 09:29:21 +08:00
parent 755ac2db3c
commit 0aedd662f0
8 changed files with 89 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@ -21,6 +22,7 @@ import javax.persistence.Transient;
import org.apache.log4j.Logger;
import org.bench4q.master.domain.factory.TestPlanFactory;
import org.bench4q.master.domain.service.TestPlanEngine;
import org.bench4q.master.domain.valueobject.datastatistics.TestMonitorSampler;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.helper.ApplicationContextHelper;
@ -121,6 +123,8 @@ public class Monitor {
MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult(
hostName, port);
System.out.println(MarshalHelper.tryMarshal(monitorMain));
//tell test plan has to stop itself
testPlan.setHasToStop(monitorMain.isFinished());
List<MonitorResult> monitorResults = this.getTestPlanFactory()
.createMonitorResultListWithOutId(monitorMain, testPlan,
this, sampeTime);

View File

@ -4,6 +4,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -24,6 +25,7 @@ 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.transaction.impl.TestPlanLoadApplication;
import org.bench4q.share.enums.master.TestPlanStatus;
@ -45,6 +47,8 @@ public class TestPlan implements IAggregate {
private Set<Monitor> monitors;
private TestResultSave testResultSave;
private TestPlanRepository repository;
private TestPlanEngine testPlanEngine;
private boolean hasToStop;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -272,6 +276,9 @@ public class TestPlan implements IAggregate {
}
getTestResultSave().update(TestPlan.this,
collectResult(new Date()));
if(isHasToStop()){
testPlanEngine.stop(UUID.fromString(testPlanRunId));
}
}
}, 0, this.getSampleCycleInSeconds(), TimeUnit.SECONDS);
} catch (Exception e) {
@ -321,4 +328,22 @@ public class TestPlan implements IAggregate {
return getLastRunningTime();
}
@Transient
public boolean isHasToStop() {
return hasToStop;
}
public void setHasToStop(boolean hasToStop) {
this.hasToStop = hasToStop;
}
@Transient
public TestPlanEngine getTestPlanEngine() {
return testPlanEngine;
}
public void setTestPlanEngine(TestPlanEngine testPlanEngine) {
this.testPlanEngine = testPlanEngine;
}
}

View File

@ -25,6 +25,7 @@ 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;
@ -102,7 +103,7 @@ public class TestPlanFactory {
}
public TestPlan createATestPlanWithoutId(TestPlanModel testPlanModel,
User user, UUID runId) throws IllegalParameterException {
User user, UUID runId, TestPlanEngine testPlanEngine) throws IllegalParameterException {
this.logger.info("testPlanName:" + testPlanModel.getName());
TestPlan result = new TestPlan();
result.setCreateDateTime(new Date());
@ -142,6 +143,7 @@ public class TestPlanFactory {
monitors.add(monitorInBusiness);
}
result.setMonitors(monitors);
result.setTestPlanEngine(testPlanEngine);
return result;
}

View File

@ -168,4 +168,27 @@ public class PortPoolService {
}
}
@SuppressWarnings("unchecked")
public void resetAllPortState(){
Session session = this.getSessionHelper().openSession();
Transaction transaction = session.beginTransaction();
try {
List<Port> portList = (List<Port>) session
.createCriteria(Port.class)
.add(Restrictions.eq("inUse", true)).list();
for(Port port: portList){
port.setInUse(false);
}
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
transaction.rollback();
} finally {
if (session != null) {
session.close();
}
}
}
}

View File

@ -126,7 +126,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
final User user, final UUID testPlanRunId)
throws IllegalParameterException {
TestPlan testPlan = this.getTestPlanFactory().createATestPlanWithoutId(
testPlanBusinessModel, user, testPlanRunId);
testPlanBusinessModel, user, testPlanRunId, this);
Logger.getLogger(TestPlanService.class).info(
"test plan name:" + testPlan.getName());
return this.getTestPlanRepository().attach(testPlan);

View File

@ -1,11 +1,11 @@
package org.bench4q.monitor.model;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.ExecutionException;
import java.text.SimpleDateFormat;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@ -15,7 +15,7 @@ import org.hyperic.sigar.SigarException;
import com.google.gson.annotations.Expose;
@XmlRootElement(name = "history")
public class MonitorMain {
public class MonitorMain extends SampleModel{
@XmlElement
private String date;
@XmlElement(name = "processor_info")

View File

@ -0,0 +1,31 @@
package org.bench4q.monitor.model;
import java.util.Date;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public abstract class SampleModel {
protected Date samplingTime;
protected boolean finished;
@XmlElement
public Date getSamplingTime() {
return samplingTime;
}
public void setSamplingTime(Date samplingTime) {
this.samplingTime = samplingTime;
}
@XmlElement
public boolean isFinished() {
return finished;
}
public void setFinished(boolean finished) {
this.finished = finished;
}
}

View File

@ -63,5 +63,4 @@ public class MonitorMain extends SampleModel{
public void setProcessModel(ProcessModel processModel) {
this.processModel = processModel;
}
}