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;
}
@RequestMapping(value = "/getLimitableFields")
@RequestMapping(value = "/getLimitableFields/{hostName}/{port}")
@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)) {
throw new Bench4QException(400 + "", "not permitted",
"/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) {
try {
MonitorMain monitorMain = getTestMonitorSampler().getMonitorResult(
hostName, port);
hostName, port, this.testPlan.getTestPlanRunId());
System.out.println(MarshalHelper.tryMarshal(monitorMain));
//tell test plan has to stop itself
testPlan.setHasToStop(monitorMain.isTouchLimit());
@ -137,8 +137,8 @@ public class Monitor {
}
}
public void start(UUID testPlanId, String limitModel){
this.getTestMonitorSampler().startMonitor(hostName, port, testPlanId, limitModel);
public void start(){
this.getTestMonitorSampler().startMonitor(hostName, port, this.testPlan.getTestPlanRunId(), this.testPlan.getLimitModel());
}
public List<MonitorResult> createFinishedResult() {

View File

@ -225,6 +225,8 @@ public class TestPlan implements IAggregate {
result = false;
}
}
getTestResultSave().update(TestPlan.this,
collectResult(new Date()));
this.setCurrentStatus(TestPlanStatus.Complete.name());
return result;
}
@ -262,10 +264,9 @@ public class TestPlan implements IAggregate {
testPlanScript.run();
}
//start monitor to check the limit
UUID testPlanIdUuid = UUID.fromString(this.testPlanRunId);
if (getMonitors() != null && this.limitModel != null) {
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.ExceptionLog;
import org.bench4q.master.helper.SessionHelper;
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
import org.bench4q.recorder.httpcapture.generator.HtmlDocumentParser;
import org.bench4q.share.helper.MarshalHelper;
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.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.python.antlr.PythonParser.return_stmt_return;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -36,6 +38,8 @@ public class MonitorResultService {
private TestPlanRepository testPlanRepository;
private SessionHelper sessionHelper;
private LimitableFieldsModel limitableField = null;
@Autowired
private MonitorMessenger monitorMessenger;
private static Logger logger = Logger.getLogger(MonitorResult.class);
private TestPlanRepository getTestPlanRepository() {
@ -199,10 +203,7 @@ public class MonitorResultService {
e.printStackTrace();
}
}
public LimitableFieldsModel getLimitableFields(){
if(limitableField == null){
initLimitableFields();
}
return limitableField;
public LimitableFieldsModel getLimitableFields(String hostName, int port){
return monitorMessenger.getLimitableFields(hostName, port);
}
}

View File

@ -1,7 +1,5 @@
package org.bench4q.master.domain.valueobject.datastatistics;
import java.util.UUID;
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
import org.bench4q.share.models.monitor.MonitorMain;
import org.springframework.beans.factory.annotation.Autowired;
@ -17,11 +15,15 @@ public class TestMonitorSampler {
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) {
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);
}
}

View File

@ -1,7 +1,6 @@
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.MonitorMain;
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;
public interface MonitorMessenger {
public MonitorMain monitorModel(String hostName, int port, String testPlanId);
public MonitorMain monitorModel(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 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.util.Date;
import java.util.UUID;
import org.apache.log4j.Logger;
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.helper.MarshalHelper;
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.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
@ -86,7 +86,7 @@ public class MonitorMessengerImpl implements MonitorMessenger {
public MonitorMain monitorModel(String hostName, int port) {
MonitorMain monitorMain = this.getMonitorModel(hostName, port,
MonitorMain.class, "all");
MonitorMain.class, "/all");
monitorMain.getMemoryModel().setSamplingTime(
monitorMain.getSamplingTime());
monitorMain.getNetworkInterfaceModel().setSamplingTime(
@ -101,7 +101,24 @@ public class MonitorMessengerImpl implements MonitorMessenger {
return monitorMain;
}
public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel) {
public MonitorMain monitorModel(String hostName, int port, String testPlanId) {
MonitorMain monitorMain = this.getMonitorModel(hostName, port,
MonitorMain.class, "/brief/"+testPlanId);
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 boolean startMonitor(String hostName, int port, String testPlanId, String limitModel) {
HttpResponse httpResponse;
try {
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 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.MonitorMain;
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
@ -53,5 +54,21 @@ public class Mock_MonitorMessenger implements MonitorMessenger {
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.XmlRootElement;
@XmlRootElement
@XmlRootElement(name = "limitableFields")
public class LimitableFieldsModel {
private List<String> fields;

View File

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

View File

@ -26,6 +26,7 @@ public class MonitorController extends BaseController {
private MonitorMessager monitorMessager;
private final String port = "5556";
private final String localHostName = "127.0.0.1";
private MonitorService monitorService;
public MonitorMessager getMonitorMessager() {
@ -194,7 +195,7 @@ public class MonitorController extends BaseController {
@ResponseBody
public Map<String, Object> getLimitableFields(@ModelAttribute("accessToken") String accessToken){
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){
return fail(map, SERVER_ERROR);
}

View File

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

View File

@ -52,3 +52,7 @@ failed-connect-server=failed to connect server
close-proxy-setting=clear the proxy setting
custom-mode=custom mode
target-mode=target mode
memoryUsedPercent=Memory(%)
processorTimePercent=Processor Time(%)
userTimePercent=User Time(%)
privilegedTimePercent=Privileged Time(%)

View File

@ -48,3 +48,7 @@ failed-connect-server=\u8FDE\u63A5\u670D\u52A1\u5668\u5931\u8D25\uFF01
close-proxy-setting=\u8BF7\u5173\u95ED\u4EE3\u7406
custom-mode=\u5E38\u89C4\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]);
var tbodyNode = document.getElementById("loadConfig2").children[0];
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 tdNode2 = document.createElement("td");
var inputNode = document.createElement("input");