refator and i want to load the agents from db when start up

This commit is contained in:
Tienan Chen 2013-11-04 16:18:32 +08:00
parent 0c1ce42d3a
commit 31753cc530
4 changed files with 41 additions and 20 deletions

View File

@ -1,18 +1,19 @@
package org.bench4q.master;
import org.bench4q.master.service.AgentService;
import org.bench4q.master.testPlan.highavailable.HighAvailablePool;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.bio.SocketConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.DispatcherServlet;
public class MasterServer {
private Server server;
private int port;
private AgentService agentPoolService = new AgentService();
private AgentService agentService;
private HighAvailablePool highAvailablePool;
private Server getServer() {
return server;
@ -34,13 +35,20 @@ public class MasterServer {
this.setPort(port);
}
public AgentService getAgentPoolService() {
return agentPoolService;
public AgentService getAgentService() {
return agentService;
}
@Autowired
public void setAgentPoolService(AgentService agentPoolService) {
this.agentPoolService = agentPoolService;
public void setAgentService(AgentService agentPoolService) {
this.agentService = agentPoolService;
}
public HighAvailablePool getHighAvailablePool() {
return highAvailablePool;
}
public void setHighAvailablePool(HighAvailablePool highAvailablePool) {
this.highAvailablePool = highAvailablePool;
}
public boolean start() {
@ -57,7 +65,11 @@ public class MasterServer {
"classpath*:org/bench4q/master/config/application-context.xml");
this.getServer().setHandler(servletContextHandler);
this.getServer().start();
// this.setAgentService(ApplicationContextHelper.getContext().getBean(
// AgentService.class));
// this.setHighAvailablePool(ApplicationContextHelper.getContext()
// .getBean(HighAvailablePool.class));
// this.loadAgentList();
return true;
} catch (Exception e) {
e.printStackTrace();
@ -65,6 +77,15 @@ public class MasterServer {
}
}
// private void loadAgentList() {
// Map<String, Agent> pool = this.getHighAvailablePool().getPool();
// pool.clear();
// for (Agent agent : this.getAgentService().loadAgentPoolFromDB()) {
// pool.put(agent.getHostName(), agent);
// }
//
// }
public boolean stop() {
try {
if (this.getServer() != null) {

View File

@ -4,7 +4,7 @@ import java.util.UUID;
import org.apache.log4j.Logger;
import org.bench4q.master.api.model.RunningScriptModel;
import org.bench4q.master.testPlan.highavailable.HighAvailableAgentPool;
import org.bench4q.master.testPlan.highavailable.HighAvailablePool;
import org.bench4q.master.testPlan.loadcommand.LoadTransaction;
import org.bench4q.master.testPlan.loadcommand.ScriptLoadCommand;
import org.springframework.beans.factory.annotation.Autowired;
@ -13,16 +13,16 @@ import org.springframework.stereotype.Component;
@Component
public class LoadDistribute {
private HighAvailableAgentPool highAvailableAgentPool;
private HighAvailablePool highAvailableAgentPool;
private static Logger logger = Logger.getLogger(LoadDistribute.class);
public HighAvailableAgentPool getHighAvailableAgentPool() {
public HighAvailablePool getHighAvailableAgentPool() {
return highAvailableAgentPool;
}
@Autowired
public void setHighAvailableAgentPool(
HighAvailableAgentPool highAvailableAgentPool) {
HighAvailablePool highAvailableAgentPool) {
this.highAvailableAgentPool = highAvailableAgentPool;
}

View File

@ -24,7 +24,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class HighAvailableAgentPool {
public class HighAvailablePool {
private Map<String, Agent> pool;
private AgentService agentService;
private ScriptService scriptService;
@ -34,7 +34,7 @@ public class HighAvailableAgentPool {
private Map<UUID, AgentRunBlotter> agentRunBlotters;
private long maxLoadOfHAPool;
private static Logger logger = Logger
.getLogger(HighAvailableAgentPool.class);
.getLogger(HighAvailablePool.class);
public Map<String, Agent> getPool() {
return this.pool;
@ -93,7 +93,7 @@ public class HighAvailableAgentPool {
this.agentRunBlotters = agentRunningInfo;
}
public HighAvailableAgentPool() {
public HighAvailablePool() {
this.setPool(new HashMap<String, Agent>());
this.setAgentRunBlotters(new HashMap<UUID, AgentRunBlotter>());
this.setAgentStatusOfPreviousBeatMap(new HashMap<String, ServerStatusModel>());

View File

@ -18,7 +18,7 @@ import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.service.AgentService;
import org.bench4q.master.service.ScriptService;
import org.bench4q.master.testPlan.AgentRunBlotter;
import org.bench4q.master.testPlan.highavailable.HighAvailableAgentPool;
import org.bench4q.master.testPlan.highavailable.HighAvailablePool;
public abstract class ScriptLoadBase implements LoadTransaction {
private RunningScriptModel runningScriptModel;
@ -26,7 +26,7 @@ public abstract class ScriptLoadBase implements LoadTransaction {
private List<RunningAgentModel> agentListThisTime = new ArrayList<RunningAgentModel>();
private AgentService agentService;
private ScriptService scriptService;
private HighAvailableAgentPool highAvailableAgentPool;
private HighAvailablePool highAvailableAgentPool;
private static Logger logger = Logger.getLogger(ScriptLoadCommand.class);
public RunningScriptModel getRunningScriptModel() {
@ -69,12 +69,12 @@ public abstract class ScriptLoadBase implements LoadTransaction {
this.scriptService = scriptService;
}
public HighAvailableAgentPool getHighAvailableAgentPool() {
public HighAvailablePool getHighAvailableAgentPool() {
return highAvailableAgentPool;
}
public void setHighAvailableAgentPool(
HighAvailableAgentPool highAvailableAgentPool) {
HighAvailablePool highAvailableAgentPool) {
this.highAvailableAgentPool = highAvailableAgentPool;
}
@ -95,7 +95,7 @@ public abstract class ScriptLoadBase implements LoadTransaction {
this.setScriptService(ApplicationContextHelper.getContext().getBean(
ScriptService.class));
this.setHighAvailableAgentPool(ApplicationContextHelper.getContext()
.getBean(HighAvailableAgentPool.class));
.getBean(HighAvailablePool.class));
}
public Object execute() {