add function filter type of behavior and timer

This commit is contained in:
hmm 2014-09-02 10:57:50 +08:00
parent f3816e8304
commit 3c46fdda89
20 changed files with 230 additions and 116 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd"> --> <!DOCTYPE ui SYSTEM "../../dtd/ui.dtd">
<ui> <ui>
<plugin name="Http"> <plugin name="Http">
<params> <params>

View File

@ -102,14 +102,14 @@ public class ScriptController extends BaseController {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false, return buildReponseModel(false,
"has no power for recording script!!!", "", -1, null, null, "has no power for recording script!!!", "", -1, null, null,
null,null); null);
} }
Port port = new Port(); Port port = new Port();
synchronized (PORT_LOCK) { synchronized (PORT_LOCK) {
port = this.getPortPoolService().getAPortNotInUse(); port = this.getPortPoolService().getAPortNotInUse();
if (port == null) { if (port == null) {
return buildReponseModel(false, "port is in use!", "", -1, return buildReponseModel(false, "port is in use!", "", -1,
null, null, null,null); null, null, null);
} }
} }
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
@ -118,7 +118,7 @@ public class ScriptController extends BaseController {
return buildReponseModel(true, "", this.getScriptCapturer() return buildReponseModel(true, "", this.getScriptCapturer()
.getIpHttpCaptureServerAdress(), port.getPort(), null, null, .getIpHttpCaptureServerAdress(), port.getPort(), null, null,
uuid.toString(),null); uuid.toString());
} }
@RequestMapping(value = "/startScriptRecording", method = { @RequestMapping(value = "/startScriptRecording", method = {
@ -129,13 +129,13 @@ public class ScriptController extends BaseController {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) { if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false, return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null, "has no power for stopScriptCapture!!!", "", -1, null,
null, null,null); null, null);
} }
this.getScriptCapturer().startRecording(port); this.getScriptCapturer().startRecording(port);
return buildReponseModel(true, "RecordServer stop", "", port, null, return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID,null); null, fileNameUUID);
} }
private String buildScriptSavePath() { private String buildScriptSavePath() {
@ -158,7 +158,7 @@ public class ScriptController extends BaseController {
if (!checkScope(UserService.NORAML_AUTHENTICATION)) { if (!checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false, return buildReponseModel(false,
"has no power for stopScriptCapture!!!", "", -1, null, "has no power for stopScriptCapture!!!", "", -1, null,
null, null,null); null, null);
} }
this.getScriptCapturer().stopCurrentRecord(port); this.getScriptCapturer().stopCurrentRecord(port);
@ -167,7 +167,7 @@ public class ScriptController extends BaseController {
} }
return buildReponseModel(true, "RecordServer stop", "", port, null, return buildReponseModel(true, "RecordServer stop", "", port, null,
null, fileNameUUID,null); null, fileNameUUID);
} }
@RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET, @RequestMapping(value = "/saveScriptToDB", method = { RequestMethod.GET,
@ -179,14 +179,14 @@ public class ScriptController extends BaseController {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildReponseModel(false, return buildReponseModel(false,
"saveScriptToDB check your scope fail!", "", -1, null, "saveScriptToDB check your scope fail!", "", -1, null,
null, null,null); null, null);
} }
File file = new File(buildScriptSavePath() File file = new File(buildScriptSavePath()
+ System.getProperty("file.separator") + fileNameUUID + ".xml"); + System.getProperty("file.separator") + fileNameUUID + ".xml");
if (!file.exists()) { if (!file.exists()) {
return buildReponseModel(false, "no that script", null, -1, null, return buildReponseModel(false, "no that script", null, -1, null,
null, fileNameUUID,null); null, fileNameUUID);
} }
try { try {
String content = FileUtils.readFileToString(file); String content = FileUtils.readFileToString(file);
@ -195,10 +195,10 @@ public class ScriptController extends BaseController {
this.getPrincipal().getId(), content, null); this.getPrincipal().getId(), content, null);
// this.getUserService().add // this.getUserService().add
return buildReponseModel(success, "Save to DataBase!!", "", port, return buildReponseModel(success, "Save to DataBase!!", "", port,
null, null, null,null); null, null, null);
} catch (Exception e) { } catch (Exception e) {
return buildReponseModel(false, "exception when read from file", return buildReponseModel(false, "exception when read from file",
null, -1, null, null, fileNameUUID,null); null, -1, null, null, fileNameUUID);
} }
} }
@ -218,12 +218,12 @@ public class ScriptController extends BaseController {
boolean success = this.getScriptService().saveScript(scriptName, boolean success = this.getScriptService().saveScript(scriptName,
this.getPrincipal().getId(), scenarioModel, paramFiles); this.getPrincipal().getId(), scenarioModel, paramFiles);
logger.info("upload script:" + scenarioModel); logger.info("upload script:" + scenarioModel);
return buildReponseModel(success, null, null, -1, null, null, null,null); return buildReponseModel(success, null, null, -1, null, null, null);
} catch (Exception e) { } catch (Exception e) {
this.logger.error(ExceptionLog.getStackTrace(e)); this.logger.error(ExceptionLog.getStackTrace(e));
return buildReponseModel(false, return buildReponseModel(false,
"The script is not in the right format", null, -1, null, "The script is not in the right format", null, -1, null,
null, null,null); null, null);
} }
} }
@ -238,23 +238,9 @@ public class ScriptController extends BaseController {
this.getPrincipal()); this.getPrincipal());
return this.buildReponseModel(true, null, null, 0, return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null,null); dealWithCollection(scripts), null, null);
} }
@RequestMapping(value = "/loadFilterTypeList", method = { RequestMethod.POST,
RequestMethod.GET })
@ResponseBody
public OperateScriptServerResponseModel loadFilterTypeList() {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return null;
}
String[] filterTypeList = this.getScriptService().loadFilterTypeList();
return this.buildReponseModel(true, null, null, 0,
null, null, null,filterTypeList);
}
@RequestMapping(value = "/queryScriptsByDate", method = RequestMethod.POST) @RequestMapping(value = "/queryScriptsByDate", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public OperateScriptServerResponseModel queryScriptsByDate( public OperateScriptServerResponseModel queryScriptsByDate(
@ -266,7 +252,7 @@ public class ScriptController extends BaseController {
.queryScriptsByCreateTime(startDate, endDate, .queryScriptsByCreateTime(startDate, endDate,
this.getPrincipal()); this.getPrincipal());
return this.buildReponseModel(true, null, null, 0, return this.buildReponseModel(true, null, null, 0,
dealWithCollection(scripts), null, null,null); dealWithCollection(scripts), null, null);
} }
private List<ScriptModel> dealWithCollection(Collection<Script> scripts) { private List<ScriptModel> dealWithCollection(Collection<Script> scripts) {
@ -287,7 +273,7 @@ public class ScriptController extends BaseController {
} }
return this.buildReponseModel(true, null, null, 0, null, return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService() BusinessModelMapFactory.toModel(this.getScriptService()
.getScript(scriptId)), null,null); .getScript(scriptId)), null);
} }
@RequestMapping(value = "/queryScriptByName", method = { RequestMethod.GET, @RequestMapping(value = "/queryScriptByName", method = { RequestMethod.GET,
@ -301,7 +287,7 @@ public class ScriptController extends BaseController {
} }
return this.buildReponseModel(true, null, null, 0, null, return this.buildReponseModel(true, null, null, 0, null,
BusinessModelMapFactory.toModel(this.getScriptService() BusinessModelMapFactory.toModel(this.getScriptService()
.getScriptByName(name)), null,null); .getScriptByName(name)), null);
} }
@RequestMapping(value = "/deleteScript", method = { RequestMethod.GET, @RequestMapping(value = "/deleteScript", method = { RequestMethod.GET,
@ -315,7 +301,7 @@ public class ScriptController extends BaseController {
return this.buildReponseModel( return this.buildReponseModel(
this.getScriptService().deleteScript(scriptId, this.getScriptService().deleteScript(scriptId,
this.getPrincipal().getId()), "", "", 0, null, null, this.getPrincipal().getId()), "", "", 0, null, null,
null,null); null);
} }
@RequestMapping(value = "updateScript/{scriptId}", method = { @RequestMapping(value = "updateScript/{scriptId}", method = {
@ -330,7 +316,7 @@ public class ScriptController extends BaseController {
return this.buildReponseModel( return this.buildReponseModel(
this.getScriptService().alterScriptContent(scriptId, this.getScriptService().alterScriptContent(scriptId,
this.getPrincipal().getId(),content,scriptName), "", "", 0, null, this.getPrincipal().getId(),content,scriptName), "", "", 0, null,
null, null,null); null, null);
} }
// @RequestMapping(value = "updateScript/{scriptId}", method = { // @RequestMapping(value = "updateScript/{scriptId}", method = {
@ -361,7 +347,7 @@ public class ScriptController extends BaseController {
private OperateScriptServerResponseModel buildReponseModel( private OperateScriptServerResponseModel buildReponseModel(
boolean isSuccess, String failCauseString, String hostName, boolean isSuccess, String failCauseString, String hostName,
int port, List<ScriptModel> scriptModels, ScriptModel scriptModel, int port, List<ScriptModel> scriptModels, ScriptModel scriptModel,
String fileName,String[] filterTypeList) { String fileName) {
OperateScriptServerResponseModel responseModel = new OperateScriptServerResponseModel(); OperateScriptServerResponseModel responseModel = new OperateScriptServerResponseModel();
responseModel.setSuccess(isSuccess); responseModel.setSuccess(isSuccess);
responseModel.setFailCauseString(failCauseString); responseModel.setFailCauseString(failCauseString);
@ -373,7 +359,6 @@ public class ScriptController extends BaseController {
scriptModels.add(scriptModel); scriptModels.add(scriptModel);
} }
responseModel.setScriptModels(scriptModels); responseModel.setScriptModels(scriptModels);
responseModel.setFilterTypeList(filterTypeList);
return responseModel; return responseModel;
} }

View File

@ -21,6 +21,7 @@ import org.bench4q.master.exception.Bench4QException;
import org.bench4q.master.exception.Bench4QRunTimeException; import org.bench4q.master.exception.Bench4QRunTimeException;
import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.ScriptHandleModel;
import org.bench4q.share.models.master.TestPlanScriptBriefResultModel; import org.bench4q.share.models.master.TestPlanScriptBriefResultModel;
import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanModel;
@ -206,13 +207,13 @@ public class TestPlanController extends BaseController {
@ResponseBody @ResponseBody
public TestPlanResponseModel loadTestPlans() { public TestPlanResponseModel loadTestPlans() {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildTestPlanResponseModel(false, "no scope", null); return buildTestPlanResponseModel(false, "no scope", null,null);
} }
List<TestPlan> testPlanDBs = this.testPlanService.loadTestPlans(this List<TestPlan> testPlanDBs = this.testPlanService.loadTestPlans(this
.getPrincipal()); .getPrincipal());
return testPlanDBs == null ? buildTestPlanResponseModel(false, return testPlanDBs == null ? buildTestPlanResponseModel(false,
"exception", null) : buildTestPlanResponseModel(true, null, "exception", null,null) : buildTestPlanResponseModel(true, null,
testPlanDBs); testPlanDBs,null);
} }
@RequestMapping(value = "/queryTestPlan/{runId}", method = RequestMethod.GET) @RequestMapping(value = "/queryTestPlan/{runId}", method = RequestMethod.GET)
@ -233,14 +234,14 @@ public class TestPlanController extends BaseController {
@ResponseBody @ResponseBody
public TestPlanResponseModel removeTestPlanFromPool(int testPlanId) { public TestPlanResponseModel removeTestPlanFromPool(int testPlanId) {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) { if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
return buildTestPlanResponseModel(false, "no scope", null); return buildTestPlanResponseModel(false, "no scope", null,null);
} }
return buildTestPlanResponseModel( return buildTestPlanResponseModel(
this.testPlanService.removeTestPlanInDB(testPlanId), null, null); this.testPlanService.removeTestPlanInDB(testPlanId), null, null,null);
} }
private TestPlanResponseModel buildTestPlanResponseModel(boolean success, private TestPlanResponseModel buildTestPlanResponseModel(boolean success,
String failCause, List<TestPlan> testPlanDBs) { String failCause, List<TestPlan> testPlanDBs,String[] filterTypeList) {
TestPlanResponseModel result = new TestPlanResponseModel(); TestPlanResponseModel result = new TestPlanResponseModel();
result.setSuccess(success); result.setSuccess(success);
result.setFailCause(failCause); result.setFailCause(failCause);
@ -251,6 +252,7 @@ public class TestPlanController extends BaseController {
} }
} }
result.setTestPlanDBModels(modelList); result.setTestPlanDBModels(modelList);
result.setFilterTypeList(filterTypeList);
return result; return result;
} }
@ -312,7 +314,7 @@ public class TestPlanController extends BaseController {
guardIsTheOwner(testPlanId); guardIsTheOwner(testPlanId);
return buildTestPlanResponseModel( return buildTestPlanResponseModel(
this.getTestPlanRunner().stop(testPlanId), "", this.getTestPlanRunner().stop(testPlanId), "",
Collections.<TestPlan> emptyList()); Collections.<TestPlan> emptyList(),null);
} }
private void guardIsTheOwner(UUID testPlanId) { private void guardIsTheOwner(UUID testPlanId) {
@ -322,4 +324,18 @@ public class TestPlanController extends BaseController {
throw new Bench4QRunTimeException("You are not the owner"); throw new Bench4QRunTimeException("You are not the owner");
} }
} }
@RequestMapping(value = "/loadFilterTypeList", method = { RequestMethod.POST,
RequestMethod.GET })
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public TestPlanResponseModel loadFilterTypeList() throws Bench4QException {
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
throw new Bench4QException(HAVE_NO_POWER,
"You don't have enough power to get filter type list!",
"/loadFilterTypeList");
}
String[] filterTypeList = this.getTestPlanService().loadFilterTypeList();
return this.buildTestPlanResponseModel(true, null, null,filterTypeList);
}
} }

View File

@ -180,7 +180,7 @@ public class RunningAgentDB implements RunningAgentInterface {
Script script2 = this.getTestPlanScript().getScript(); Script script2 = this.getTestPlanScript().getScript();
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
.tryUnmarshal(RunScenarioModel.class, .tryUnmarshal(RunScenarioModel.class,
script2.getScriptContent()); script2.getFilteredScriptCnt());
runScenarioModel.setPoolSize(getLoadInUse()); runScenarioModel.setPoolSize(getLoadInUse());
RunScenarioResultModel runScenarioResultModel = this RunScenarioResultModel runScenarioResultModel = this
.getAgentMessenger().submitScenrioWithParams(this.getAgent(), .getAgentMessenger().submitScenrioWithParams(this.getAgent(),

View File

@ -27,6 +27,7 @@ public class Script {
private int id; private int id;
private String name; private String name;
private String scriptContent; private String scriptContent;
private String filteredScriptCnt;
private int behaviorCount; private int behaviorCount;
private Date createDateTime; private Date createDateTime;
private User user; private User user;
@ -134,4 +135,12 @@ public class Script {
} }
return Arrays.asList(folder.listFiles()); return Arrays.asList(folder.listFiles());
} }
public String getFilteredScriptCnt() {
return filteredScriptCnt;
}
public void setFilteredScriptCnt(String filteredScriptCnt) {
this.filteredScriptCnt = filteredScriptCnt;
}
} }

View File

@ -1,6 +1,7 @@
package org.bench4q.master.domain.factory; package org.bench4q.master.domain.factory;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
@ -16,6 +17,7 @@ import org.bench4q.master.domain.entity.Monitor;
import org.bench4q.master.domain.entity.MonitorResult; import org.bench4q.master.domain.entity.MonitorResult;
import org.bench4q.master.domain.entity.PlanedConfig; import org.bench4q.master.domain.entity.PlanedConfig;
import org.bench4q.master.domain.entity.RunningAgentDB; import org.bench4q.master.domain.entity.RunningAgentDB;
import org.bench4q.master.domain.entity.Script;
import org.bench4q.master.domain.entity.TestPlan; import org.bench4q.master.domain.entity.TestPlan;
import org.bench4q.master.domain.entity.TestPlanScript; import org.bench4q.master.domain.entity.TestPlanScript;
import org.bench4q.master.domain.entity.TestPlanScriptResult; import org.bench4q.master.domain.entity.TestPlanScriptResult;
@ -28,12 +30,20 @@ import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.ParameterModel;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.ScriptFilterOptionsModel;
import org.bench4q.share.models.agent.scriptrecord.BatchModel;
import org.bench4q.share.models.agent.scriptrecord.BehaviorModel;
import org.bench4q.share.models.agent.scriptrecord.PageModel;
import org.bench4q.share.models.agent.scriptrecord.UsePluginModel;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanModel;
import org.bench4q.share.models.master.TestScriptConfig; import org.bench4q.share.models.master.TestScriptConfig;
import org.bench4q.share.models.master.statistics.ScriptResultModel; import org.bench4q.share.models.master.statistics.ScriptResultModel;
import org.bench4q.share.models.monitor.MonitorMain; import org.bench4q.share.models.monitor.MonitorMain;
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;
@ -117,7 +127,7 @@ public class TestPlanFactory {
testPlanScripts.add(createATestPlanScriptWithoutId( testPlanScripts.add(createATestPlanScriptWithoutId(
runningScriptModel.getRequireLoad(), runningScriptModel.getRequireLoad(),
runningScriptModel.getScriptId(), runningScriptModel.getScriptId(),
runningScriptModel.getConfig(), result)); runningScriptModel.getConfig(), result, runningScriptModel.getScriptFilterOptionsModel()));
} }
result.setRequiredLoad(requiredLoad); result.setRequiredLoad(requiredLoad);
result.setTestPlanScripts(testPlanScripts); result.setTestPlanScripts(testPlanScripts);
@ -140,15 +150,59 @@ public class TestPlanFactory {
} }
public TestPlanScript createATestPlanScriptWithoutId(int requireLoad, public TestPlanScript createATestPlanScriptWithoutId(int requireLoad,
int scriptId, TestScriptConfig config, TestPlan testPlanDB) { int scriptId, TestScriptConfig config, TestPlan testPlanDB, ScriptFilterOptionsModel scriptFilterOptionsModel) {
TestPlanScript testPlanScript = new TestPlanScript(); TestPlanScript testPlanScript = new TestPlanScript();
testPlanScript.setRequireLoad(requireLoad); testPlanScript.setRequireLoad(requireLoad);
testPlanScript.setScript(this.getScriptService().getScript(scriptId)); //filter the script
testPlanScript.setScript(createAScriptWithFilter(scriptFilterOptionsModel, this.getScriptService().getScript(scriptId)));
testPlanScript.setPlanedConfig(createAPlanedConfigWithoutId(config)); testPlanScript.setPlanedConfig(createAPlanedConfigWithoutId(config));
testPlanScript.setTestPlan(testPlanDB); testPlanScript.setTestPlan(testPlanDB);
return testPlanScript; return testPlanScript;
} }
private Script createAScriptWithFilter(ScriptFilterOptionsModel scriptFilterOptionsModel, Script script){
RunScenarioModel runScenarioModel = (RunScenarioModel) MarshalHelper
.tryUnmarshal(RunScenarioModel.class,
script.getFilteredScriptCnt());
List<String> filterPluginId = new ArrayList<String>();
if(scriptFilterOptionsModel.isFilterTimer()){
for(UsePluginModel pluginModel: runScenarioModel.getUsePlugins()){
if(pluginModel.getName().equals("ConstantTimer")){
filterPluginId.add(pluginModel.getId());
}
}
}
if(scriptFilterOptionsModel.getFilterTypeMatches() != null && !scriptFilterOptionsModel.getFilterTypeMatches().equals("")){
for(PageModel pageModel: runScenarioModel.getPages()){
for(BatchModel batchModel : pageModel.getBatches()){
for(BehaviorModel behaviorModel: batchModel.getBehaviors()){
if(filterPluginId.contains(behaviorModel.getUse()) || isFilterType(scriptFilterOptionsModel.getFilterTypeMatches(), behaviorModel)){
batchModel.getBehaviors().remove(behaviorModel);
}
}
}
}
}
String contentString = MarshalHelper.tryMarshal(runScenarioModel);
script.setFilteredScriptCnt(contentString);
return script;
}
private boolean isFilterType(String filterTypeMatch, BehaviorModel behaviorModel){
for(ParameterModel parameterModel:behaviorModel.getParameters()){
if(parameterModel.getKey().equals("expResCnttype")){
if(parameterModel.getValue().matches(filterTypeMatch)){
return true;
}else{
return false;
}
}
}
return false;
}
private PlanedConfig createAPlanedConfigWithoutId(TestScriptConfig config) { private PlanedConfig createAPlanedConfigWithoutId(TestScriptConfig config) {
PlanedConfig planedConfig = new PlanedConfig(); PlanedConfig planedConfig = new PlanedConfig();
planedConfig.setWarmUp(config.getWarmUp()); planedConfig.setWarmUp(config.getWarmUp());

View File

@ -28,8 +28,6 @@ public class ScriptService {
private UserRepository userRepository; private UserRepository userRepository;
private Logger logger = Logger.getLogger(ScriptService.class); private Logger logger = Logger.getLogger(ScriptService.class);
private Properties properties = null;
private ScriptRepositoty getScriptRepositoty() { private ScriptRepositoty getScriptRepositoty() {
return scriptRepositoty; return scriptRepositoty;
} }
@ -82,11 +80,6 @@ public class ScriptService {
return this.getScriptRepositoty().loadEntities(user); return this.getScriptRepositoty().loadEntities(user);
} }
public String[] loadFilterTypeList() {
return getFilterTypeList();
}
public List<Script> queryScriptsByCreateTime(Date startDate, Date endDate, public List<Script> queryScriptsByCreateTime(Date startDate, Date endDate,
User user) { User user) {
return this.getScriptRepositoty().getWith( return this.getScriptRepositoty().getWith(
@ -131,19 +124,4 @@ public class ScriptService {
return this.getScriptRepositoty().update(script); return this.getScriptRepositoty().update(script);
} }
private String[] getFilterTypeList(){
if(properties == null){
try {
properties = new Properties();
InputStream inputStream = ScriptService.class.getClassLoader()
.getResourceAsStream(
"org/bench4q/master/config/FilterType.properties");
properties.load(inputStream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return properties.getProperty("filter.type.list","").split(",");
}
} }

View File

@ -1,8 +1,11 @@
package org.bench4q.master.domain.service; package org.bench4q.master.domain.service;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Properties;
import java.util.UUID; import java.util.UUID;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -26,6 +29,8 @@ public class TestPlanService {
private BusinessModelMapFactory businessMapFactory; private BusinessModelMapFactory businessMapFactory;
private TestPlanRepository testPlanRepository; private TestPlanRepository testPlanRepository;
private Properties properties = null;
private TestPlanRepository getTestPlanRepository() { private TestPlanRepository getTestPlanRepository() {
return testPlanRepository; return testPlanRepository;
} }
@ -96,4 +101,23 @@ public class TestPlanService {
public Collection<TestPlan> loadAllRunningTestPlans() { public Collection<TestPlan> loadAllRunningTestPlans() {
return this.getTestPlanRepository().loadRunningTestPlans(); return this.getTestPlanRepository().loadRunningTestPlans();
} }
public String[] loadFilterTypeList() {
return getFilterTypeList();
}
private String[] getFilterTypeList(){
if(properties == null){
try {
properties = new Properties();
InputStream inputStream = ScriptService.class.getClassLoader()
.getResourceAsStream(
"org/bench4q/master/config/FilterType.properties");
properties.load(inputStream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return properties.getProperty("filter.type.list","").split(",");
}
} }

View File

@ -16,7 +16,6 @@ public class RunScenarioModel {
private int poolSize; private int poolSize;
private List<UsePluginModel> usePlugins; private List<UsePluginModel> usePlugins;
private List<PageModel> pages; private List<PageModel> pages;
private List<String> filteredTypes;
private TestScheduleModel scheduleModel; private TestScheduleModel scheduleModel;
@XmlElement @XmlElement
public int getPoolSize() { public int getPoolSize() {
@ -61,13 +60,4 @@ public class RunScenarioModel {
this.setPages(new LinkedList<PageModel>()); this.setPages(new LinkedList<PageModel>());
} }
@XmlElementWrapper(name = "filteredTypes")
@XmlElement(name = "filteredType")
public List<String> getFilteredTypes() {
return filteredTypes;
}
public void setFilteredTypes(List<String> filteredTypes) {
this.filteredTypes = filteredTypes;
}
} }

View File

@ -0,0 +1,27 @@
package org.bench4q.share.models.agent;
import java.util.List;
public class ScriptFilterOptionsModel {
private boolean isFilterTimer = false;
private String filterTypeMatches;
public boolean isFilterTimer() {
return isFilterTimer;
}
public void setFilterTimer(boolean isFilterTimer) {
this.isFilterTimer = isFilterTimer;
}
public String getFilterTypeMatches() {
return filterTypeMatches;
}
public void setFilterTypeMatches(String filterTypeMatches) {
this.filterTypeMatches = filterTypeMatches;
}
}

View File

@ -19,7 +19,6 @@ public class OperateScriptServerResponseModel {
private int port; private int port;
private String fileName; private String fileName;
private List<ScriptModel> scriptModels; private List<ScriptModel> scriptModels;
private String[] filterTypeList;
@XmlElement @XmlElement
public boolean isSuccess() { public boolean isSuccess() {
@ -75,13 +74,5 @@ public class OperateScriptServerResponseModel {
this.scriptModels = scriptModels; this.scriptModels = scriptModels;
} }
@XmlElement
public String[] getFilterTypeList() {
return filterTypeList;
}
public void setFilterTypeList(String[] filterTypeList) {
this.filterTypeList = filterTypeList;
}
} }

View File

@ -9,12 +9,14 @@ import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.ScriptFilterOptionsModel;
@XmlRootElement(name = "runningScripModel") @XmlRootElement(name = "runningScripModel")
public class RunningScriptModel { public class RunningScriptModel {
private int scriptId; private int scriptId;
private int requireLoad; private int requireLoad;
private TestScriptConfig config; private TestScriptConfig config;
private ScriptFilterOptionsModel scriptFilterOptionsModel;
private RunScenarioModel scenarioModel; private RunScenarioModel scenarioModel;
private String scriptName; private String scriptName;
private boolean finished; private boolean finished;
@ -92,4 +94,13 @@ public class RunningScriptModel {
public void setTestPlanID(UUID testPlanID) { public void setTestPlanID(UUID testPlanID) {
this.testPlanID = testPlanID; this.testPlanID = testPlanID;
} }
@XmlElement
public ScriptFilterOptionsModel getScriptFilterOptionsModel() {
return scriptFilterOptionsModel;
}
public void setScriptFilterOptionsModel(ScriptFilterOptionsModel scriptFilterOptionsModel) {
this.scriptFilterOptionsModel = scriptFilterOptionsModel;
}
} }

View File

@ -11,6 +11,7 @@ public class TestPlanResponseModel {
private boolean success; private boolean success;
private String failCause; private String failCause;
private List<TestPlanDBModel> testPlanDBModels; private List<TestPlanDBModel> testPlanDBModels;
private String[] filterTypeList;
@XmlElement @XmlElement
public boolean isSuccess() { public boolean isSuccess() {
@ -40,4 +41,12 @@ public class TestPlanResponseModel {
this.testPlanDBModels = testPlanDBModels; this.testPlanDBModels = testPlanDBModels;
} }
public String[] getFilterTypeList() {
return filterTypeList;
}
public void setFilterTypeList(String[] filterTypeList) {
this.filterTypeList = filterTypeList;
}
} }

View File

@ -359,21 +359,6 @@ public class ScriptController extends BaseController {
return map; return map;
} }
@RequestMapping("loadFilterTypeList")
public @ResponseBody
Map<String, Object> loadFilterTypeList(HttpServletRequest request,
@ModelAttribute("accessToken") String accessToken) {
OperateScriptServerResponseModel responseModel = this.getScriptMessager().loadFilterTypeList(accessToken);
Map<String,Object> map = new HashMap<String, Object>();
if(responseModel.isSuccess()){
map.put("filterTypeList", responseModel.getFilterTypeList());
success(map);
}else{
fail(map, responseModel.getFailCauseString());
}
return map;
}
private void updateRunScenarioModel(RunScenarioModel runScenarioModel) { private void updateRunScenarioModel(RunScenarioModel runScenarioModel) {
List<BehaviorModel> behaviorModels = new LinkedList<BehaviorModel>(); List<BehaviorModel> behaviorModels = new LinkedList<BehaviorModel>();
for (PageModel pageModel : runScenarioModel.getPages()) { for (PageModel pageModel : runScenarioModel.getPages()) {

View File

@ -9,6 +9,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -16,6 +17,7 @@ import org.bench4q.share.helper.ExceptionLog;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel; import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.OperateScriptServerResponseModel;
import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.ScriptHandleModel;
import org.bench4q.share.models.master.TestPlanDBModel; import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanModel; import org.bench4q.share.models.master.TestPlanModel;
@ -418,4 +420,19 @@ public class TestPlanController extends BaseController {
return fail(map, testPlanResponseModel.getFailCause()); return fail(map, testPlanResponseModel.getFailCause());
} }
} }
@RequestMapping("loadFilterTypeList")
public @ResponseBody
Map<String, Object> loadFilterTypeList(HttpServletRequest request,
@ModelAttribute("accessToken") String accessToken) {
TestPlanResponseModel responseModel = this.getTestPlanMessager().loadFilterTypeList(accessToken);
Map<String,Object> map = new HashMap<String, Object>();
if(responseModel.isSuccess()){
map.put("filterTypeList", responseModel.getFilterTypeList());
success(map);
}else{
fail(map, responseModel.getFailCause());
}
return map;
}
} }

View File

@ -189,11 +189,7 @@ public class ScriptMessager extends MasterMessager {
accessToken); accessToken);
} }
public OperateScriptServerResponseModel loadFilterTypeList(String accessToken) {
String url = this.getBaseUrl() + "/loadFilterTypeList";
return this.getOperateScriptServerResponseModelByPost(url, null,
accessToken);
}
private OperateScriptServerResponseModel getOperateScriptServerResponseModelByPost( private OperateScriptServerResponseModel getOperateScriptServerResponseModelByPost(
String url, Map<String, String> params, String accessToken) { String url, Map<String, String> params, String accessToken) {

View File

@ -4,9 +4,12 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
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.OperateScriptServerResponseModel;
import org.bench4q.share.models.master.TestPlanDBModel; import org.bench4q.share.models.master.TestPlanDBModel;
import org.bench4q.share.models.master.TestPlanResponseModel; import org.bench4q.share.models.master.TestPlanResponseModel;
import org.bench4q.share.models.master.TestPlanResultModel; import org.bench4q.share.models.master.TestPlanResultModel;
@ -268,4 +271,9 @@ public class TestPlanMessager extends MasterMessager {
String url = this.baseUrl + "/stop" + "/" + testPlanRunId; String url = this.baseUrl + "/stop" + "/" + testPlanRunId;
return getTestPlanResponseModel(url, null, accessToken); return getTestPlanResponseModel(url, null, accessToken);
} }
public TestPlanResponseModel loadFilterTypeList(String accessToken) {
String url = this.getBaseUrl() + "/loadFilterTypeList";
return getTestPlanResponseModel(url, null, accessToken);
}
} }

View File

@ -1,5 +1,9 @@
package org.bench4q.web.model; package org.bench4q.web.model;
import java.util.ArrayList;
import java.util.List;
public class WebScriptModel { public class WebScriptModel {
private int id; private int id;
private int load; private int load;
@ -8,14 +12,16 @@ public class WebScriptModel {
private long cooldown; private long cooldown;
private boolean staticResources; private boolean staticResources;
private boolean timer; private boolean timer;
private String filterTypeMatches = null;
public WebScriptModel() { public WebScriptModel() {
} }
public WebScriptModel(int id,int load,long warmup,long executeRange,long cooldown){ public WebScriptModel(int id,int load,long warmup,long executeRange,long cooldown,String filterTypeMatches){
this.id=id; this.id=id;
this.load=load; this.load=load;
this.warmup=warmup; this.warmup=warmup;
this.executeRange=executeRange; this.executeRange=executeRange;
this.cooldown=cooldown; this.cooldown=cooldown;
this.filterTypeMatches = filterTypeMatches;
} }
public int getId() { public int getId() {
@ -69,6 +75,12 @@ public class WebScriptModel {
public void setTimer(boolean timer) { public void setTimer(boolean timer) {
this.timer = timer; this.timer = timer;
} }
public String getFilterTypeMatches() {
return filterTypeMatches;
}
public void setFilterTypeMatches(String filterTypeMatches) {
this.filterTypeMatches = filterTypeMatches;
}
} }

View File

@ -7,9 +7,11 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.share.models.agent.BehaviorBriefModel; import org.bench4q.share.models.agent.BehaviorBriefModel;
import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel; import org.bench4q.share.models.agent.BehaviorStatusCodeResultModel;
import org.bench4q.share.models.agent.ScriptFilterOptionsModel;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
import org.bench4q.share.models.master.RunningScriptModel; import org.bench4q.share.models.master.RunningScriptModel;
import org.bench4q.share.models.master.ScriptHandleModel; import org.bench4q.share.models.master.ScriptHandleModel;
@ -67,17 +69,17 @@ public class TestPlanService {
RunningScriptModel runnningScriptModel = new RunningScriptModel(); RunningScriptModel runnningScriptModel = new RunningScriptModel();
runnningScriptModel.setScriptId(scriptModel.getId()); runnningScriptModel.setScriptId(scriptModel.getId());
runnningScriptModel.setRequireLoad(scriptModel.getLoad()); runnningScriptModel.setRequireLoad(scriptModel.getLoad());
// ScriptFilterOptionsModel scriptFilterOptionsModel = new ScriptFilterOptionsModel(); ScriptFilterOptionsModel scriptFilterOptionsModel = new ScriptFilterOptionsModel();
// scriptFilterOptionsModel.setStaticResources(scriptModel scriptFilterOptionsModel.setFilterTypeMatches(scriptModel.getFilterTypeMatches());
// .isStaticResources()); scriptFilterOptionsModel.setFilterTimer(scriptModel.isTimer());
// scriptFilterOptionsModel.setTimer(scriptModel.isTimer());
TestScriptConfig testScriptConfig = new TestScriptConfig(); TestScriptConfig testScriptConfig = new TestScriptConfig();
testScriptConfig.setCoolDown(scriptModel.getCooldown()); testScriptConfig.setCoolDown(scriptModel.getCooldown());
testScriptConfig.setExecuteRange(scriptModel.getExecuteRange()); testScriptConfig.setExecuteRange(scriptModel.getExecuteRange());
testScriptConfig.setWarmUp(scriptModel.getWarmup()); testScriptConfig.setWarmUp(scriptModel.getWarmup());
runnningScriptModel.setConfig(testScriptConfig); runnningScriptModel.setConfig(testScriptConfig);
// runnningScriptModel runnningScriptModel
// .setScriptFilterOptionsModel(scriptFilterOptionsModel); .setScriptFilterOptionsModel(scriptFilterOptionsModel);
scriptList.add(runnningScriptModel); scriptList.add(runnningScriptModel);
} }
return scriptList; return scriptList;

View File

@ -1 +1 @@
masterAddress=133.133.2.105:8901 masterAddress=localhost:8901