add support for detailStatus of agent
This commit is contained in:
parent
392fbc4588
commit
20fb4e108e
|
@ -1,11 +1,9 @@
|
|||
package org.bench4q.master.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.api.model.AgentBriefModel;
|
||||
import org.bench4q.master.api.model.RunningScriptModel;
|
||||
import org.bench4q.master.api.model.AgentDetailModel;
|
||||
import org.bench4q.master.api.model.TestPlanModel;
|
||||
import org.bench4q.master.api.model.RunTestPlanResultModel;
|
||||
import org.bench4q.master.service.UserService;
|
||||
|
@ -32,36 +30,15 @@ public class TestPlanController extends BaseController {
|
|||
this.testPlanRunner = testPlanRunner;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/runTestPlanWithScriptId", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public RunTestPlanResultModel runTestPlanWithScriptId(
|
||||
@RequestParam int scriptId, @RequestParam int requireLoad) {
|
||||
// TODO:add the scriptId-requireLoad to taskList, and return a UUID
|
||||
List<RunningScriptModel> list = new ArrayList<RunningScriptModel>();
|
||||
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return _buildTestPlanResponseModel(null);
|
||||
}
|
||||
RunningScriptModel model = new RunningScriptModel();
|
||||
model.setScriptId(scriptId);
|
||||
model.setRequireLoad(requireLoad);
|
||||
model.setAgentRunIds(new ArrayList<UUID>());
|
||||
list.add(model);
|
||||
TestPlanModel testPlanModel = new TestPlanModel();
|
||||
testPlanModel.setScriptIdRequireLoads(list);
|
||||
|
||||
return _buildTestPlanResponseModel(this.testPlanRunner
|
||||
.runTestPlanWithModel(testPlanModel));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getAgentBriefStatus", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AgentBriefModel getBriefStatusModelFromAgent(
|
||||
@RequestParam UUID testPlanId, @RequestParam UUID agentRunId) {
|
||||
if (this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return null;
|
||||
}
|
||||
return this.testPlanRunner.getBriefStatusFromAgent(testPlanId, agentRunId);
|
||||
return this.testPlanRunner.getBriefStatusFromAgent(testPlanId,
|
||||
agentRunId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/runTestPlanWithTestPlanModel", method = RequestMethod.POST)
|
||||
|
@ -88,4 +65,15 @@ public class TestPlanController extends BaseController {
|
|||
@RequestParam UUID testPlanId) {
|
||||
return this.testPlanRunner.get_tasks().get(testPlanId).getResultModel();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getAgentDetailStatus", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public AgentDetailModel getAgentDetailStatus(@RequestParam UUID testPlanId,
|
||||
@RequestParam UUID agentRunId) {
|
||||
if (!this.checkScope(UserService.NORAML_AUTHENTICATION)) {
|
||||
return null;
|
||||
}
|
||||
return this.testPlanRunner.getDetailStatusOfAgent(testPlanId,
|
||||
agentRunId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import javax.xml.bind.Marshaller;
|
|||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.bench4q.master.api.model.AgentBriefModel;
|
||||
import org.bench4q.master.api.model.AgentDetailModel;
|
||||
import org.bench4q.master.api.model.RunTestPlanResultModel;
|
||||
import org.bench4q.master.api.model.RunningScriptModel;
|
||||
import org.bench4q.master.api.model.TestPlanModel;
|
||||
|
@ -27,6 +28,7 @@ import org.bench4q.master.communication.HttpRequester.HttpResponse;
|
|||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
||||
import org.bench4q.master.communication.agent.RunScenarioResultModel;
|
||||
import org.bench4q.master.communication.agent.TestBriefStatusModel;
|
||||
import org.bench4q.master.communication.agent.TestDetailStatusModel;
|
||||
import org.bench4q.master.entity.db.Agent;
|
||||
import org.bench4q.master.service.AgentService;
|
||||
import org.bench4q.master.service.ScriptService;
|
||||
|
@ -88,7 +90,7 @@ public class TestPlanRunner {
|
|||
hostNameAndLoad.getHostName() + ":" + TestPlanRunner.port
|
||||
+ "/test/brief/" + runId, null, null);
|
||||
|
||||
briefStatusModel = this.extractTestBriefStatusModel(httpResponse
|
||||
briefStatusModel = this._extractTestBriefStatusModel(httpResponse
|
||||
.getContent());
|
||||
|
||||
result = this.makeAgentBriefModel(briefStatusModel);
|
||||
|
@ -108,7 +110,7 @@ public class TestPlanRunner {
|
|||
}
|
||||
}
|
||||
|
||||
private TestBriefStatusModel extractTestBriefStatusModel(String content)
|
||||
private TestBriefStatusModel _extractTestBriefStatusModel(String content)
|
||||
throws JAXBException {
|
||||
TestBriefStatusModel resultModel = new TestBriefStatusModel();
|
||||
Unmarshaller ummarshaller = JAXBContext.newInstance(
|
||||
|
@ -181,7 +183,7 @@ public class TestPlanRunner {
|
|||
}
|
||||
}
|
||||
|
||||
public RunningScriptModel runTestWithRunScenarioModel(
|
||||
private RunningScriptModel runTestWithRunScenarioModel(
|
||||
RunScenarioModel runScenarioModel, int requireLoad, int scriptId,
|
||||
UUID testPlanId) throws JAXBException {
|
||||
// TODO: is it needed to be synchronized, but i think it is;
|
||||
|
@ -209,7 +211,7 @@ public class TestPlanRunner {
|
|||
this.getAgentService().getLoadFromAgent(agent.getHostName(), min);
|
||||
runScenarioResultModel = this._sendScriptContentToAgent(
|
||||
agent.getHostName(), agent.getPort(),
|
||||
this.marshalRunScenarioModelToString(runScenarioModel));
|
||||
this._marshalRunScenarioModelToString(runScenarioModel));
|
||||
|
||||
// this.runningAgentInfo.addToRunIdHostLoadMap(runScenarioResultModel
|
||||
// .getRunId(), new HostNameAndLoad(agent.getHostName(), min));
|
||||
|
@ -269,7 +271,7 @@ public class TestPlanRunner {
|
|||
: remainLoadByStart;
|
||||
}
|
||||
|
||||
public String marshalRunScenarioModelToString(
|
||||
private String _marshalRunScenarioModelToString(
|
||||
RunScenarioModel runScenarioModel) throws JAXBException {
|
||||
Marshaller marshaller;
|
||||
marshaller = JAXBContext.newInstance(runScenarioModel.getClass())
|
||||
|
@ -289,4 +291,57 @@ public class TestPlanRunner {
|
|||
.unmarshal(new ByteArrayInputStream(responseContent.getBytes()));
|
||||
return resultModel;
|
||||
}
|
||||
|
||||
public AgentDetailModel getDetailStatusOfAgent(UUID testPlanId,
|
||||
UUID agentRunId) {
|
||||
AgentDetailModel result = new AgentDetailModel();
|
||||
TestDetailStatusModel detailStatusModel = new TestDetailStatusModel();
|
||||
try {
|
||||
HostNameAndLoad hostNameAndLoad = this._tasks.get(testPlanId)
|
||||
.getHostNameAndLoadFromRunningAgentInfo(agentRunId);
|
||||
if (hostNameAndLoad == null) {
|
||||
return null;
|
||||
}
|
||||
HttpResponse httpResponse = this.httpRequester.sendGet(
|
||||
hostNameAndLoad.getHostName() + ":" + TestPlanRunner.port
|
||||
+ "/test/detail/" + agentRunId, null, null);
|
||||
|
||||
detailStatusModel = this._extractDetailStatusModel(httpResponse
|
||||
.getContent());
|
||||
|
||||
result = this._makeAgentDetailModel(detailStatusModel);
|
||||
|
||||
if (result.isFinish()) {
|
||||
this.agentService.backLoadToAgent(
|
||||
hostNameAndLoad.getHostName(),
|
||||
hostNameAndLoad.getLoad());
|
||||
}
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return result;
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private TestDetailStatusModel _extractDetailStatusModel(String content)
|
||||
throws JAXBException {
|
||||
TestDetailStatusModel result = new TestDetailStatusModel();
|
||||
Unmarshaller unmarshaller = JAXBContext.newInstance(result.getClass())
|
||||
.createUnmarshaller();
|
||||
result = (TestDetailStatusModel) unmarshaller
|
||||
.unmarshal(new ByteArrayInputStream(content.getBytes()));
|
||||
return result;
|
||||
}
|
||||
|
||||
private AgentDetailModel _makeAgentDetailModel(
|
||||
TestDetailStatusModel detailStatusModel) {
|
||||
AgentDetailModel result = new AgentDetailModel();
|
||||
result.setTestStatusModel(detailStatusModel);
|
||||
result.setFinish(detailStatusModel.getFinishedCount() == detailStatusModel
|
||||
.getTotalCount());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue