diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java index 4699e5b2..d4166d3c 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/Monitor.java @@ -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 monitorResults = this.getTestPlanFactory() .createMonitorResultListWithOutId(monitorMain, testPlan, this, sampeTime); diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java index 70fbf3f0..9b549084 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/entity/TestPlan.java @@ -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 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; + } + } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java index be883eac..45aa5ac5 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/factory/TestPlanFactory.java @@ -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; } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PortPoolService.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PortPoolService.java index 6c4dac61..0ba57a77 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PortPoolService.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/PortPoolService.java @@ -168,4 +168,27 @@ public class PortPoolService { } } + + @SuppressWarnings("unchecked") + public void resetAllPortState(){ + Session session = this.getSessionHelper().openSession(); + Transaction transaction = session.beginTransaction(); + try { + List portList = (List) 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(); + } + } + } } diff --git a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java index eed1ae10..d6638876 100644 --- a/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java +++ b/Bench4Q-Master/src/main/java/org/bench4q/master/domain/service/TestPlanEngine.java @@ -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); diff --git a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java index 3fba494a..ecc18b58 100644 --- a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/MonitorMain.java @@ -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") diff --git a/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/SampleModel.java b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/SampleModel.java new file mode 100644 index 00000000..46842036 --- /dev/null +++ b/Bench4Q-Monitor-Sigar/src/main/java/org/bench4q/monitor/model/SampleModel.java @@ -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; + } + +} diff --git a/Bench4Q-Share/src/main/java/org/bench4q/share/models/monitor/MonitorMain.java b/Bench4Q-Share/src/main/java/org/bench4q/share/models/monitor/MonitorMain.java index 61e30a6d..9e02823d 100644 --- a/Bench4Q-Share/src/main/java/org/bench4q/share/models/monitor/MonitorMain.java +++ b/Bench4Q-Share/src/main/java/org/bench4q/share/models/monitor/MonitorMain.java @@ -63,5 +63,4 @@ public class MonitorMain extends SampleModel{ public void setProcessModel(ProcessModel processModel) { this.processModel = processModel; } - }