plugin info api added.

This commit is contained in:
Zhen Tang 2013-06-27 16:10:04 +08:00
parent b2b754c429
commit 7344b4e3e1
5 changed files with 163 additions and 7 deletions

View File

@ -28,6 +28,7 @@ public class HomeController {
@RequestMapping(value = { "/" }, method = RequestMethod.GET)
@ResponseBody
public String index() {
Scenario scenario = new Scenario();
scenario.setUsePlugins(new UsePlugin[2]);
@ -39,10 +40,7 @@ public class HomeController {
scenario.getUsePlugins()[1] = new UsePlugin();
scenario.getUsePlugins()[1].setId("timer");
scenario.getUsePlugins()[1].setName("ConstantTimer");
scenario.getUsePlugins()[1].setParameters(new Parameter[1]);
scenario.getUsePlugins()[1].getParameters()[0] = new Parameter();
scenario.getUsePlugins()[1].getParameters()[0].setKey("time");
scenario.getUsePlugins()[1].getParameters()[0].setValue("100");
scenario.getUsePlugins()[1].setParameters(new Parameter[0]);
scenario.setUserBehaviors(new UserBehavior[3]);
scenario.getUserBehaviors()[0] = new UserBehavior();
@ -79,8 +77,8 @@ public class HomeController {
scenario.getUserBehaviors()[2].getParameters()[0] = new Parameter();
scenario.getUserBehaviors()[2].getParameters()[0].setKey("time");
scenario.getUserBehaviors()[2].getParameters()[0].setValue("1000");
this.getScenarioEngine().runScenario(scenario, 100);
this.getScenarioEngine().runScenario(scenario, 100);
return "It works!";
}
}
}

View File

@ -0,0 +1,60 @@
package org.bench4q.agent.api;
import java.util.ArrayList;
import java.util.List;
import org.bench4q.agent.api.model.BehaviorInfoModel;
import org.bench4q.agent.api.model.PluginInfoListModel;
import org.bench4q.agent.api.model.PluginInfoModel;
import org.bench4q.agent.plugin.BehaviorInfo;
import org.bench4q.agent.plugin.PluginInfo;
import org.bench4q.agent.plugin.PluginManager;
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;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/plugin")
public class PluginController {
private PluginManager pluginManager;
public PluginManager getPluginManager() {
return pluginManager;
}
@Autowired
public void setPluginManager(PluginManager pluginManager) {
this.pluginManager = pluginManager;
}
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public PluginInfoListModel list() {
List<PluginInfo> pluginInfos = this.getPluginManager().getPluginInfo();
PluginInfoListModel pluginInfoListModel = new PluginInfoListModel();
pluginInfoListModel.setPlugins(new ArrayList<PluginInfoModel>());
for (PluginInfo pluginInfo : pluginInfos) {
PluginInfoModel pluginInfoModel = new PluginInfoModel();
pluginInfoModel.setName(pluginInfo.getName());
pluginInfoModel.setParameters(new ArrayList<String>());
for (String param : pluginInfo.getParameters()) {
pluginInfoModel.getParameters().add(param);
}
pluginInfoModel.setBehaviors(new ArrayList<BehaviorInfoModel>());
for (BehaviorInfo behaviorInfo : pluginInfo.getBehaviors()) {
BehaviorInfoModel behaviorInfoModel = new BehaviorInfoModel();
behaviorInfoModel.setName(behaviorInfo.getName());
behaviorInfoModel.setParameters(new ArrayList<String>());
for (String param : behaviorInfo.getParameters()) {
behaviorInfoModel.getParameters().add(param);
}
pluginInfoModel.getBehaviors().add(behaviorInfoModel);
}
pluginInfoListModel.getPlugins().add(pluginInfoModel);
}
return pluginInfoListModel;
}
}

View File

@ -0,0 +1,32 @@
package org.bench4q.agent.api.model;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "behaviorInfo")
public class BehaviorInfoModel {
private String name;
private List<String> parameters;
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElementWrapper(name = "parameters")
@XmlElement(name = "parameter")
public List<String> getParameters() {
return parameters;
}
public void setParameters(List<String> parameters) {
this.parameters = parameters;
}
}

View File

@ -0,0 +1,23 @@
package org.bench4q.agent.api.model;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "pluginList")
public class PluginInfoListModel {
private List<PluginInfoModel> plugins;
@XmlElementWrapper(name = "plugins")
@XmlElement(name = "plugin")
public List<PluginInfoModel> getPlugins() {
return plugins;
}
public void setPlugins(List<PluginInfoModel> plugins) {
this.plugins = plugins;
}
}

View File

@ -0,0 +1,43 @@
package org.bench4q.agent.api.model;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "pluginInfoItem")
public class PluginInfoModel {
private String name;
private List<String> parameters;
private List<BehaviorInfoModel> behaviors;
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElementWrapper(name = "parameters")
@XmlElement(name = "parameter")
public List<String> getParameters() {
return parameters;
}
public void setParameters(List<String> parameters) {
this.parameters = parameters;
}
@XmlElementWrapper(name = "behaviors")
@XmlElement(name = "behavior")
public List<BehaviorInfoModel> getBehaviors() {
return behaviors;
}
public void setBehaviors(List<BehaviorInfoModel> behaviors) {
this.behaviors = behaviors;
}
}