add faultTolerances

This commit is contained in:
coderfengyun 2014-02-27 17:46:36 +08:00
parent 44f36e8a7a
commit b652556278
4 changed files with 69 additions and 50 deletions

View File

@ -8,7 +8,6 @@ import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
import org.bench4q.master.testplan.highavailable.faultolerence.FaultTolerenceFactory; import org.bench4q.master.testplan.highavailable.faultolerence.FaultTolerenceFactory;
import org.bench4q.share.communication.HttpRequester; import org.bench4q.share.communication.HttpRequester;
import org.bench4q.share.communication.HttpRequester.HttpResponse; import org.bench4q.share.communication.HttpRequester.HttpResponse;
@ -27,7 +26,6 @@ import org.springframework.stereotype.Component;
@Component @Component
public class AgentMessenger { public class AgentMessenger {
private HttpRequester httpRequester; private HttpRequester httpRequester;
private HighAvailablePool haPool;
private Logger logger = Logger.getLogger(AgentMessenger.class); private Logger logger = Logger.getLogger(AgentMessenger.class);
public HttpRequester getHttpRequester() { public HttpRequester getHttpRequester() {
@ -39,15 +37,6 @@ public class AgentMessenger {
this.httpRequester = httpRequester; this.httpRequester = httpRequester;
} }
private HighAvailablePool getHaPool() {
return haPool;
}
@Autowired
private void setHaPool(HighAvailablePool haPool) {
this.haPool = haPool;
}
public RunScenarioResultModel run(Agent agent, public RunScenarioResultModel run(Agent agent,
RunScenarioModel runScenarioModel) throws IOException { RunScenarioModel runScenarioModel) throws IOException {
HttpResponse httpResponse; HttpResponse httpResponse;
@ -62,16 +51,13 @@ public class AgentMessenger {
RunScenarioResultModel.class, httpResponse.getContent()); RunScenarioResultModel.class, httpResponse.getContent());
} catch (JAXBException e) { } catch (JAXBException e) {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
handleBreakDown(agent); FaultTolerenceFactory.getRunAgentFault(agent, runScenarioModel)
.doTolerance();
return null; return null;
} }
} }
private void handleBreakDown(Agent agent) {
this.getHaPool().timerTask();
}
public AgentBriefStatusModel brief(Agent agent, UUID agentRunId) { public AgentBriefStatusModel brief(Agent agent, UUID agentRunId) {
HttpResponse httpResponse; HttpResponse httpResponse;
try { try {
@ -89,8 +75,7 @@ public class AgentMessenger {
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString() + " When brief the agent with hostName " logger.error(e.toString() + " When brief the agent with hostName "
+ agent.getHostName()); + agent.getHostName());
handleBreakDown(agent); FaultTolerenceFactory.getBriefFaultTolerance(agent).doTolerance();
FaultTolerenceFactory.getBriefFaultTolerance().doTolerance();
return null; return null;
} }
} }
@ -111,7 +96,7 @@ public class AgentMessenger {
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString() + " when stop the agent with hostName " logger.error(e.toString() + " when stop the agent with hostName "
+ agent.getHostName()); + agent.getHostName());
handleBreakDown(agent); FaultTolerenceFactory.getStopAgentFault(agent, runId).doTolerance();
return null; return null;
} }
} }
@ -133,7 +118,7 @@ public class AgentMessenger {
AgentBehaviorsBriefModel.class, httpResponse.getContent()); AgentBehaviorsBriefModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e) + " When behaviorsBrief"); logger.error(ExceptionLog.getStackTrace(e) + " When behaviorsBrief");
handleBreakDown(agent); FaultTolerenceFactory.getBriefFaultTolerance(agent).doTolerance();
return null; return null;
} }
} }
@ -151,7 +136,7 @@ public class AgentMessenger {
AgentPageBriefModel.class, httpResponse.getContent()); AgentPageBriefModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
handleBreakDown(agent); FaultTolerenceFactory.getBriefFaultTolerance(agent).doTolerance();
return null; return null;
} }
} }
@ -169,7 +154,7 @@ public class AgentMessenger {
AgentPagesBriefModel.class, httpResponse.getContent()); AgentPagesBriefModel.class, httpResponse.getContent());
} catch (Exception e) { } catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e)); logger.error(ExceptionLog.getStackTrace(e));
handleBreakDown(agent); FaultTolerenceFactory.getBriefFaultTolerance(agent).doTolerance();
return null; return null;
} }

View File

@ -1,10 +1,14 @@
package org.bench4q.master.testplan.highavailable.faultolerence; package org.bench4q.master.testplan.highavailable.faultolerence;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.helper.ApplicationContextHelper; import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.infrastructure.communication.AgentMessenger;
import org.bench4q.master.testplan.highavailable.HighAvailablePool; import org.bench4q.master.testplan.highavailable.HighAvailablePool;
public class BriefAgentFault implements FaultTolerance { public class BriefAgentFault implements FaultTolerance {
private HighAvailablePool haPool; private HighAvailablePool haPool;
private AgentMessenger agentMessenger;
private Agent agent;
private HighAvailablePool getHaPool() { private HighAvailablePool getHaPool() {
return haPool; return haPool;
@ -14,12 +18,39 @@ public class BriefAgentFault implements FaultTolerance {
this.haPool = haPool; this.haPool = haPool;
} }
BriefAgentFault() { private AgentMessenger getAgentMessenger() {
return agentMessenger;
}
private void setAgentMessenger(AgentMessenger agentMessenger) {
this.agentMessenger = agentMessenger;
}
private Agent getAgent() {
return agent;
}
private void setAgent(Agent agent) {
this.agent = agent;
}
BriefAgentFault(Agent agent) {
this.setAgent(agent);
this.setHaPool(ApplicationContextHelper.getContext().getBean( this.setHaPool(ApplicationContextHelper.getContext().getBean(
HighAvailablePool.class)); HighAvailablePool.class));
this.setAgentMessenger(ApplicationContextHelper.getContext().getBean(
AgentMessenger.class));
} }
public void doTolerance() { public void doTolerance() {
if (isLiving()) {
return;
}
this.getHaPool().timerTask(); this.getHaPool().timerTask();
} }
private boolean isLiving() {
return this.getAgentMessenger().askLiving(this.getAgent().getHostName(),
this.getAgent().getPort()) != null;
}
} }

View File

@ -1,17 +1,22 @@
package org.bench4q.master.testplan.highavailable.faultolerence; package org.bench4q.master.testplan.highavailable.faultolerence;
import java.util.UUID;
import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.Agent;
import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioModel;
public class FaultTolerenceFactory { public class FaultTolerenceFactory {
private static final BriefAgentFault briefAgentFault = new BriefAgentFault();
public static FaultTolerance getBriefFaultTolerance() { public static FaultTolerance getBriefFaultTolerance(Agent agent) {
return briefAgentFault; return new BriefAgentFault(agent);
} }
public static FaultTolerance getRunAgentFault(Agent agent, public static FaultTolerance getRunAgentFault(Agent agent,
RunScenarioModel runScenarioModel) { RunScenarioModel runScenarioModel) {
return new RunAgentFault(agent, runScenarioModel); return new RunAgentFault(agent, runScenarioModel);
} }
public static FaultTolerance getStopAgentFault(Agent agent, UUID runId) {
return new StopAgentFault(agent, runId);
}
} }

View File

@ -1,20 +1,18 @@
package org.bench4q.master.testplan.highavailable.faultolerence; package org.bench4q.master.testplan.highavailable.faultolerence;
import java.util.UUID;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.testplan.highavailable.AgentRunBlotter; import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
public class StopAgentFault implements FaultTolerance { public class StopAgentFault implements FaultTolerance {
private AgentRunBlotter agentBlotter;
public AgentRunBlotter getAgentBlotter() { public StopAgentFault(Agent agent, UUID runId) {
return agentBlotter; // TODO Auto-generated constructor stub
} }
public void setAgentBlotter(AgentRunBlotter agentBlotter) { public StopAgentFault(AgentRunBlotter buildAgentRunBlotter) {
this.agentBlotter = agentBlotter; // TODO Auto-generated constructor stub
}
public StopAgentFault(AgentRunBlotter agentRunBlotter) {
this.setAgentBlotter(agentRunBlotter);
} }
public void doTolerance() { public void doTolerance() {