From 13cd25a92712baae34ebd8d5cae52fdd49b5d2bb Mon Sep 17 00:00:00 2001 From: Tienan Chen Date: Fri, 1 Nov 2013 15:08:16 +0800 Subject: [PATCH] remove redundant code --- .../master/testPlan/LoadBallancer.java | 185 ------------------ .../bench4q/master/test/TestPlanTester.java | 2 +- 2 files changed, 1 insertion(+), 186 deletions(-) diff --git a/src/main/java/org/bench4q/master/testPlan/LoadBallancer.java b/src/main/java/org/bench4q/master/testPlan/LoadBallancer.java index 7c6124d4..aef151dc 100644 --- a/src/main/java/org/bench4q/master/testPlan/LoadBallancer.java +++ b/src/main/java/org/bench4q/master/testPlan/LoadBallancer.java @@ -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 runningAgentModelList = new - // ArrayList(); - // 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 rollbackForUnfinishedAllocation( - // List runningAgentModelList) { - // stopAgentsRunningThisScript(runningAgentModelList); - // runningAgentModelList = null; - // return runningAgentModelList; - // } - - // private boolean allocationFinish(int requireLoad) { - // return requireLoad <= 0; - // } - - // private void stopAgentsRunningThisScript( - // List 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 runningAgentModels, int scriptId) { - // RunningScriptModel result = new RunningScriptModel(); - // result.setScriptId(scriptId); - // result.setRunningAgents(runningAgentModels); - // return result; - // } } diff --git a/src/test/java/org/bench4q/master/test/TestPlanTester.java b/src/test/java/org/bench4q/master/test/TestPlanTester.java index 75fa49e8..086bbfd4 100644 --- a/src/test/java/org/bench4q/master/test/TestPlanTester.java +++ b/src/test/java/org/bench4q/master/test/TestPlanTester.java @@ -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";