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

View File

@ -1,10 +1,14 @@
package org.bench4q.master.testplan.highavailable.faultolerence;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.infrastructure.communication.AgentMessenger;
import org.bench4q.master.testplan.highavailable.HighAvailablePool;
public class BriefAgentFault implements FaultTolerance {
private HighAvailablePool haPool;
private AgentMessenger agentMessenger;
private Agent agent;
private HighAvailablePool getHaPool() {
return haPool;
@ -14,12 +18,39 @@ public class BriefAgentFault implements FaultTolerance {
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(
HighAvailablePool.class));
this.setAgentMessenger(ApplicationContextHelper.getContext().getBean(
AgentMessenger.class));
}
public void doTolerance() {
if (isLiving()) {
return;
}
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;
import java.util.UUID;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.share.models.agent.RunScenarioModel;
public class FaultTolerenceFactory {
private static final BriefAgentFault briefAgentFault = new BriefAgentFault();
public static FaultTolerance getBriefFaultTolerance() {
return briefAgentFault;
public static FaultTolerance getBriefFaultTolerance(Agent agent) {
return new BriefAgentFault(agent);
}
public static FaultTolerance getRunAgentFault(Agent agent,
RunScenarioModel 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;
import java.util.UUID;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.testplan.highavailable.AgentRunBlotter;
public class StopAgentFault implements FaultTolerance {
private AgentRunBlotter agentBlotter;
public AgentRunBlotter getAgentBlotter() {
return agentBlotter;
public StopAgentFault(Agent agent, UUID runId) {
// TODO Auto-generated constructor stub
}
public void setAgentBlotter(AgentRunBlotter agentBlotter) {
this.agentBlotter = agentBlotter;
}
public StopAgentFault(AgentRunBlotter agentRunBlotter) {
this.setAgentBlotter(agentRunBlotter);
public StopAgentFault(AgentRunBlotter buildAgentRunBlotter) {
// TODO Auto-generated constructor stub
}
public void doTolerance() {