edit UploadScriptWithParams
edit UploadScriptWithParams, and need to be tested
This commit is contained in:
parent
dc45262df6
commit
8331391b35
File diff suppressed because one or more lines are too long
|
@ -5,6 +5,7 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.share.helper.FileHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
@ -24,10 +25,7 @@ public class ParameterFileCollector {
|
|||
private String guardDirExists(UUID runId) {
|
||||
String dirPath = "ScenarioParameters" + FILE_SEPARATOR
|
||||
+ runId.toString() + FILE_SEPARATOR;
|
||||
File dirFile = new File(dirPath);
|
||||
if (!dirFile.exists()) {
|
||||
dirFile.mkdirs();
|
||||
}
|
||||
FileHelper.guardFolderExist(dirPath);
|
||||
return dirPath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public class TestWithScriptFile {
|
|||
+ "forGoodRecord.xml"));
|
||||
files.add(new File("Scripts" + System.getProperty("file.separator")
|
||||
+ "testJD.xml"));
|
||||
HttpResponse httpResponse = this.getHttpRequester().postFiles(
|
||||
HttpResponse httpResponse = this.getHttpRequester().postFiles(null,
|
||||
url + "/submitScenarioWithParams", "files[]", files,
|
||||
"scenarioModel", new LinkedList<String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
@ -136,6 +136,13 @@
|
|||
<artifactId>httpcore-nio</artifactId>
|
||||
<version>4.3</version>
|
||||
</dependency>
|
||||
<!--Start: for upload file -->
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<!--End : for upload file -->
|
||||
<dependency>
|
||||
<groupId>org.bench4q</groupId>
|
||||
<artifactId>bench4q-recorder</artifactId>
|
||||
|
|
|
@ -15,6 +15,8 @@ public class Main {
|
|||
public static int MAX_FAIL_TIMES = 10;
|
||||
public static int MIN_EXECUTE_INTERVAL_IN_SECONDS = 600;
|
||||
public static int PICK_CYCLE_IN_SECONDS = 60;
|
||||
public static String SCRIPT_PARAM_ROOT_FOLDER = "ScriptParameterization";
|
||||
public static String FILE_SEPARATOR = System.getProperty("file.separator");
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
@ -43,12 +45,15 @@ public class Main {
|
|||
.getProperty("pickTestPlanCycleInSeconds"));
|
||||
Min_Sample_Cycle_InSecond = Integer.parseInt(prop
|
||||
.getProperty("minSampleCycleInSeconds"));
|
||||
SCRIPT_PARAM_ROOT_FOLDER = prop
|
||||
.getProperty("scriptParamRootFolder");
|
||||
} catch (Exception e) {
|
||||
portToUse = 8080;
|
||||
MAX_FAIL_TIMES = 10;
|
||||
MIN_EXECUTE_INTERVAL_IN_SECONDS = 600;
|
||||
PICK_CYCLE_IN_SECONDS = 60;
|
||||
Min_Sample_Cycle_InSecond = 10;
|
||||
SCRIPT_PARAM_ROOT_FOLDER = "ScriptParameterization";
|
||||
logger.error("There is no config file for port to serve! where path is "
|
||||
+ configFile);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/RecordScript")
|
||||
|
@ -152,7 +153,7 @@ public class ScriptController extends BaseController {
|
|||
String content = FileUtils.readFileToString(file);
|
||||
logger.info("when saveToDB, scriptContent is " + content);
|
||||
boolean success = this.getScriptService().saveScript(scriptName,
|
||||
this.getPrincipal().getId(), content);
|
||||
this.getPrincipal().getId(), content, null);
|
||||
// this.getUserService().add
|
||||
return buildReponseModel(success, "Save to DataBase!!", "", port,
|
||||
null, null, null);
|
||||
|
@ -166,7 +167,8 @@ public class ScriptController extends BaseController {
|
|||
@ResponseBody
|
||||
public OperateScriptServerResponseModel uploadScriptToDB(
|
||||
@PathVariable String scriptName,
|
||||
@RequestBody RunScenarioModel scenarioModel)
|
||||
@RequestParam RunScenarioModel scenarioModel,
|
||||
@RequestParam(value = "paramFiles[]", required = false) List<MultipartFile> paramFiles)
|
||||
throws Bench4QException {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
throw new Bench4QException(HAVE_NO_POWER, HAVE_NO_POWER
|
||||
|
@ -177,7 +179,8 @@ public class ScriptController extends BaseController {
|
|||
scriptName,
|
||||
this.getPrincipal().getId(),
|
||||
MarshalHelper
|
||||
.marshal(RunScenarioModel.class, scenarioModel));
|
||||
.marshal(RunScenarioModel.class, scenarioModel),
|
||||
paramFiles);
|
||||
logger.info("upload script:"
|
||||
+ MarshalHelper.marshal(RunScenarioModel.class,
|
||||
scenarioModel));
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
@ -11,6 +14,10 @@ import javax.persistence.JoinColumn;
|
|||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.bench4q.master.Main;
|
||||
import org.bench4q.share.helper.FileHelper;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Entity
|
||||
@Table(name = "Script")
|
||||
public class Script {
|
||||
|
@ -79,13 +86,29 @@ public class Script {
|
|||
}
|
||||
|
||||
public static Script createScriptWithoutId(String name,
|
||||
String scriptContent, User user) {
|
||||
String scriptContent, User user, List<MultipartFile> paramFiles) {
|
||||
Script script = new Script();
|
||||
script.setBehaviorCount(0);
|
||||
script.setCreateDateTime(new Date());
|
||||
script.setName(name);
|
||||
script.setScriptContent(scriptContent);
|
||||
script.setUser(user);
|
||||
script.saveScriptParamFiles(paramFiles);
|
||||
return script;
|
||||
}
|
||||
|
||||
private void saveScriptParamFiles(List<MultipartFile> paramFiles) {
|
||||
String folderPath = Main.SCRIPT_PARAM_ROOT_FOLDER + Main.FILE_SEPARATOR
|
||||
+ this.getId() + Main.FILE_SEPARATOR;
|
||||
FileHelper.guardFolderExist(folderPath);
|
||||
for (MultipartFile multipartFile : paramFiles) {
|
||||
try {
|
||||
multipartFile.transferTo(new File(folderPath
|
||||
+ Main.FILE_SEPARATOR
|
||||
+ multipartFile.getOriginalFilename()));
|
||||
} catch (IllegalStateException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,10 +31,10 @@ import org.bench4q.master.domain.service.TestPlanService;
|
|||
import org.bench4q.master.domain.valueobject.datastatistics.RunningScriptSampler;
|
||||
import org.bench4q.master.domain.valueobject.schedulscript.ExecutionOverTask;
|
||||
import org.bench4q.master.domain.valueobject.schedulscript.WarmUpOverTask;
|
||||
import org.bench4q.master.domain.valueobject.transaction.Transaction;
|
||||
import org.bench4q.master.domain.valueobject.transaction.TransactionFactory;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.master.infrastructure.highavailable.AgentRunBlotter;
|
||||
import org.bench4q.master.infrastructure.highavailable.faultolerence.StopAgentFault;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.StopTestModel;
|
||||
|
@ -235,7 +235,6 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
agentsAfterDistribute, this));
|
||||
this.setSampler(new RunningScriptSampler(Collections
|
||||
.unmodifiableCollection(this.getRunningAgentsDB())));
|
||||
this.scheduleAsConfig();
|
||||
}
|
||||
|
||||
public List<TestPlanScriptResult> doAfterRun() {
|
||||
|
@ -253,6 +252,29 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean distributeLoad() {
|
||||
return this.distributeLoad(this.getRequireLoad());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean distributeLoad(int requiredLoad) {
|
||||
Transaction scriptLoadCommand = TransactionFactory
|
||||
.buildScriptTransaction(this, this.getRequireLoad());
|
||||
List<? extends RunningAgentInterface> runningAgents = null;
|
||||
try {
|
||||
runningAgents = (List<? extends RunningAgentInterface>) scriptLoadCommand
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
logger.error("distribute load error, the runningAgents is null", e);
|
||||
scriptLoadCommand.rollBack();
|
||||
return false;
|
||||
}
|
||||
this.doAfterDistributeLoad(runningAgents);
|
||||
this.scheduleAsConfig();
|
||||
// this.getTestPlanRepository().updateEntity(this.getTestPlan());
|
||||
return true;
|
||||
}
|
||||
|
||||
public TestPlanScript doForComplete() {
|
||||
for (RunningAgentInterface runningAgent : this.getRunningAgentsDB()) {
|
||||
if (runningAgent == null) {
|
||||
|
@ -263,7 +285,6 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
if (resultModel == null || !resultModel.isSuccess()) {
|
||||
logger.error("can't stop the agent with hostName"
|
||||
+ runningAgent.getAgent().getHostName());
|
||||
doFaultTolerance(runningAgent);
|
||||
continue;
|
||||
}
|
||||
backLoadAndCleanUp(runningAgent);
|
||||
|
@ -272,28 +293,10 @@ public class TestPlanScript implements RunningScriptInterface {
|
|||
return this;
|
||||
}
|
||||
|
||||
private void doFaultTolerance(RunningAgentInterface runningAgent) {
|
||||
logger.error("when stop agent with hostName "
|
||||
+ runningAgent.getAgent().getHostName() + " returns null!");
|
||||
StopAgentFault stopAgentFault = new StopAgentFault(
|
||||
AgentRunBlotter.buildAgentRunBlotter(this.getTestPlanID(),
|
||||
runningAgent));
|
||||
stopAgentFault.doTolerance();
|
||||
}
|
||||
|
||||
private void backLoadAndCleanUp(RunningAgentInterface runningAgent) {
|
||||
String hostName = runningAgent.getAgent().getHostName();
|
||||
this.getAgentService().backLoadToAgent(hostName,
|
||||
runningAgent.getLoadInUse());
|
||||
}
|
||||
|
||||
public RunningAgentDB extractSpecificRunningAgentDB(String hostName) {
|
||||
for (RunningAgentDB runningAgentDB : this.getRunningAgentsDB()) {
|
||||
if (runningAgentDB.getAgent().getHostName().equals(hostName)) {
|
||||
return runningAgentDB;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.bench4q.share.models.agent.RunScenarioModel;
|
|||
import org.hibernate.criterion.Restrictions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Component
|
||||
public class ScriptService {
|
||||
|
@ -41,11 +42,20 @@ public class ScriptService {
|
|||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param scriptName
|
||||
* @param userId
|
||||
* @param scriptContent
|
||||
* @param paramFiles
|
||||
* , this param may be null, and is permitted so.
|
||||
* @return
|
||||
*/
|
||||
public boolean saveScript(String scriptName, int userId,
|
||||
String scriptContent) {
|
||||
String scriptContent, List<MultipartFile> paramFiles) {
|
||||
return this.getScriptRepositoty().attach(
|
||||
Script.createScriptWithoutId(scriptName, scriptContent, this
|
||||
.getUserRepository().getEntity(userId)));
|
||||
.getUserRepository().getEntity(userId), paramFiles));
|
||||
}
|
||||
|
||||
public Script getScript(int scriptId) {
|
||||
|
|
|
@ -118,27 +118,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
|||
return;
|
||||
}
|
||||
TestPlanStatus returnStatus = testPlan.run();
|
||||
commitTestPlanStaus(returnStatus, testPlan);
|
||||
}
|
||||
|
||||
private void commitTestPlanStaus(TestPlanStatus returnStatus,
|
||||
TestPlan testPlan) {
|
||||
if (returnStatus == TestPlanStatus.InRunning) {
|
||||
commitInRunning(testPlan);
|
||||
} else {
|
||||
commitError(testPlan, returnStatus);
|
||||
}
|
||||
}
|
||||
|
||||
private void commitError(TestPlan testPlan, TestPlanStatus errorStatus) {
|
||||
testPlan.setCurrentStatus(errorStatus.name());
|
||||
getTestPlanRepository().updateEntity(testPlan);
|
||||
}
|
||||
|
||||
private void commitInRunning(TestPlan testPlan) {
|
||||
testPlan.setCurrentStatus(TestPlanStatus.InRunning.name());
|
||||
testPlan.setLastRunningTime(new Date());
|
||||
getTestPlanRepository().attachRunningTestPlan(testPlan);
|
||||
testPlan.setCurrentStatus(returnStatus.name());
|
||||
getTestPlanRepository().updateEntity(testPlan);
|
||||
}
|
||||
|
||||
|
@ -159,11 +139,7 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
|||
this.getTestPlanRepository().updateEntity(testPlan);
|
||||
}
|
||||
|
||||
public void executePendingTestPlan() {
|
||||
|
||||
}
|
||||
|
||||
public TestPlan pickATestPlan() {
|
||||
public synchronized TestPlan pickATestPlan() {
|
||||
logger.info("enter pick");
|
||||
try {
|
||||
List<Criterion> criterions = new ArrayList<Criterion>();
|
||||
|
@ -191,4 +167,9 @@ public class TestPlanEngine implements TaskCompleteCallback,
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executePendingTestPlan() {
|
||||
pickATestPlan();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
package org.bench4q.master.domain.valueobject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgentInterface;
|
||||
import org.bench4q.master.domain.RunningScriptInterface;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.domain.valueobject.transaction.Transaction;
|
||||
import org.bench4q.master.domain.valueobject.transaction.TransactionFactory;
|
||||
import org.bench4q.master.infrastructure.highavailable.HighAvailablePool;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -19,7 +12,6 @@ import org.springframework.stereotype.Component;
|
|||
public class LoadDistribute {
|
||||
|
||||
private HighAvailablePool highAvailableAgentPool;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private static Logger logger = Logger.getLogger(LoadDistribute.class);
|
||||
|
||||
public HighAvailablePool getHighAvailableAgentPool() {
|
||||
|
@ -32,15 +24,6 @@ public class LoadDistribute {
|
|||
this.highAvailableAgentPool = highAvailableAgentPool;
|
||||
}
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanRepository(TestPlanRepository testPlanRepository) {
|
||||
this.testPlanRepository = testPlanRepository;
|
||||
}
|
||||
|
||||
private boolean hasEnoughCurrentLoad(int totalRequireLoad) {
|
||||
return this.highAvailableAgentPool.getCurrentAvailableLoad() >= totalRequireLoad;
|
||||
}
|
||||
|
@ -59,9 +42,9 @@ public class LoadDistribute {
|
|||
logger.info("There is no enough current load in the pool!");
|
||||
return TestPlanStatus.PendingNoEnoughCurrentLoad;
|
||||
}
|
||||
for (RunningScriptInterface testPlanScript : testPlanInDomain
|
||||
for (TestPlanScript testPlanScript : testPlanInDomain
|
||||
.getTestPlanScripts()) {
|
||||
if (!distributeLoadForScript(testPlanScript)) {
|
||||
if (!testPlanScript.distributeLoad()) {
|
||||
return TestPlanStatus.ErrorInDistributeLoadForScript;
|
||||
}
|
||||
}
|
||||
|
@ -75,43 +58,4 @@ public class LoadDistribute {
|
|||
testPlanInDomain.doAfterRun();
|
||||
}
|
||||
|
||||
private boolean distributeLoadForScript(RunningScriptInterface runningScript) {
|
||||
return distributeLoadForScript(runningScript,
|
||||
runningScript.getRequireLoad());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean distributeLoadForScript(
|
||||
RunningScriptInterface runningScript, int requireLoad) {
|
||||
Transaction scriptLoadCommand = TransactionFactory
|
||||
.buildScriptTransaction(runningScript, requireLoad);
|
||||
|
||||
List<? extends RunningAgentInterface> runningAgents = null;
|
||||
try {
|
||||
runningAgents = (List<? extends RunningAgentInterface>) scriptLoadCommand
|
||||
.execute();
|
||||
} catch (Exception e) {
|
||||
logger.error("distribute load error, the runningAgents is null");
|
||||
scriptLoadCommand.rollBack();
|
||||
return false;
|
||||
}
|
||||
if (runningAgents == null) {
|
||||
logger.error("distribute load error, the runningAgents is null");
|
||||
scriptLoadCommand.rollBack();
|
||||
return false;
|
||||
}
|
||||
doAfterDistributeLoadSuccessForScript(runningScript, runningAgents);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void doAfterDistributeLoadSuccessForScript(
|
||||
RunningScriptInterface scriptInput,
|
||||
List<? extends RunningAgentInterface> runningAgents) {
|
||||
scriptInput.doAfterDistributeLoad(runningAgents);
|
||||
if (!(scriptInput instanceof TestPlanScript)) {
|
||||
return;
|
||||
}
|
||||
this.getTestPlanRepository().updateEntity(
|
||||
((TestPlanScript) scriptInput).getTestPlan());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,19 +105,14 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
throw new IllegalArgumentException("runScenarioModel is null!");
|
||||
}
|
||||
try {
|
||||
this.runAgentsWithScenario(runScenarioModel, getRequireLoad(), this
|
||||
.getRunningScript().getScriptId(), this.getTestPlanRunID());
|
||||
|
||||
if (this.getAgentListThisTime() == null) {
|
||||
logger.error("runAgentsWithScenario fails where scriptId = "
|
||||
+ this.getRunningScript().getScriptId());
|
||||
return null;
|
||||
}
|
||||
if (isNotValidScript(this.getRunningScript())) {
|
||||
logger.error("The running agents of runningScriptModel is null, whose scriptId is"
|
||||
+ this.getRunningScript().getScriptId());
|
||||
return null;
|
||||
throw new RuntimeException("Running Script not valid!");
|
||||
}
|
||||
this.runAgentsWithScenario(runScenarioModel, getRequireLoad(), this
|
||||
.getRunningScript().getScriptId(), this.getTestPlanRunID());
|
||||
|
||||
return this.getAgentListThisTime();
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e).toString()
|
||||
|
@ -125,7 +120,7 @@ public abstract class ScriptLoadBase implements Transaction {
|
|||
+ this.getRunningScript().getScriptId()
|
||||
+ " and TestPlanID is "
|
||||
+ this.getTestPlanRunID().toString());
|
||||
return null;
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,9 +73,10 @@ public class AgentMessenger {
|
|||
try {
|
||||
final String modelCOntent = MarshalHelper
|
||||
.tryMarshal(runScenarioModel);
|
||||
httpResponse = this.httpRequester.postFiles(buildBaseUrl(agent)
|
||||
+ "/test/submitScenarioWithParams", "files[]", paramFiles,
|
||||
"scenarioModel", new LinkedList<String>() {
|
||||
httpResponse = this.httpRequester.postFiles(null,
|
||||
buildBaseUrl(agent) + "/test/submitScenarioWithParams",
|
||||
"files[]", paramFiles, "scenarioModel",
|
||||
new LinkedList<String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
{
|
||||
add(modelCOntent);
|
||||
|
@ -112,7 +113,8 @@ public class AgentMessenger {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
//there is bug in here
|
||||
|
||||
// there is bug in here
|
||||
public TestBriefStatusModel scriptBriefAll(Agent agent, UUID runId) {
|
||||
HttpResponse httpResponse = null;
|
||||
try {
|
||||
|
@ -129,7 +131,8 @@ public class AgentMessenger {
|
|||
TestBriefStatusModel.class, httpResponse.getContent());
|
||||
} catch (Exception e) {
|
||||
logIt(httpResponse, e);
|
||||
logger.error(e.toString() + " When get script all brief the agent with hostName "
|
||||
logger.error(e.toString()
|
||||
+ " When get script all brief the agent with hostName "
|
||||
+ agent.getHostName());
|
||||
FaultTolerenceFactory.getBriefFaultTolerance(agent).doTolerance();
|
||||
return null;
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.bench4q.master.domain.RunningAgentInterface;
|
|||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
import org.bench4q.master.domain.valueobject.LoadDistribute;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
|
||||
public class AgentRunBlotter {
|
||||
|
@ -15,7 +14,6 @@ public class AgentRunBlotter {
|
|||
private UUID testPlanId;
|
||||
private boolean hasSubstitute;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private LoadDistribute loadDistribute;
|
||||
|
||||
public RunningAgentInterface getRunningAgent() {
|
||||
return runningAgent;
|
||||
|
@ -49,20 +47,10 @@ public class AgentRunBlotter {
|
|||
this.testPlanRepository = testPlanRepository;
|
||||
}
|
||||
|
||||
private LoadDistribute getLoadDistribute() {
|
||||
return loadDistribute;
|
||||
}
|
||||
|
||||
private void setLoadDistribute(LoadDistribute loadDistribute) {
|
||||
this.loadDistribute = loadDistribute;
|
||||
}
|
||||
|
||||
private AgentRunBlotter() {
|
||||
this.setHasSubstitute(false);
|
||||
this.setTestPlanRepository(ApplicationContextHelper.getContext()
|
||||
.getBean(TestPlanRepository.class));
|
||||
this.setLoadDistribute(ApplicationContextHelper.getContext().getBean(
|
||||
LoadDistribute.class));
|
||||
}
|
||||
|
||||
private AgentRunBlotter(UUID testPlanID, RunningAgentInterface runningAgent) {
|
||||
|
@ -92,8 +80,8 @@ public class AgentRunBlotter {
|
|||
}
|
||||
final TestPlanScript testPlanScript = testPlan
|
||||
.extracSpecifiedScript(getRunningAgent().getScriptId());
|
||||
this.getLoadDistribute().distributeLoadForScript(testPlanScript,
|
||||
this.getRunningAgent().getLoadInUse());
|
||||
testPlanScript.distributeLoad(this.getRunningAgent().getLoadInUse());
|
||||
handleAfterSubstituteOn();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,3 +3,4 @@ pickTestPlanCycleInSeconds=60
|
|||
maxFailTime=10
|
||||
minExcuteIntervalInSeconds=600
|
||||
minSampleCycleInSeconds=10
|
||||
scriptParamRootFolder=ScriptParameterization
|
|
@ -10,4 +10,10 @@
|
|||
<context:component-scan base-package="org.bench4q" />
|
||||
<mvc:annotation-driven />
|
||||
<task:annotation-driven />
|
||||
|
||||
<bean id="multipartResolver"
|
||||
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||
<property name="maxUploadSize" value="5000000" />
|
||||
<property name="maxInMemorySize" value="5000000" />
|
||||
</bean>
|
||||
</beans>
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.UUID;
|
|||
|
||||
import org.bench4q.master.domain.entity.RunningAgentDB;
|
||||
import org.bench4q.master.domain.entity.TestPlan;
|
||||
import org.bench4q.master.domain.entity.TestPlanScript;
|
||||
import org.bench4q.master.domain.entity.User;
|
||||
import org.bench4q.master.domain.repository.AgentRepository;
|
||||
import org.bench4q.master.domain.repository.TestPlanRepository;
|
||||
|
@ -165,8 +166,6 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
this.testPlanEngine = testPlanEngine;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public UUID getTestPlanRunIdUuid() {
|
||||
return testPlanRunIdUuid;
|
||||
}
|
||||
|
@ -213,8 +212,8 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
TestPlan testPlan = this.getTestPlanRepository().getTestPlanBy(
|
||||
getTestPlanRunIdUuid());
|
||||
testPlan.setCurrentStatus(TestPlanStatus.Complete.name());
|
||||
RunningAgentDB runningAgent = testPlan.extracSpecifiedScript(
|
||||
getScriptId()).extractSpecificRunningAgentDB(
|
||||
RunningAgentDB runningAgent = extractRunningAgent(
|
||||
testPlan.extracSpecifiedScript(getScriptId()),
|
||||
Test_AGENT_HOSTNAME);
|
||||
if (runningAgent == null)
|
||||
return;
|
||||
|
@ -226,6 +225,17 @@ public class TestBase_MakeUpTestPlan extends TestBase {
|
|||
this.getTestPlanRepository().detach(testPlan.getId());
|
||||
}
|
||||
|
||||
protected RunningAgentDB extractRunningAgent(TestPlanScript testPlanScript,
|
||||
String hostName) {
|
||||
for (RunningAgentDB runningAgentDB : testPlanScript
|
||||
.getRunningAgentsDB()) {
|
||||
if (runningAgentDB.getAgent().getHostName().equals(hostName)) {
|
||||
return runningAgentDB;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected UUID submitATestPlanWithOneScript() {
|
||||
return submitATestPlan(1);
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
|
|||
TestPlanStatus returnStatus = testPlanInDomain.run();
|
||||
assertEquals(TestPlanStatus.InRunning, returnStatus);
|
||||
|
||||
|
||||
assertTrue(this.getTestPlanRepository().updateEntity(testPlanInDomain));
|
||||
TestPlan testPlanAfterRun = this.getTestPlanRepository().getTestPlanBy(
|
||||
getTestPlanRunIdUuid());
|
||||
|
@ -77,8 +76,8 @@ public class Test_TestPlan extends TestBase_MakeUpTestPlan {
|
|||
testPlanScript.getRequireLoad());
|
||||
assertNotNull(testPlanScript.getRunningAgentsDB());
|
||||
assertEquals(1, testPlanScript.getRunningAgentsDB().size());
|
||||
RunningAgentDB runningAgentDB = testPlanScript
|
||||
.extractSpecificRunningAgentDB(Test_AGENT_HOSTNAME);
|
||||
RunningAgentDB runningAgentDB = extractRunningAgent(testPlanScript,
|
||||
Test_AGENT_HOSTNAME);
|
||||
assertNotNull(runningAgentDB);
|
||||
assertEquals(EACH_SCRIPT_LOAD_SMALLSCALE, runningAgentDB.getLoadInUse());
|
||||
Thread.sleep(10000);
|
||||
|
|
|
@ -85,7 +85,7 @@ public class Test_ScriptService {
|
|||
user.getId(),
|
||||
FileUtils.readFileToString(new File("Scripts"
|
||||
+ System.getProperty("file.separator")
|
||||
+ "HBaseScript.xml")));
|
||||
+ "HBaseScript.xml")), null);
|
||||
}
|
||||
|
||||
private boolean doSaveAScript(User user) throws JAXBException {
|
||||
|
@ -93,7 +93,7 @@ public class Test_ScriptService {
|
|||
"ad",
|
||||
user.getId(),
|
||||
MarshalHelper.marshal(RunScenarioModel.class,
|
||||
new RunScenarioModel()));
|
||||
new RunScenarioModel()), null);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -110,7 +110,7 @@ public class Test_ScriptService {
|
|||
"adef",
|
||||
user.getId(),
|
||||
MarshalHelper.marshal(RunScenarioModel.class,
|
||||
new RunScenarioModel())));
|
||||
new RunScenarioModel()), null));
|
||||
assertEquals(1, this.getScriptService().loadScripts(user).size());
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.nio.charset.Charset;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
|
@ -110,10 +111,16 @@ public class HttpRequester {
|
|||
return httpResponse;
|
||||
}
|
||||
|
||||
public HttpResponse postFiles(String url, String filePartName,
|
||||
List<File> files, String stringPartName, List<String> strings) {
|
||||
public HttpResponse postFiles(Map<String, String> headers, String url,
|
||||
String filePartName, List<File> files, String stringPartName,
|
||||
List<String> strings) {
|
||||
PostMethod postMethod = new PostMethod(url);
|
||||
try {
|
||||
if (headers != null) {
|
||||
for (Entry<String, String> entry : headers.entrySet()) {
|
||||
postMethod.addParameter(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
Part[] parts = new Part[files.size() + strings.size()];
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
parts[i] = new FilePart(filePartName, files.get(i));
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package org.bench4q.share.helper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FileHelper {
|
||||
public static void guardFolderExist(String folderFullPath) {
|
||||
guardFolderExist(new File(folderFullPath));
|
||||
}
|
||||
|
||||
public static void guardFolderExist(File folder) {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
123,234,566
|
||||
167,567,789
|
|
@ -4,6 +4,8 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -13,7 +15,9 @@ import org.apache.log4j.Logger;
|
|||
import org.bench4q.share.communication.HttpRequester;
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.ExceptionLog;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.ErrorResponseModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.web.api.BaseControllerService;
|
||||
import org.bench4q.web.exception.CustomGenericException;
|
||||
import org.bench4q.web.extractObjectFromXml.ObjectXmlExchange;
|
||||
|
@ -70,6 +74,18 @@ public class CommunicateWithMaster {
|
|||
|
||||
}
|
||||
|
||||
public HttpResponse uploadScriptWithParamFiles(String accessToken,
|
||||
String scriptName, RunScenarioModel runScenarioModel,
|
||||
List<File> paramFiles) {
|
||||
String url = masterAddress + "/uploadScript/" + scriptName;
|
||||
List<String> stringPart = new LinkedList<String>();
|
||||
stringPart.add(MarshalHelper.tryMarshal(runScenarioModel));
|
||||
|
||||
return this.getHttpRequester().postFiles(
|
||||
makeAccessTockenMap(accessToken), url, "paramFiles[]",
|
||||
paramFiles, "", stringPart);
|
||||
}
|
||||
|
||||
public Object getRespnseObjectByPostXml(String accessToken, String url,
|
||||
Class<?> objectClass, String content, String caller)
|
||||
throws CustomGenericException {
|
||||
|
|
|
@ -1 +1 @@
|
|||
masterAddress=133.133.12.1:7979/
|
||||
masterAddress=127.0.0.1:7979/
|
|
@ -0,0 +1,35 @@
|
|||
package org.bench4q.web.tool.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bench4q.share.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.share.helper.TestHelper;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.web.service.CommunicateWithMaster;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
public class Test_CommunicateWithMaster {
|
||||
private CommunicateWithMaster communicateWithMaster = new CommunicateWithMaster();
|
||||
private LoginHelper loginHelper = new LoginHelper();
|
||||
|
||||
@Test
|
||||
public void test_uploadScriptWithParamFiles() {
|
||||
String accessToken = this.loginHelper.login();
|
||||
List<File> paramFiles = new ArrayList<File>();
|
||||
String filePath = "ScriptParameters"
|
||||
+ System.getProperty("file.separator") + "param1.txt";
|
||||
TestHelper.createFileIfNotExist(new File(filePath));
|
||||
paramFiles.add(new File(filePath));
|
||||
HttpResponse httpResponse = this.communicateWithMaster
|
||||
.uploadScriptWithParamFiles(accessToken, "test_chen",
|
||||
new RunScenarioModel(), paramFiles);
|
||||
assertEquals(200, httpResponse.getCode());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue