go through the road
This commit is contained in:
parent
d92a2b0a85
commit
c3150edb34
|
@ -69,11 +69,11 @@ public class AgentController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/RemoveAgentFromPool", method = RequestMethod.POST)
|
@RequestMapping(value = "/RemoveAgentFromPool", method = RequestMethod.GET)
|
||||||
public AgentResponseModel removeAgentFromPool(
|
public AgentResponseModel removeAgentFromPool(
|
||||||
@RequestParam String hostNameString) {
|
@RequestParam String hostName) {
|
||||||
synchronized (this.getAgentPoolService().getAgentLock()) {
|
synchronized (this.getAgentPoolService().getAgentLock()) {
|
||||||
if (!this.getAgentPoolService().removeAgentFromPool(hostNameString)) {
|
if (!this.getAgentPoolService().removeAgentFromPool(hostName)) {
|
||||||
return setAgentResponseModel(false,
|
return setAgentResponseModel(false,
|
||||||
"remove agent from DB fails in removeAgentFromPool");
|
"remove agent from DB fails in removeAgentFromPool");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,15 @@ package org.bench4q.master.api;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
|
||||||
|
import org.bench4q.master.api.model.TestPlanResponseModel;
|
||||||
import org.bench4q.master.communication.AgentStateService;
|
import org.bench4q.master.communication.AgentStateService;
|
||||||
import org.bench4q.master.communication.HttpRequester;
|
import org.bench4q.master.communication.HttpRequester;
|
||||||
import org.bench4q.master.communication.HttpRequester.HttpResponse;
|
import org.bench4q.master.communication.HttpRequester.HttpResponse;
|
||||||
|
@ -26,6 +25,7 @@ import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/testPlan")
|
@RequestMapping("/testPlan")
|
||||||
|
@ -72,15 +72,23 @@ public class TestPlanController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/runTestPlanWithScriptId", method = RequestMethod.GET)
|
@RequestMapping(value = "/runTestPlanWithScriptId", method = RequestMethod.GET)
|
||||||
public void runTestPlanWithScriptId(@RequestParam int scriptId,
|
@ResponseBody
|
||||||
@RequestParam int requireLoad) {
|
public TestPlanResponseModel runTestPlanWithScriptId(
|
||||||
|
@RequestParam int scriptId, @RequestParam int requireLoad) {
|
||||||
// TODO:
|
// TODO:
|
||||||
RunScenarioModel runScenarioModel = this.getScriptService()
|
RunScenarioModel runScenarioModel = this.getScriptService()
|
||||||
.getRunSceniroModelByScriptId(scriptId);
|
.getRunSceniroModelByScriptId(scriptId);
|
||||||
|
if (runScenarioModel == null) {
|
||||||
|
return setTestPlanResponseModel(false,
|
||||||
|
"RunScenarioModel's content is null", null);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
this.runTestWithRunScenarioModel(runScenarioModel, requireLoad);
|
List<RunScenarioResultModel> list = this
|
||||||
|
.runTestWithRunScenarioModel(runScenarioModel, requireLoad);
|
||||||
|
return setTestPlanResponseModel(true, "success", list);
|
||||||
} catch (JAXBException e) {
|
} catch (JAXBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return setTestPlanResponseModel(false, "Run test fails", null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,31 +99,31 @@ public class TestPlanController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
public Map<String, UUID> runTestWithRunScenarioModel(
|
public List<RunScenarioResultModel> runTestWithRunScenarioModel(
|
||||||
RunScenarioModel runScenarioModel, int requireLoad)
|
RunScenarioModel runScenarioModel, int requireLoad)
|
||||||
throws JAXBException {
|
throws JAXBException {
|
||||||
// TODO: is it needed to be synchronized, but i think it is;
|
// TODO: is it needed to be synchronized, but i think it is;
|
||||||
Iterator<Agent> iterator;
|
Iterator<Agent> iterator;
|
||||||
Agent agent;
|
Agent agent;
|
||||||
Map<String, UUID> map = new HashMap<String, UUID>();
|
List<RunScenarioResultModel> resulList = new ArrayList<RunScenarioResultModel>();
|
||||||
|
|
||||||
if (!waitOnAgentLock()) {
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// TODO:i think this should be done by HA and Ballancer
|
||||||
for (iterator = this.getAgentPoolService().loadAgentPoolFromDB()
|
for (iterator = this.getAgentPoolService().loadAgentPoolFromDB()
|
||||||
.iterator(); iterator.hasNext();) {
|
.iterator(); iterator.hasNext();) {
|
||||||
|
if (requireLoad <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
agent = iterator.next();
|
agent = iterator.next();
|
||||||
|
|
||||||
if (!this.getAgentStateService().askLiving(agent.getHostName(),
|
if (!this.getAgentStateService().askLiving(agent.getHostName(),
|
||||||
agent.getPort())) {
|
agent.getPort())) {
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (agent.getRemainLoad() > requireLoad) {
|
if (agent.getRemainLoad() > requireLoad) {
|
||||||
|
|
||||||
|
runScenarioModel.setPoolSize(agent.getMaxLoad());
|
||||||
|
runScenarioModel.setTotalCount(requireLoad);
|
||||||
this.getAgentPoolService().getLoadFromAgent(
|
this.getAgentPoolService().getLoadFromAgent(
|
||||||
agent.getHostName(), requireLoad);
|
agent.getHostName(), requireLoad);
|
||||||
|
|
||||||
|
@ -124,25 +132,12 @@ public class TestPlanController extends BaseController {
|
||||||
agent.getPort(),
|
agent.getPort(),
|
||||||
this.marShallRunScenarioModel(runScenarioModel));
|
this.marShallRunScenarioModel(runScenarioModel));
|
||||||
|
|
||||||
if (!runScenarioResultModel.getRunId().equals(null)) {
|
// TODO:for now, i just think it's stable
|
||||||
map.put(agent.getHostName(),
|
resulList.add(runScenarioResultModel);
|
||||||
runScenarioResultModel.getRunId());
|
requireLoad = 0;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return resulList;
|
||||||
}
|
|
||||||
|
|
||||||
private boolean waitOnAgentLock() {
|
|
||||||
try {
|
|
||||||
this.getAgentPoolService().getAgentLock().wait();
|
|
||||||
return true;
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String marShallRunScenarioModel(RunScenarioModel runScenarioModel)
|
public String marShallRunScenarioModel(RunScenarioModel runScenarioModel)
|
||||||
|
@ -185,4 +180,13 @@ public class TestPlanController extends BaseController {
|
||||||
.unmarshal(new ByteArrayInputStream(responseContent.getBytes()));
|
.unmarshal(new ByteArrayInputStream(responseContent.getBytes()));
|
||||||
return resultModel;
|
return resultModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TestPlanResponseModel setTestPlanResponseModel(boolean success,
|
||||||
|
String failCause, List<RunScenarioResultModel> list) {
|
||||||
|
TestPlanResponseModel resultModel = new TestPlanResponseModel();
|
||||||
|
resultModel.setSuccess(success);
|
||||||
|
resultModel.setFailCause(failCause);
|
||||||
|
resultModel.setRunScenarioResultModels(list);
|
||||||
|
return resultModel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
package org.bench4q.master.api.model;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
|
|
||||||
@XmlRootElement
|
|
||||||
public class RunTestPlanResultModel {
|
|
||||||
private Vector<UUID> runIds;
|
|
||||||
|
|
||||||
@XmlElementWrapper
|
|
||||||
@XmlElement
|
|
||||||
public Vector<UUID> getRunIds() {
|
|
||||||
return runIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRunIds(Vector<UUID> runIds) {
|
|
||||||
this.runIds = runIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -8,6 +8,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||||
@XmlRootElement(name = "runScenarioResult")
|
@XmlRootElement(name = "runScenarioResult")
|
||||||
public class RunScenarioResultModel {
|
public class RunScenarioResultModel {
|
||||||
private UUID runId;
|
private UUID runId;
|
||||||
|
private String hostName;
|
||||||
|
|
||||||
@XmlElement
|
@XmlElement
|
||||||
public UUID getRunId() {
|
public UUID getRunId() {
|
||||||
|
@ -18,4 +19,13 @@ public class RunScenarioResultModel {
|
||||||
this.runId = runId;
|
this.runId = runId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@XmlElement
|
||||||
|
public String getHostName() {
|
||||||
|
return hostName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHostName(String hostName) {
|
||||||
|
this.hostName = hostName;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
||||||
|
|
||||||
usePlugin1.setParameters(new ArrayList<ParameterModel>());
|
usePlugin1.setParameters(new ArrayList<ParameterModel>());
|
||||||
usePlugin1.setId("http");
|
usePlugin1.setId("http");
|
||||||
usePlugin1.setName("Http");
|
usePlugin1.setName("http");
|
||||||
|
|
||||||
usePlugin2.setId("timer");
|
usePlugin2.setId("timer");
|
||||||
usePlugin2.setParameters(new ArrayList<ParameterModel>());
|
usePlugin2.setParameters(new ArrayList<ParameterModel>());
|
||||||
|
@ -172,7 +172,7 @@ public class Bench4qCodeGenerator extends AbstractCodeGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
userBehavior.setName(method);
|
userBehavior.setName(method);
|
||||||
userBehavior.setUse("Http");
|
userBehavior.setUse("http");
|
||||||
userBehavior.setParameters(params);
|
userBehavior.setParameters(params);
|
||||||
|
|
||||||
return userBehavior;
|
return userBehavior;
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AgentService {
|
public class AgentService {
|
||||||
private SessionHelper sessionHelper;
|
private SessionHelper sessionHelper = new SessionHelper();
|
||||||
private Object AGENT_LOCK = new Object();
|
private Object AGENT_LOCK = new Object();
|
||||||
|
|
||||||
public AgentService() {
|
public AgentService() {
|
||||||
|
|
|
@ -17,7 +17,8 @@ public class AgentPoolControllerTest extends AbstractJUnit4SpringContextTests {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
AgentController agentController = new AgentController();
|
AgentController agentController = new AgentController();
|
||||||
Agent agent = new Agent();
|
Agent agent = new Agent();
|
||||||
agent.setHostName("133.133.12.6");
|
// agent.setHostName("133.133.12.6");
|
||||||
|
agent.setHostName("127.0.0.1");
|
||||||
agent.setMaxLoad(500);
|
agent.setMaxLoad(500);
|
||||||
agent.setRemainLoad(500);
|
agent.setRemainLoad(500);
|
||||||
agent.setPort(6565);
|
agent.setPort(6565);
|
||||||
|
@ -34,7 +35,8 @@ public class AgentPoolControllerTest extends AbstractJUnit4SpringContextTests {
|
||||||
AgentController agentController = new AgentController();
|
AgentController agentController = new AgentController();
|
||||||
|
|
||||||
Agent agent = new Agent();
|
Agent agent = new Agent();
|
||||||
agent.setHostName("133.133.12.6");
|
// agent.setHostName("133.133.12.6");
|
||||||
|
agent.setHostName("127.0.0.1");
|
||||||
agent.setMaxLoad(500);
|
agent.setMaxLoad(500);
|
||||||
agent.setRemainLoad(500);
|
agent.setRemainLoad(500);
|
||||||
agent.setPort(6565);
|
agent.setPort(6565);
|
||||||
|
|
|
@ -3,9 +3,7 @@ package org.bench4q.master.test;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
|
@ -14,6 +12,7 @@ import org.bench4q.master.api.AgentController;
|
||||||
import org.bench4q.master.api.TestPlanController;
|
import org.bench4q.master.api.TestPlanController;
|
||||||
import org.bench4q.master.communication.agent.ParameterModel;
|
import org.bench4q.master.communication.agent.ParameterModel;
|
||||||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
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.TestBriefStatusModel;
|
||||||
import org.bench4q.master.communication.agent.UsePluginModel;
|
import org.bench4q.master.communication.agent.UsePluginModel;
|
||||||
import org.bench4q.master.communication.agent.UserBehaviorModel;
|
import org.bench4q.master.communication.agent.UserBehaviorModel;
|
||||||
|
@ -81,16 +80,16 @@ public class TestPlanTester {
|
||||||
marshaller.marshal(runScenarioModel, stringWriter);
|
marshaller.marshal(runScenarioModel, stringWriter);
|
||||||
// String content = stringWriter.toString();
|
// String content = stringWriter.toString();
|
||||||
|
|
||||||
Map<String, UUID> vector = testPlanController
|
List<RunScenarioResultModel> map = testPlanController
|
||||||
.runTestWithRunScenarioModel(runScenarioModel,
|
.runTestWithRunScenarioModel(runScenarioModel,
|
||||||
runScenarioModel.getTotalCount());
|
runScenarioModel.getTotalCount());
|
||||||
Iterator<String> iterator = vector.keySet().iterator();
|
Iterator<RunScenarioResultModel> iterator = map.iterator();
|
||||||
String hostNameString;
|
RunScenarioResultModel runResultModel;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
hostNameString = iterator.next();
|
runResultModel = iterator.next();
|
||||||
TestBriefStatusModel testBriefStatusModel = (new AgentController())
|
TestBriefStatusModel testBriefStatusModel = (new AgentController())
|
||||||
.getBriefStatusModelFromAgent(hostNameString, 6565,
|
.getBriefStatusModelFromAgent(runResultModel.getHostName(),
|
||||||
vector.get(hostNameString));
|
6565, runResultModel.getRunId());
|
||||||
System.out.println(testBriefStatusModel.getAverageResponseTime());
|
System.out.println(testBriefStatusModel.getAverageResponseTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue