test target mode and success

This commit is contained in:
hmm 2014-09-26 11:34:45 +08:00
parent 401c3b16d6
commit 44fd53c668
15 changed files with 101 additions and 31 deletions

View File

@ -98,13 +98,14 @@ public class MonitorController extends BaseController {
return ret == null ? new MonitorNetworkReponseModel() : ret; return ret == null ? new MonitorNetworkReponseModel() : ret;
} }
@RequestMapping(value = "/getLimitableFields") @RequestMapping(value = "/getLimitableFields/{hostName}/{port}")
@ResponseBody @ResponseBody
public LimitableFieldsModel getLimitableFields(@ModelAttribute("accessToken") String accessToken) throws Bench4QException{ public LimitableFieldsModel getLimitableFields(@ModelAttribute("accessToken") String accessToken,
@PathVariable String hostName, @PathVariable int port) throws Bench4QException{
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
throw new Bench4QException(400 + "", "not permitted", throw new Bench4QException(400 + "", "not permitted",
"/networkInfo"); "/networkInfo");
} }
return this.getMonitorResultService().getLimitableFields(); return this.getMonitorResultService().getLimitableFields(hostName, port);
} }
} }

View File

@ -122,7 +122,7 @@ public class Monitor {
public List<MonitorResult> doAfterRun(Date sampeTime) { public List<MonitorResult> doAfterRun(Date sampeTime) {
try { try {
MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult( MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult(
hostName, port); hostName, port, this.testPlan.getTestPlanRunId());
System.out.println(MarshalHelper.tryMarshal(monitorMain)); System.out.println(MarshalHelper.tryMarshal(monitorMain));
//tell test plan has to stop itself //tell test plan has to stop itself
testPlan.setHasToStop(monitorMain.isTouchLimit()); testPlan.setHasToStop(monitorMain.isTouchLimit());
@ -137,8 +137,8 @@ public class Monitor {
} }
} }
public void start(UUID testPlanId, String limitModel){ public void start(){
this.getTestMonitorSampler().startMonitor(hostName, port, testPlanId, limitModel); this.getTestMonitorSampler().startMonitor(hostName, port, this.testPlan.getTestPlanRunId(), this.testPlan.getLimitModel());
} }
public List<MonitorResult> createFinishedResult() { public List<MonitorResult> createFinishedResult() {

View File

@ -225,6 +225,8 @@ public class TestPlan implements IAggregate {
result = false; result = false;
} }
} }
getTestResultSave().update(TestPlan.this,
collectResult(new Date()));
this.setCurrentStatus(TestPlanStatus.Complete.name()); this.setCurrentStatus(TestPlanStatus.Complete.name());
return result; return result;
} }
@ -262,10 +264,9 @@ public class TestPlan implements IAggregate {
testPlanScript.run(); testPlanScript.run();
} }
//start monitor to check the limit //start monitor to check the limit
UUID testPlanIdUuid = UUID.fromString(this.testPlanRunId);
if (getMonitors() != null && this.limitModel != null) { if (getMonitors() != null && this.limitModel != null) {
for (Monitor monitor : getMonitors()) { for (Monitor monitor : getMonitors()) {
monitor.start(testPlanIdUuid, this.limitModel); monitor.start();
} }
} }
} }

View File

@ -12,6 +12,7 @@ import org.bench4q.master.domain.repository.TestPlanRepository;
import org.bench4q.master.exception.Bench4QException; import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.helper.SessionHelper; import org.bench4q.master.helper.SessionHelper;
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
import org.bench4q.recorder.httpcapture.generator.HtmlDocumentParser; import org.bench4q.recorder.httpcapture.generator.HtmlDocumentParser;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.MonitorMemoryResponseModel; import org.bench4q.share.models.master.MonitorMemoryResponseModel;
@ -28,6 +29,7 @@ import org.bench4q.share.models.monitor.ProcessorModel;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.python.antlr.PythonParser.return_stmt_return;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -36,6 +38,8 @@ public class MonitorResultService {
private TestPlanRepository testPlanRepository; private TestPlanRepository testPlanRepository;
private SessionHelper sessionHelper; private SessionHelper sessionHelper;
private LimitableFieldsModel limitableField = null; private LimitableFieldsModel limitableField = null;
@Autowired
private MonitorMessenger monitorMessenger;
private static Logger logger = Logger.getLogger(MonitorResult.class); private static Logger logger = Logger.getLogger(MonitorResult.class);
private TestPlanRepository getTestPlanRepository() { private TestPlanRepository getTestPlanRepository() {
@ -199,10 +203,7 @@ public class MonitorResultService {
e.printStackTrace(); e.printStackTrace();
} }
} }
public LimitableFieldsModel getLimitableFields(){ public LimitableFieldsModel getLimitableFields(String hostName, int port){
if(limitableField == null){ return monitorMessenger.getLimitableFields(hostName, port);
initLimitableFields();
}
return limitableField;
} }
} }

View File

@ -1,7 +1,5 @@
package org.bench4q.master.domain.valueobject.datastatistics; package org.bench4q.master.domain.valueobject.datastatistics;
import java.util.UUID;
import org.bench4q.master.infrastructure.communication.MonitorMessenger; import org.bench4q.master.infrastructure.communication.MonitorMessenger;
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;
@ -17,11 +15,15 @@ public class TestMonitorSampler {
this.monitorMessenger = monitorMessenger; this.monitorMessenger = monitorMessenger;
} }
public MonitorMain getMonitorResult(String hostName, int port, String testPlanId) {
return this.monitorMessenger.monitorModel(hostName, port, testPlanId);
}
public MonitorMain getMonitorResult(String hostName, int port) { public MonitorMain getMonitorResult(String hostName, int port) {
return this.monitorMessenger.monitorModel(hostName, port); return this.monitorMessenger.monitorModel(hostName, port);
} }
public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel){ public boolean startMonitor(String hostName, int port, String testPlanId, String limitModel){
return this.monitorMessenger.startMonitor(hostName, port, testPlanId, limitModel); return this.monitorMessenger.startMonitor(hostName, port, testPlanId, limitModel);
} }
} }

View File

@ -1,7 +1,6 @@
package org.bench4q.master.infrastructure.communication; package org.bench4q.master.infrastructure.communication;
import java.util.UUID; import org.bench4q.share.models.monitor.LimitableFieldsModel;
import org.bench4q.share.models.monitor.MemoryModel; import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel; import org.bench4q.share.models.monitor.NetworkInterfaceModel;
@ -10,6 +9,8 @@ import org.bench4q.share.models.monitor.ProcessModel;
import org.bench4q.share.models.monitor.ProcessorModel; import org.bench4q.share.models.monitor.ProcessorModel;
public interface MonitorMessenger { public interface MonitorMessenger {
public MonitorMain monitorModel(String hostName, int port, String testPlanId);
public MonitorMain monitorModel(String hostName, int port); public MonitorMain monitorModel(String hostName, int port);
public PhysicalDiskModel physicalDisk(String hostName, int port); public PhysicalDiskModel physicalDisk(String hostName, int port);
@ -22,6 +23,8 @@ public interface MonitorMessenger {
public ProcessModel process(String hostName, int port); public ProcessModel process(String hostName, int port);
public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel) ; public boolean startMonitor(String hostName, int port, String testPlanId, String limitModel) ;
public LimitableFieldsModel getLimitableFields(String hostName, int port);
} }

View File

@ -2,7 +2,6 @@ package org.bench4q.master.infrastructure.communication.impl;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.UUID;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
@ -11,6 +10,7 @@ import org.bench4q.share.communication.HttpRequester;
import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.communication.HttpRequester.HttpResponse;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.statistics.SampleModel; import org.bench4q.share.models.master.statistics.SampleModel;
import org.bench4q.share.models.monitor.LimitableFieldsModel;
import org.bench4q.share.models.monitor.MemoryModel; import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel; import org.bench4q.share.models.monitor.NetworkInterfaceModel;
@ -86,7 +86,24 @@ public class MonitorMessengerImpl implements MonitorMessenger {
public MonitorMain monitorModel(String hostName, int port) { public MonitorMain monitorModel(String hostName, int port) {
MonitorMain monitorMain = this.getMonitorModel(hostName, port, MonitorMain monitorMain = this.getMonitorModel(hostName, port,
MonitorMain.class, "all"); MonitorMain.class, "/all");
monitorMain.getMemoryModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getNetworkInterfaceModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getPhysicalDiskModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getProcessModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getProcessorModel().setSamplingTime(
monitorMain.getSamplingTime());
return monitorMain;
}
public MonitorMain monitorModel(String hostName, int port, String testPlanId) {
MonitorMain monitorMain = this.getMonitorModel(hostName, port,
MonitorMain.class, "/brief/"+testPlanId);
monitorMain.getMemoryModel().setSamplingTime( monitorMain.getMemoryModel().setSamplingTime(
monitorMain.getSamplingTime()); monitorMain.getSamplingTime());
monitorMain.getNetworkInterfaceModel().setSamplingTime( monitorMain.getNetworkInterfaceModel().setSamplingTime(
@ -101,7 +118,7 @@ public class MonitorMessengerImpl implements MonitorMessenger {
return monitorMain; return monitorMain;
} }
public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel) { public boolean startMonitor(String hostName, int port, String testPlanId, String limitModel) {
HttpResponse httpResponse; HttpResponse httpResponse;
try { try {
httpResponse = this.getHttpRequester().sendPutXml( httpResponse = this.getHttpRequester().sendPutXml(
@ -120,4 +137,22 @@ public class MonitorMessengerImpl implements MonitorMessenger {
} }
public LimitableFieldsModel getLimitableFields(String hostName, int port) {
try {
HttpResponse httpResponse = this.getHttpRequester().sendGet(
buildUrl(hostName, port, "/monitor/limitableFields" ),
null, null);
if (HttpRequester.isInvalidResponse(httpResponse)) {
logger.info("The httpResponse is invalid ");
return null;
}
LimitableFieldsModel model = MarshalHelper.unmarshal(LimitableFieldsModel.class,
httpResponse.getContent());
return model;
} catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e));
return null;
}
}
} }

View File

@ -4,6 +4,7 @@ import java.util.Date;
import java.util.UUID; import java.util.UUID;
import org.bench4q.master.infrastructure.communication.MonitorMessenger; import org.bench4q.master.infrastructure.communication.MonitorMessenger;
import org.bench4q.share.models.monitor.LimitableFieldsModel;
import org.bench4q.share.models.monitor.MemoryModel; import org.bench4q.share.models.monitor.MemoryModel;
import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel; import org.bench4q.share.models.monitor.NetworkInterfaceModel;
@ -53,5 +54,21 @@ public class Mock_MonitorMessenger implements MonitorMessenger {
return false; return false;
} }
public MonitorMain monitorModel(String hostName, int port, String testPlanId) {
// TODO Auto-generated method stub
return null;
}
public boolean startMonitor(String hostName, int port, String testPlanId,
String limitModel) {
// TODO Auto-generated method stub
return false;
}
public LimitableFieldsModel getLimitableFields(String hostName, int port) {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement @XmlRootElement(name = "limitableFields")
public class LimitableFieldsModel { public class LimitableFieldsModel {
private List<String> fields; private List<String> fields;

View File

@ -28,7 +28,6 @@ public class MonitorMain extends SampleModel {
private NetworkInterfaceModel networkInterfaceModel; private NetworkInterfaceModel networkInterfaceModel;
@XmlElement(name = "process_info") @XmlElement(name = "process_info")
private ProcessModel processModel; private ProcessModel processModel;
@XmlElement(name = "reach_limit")
private boolean isReachLimit; private boolean isReachLimit;
private SimpleDateFormat dateFormat = new SimpleDateFormat( private SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd-HH-mm-ss"); "yyyy-MM-dd-HH-mm-ss");
@ -81,6 +80,8 @@ public class MonitorMain extends SampleModel {
System.out.println(System.currentTimeMillis() - startTime); System.out.println(System.currentTimeMillis() - startTime);
} }
@XmlElement(name = "touch_limit")
public boolean getIsReachLimit() { public boolean getIsReachLimit() {
return isReachLimit; return isReachLimit;
} }

View File

@ -26,6 +26,7 @@ public class MonitorController extends BaseController {
private MonitorMessager monitorMessager; private MonitorMessager monitorMessager;
private final String port = "5556"; private final String port = "5556";
private final String localHostName = "127.0.0.1";
private MonitorService monitorService; private MonitorService monitorService;
public MonitorMessager getMonitorMessager() { public MonitorMessager getMonitorMessager() {
@ -194,7 +195,7 @@ public class MonitorController extends BaseController {
@ResponseBody @ResponseBody
public Map<String, Object> getLimitableFields(@ModelAttribute("accessToken") String accessToken){ public Map<String, Object> getLimitableFields(@ModelAttribute("accessToken") String accessToken){
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
LimitableFieldsModel limitableFieldsModel = this.getMonitorMessager().getLimitableFields(accessToken); LimitableFieldsModel limitableFieldsModel = this.getMonitorMessager().getLimitableFields(accessToken,localHostName, port);
if(limitableFieldsModel == null){ if(limitableFieldsModel == null){
return fail(map, SERVER_ERROR); return fail(map, SERVER_ERROR);
} }

View File

@ -122,8 +122,8 @@ public class MonitorMessager extends MasterMessager {
} }
} }
public LimitableFieldsModel getLimitableFields(String accessToken){ public LimitableFieldsModel getLimitableFields(String accessToken, String localHostName, String port){
String url = this.baseUrl + "/getLimitableFields"; String url = this.baseUrl + "/getLimitableFields"+"/"+localHostName+"/"+port;
HttpResponse httpResponse = null; HttpResponse httpResponse = null;
try { try {
httpResponse = this.getHttpRequester().sendGet(url, null, httpResponse = this.getHttpRequester().sendGet(url, null,

View File

@ -51,4 +51,8 @@ stopRecordingMessage=Please click stop recording
failed-connect-server=failed to connect server failed-connect-server=failed to connect server
close-proxy-setting=clear the proxy setting close-proxy-setting=clear the proxy setting
custom-mode=custom mode custom-mode=custom mode
target-mode=target mode target-mode=target mode
memoryUsedPercent=Memory(%)
processorTimePercent=Processor Time(%)
userTimePercent=User Time(%)
privilegedTimePercent=Privileged Time(%)

View File

@ -47,4 +47,8 @@ stopRecordingMessage=\u8bf7\u70b9\u51fb\u505c\u6b62\u5f55\u5236
failed-connect-server=\u8FDE\u63A5\u670D\u52A1\u5668\u5931\u8D25\uFF01 failed-connect-server=\u8FDE\u63A5\u670D\u52A1\u5668\u5931\u8D25\uFF01
close-proxy-setting=\u8BF7\u5173\u95ED\u4EE3\u7406 close-proxy-setting=\u8BF7\u5173\u95ED\u4EE3\u7406
custom-mode=\u5E38\u89C4\u6A21\u5F0F custom-mode=\u5E38\u89C4\u6A21\u5F0F
target-mode=\u76EE\u6807\u6A21\u5F0F target-mode=\u76EE\u6807\u6A21\u5F0F
memoryUsedPercent=\u5185\u5B58%
processorTimePercent=\u5904\u7406\u673A\u65F6\u95F4%
userTimePercent=\u7528\u6237\u65F6\u95F4%
privilegedTimePercent=\u6743\u9650\u65F6\u95F4%

View File

@ -172,7 +172,7 @@ function loadLimitableFields(){
script.push(data[i]); script.push(data[i]);
var tbodyNode = document.getElementById("loadConfig2").children[0]; var tbodyNode = document.getElementById("loadConfig2").children[0];
for ( var j = 0; j < script.length; j++) { for ( var j = 0; j < script.length; j++) {
var textNode = document.createTextNode(script[j]); var textNode = document.createTextNode($.i18n.prop(script[j]));
var tdNode = document.createElement("td"); var tdNode = document.createElement("td");
var tdNode2 = document.createElement("td"); var tdNode2 = document.createElement("td");
var inputNode = document.createElement("input"); var inputNode = document.createElement("input");