add function: web get limit field from master
add function: web submit testplan with LimitModel to master and submit LimitModel to monitor
This commit is contained in:
parent
33d937b1e1
commit
937391a995
|
@ -5,12 +5,14 @@ import java.util.UUID;
|
|||
import org.bench4q.master.domain.service.MonitorResultService;
|
||||
import org.bench4q.master.domain.service.UserService;
|
||||
import org.bench4q.master.exception.Bench4QException;
|
||||
import org.bench4q.share.models.master.MonitorPhysicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorNetworkReponseModel;
|
||||
import org.bench4q.share.models.master.MonitorPhysicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorProcessorResponseModel;
|
||||
import org.bench4q.share.models.monitor.LimitableFieldsModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
@ -95,4 +97,14 @@ public class MonitorController extends BaseController {
|
|||
duationBegin);
|
||||
return ret == null ? new MonitorNetworkReponseModel() : ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getLimitableFields")
|
||||
@ResponseBody
|
||||
public LimitableFieldsModel getLimitableFields(@ModelAttribute("accessToken") String accessToken) throws Bench4QException{
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(400 + "", "not permitted",
|
||||
"/networkInfo");
|
||||
}
|
||||
return this.getMonitorResultService().getLimitableFields();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ 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;
|
||||
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.monitor.MemoryModel;
|
||||
import org.bench4q.share.models.monitor.MonitorMain;
|
||||
|
@ -35,6 +35,7 @@ import org.bench4q.share.models.monitor.ProcessModel;
|
|||
import org.bench4q.share.models.monitor.ProcessModelChild;
|
||||
import org.bench4q.share.models.monitor.ProcessorModel;
|
||||
import org.bench4q.share.models.monitor.ProcessorModelChild;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Entity
|
||||
@Table(name = "monitor")
|
||||
|
@ -46,7 +47,13 @@ public class Monitor {
|
|||
private Set<MonitorResult> results;
|
||||
private Logger logger = Logger.getLogger(Monitor.class);
|
||||
private TestPlanFactory testPlanFactory;
|
||||
private MonitorMessenger monitorMessenger;
|
||||
|
||||
@Autowired
|
||||
private void setMonitorMessenger(MonitorMessenger monitorMessenger) {
|
||||
this.monitorMessenger = monitorMessenger;
|
||||
}
|
||||
|
||||
public Monitor() {
|
||||
this.results = new HashSet<MonitorResult>();
|
||||
}
|
||||
|
@ -135,6 +142,10 @@ public class Monitor {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void start(UUID testPlanId, String limitModel){
|
||||
monitorMessenger.startMonitor(hostName, port, testPlanId, limitModel);
|
||||
}
|
||||
|
||||
public List<MonitorResult> createFinishedResult() {
|
||||
try {
|
||||
|
|
|
@ -29,6 +29,8 @@ 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;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.monitor.LimitModel;
|
||||
|
||||
@Entity
|
||||
@Table(name = "testplan")
|
||||
|
@ -49,6 +51,7 @@ public class TestPlan implements IAggregate {
|
|||
private TestPlanRepository repository;
|
||||
private TestPlanEngine testPlanEngine;
|
||||
private boolean hasToStop;
|
||||
private LimitModel limitModel;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
@ -259,6 +262,14 @@ public class TestPlan implements IAggregate {
|
|||
for (TestPlanScript testPlanScript : this.getTestPlanScripts()) {
|
||||
testPlanScript.run();
|
||||
}
|
||||
//start monitor to check the limit
|
||||
UUID testPlanIdUuid = UUID.fromString(this.testPlanRunId);
|
||||
String limitModelString = MarshalHelper.tryMarshal(this.limitModel);
|
||||
if (getMonitors() != null) {
|
||||
for (Monitor monitor : getMonitors()) {
|
||||
monitor.start(testPlanIdUuid, limitModelString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -346,4 +357,13 @@ public class TestPlan implements IAggregate {
|
|||
this.testPlanEngine = testPlanEngine;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public LimitModel getLimitModel() {
|
||||
return limitModel;
|
||||
}
|
||||
|
||||
public void setLimitModel(LimitModel limitModel) {
|
||||
limitModel = limitModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -144,6 +144,7 @@ public class TestPlanFactory {
|
|||
}
|
||||
result.setMonitors(monitors);
|
||||
result.setTestPlanEngine(testPlanEngine);
|
||||
result.setLimitModel(testPlanModel.getLimitModel());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.bench4q.master.domain.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -10,13 +12,15 @@ 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.recorder.httpcapture.generator.HtmlDocumentParser;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.MonitorPhysicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorNetworkReponseModel;
|
||||
import org.bench4q.share.models.master.MonitorPhysicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorProcessorResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorResultBase;
|
||||
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.NetworkInterfaceModel;
|
||||
import org.bench4q.share.models.monitor.PhysicalDiskModel;
|
||||
|
@ -31,6 +35,7 @@ import org.springframework.stereotype.Component;
|
|||
public class MonitorResultService {
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private SessionHelper sessionHelper;
|
||||
private LimitableFieldsModel limitableField = null;
|
||||
private static Logger logger = Logger.getLogger(MonitorResult.class);
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
|
@ -172,4 +177,32 @@ public class MonitorResultService {
|
|||
}
|
||||
}
|
||||
|
||||
private void initLimitableFields(){
|
||||
String pathSep = System.getProperty("file.separator");
|
||||
String limitableFieldsPath = "org" + pathSep + "bench4q" + pathSep
|
||||
+ "master" + pathSep + "config" + pathSep + "MonitorLimitableFields.xml";
|
||||
|
||||
InputStream is = HtmlDocumentParser.class.getClassLoader()
|
||||
.getResourceAsStream(limitableFieldsPath);
|
||||
if (is == null)
|
||||
return;
|
||||
StringBuffer out = new StringBuffer();
|
||||
byte[] b = new byte[4096];
|
||||
int n;
|
||||
try {
|
||||
while ((n = is.read(b)) != -1) {
|
||||
out.append(new String(b, 0, n));
|
||||
}
|
||||
limitableField = MarshalHelper.tryUnmarshal(LimitableFieldsModel.class, out.toString());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public LimitableFieldsModel getLimitableFields(){
|
||||
if(limitableField == null){
|
||||
initLimitableFields();
|
||||
}
|
||||
return limitableField;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.bench4q.master.infrastructure.communication;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.share.models.monitor.MemoryModel;
|
||||
import org.bench4q.share.models.monitor.MonitorMain;
|
||||
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
|
||||
|
@ -20,4 +22,6 @@ public interface MonitorMessenger {
|
|||
|
||||
public ProcessModel process(String hostName, int port);
|
||||
|
||||
public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel) ;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
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;
|
||||
|
@ -9,8 +11,8 @@ 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.MonitorMain;
|
||||
import org.bench4q.share.models.monitor.MemoryModel;
|
||||
import org.bench4q.share.models.monitor.MonitorMain;
|
||||
import org.bench4q.share.models.monitor.NetworkInterfaceModel;
|
||||
import org.bench4q.share.models.monitor.PhysicalDiskModel;
|
||||
import org.bench4q.share.models.monitor.ProcessModel;
|
||||
|
@ -98,4 +100,24 @@ public class MonitorMessengerImpl implements MonitorMessenger {
|
|||
|
||||
return monitorMain;
|
||||
}
|
||||
|
||||
public boolean startMonitor(String hostName, int port, UUID testPlanId, String limitModel) {
|
||||
HttpResponse httpResponse;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendPutXml(
|
||||
buildUrl(hostName, port, "/monitor/submitLimit/" + testPlanId)
|
||||
, limitModel, null);
|
||||
if (HttpRequester.isInvalidResponse(httpResponse)) {
|
||||
logger.info("The httpResponse is invalid ");
|
||||
return false;
|
||||
}
|
||||
return testPlanId.toString().equals(httpResponse.getContent());
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<limitableFields>
|
||||
<fieldList>
|
||||
<field></field>>
|
||||
</fieldList>>
|
||||
</limitableFields>>
|
|
@ -1,6 +1,7 @@
|
|||
package stubs;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.infrastructure.communication.MonitorMessenger;
|
||||
import org.bench4q.share.models.monitor.MemoryModel;
|
||||
|
@ -46,4 +47,11 @@ public class Mock_MonitorMessenger implements MonitorMessenger {
|
|||
return monitorModel(hostName, port).getProcessModel();
|
||||
}
|
||||
|
||||
public boolean startMonitor(String hostName, int port, UUID testPlanId,
|
||||
String limitModel) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class MainController {
|
|||
return new LimitableFieldsModel();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{testPlanId}", method = RequestMethod.PUT)
|
||||
@RequestMapping(value = "/submitLimit/{testPlanId}", method = RequestMethod.PUT)
|
||||
@ResponseBody
|
||||
public String submitLimit(@PathVariable UUID testPlanId,
|
||||
@RequestBody LimitModel limits) {
|
||||
|
@ -42,7 +42,7 @@ public class MainController {
|
|||
return testPlanId.toString();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{testPlanId}", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/brief/{testPlanId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
MonitorMain brief(@PathVariable UUID testPlanId) throws SigarException,
|
||||
InterruptedException, ExecutionException {
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
package org.bench4q.share.models.master;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.bench4q.share.models.monitor.LimitModel;
|
||||
|
||||
@XmlRootElement(name = "testPlanModel")
|
||||
public class TestPlanModel {
|
||||
private String name = "";
|
||||
private int sampleCycleInSeconds;
|
||||
private List<RunningScriptModel> runningScriptModels;
|
||||
private List<MonitorModel> monitorModels;
|
||||
private LimitModel limitModel;
|
||||
|
||||
@XmlElement
|
||||
public String getName() {
|
||||
|
@ -51,4 +55,13 @@ public class TestPlanModel {
|
|||
this.sampleCycleInSeconds = sampleCycleInSeconds;
|
||||
}
|
||||
|
||||
@XmlElement(name = "limitModel")
|
||||
public LimitModel getLimitModel() {
|
||||
return limitModel;
|
||||
}
|
||||
|
||||
public void setLimitModel(LimitModel limitModel) {
|
||||
this.limitModel = limitModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package org.bench4q.share.models.monitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class LimitModel {
|
||||
@XmlElementWrapper
|
||||
@XmlElement
|
||||
private List<ParameterModel> params;
|
||||
|
||||
public List<ParameterModel> getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(List<ParameterModel> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
public static class ParameterModel {
|
||||
private String name;
|
||||
private double limit;
|
||||
|
||||
@XmlElement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public double getLimit() {
|
||||
return limit;
|
||||
}
|
||||
|
||||
public void setLimit(double limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package org.bench4q.share.models.monitor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "limitableFields")
|
||||
public class LimitableFieldsModel {
|
||||
private List<String> fields;
|
||||
|
||||
@XmlElementWrapper(name = "fieldList")
|
||||
@XmlElement(name = "field")
|
||||
public List<String> getFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public void setFields(List<String> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -3,10 +3,12 @@ package org.bench4q.web.api;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorNetworkReponseModel;
|
||||
import org.bench4q.share.models.master.MonitorPhysicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorProcessorResponseModel;
|
||||
import org.bench4q.share.models.monitor.LimitableFieldsModel;
|
||||
import org.bench4q.web.masterMessager.MonitorMessager;
|
||||
import org.bench4q.web.model.ResultModel;
|
||||
import org.bench4q.web.service.MonitorService;
|
||||
|
@ -187,4 +189,18 @@ public class MonitorController extends BaseController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getLimitableFields")
|
||||
@ResponseBody
|
||||
public Map<String, Object> getLimitableFields(@ModelAttribute("accessToken") String accessToken){
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
LimitableFieldsModel limitableFieldsModel = this.getMonitorMessager().getLimitableFields(accessToken);
|
||||
if(limitableFieldsModel == null){
|
||||
return fail(map, SERVER_ERROR);
|
||||
}
|
||||
success(map);
|
||||
map.put("limitableFields", limitableFieldsModel);
|
||||
return map;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package org.bench4q.web.masterMessager;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.MonitorMemoryResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorNetworkReponseModel;
|
||||
import org.bench4q.share.models.master.MonitorPhysicalDiskResponseModel;
|
||||
import org.bench4q.share.models.master.MonitorProcessorResponseModel;
|
||||
import org.bench4q.share.models.monitor.LimitableFieldsModel;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
@ -120,6 +122,25 @@ public class MonitorMessager extends MasterMessager {
|
|||
}
|
||||
}
|
||||
|
||||
public LimitableFieldsModel getLimitableFields(String accessToken){
|
||||
String url = this.baseUrl + "/getLimitableFields";
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
httpResponse = this.getHttpRequester().sendGet(url, null,
|
||||
makeAccessTockenMap(accessToken));
|
||||
if (!validateHttpResponse(httpResponse)) {
|
||||
this.handleInvalidatedResponse(url);
|
||||
return null;
|
||||
}
|
||||
LimitableFieldsModel limitableFieldsModel = MarshalHelper
|
||||
.unmarshal(LimitableFieldsModel.class,
|
||||
httpResponse.getContent());
|
||||
return limitableFieldsModel;
|
||||
}catch (Exception e) {
|
||||
this.handleException(httpResponse, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private Map<String, String> createParmsMap(String testPlanRunId,
|
||||
String hostName, String port, String duationBegin) {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
|
|
|
@ -2,12 +2,14 @@ package org.bench4q.web.model;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.share.models.monitor.LimitModel;
|
||||
|
||||
public class TestPlanRequestModel {
|
||||
|
||||
private List<String> ipList;
|
||||
private List<WebScriptModel> scriptList;
|
||||
private String testPlanName;
|
||||
|
||||
private LimitModel limitModel;
|
||||
|
||||
public TestPlanRequestModel() {
|
||||
|
||||
|
@ -47,4 +49,12 @@ public class TestPlanRequestModel {
|
|||
public void setScriptList(List<WebScriptModel> scriptList) {
|
||||
this.scriptList = scriptList;
|
||||
}
|
||||
|
||||
public LimitModel getLimitModel() {
|
||||
return limitModel;
|
||||
}
|
||||
|
||||
public void setLimitModel(LimitModel limitModel) {
|
||||
this.limitModel = limitModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ public class TestPlanService {
|
|||
} else
|
||||
testPlanModel.setMonitorModels(new ArrayList<MonitorModel>());
|
||||
|
||||
testPlanModel.setLimitModel(testPlan.getLimitModel());
|
||||
return testPlanModel;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue