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