remove redundant code

This commit is contained in:
Tienan Chen 2013-11-01 15:08:16 +08:00
parent 57d9329dd9
commit 13cd25a927
2 changed files with 1 additions and 186 deletions

View File

@ -4,7 +4,6 @@ import java.util.UUID;
import org.apache.log4j.Logger;
import org.bench4q.master.api.model.RunningScriptModel;
import org.bench4q.master.communication.HttpRequester;
import org.bench4q.master.testPlan.highavailable.HighAvailableAgentPool;
import org.bench4q.master.testPlan.loadcommand.LoadCommand;
import org.bench4q.master.testPlan.loadcommand.ScriptLoadCommand;
@ -14,29 +13,9 @@ import org.springframework.stereotype.Component;
@Component
public class LoadBallancer {
// private ScriptService scriptService;
// private AgentService agentService;
private HighAvailableAgentPool highAvailableAgentPool;
private static Logger logger = Logger.getLogger(LoadBallancer.class);
// @Autowired
// public void setScriptService(ScriptService scriptService) {
// this.scriptService = scriptService;
// }
// private AgentService getAgentService() {
// return agentService;
// }
//
// @Autowired
// public void setAgentService(AgentService agentService) {
// this.agentService = agentService;
// }
@Autowired
public void setHttpRequester(HttpRequester httpRequester) {
}
public HighAvailableAgentPool getHighAvailableAgentPool() {
return highAvailableAgentPool;
}
@ -56,15 +35,6 @@ public class LoadBallancer {
}
for (RunningScriptModel scriptInputModel : testPlanContext
.getRunningScriptMap().values()) {
// RunningScriptModel sOutputModel = this.generateLoadForScript(
// scriptInputModel, testPlanId);
// if (sOutputModel == null) {
// logger.error("generateLoadForScriptFails where scriptInputModel is null and script num is :"
// + testPlanContext.getRunningScriptMap().size());
// return false;
// }
// testPlanContext.addToScriptMap(sOutputModel.getScriptId(),
// sOutputModel);
LoadCommand scriptLoadCommand = new ScriptLoadCommand(
scriptInputModel, testPlanId);
RunningScriptModel sOutputModel = (RunningScriptModel) scriptLoadCommand
@ -84,159 +54,4 @@ public class LoadBallancer {
.getTotalLoad();
}
// private RunningScriptModel generateLoadForScript(
// RunningScriptModel scriptInputModel, UUID testPlanId) {
// RunScenarioModel runScenarioModel = this.scriptService
// .getRunSceniroModelByScriptId(scriptInputModel.getScriptId());
// if (runScenarioModel == null) {
// return null;
// }
// try {
// RunningScriptModel result = this.runAgentsWithScenario(
// runScenarioModel, scriptInputModel.getRequireLoad(),
// scriptInputModel.getScriptId(), testPlanId);
//
// if (result.getRunningAgents() == null) {
// // this means that allocation for this script fails
// // TODO: sign the script's failure in response.
// logger.error("runAgentsWithScenario fails where scriptId = "
// + result.getScriptId());
// return null;
// }
// result.setRequireLoad(scriptInputModel.getRequireLoad());
// result.setConfig(scriptInputModel.getConfig());
// return result;
// } catch (JAXBException e) {
// e.printStackTrace();
// return null;
// }
// }
// private RunningScriptModel runAgentsWithScenario(
// RunScenarioModel runScenarioModel, int totalRequireLoad,
// int scriptId, UUID testPlanId) throws JAXBException {
// RunningAgentModel runningAgentModel = new RunningAgentModel();
// RunScenarioResultModel runScenarioResultModel = new
// RunScenarioResultModel();
// List<RunningAgentModel> runningAgentModelList = new
// ArrayList<RunningAgentModel>();
// int loadForRunCurrent;
//
// for (Agent agent : this.getHighAvailableAgentPool()
// .getHighAvailablePool()) {
// if (allocationFinish(totalRequireLoad)) {
// break;
// }
// if (this.highAvailableAgentPool.queryAgentStatus(agent) == null
// || inUse(agent)) {
// continue;
// }
// loadForRunCurrent = getMin(totalRequireLoad, agent.getRemainLoad());
// runScenarioModel.setPoolSize(loadForRunCurrent);
// runScenarioModel.setTotalCount(loadForRunCurrent);
// runScenarioResultModel = runAgentWithScenario(runScenarioModel,
// agent);
// if (runScenarioResultModel == null) {
// continue;
// }
// runningAgentModel = buildRunningAgentModel(agent,
// loadForRunCurrent, scriptId,
// runScenarioResultModel.getRunId());
// runningAgentModelList.add(runningAgentModel);
//
// this.highAvailableAgentPool.getAgentRunBlotters().put(
// runScenarioResultModel.getRunId(),
// buildAgentRunBlotter(runningAgentModel, testPlanId));
// totalRequireLoad -= loadForRunCurrent;
// }
//
// if (!allocationFinish(totalRequireLoad)) {
// logger.error("allocationUnfinished, remain " + totalRequireLoad
// + " unallocated");
// runningAgentModelList =
// rollbackForUnfinishedAllocation(runningAgentModelList);
// }
// return buildRunningScriptModel(runningAgentModelList, scriptId);
// }
// private List<RunningAgentModel> rollbackForUnfinishedAllocation(
// List<RunningAgentModel> runningAgentModelList) {
// stopAgentsRunningThisScript(runningAgentModelList);
// runningAgentModelList = null;
// return runningAgentModelList;
// }
// private boolean allocationFinish(int requireLoad) {
// return requireLoad <= 0;
// }
// private void stopAgentsRunningThisScript(
// List<RunningAgentModel> runningAgentModels) {
// for (RunningAgentModel runningAgentModel : runningAgentModels) {
// this.getAgentService().stop(runningAgentModel.getAgent(),
// runningAgentModel.getAgentRunId());
// }
// }
// private RunScenarioResultModel runAgentWithScenario(
// RunScenarioModel runScenarioModel, Agent agent)
// throws JAXBException {
// try {
// if (!this.getAgentService().getLoadFromAgent(agent.getHostName(),
// runScenarioModel.getPoolSize())) {
// return null;
// }
// return this.getAgentService().run(agent,
// this._marshalRunScenarioModelToString(runScenarioModel));
//
// } catch (IOException e) {
// e.printStackTrace();
// return null;
// }
// }
// private RunningAgentModel buildRunningAgentModel(Agent agent,
// int loadInUse, int scriptId, UUID agentRunId) {
// RunningAgentModel runningAgentModel = new RunningAgentModel();
// runningAgentModel.setAgent(agent);
// runningAgentModel.setLoadInUse(loadInUse);
// runningAgentModel.setScriptId(scriptId);
// runningAgentModel.setAgentRunId(agentRunId);
// return runningAgentModel;
// }
//
// private AgentRunBlotter buildAgentRunBlotter(
// RunningAgentModel runningAgentModel, UUID testPlanId) {
// AgentRunBlotter result = new AgentRunBlotter();
// result.setRunningAgentModel(runningAgentModel);
// result.setTestPlanId(testPlanId);
// return result;
// }
// private boolean inUse(Agent agent) {
// return agent.getRemainLoad() < agent.getMaxLoad();
// }
//
// private int getMin(int requireLoad, int remainLoadByStart) {
// return remainLoadByStart >= requireLoad ? requireLoad
// : remainLoadByStart;
// }
// private String _marshalRunScenarioModelToString(
// RunScenarioModel runScenarioModel) throws JAXBException {
// Marshaller marshaller;
// marshaller = JAXBContext.newInstance(runScenarioModel.getClass())
// .createMarshaller();
// StringWriter stringWriter = new StringWriter();
// marshaller.marshal(runScenarioModel, stringWriter);
// return stringWriter.toString();
// }
//
// private RunningScriptModel buildRunningScriptModel(
// List<RunningAgentModel> runningAgentModels, int scriptId) {
// RunningScriptModel result = new RunningScriptModel();
// result.setScriptId(scriptId);
// result.setRunningAgents(runningAgentModels);
// return result;
// }
}

View File

@ -29,7 +29,7 @@ public class TestPlanTester extends TestBase {
private int scriptSumNum;
private static int SCRIPTID1 = 18;
private static int SCRIPTID2 = 2;
private static int EACH_SCRIPT_LOAD = 500;
private static int EACH_SCRIPT_LOAD = 600;
private static String Monitor_Host_Name = "133.133.12.3";
private static String monitor_port = "5556";