a little step and need to test

a little step and need to test
This commit is contained in:
coderfengyun 2014-05-07 17:11:32 +08:00
parent dd3cfe2453
commit 8f55e6fcb1
5 changed files with 23 additions and 110 deletions

View File

@ -23,6 +23,8 @@ public interface RunningAgentInterface {
public void substituteOnBoard();
public boolean stop();
public abstract class AbstractRunningAgent {
public static RunningAgentInterface buildRunningAgentDBWithoutId(

View File

@ -18,6 +18,7 @@ import org.bench4q.master.infrastructure.communication.AgentMessenger;
import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.RunScenarioResultModel;
import org.bench4q.share.models.agent.StopTestModel;
@Entity
@Table(name = "runningAgent")
@ -167,6 +168,12 @@ public class RunningAgentDB implements RunningAgentInterface {
// this.getAgentMessenger().
}
public boolean stop() {
StopTestModel result = this.getAgentMessenger().stop(getAgent(),
getAgentRunId());
return result != null && result.isSuccess();
}
public void substituteOnBoard() {
this.getTestPlanScript().applyForLoad(this.getLoadInUse());
this.distributeScriptAndParams();

View File

@ -1,9 +1,8 @@
package org.bench4q.master.domain.valueobject.transaction.impl;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import javax.xml.bind.JAXBException;
import org.apache.log4j.Logger;
@ -15,19 +14,15 @@ import org.bench4q.master.domain.valueobject.transaction.Transaction;
import org.bench4q.master.domain.valueobject.transaction.exception.ScriptLoadDistributeException;
import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.infrastructure.communication.AgentMessenger;
import org.bench4q.master.infrastructure.highavailable.HighAvailablePool;
import org.bench4q.master.infrastructure.highavailable.impl.HighAvailablePoolImpl;
import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.RunScenarioResultModel;
import org.bench4q.share.models.agent.StopTestModel;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class ScriptLoadBase implements Transaction {
private RunningScriptInterface runningScript;
private UUID testPlanRunID;
private List<RunningAgentInterface> agentListThisTime;
private AgentMessenger runningAgentService;
private HighAvailablePool highAvailableAgentPool;
private static Logger logger = Logger
.getLogger(ScriptLoadApplication.class);
@ -40,14 +35,6 @@ public abstract class ScriptLoadBase implements Transaction {
this.runningScript = runningScript;
}
private UUID getTestPlanRunID() {
return testPlanRunID;
}
protected void setTestPlanRunID(UUID testPlanRunID) {
this.testPlanRunID = testPlanRunID;
}
private List<RunningAgentInterface> getAgentListThisTime() {
return agentListThisTime;
}
@ -57,14 +44,6 @@ public abstract class ScriptLoadBase implements Transaction {
this.agentListThisTime = agentListThisTime;
}
private AgentMessenger getRunningAgentService() {
return runningAgentService;
}
private void setRunningAgentService(AgentMessenger runningAgentService) {
this.runningAgentService = runningAgentService;
}
private HighAvailablePool getHighAvailableAgentPool() {
return highAvailableAgentPool;
}
@ -84,15 +63,11 @@ public abstract class ScriptLoadBase implements Transaction {
}
public ScriptLoadBase(RunningScriptInterface runningScript) {
initialize(runningScript, runningScript.getTestPlanID());
initialize(runningScript);
}
private void initialize(RunningScriptInterface runningScript,
UUID testPlanID) {
private void initialize(RunningScriptInterface runningScript) {
this.setRunningScript(runningScript);
this.setTestPlanRunID(testPlanID);
this.setRunningAgentService(ApplicationContextHelper.getContext()
.getBean(AgentMessenger.class));
this.setHighAvailableAgentPool(ApplicationContextHelper.getContext()
.getBean(HighAvailablePoolImpl.class));
this.setAgentListThisTime(new ArrayList<RunningAgentInterface>());
@ -112,15 +87,15 @@ public abstract class ScriptLoadBase implements Transaction {
+ this.getRunningScript().getScriptId());
throw new RuntimeException("Running Script not valid!");
}
this.applyForLoad(getRequireLoad(), this.getTestPlanRunID());
this.getAgentListThisTime().addAll(
this.applyForLoad(getRequireLoad()));
return this.getAgentListThisTime();
} catch (Exception e) {
logger.error(ExceptionLog.getStackTrace(e).toString()
+ " whose scriptID is "
+ this.getRunningScript().getScriptId()
+ " and TestPlanID is "
+ this.getTestPlanRunID().toString());
+ this.getRunningScript().getTestPlanID().toString());
throw new RuntimeException(e);
}
}
@ -131,15 +106,16 @@ public abstract class ScriptLoadBase implements Transaction {
protected abstract int getRequireLoad();
private void applyForLoad(int totalRequireLoad, UUID testPlanId)
private List<RunningAgentInterface> applyForLoad(int totalRequireLoad)
throws JAXBException, ScriptLoadDistributeException {
RunScenarioResultModel runScenarioResultModel = null;
List<RunningAgentInterface> result = new LinkedList<RunningAgentInterface>();
int loadForRunCurrent;
if (totalRequireLoad >= this.getHighAvailableAgentPool()
.getCurrentAvailableLoad()) {
logger.info("currentAvailableLoad not enough for substitute");
return;
return result;
}
for (Agent agent : this.getHighAvailableAgentPool().getPool().values()) {
if (allocationFinish(totalRequireLoad)) {
@ -162,8 +138,8 @@ public abstract class ScriptLoadBase implements Transaction {
.buildRunningAgentDBWithoutId(agent, loadForRunCurrent,
this.getRunningScript(),
runScenarioResultModel.getRunId());
this.getAgentListThisTime().add(runningAgent);
addAgentBlotterToHA(testPlanId, runningAgent);
result.add(runningAgent);
this.getHighAvailableAgentPool().addABlotter(runningAgent);
totalRequireLoad -= loadForRunCurrent;
}
if (!allocationFinish(totalRequireLoad)) {
@ -171,6 +147,7 @@ public abstract class ScriptLoadBase implements Transaction {
+ " unallocated");
throw new ScriptLoadDistributeException();
}
return result;
}
private boolean allocationFinish(int requireLoad) {
@ -187,12 +164,6 @@ public abstract class ScriptLoadBase implements Transaction {
: remainLoadByStart;
}
private void addAgentBlotterToHA(UUID testPlanId,
RunningAgentInterface runningAgent) {
this.getHighAvailableAgentPool().addABlotter(runningAgent);
// AgentRunBlotter.buildAgentRunBlotter(testPlanId, runningAgent));
}
public void rollBack() {
stopAgentsRunningThisScript();
}
@ -203,17 +174,12 @@ public abstract class ScriptLoadBase implements Transaction {
}
for (RunningAgentInterface runningAgent : this.getAgentListThisTime()) {
if (runningAgent.isBreakDown()) {
} else if (stopAgentSuccess(runningAgent)) {
continue;
}
runningAgent.stop();
this.getAgentListThisTime().remove(runningAgent);
this.highAvailableAgentPool.removeABlotter(runningAgent
.getAgentRunId());
}
}
private boolean stopAgentSuccess(RunningAgentInterface runningAgent) {
StopTestModel resultModel = this.getRunningAgentService().stop(
runningAgent.getAgent(), runningAgent.getAgentRunId());
return (resultModel != null) && resultModel.isSuccess();
}
}

View File

@ -3,16 +3,12 @@ package org.bench4q.master.infrastructure.faultolerence;
import java.util.UUID;
import org.bench4q.master.domain.entity.Agent;
import org.bench4q.master.infrastructure.highavailable.impl.AgentRunBlotter;
public class StopAgentFault implements FaultTolerance {
public StopAgentFault(Agent agent, UUID runId) {
}
public StopAgentFault(AgentRunBlotter buildAgentRunBlotter) {
}
public void doTolerance() {
// TODO: fulfill this function
}

View File

@ -1,58 +0,0 @@
package org.bench4q.master.infrastructure.highavailable.impl;
import java.util.UUID;
import org.bench4q.master.domain.RunningAgentInterface;
public class AgentRunBlotter {
private RunningAgentInterface runningAgent;
private UUID testPlanId;
private boolean hasSubstitute;
public RunningAgentInterface getRunningAgent() {
return runningAgent;
}
public void setRunningAgent(RunningAgentInterface runningAgent) {
this.runningAgent = runningAgent;
}
public UUID getTestPlanId() {
return testPlanId;
}
public void setTestPlanId(UUID testPlanId) {
this.testPlanId = testPlanId;
}
public boolean hasSubstitute() {
return hasSubstitute;
}
private void setHasSubstitute(boolean hasSubstitute) {
this.hasSubstitute = hasSubstitute;
}
private AgentRunBlotter() {
this.setHasSubstitute(false);
}
private AgentRunBlotter(UUID testPlanID, RunningAgentInterface runningAgent) {
this();
this.setTestPlanId(testPlanID);
this.setRunningAgent(runningAgent);
}
public static AgentRunBlotter buildAgentRunBlotter(UUID testPlanID,
RunningAgentInterface runningAgent) {
return new AgentRunBlotter(testPlanID, runningAgent);
}
void substituteOnBoard(UUID deadRunId) {
if (this.getRunningAgent().hasSubstitute()) {
return;
}
this.getRunningAgent().substituteOnBoard();
}
}