add server status report.

This commit is contained in:
Zhen Tang 2013-07-01 16:48:07 +08:00
parent 14d9f54e3d
commit 1aa4f9465c
3 changed files with 68 additions and 4 deletions

View File

@ -1,5 +1,14 @@
package org.bench4q.agent.api;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bench4q.agent.api.model.ServerStatusModel;
import org.bench4q.agent.scenario.ScenarioContext;
import org.bench4q.agent.scenario.ScenarioEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -8,10 +17,33 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/")
public class HomeController {
private ScenarioEngine scenarioEngine;
private ScenarioEngine getScenarioEngine() {
return scenarioEngine;
}
@Autowired
private void setScenarioEngine(ScenarioEngine scenarioEngine) {
this.scenarioEngine = scenarioEngine;
}
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
@ResponseBody
public String index() {
return "It works!";
public ServerStatusModel index() {
ServerStatusModel serverStatusModel = new ServerStatusModel();
serverStatusModel.setFinishedTests(new ArrayList<UUID>());
serverStatusModel.setRunningTests(new ArrayList<UUID>());
Map<UUID, ScenarioContext> contexts = new HashMap<UUID, ScenarioContext>(
getScenarioEngine().getRunningTests());
for (UUID key : contexts.keySet()) {
ScenarioContext value = contexts.get(key);
if (value.getResults().size() == value.getTotalCount()) {
serverStatusModel.getFinishedTests().add(key);
} else {
serverStatusModel.getRunningTests().add(key);
}
}
return serverStatusModel;
}
}

View File

@ -0,0 +1,32 @@
package org.bench4q.agent.api.model;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "serverStatus")
public class ServerStatusModel {
private List<UUID> runningTests;
private List<UUID> finishedTests;
@XmlElement
public List<UUID> getRunningTests() {
return runningTests;
}
public void setRunningTests(List<UUID> runningTests) {
this.runningTests = runningTests;
}
@XmlElement
public List<UUID> getFinishedTests() {
return finishedTests;
}
public void setFinishedTests(List<UUID> finishedTests) {
this.finishedTests = finishedTests;
}
}

View File

@ -23,8 +23,8 @@ public class RunScenarioTest {
public void testRunScenario() {
try {
RunScenarioModel runScenarioModel = new RunScenarioModel();
runScenarioModel.setTotalCount(30000);
runScenarioModel.setPoolSize(300);
runScenarioModel.setTotalCount(10000);
runScenarioModel.setPoolSize(100);
runScenarioModel.setUsePlugins(new ArrayList<UsePluginModel>());
runScenarioModel
.setUserBehaviors(new ArrayList<UserBehaviorModel>());