refactor go on

refactor go on
This commit is contained in:
coderfengyun 2014-05-08 15:25:05 +08:00
parent 9af631ad1c
commit 3cb3768da1
7 changed files with 37 additions and 59 deletions

View File

@ -3,6 +3,7 @@ package org.bench4q.master.domain;
import java.util.UUID; import java.util.UUID;
import org.bench4q.master.domain.entity.Agent; import org.bench4q.master.domain.entity.Agent;
import org.bench4q.share.models.agent.TestBriefStatusModel;
public interface RunningAgentInterface { public interface RunningAgentInterface {
public Agent getAgent(); public Agent getAgent();
@ -19,6 +20,8 @@ public interface RunningAgentInterface {
public void substituteOnBoard(); public void substituteOnBoard();
public TestBriefStatusModel briefAll();
public boolean stop(); public boolean stop();
} }

View File

@ -19,6 +19,7 @@ import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.RunScenarioResultModel; import org.bench4q.share.models.agent.RunScenarioResultModel;
import org.bench4q.share.models.agent.StopTestModel; import org.bench4q.share.models.agent.StopTestModel;
import org.bench4q.share.models.agent.TestBriefStatusModel;
@Entity @Entity
@Table(name = "runningAgent") @Table(name = "runningAgent")
@ -164,10 +165,6 @@ public class RunningAgentDB implements RunningAgentInterface {
return runScenarioResultModel != null; return runScenarioResultModel != null;
} }
public void briefAll() {
// this.getAgentMessenger().
}
public boolean stop() { public boolean stop() {
StopTestModel result = this.getAgentMessenger().stop(getAgent(), StopTestModel result = this.getAgentMessenger().stop(getAgent(),
getAgentRunId()); getAgentRunId());
@ -180,4 +177,10 @@ public class RunningAgentDB implements RunningAgentInterface {
this.run(); this.run();
this.setHasSubstitute(true); this.setHasSubstitute(true);
} }
@Override
public TestBriefStatusModel briefAll() {
return this.getAgentMessenger().scriptBriefAll(this.getAgent(),
this.getAgentRunId());
}
} }

View File

@ -33,10 +33,8 @@ import org.bench4q.master.domain.valueobject.schedulscript.WarmUpOverTask;
import org.bench4q.master.domain.valueobject.transaction.Transaction; import org.bench4q.master.domain.valueobject.transaction.Transaction;
import org.bench4q.master.domain.valueobject.transaction.TransactionFactory; import org.bench4q.master.domain.valueobject.transaction.TransactionFactory;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.infrastructure.communication.impl.AgentMessengerImpl;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.agent.RunScenarioModel; import org.bench4q.share.models.agent.RunScenarioModel;
import org.bench4q.share.models.agent.StopTestModel;
import org.bench4q.share.models.master.statistics.ScriptResultModel; import org.bench4q.share.models.master.statistics.ScriptResultModel;
@Entity @Entity
@ -52,7 +50,6 @@ public class TestPlanScript implements RunningScriptInterface {
private boolean finish; private boolean finish;
private TestPlanFactory testPlanFactory; private TestPlanFactory testPlanFactory;
private AgentMessengerImpl agentMessenger;
private TransactionFactory transactionFactory; private TransactionFactory transactionFactory;
private RunningScriptSampler sampler; private RunningScriptSampler sampler;
private AgentService agentService; private AgentService agentService;
@ -183,15 +180,6 @@ public class TestPlanScript implements RunningScriptInterface {
this.sampler = sampler; this.sampler = sampler;
} }
@Transient
private AgentMessengerImpl getAgentMessenger() {
return agentMessenger;
}
public void setAgentMessenger(AgentMessengerImpl agentMessenger) {
this.agentMessenger = agentMessenger;
}
@Transient @Transient
private AgentService getAgentService() { private AgentService getAgentService() {
return agentService; return agentService;
@ -248,8 +236,8 @@ public class TestPlanScript implements RunningScriptInterface {
for (RunningAgentInterface runningAgent : agentsAfterDistribute) { for (RunningAgentInterface runningAgent : agentsAfterDistribute) {
this.getRunningAgentsDB().add((RunningAgentDB) runningAgent); this.getRunningAgentsDB().add((RunningAgentDB) runningAgent);
} }
this.setSampler(new RunningScriptSampler(this.getAgentMessenger(), this.setSampler(new RunningScriptSampler(Collections
Collections.unmodifiableCollection(this.getRunningAgentsDB()))); .unmodifiableCollection(this.getRunningAgentsDB())));
} }
public List<TestPlanScriptResult> doAfterRun() { public List<TestPlanScriptResult> doAfterRun() {
@ -294,9 +282,7 @@ public class TestPlanScript implements RunningScriptInterface {
if (runningAgent == null) { if (runningAgent == null) {
continue; continue;
} }
StopTestModel resultModel = this.getAgentMessenger().stop( if (!runningAgent.stop()) {
runningAgent.getAgent(), runningAgent.getAgentRunId());
if (resultModel == null || !resultModel.isSuccess()) {
logger.error("can't stop the agent with hostName" logger.error("can't stop the agent with hostName"
+ runningAgent.getAgent().getHostName() + runningAgent.getAgent().getHostName()
+ "and currentRunId is " + runningAgent.getAgentRunId()); + "and currentRunId is " + runningAgent.getAgentRunId());

View File

@ -24,4 +24,8 @@ public class RunningAgentFactory {
runningAgent.setAgentMessenger(this.agentMessenger); runningAgent.setAgentMessenger(this.agentMessenger);
return runningAgent; return runningAgent;
} }
public void convertToDomain(RunningAgentDB fromReop) {
fromReop.setAgentMessenger(this.agentMessenger);
}
} }

View File

@ -27,7 +27,6 @@ import org.bench4q.master.domain.service.TestResultSave;
import org.bench4q.master.domain.valueobject.transaction.TransactionFactory; import org.bench4q.master.domain.valueobject.transaction.TransactionFactory;
import org.bench4q.master.exception.ExceptionLog; import org.bench4q.master.exception.ExceptionLog;
import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException; import org.bench4q.master.exception.ExceptionUtils.IllegalParameterException;
import org.bench4q.master.infrastructure.communication.impl.AgentMessengerImpl;
import org.bench4q.share.enums.master.TestPlanStatus; import org.bench4q.share.enums.master.TestPlanStatus;
import org.bench4q.share.helper.MarshalHelper; import org.bench4q.share.helper.MarshalHelper;
import org.bench4q.share.models.master.MonitorModel; import org.bench4q.share.models.master.MonitorModel;
@ -43,36 +42,27 @@ import org.springframework.stereotype.Component;
public class TestPlanFactory { public class TestPlanFactory {
private Logger logger = Logger.getLogger(TestPlanFactory.class); private Logger logger = Logger.getLogger(TestPlanFactory.class);
private ScriptService scriptService; private ScriptService scriptService;
private AgentMessengerImpl agentMessenger;
private AgentService agentService; private AgentService agentService;
private TestResultSave testResultSave; private TestResultSave testResultSave;
private TestPlanRepository testPlanRepository; private TestPlanRepository testPlanRepository;
private TransactionFactory transactionFactory; private TransactionFactory transactionFactory;
private RunningAgentFactory runningAgentFactory;
public AgentMessengerImpl getAgentMessenger() { private AgentService getAgentService() {
return agentMessenger;
}
@Autowired
public void setAgentMessenger(AgentMessengerImpl agentMessenger) {
this.agentMessenger = agentMessenger;
}
public AgentService getAgentService() {
return agentService; return agentService;
} }
@Autowired @Autowired
public void setAgentService(AgentService agentService) { private void setAgentService(AgentService agentService) {
this.agentService = agentService; this.agentService = agentService;
} }
public TestResultSave getTestResultSave() { private TestResultSave getTestResultSave() {
return testResultSave; return testResultSave;
} }
@Autowired @Autowired
public void setTestResultSave(TestResultSave testResultSave) { private void setTestResultSave(TestResultSave testResultSave) {
this.testResultSave = testResultSave; this.testResultSave = testResultSave;
} }
@ -103,6 +93,15 @@ public class TestPlanFactory {
this.transactionFactory = transactionFactory; this.transactionFactory = transactionFactory;
} }
private RunningAgentFactory getRunningAgentFactory() {
return runningAgentFactory;
}
@Autowired
private void setRunningAgentFactory(RunningAgentFactory runningAgentFactory) {
this.runningAgentFactory = runningAgentFactory;
}
public TestPlan createATestPlanWithoutIdentity(TestPlanModel testPlanModel, public TestPlan createATestPlanWithoutIdentity(TestPlanModel testPlanModel,
User user, UUID runId) throws IllegalParameterException { User user, UUID runId) throws IllegalParameterException {
Logger.getLogger(TestPlanFactory.class).info( Logger.getLogger(TestPlanFactory.class).info(
@ -247,7 +246,7 @@ public class TestPlanFactory {
if (testPlanInRepo == null) { if (testPlanInRepo == null) {
return null; return null;
} }
testPlanInRepo.setTestResultSave(testResultSave); testPlanInRepo.setTestResultSave(this.getTestResultSave());
testPlanInRepo.setRepository(this.getTestPlanRepository()); testPlanInRepo.setRepository(this.getTestPlanRepository());
for (TestPlanScript testPlanScript : testPlanInRepo for (TestPlanScript testPlanScript : testPlanInRepo
.getTestPlanScripts()) { .getTestPlanScripts()) {
@ -265,11 +264,10 @@ public class TestPlanFactory {
private void converToDomain(TestPlanScript testPlanScript) { private void converToDomain(TestPlanScript testPlanScript) {
testPlanScript.setTestPlanFactory(this); testPlanScript.setTestPlanFactory(this);
testPlanScript.setAgentMessenger(this.getAgentMessenger());
testPlanScript.setAgentService(this.getAgentService()); testPlanScript.setAgentService(this.getAgentService());
testPlanScript.setTransactionFactory(this.getTransactionFactory()); testPlanScript.setTransactionFactory(this.getTransactionFactory());
for (RunningAgentDB runningAgent : testPlanScript.getRunningAgentsDB()) { for (RunningAgentDB runningAgent : testPlanScript.getRunningAgentsDB()) {
runningAgent.setAgentMessenger(this.getAgentMessenger()); this.getRunningAgentFactory().convertToDomain(runningAgent);
} }
} }

View File

@ -8,8 +8,6 @@ import java.util.List;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import org.bench4q.master.domain.RunningAgentInterface; import org.bench4q.master.domain.RunningAgentInterface;
import org.bench4q.master.helper.ApplicationContextHelper;
import org.bench4q.master.infrastructure.communication.impl.AgentMessengerImpl;
import org.bench4q.share.models.agent.TestBriefStatusModel; import org.bench4q.share.models.agent.TestBriefStatusModel;
import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel; import org.bench4q.share.models.agent.statistics.AgentBehaviorsBriefModel;
import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel; import org.bench4q.share.models.agent.statistics.AgentBriefStatusModel;
@ -23,7 +21,6 @@ import org.bench4q.share.models.master.statistics.ScriptResultModel;
public class RunningScriptSampler { public class RunningScriptSampler {
private List<DataStatistics> dataStatisticsList; private List<DataStatistics> dataStatisticsList;
private List<RunningAgentInterface> runningAgents; private List<RunningAgentInterface> runningAgents;
private AgentMessengerImpl agentMessenger;
private List<DataStatistics> getDataStatisticsList() { private List<DataStatistics> getDataStatisticsList() {
return dataStatisticsList; return dataStatisticsList;
@ -41,25 +38,15 @@ public class RunningScriptSampler {
this.runningAgents = runningAgents; this.runningAgents = runningAgents;
} }
private AgentMessengerImpl getAgentMessenger() {
return agentMessenger;
}
private void setAgentMessenger(AgentMessengerImpl agentMessenger) {
this.agentMessenger = agentMessenger;
}
private RunningScriptSampler() { private RunningScriptSampler() {
this.setDataStatisticsList(new ArrayList<DataStatistics>()); this.setDataStatisticsList(new ArrayList<DataStatistics>());
this.getDataStatisticsList().add(new ScriptBriefStatistics()); this.getDataStatisticsList().add(new ScriptBriefStatistics());
this.getDataStatisticsList().add(new BehaviorsBriefStatistics()); this.getDataStatisticsList().add(new BehaviorsBriefStatistics());
this.getDataStatisticsList().add(new PagesBriefStatistics()); this.getDataStatisticsList().add(new PagesBriefStatistics());
this.setAgentMessenger(ApplicationContextHelper.getContext().getBean(
AgentMessengerImpl.class));
this.setRunningAgents(new LinkedList<RunningAgentInterface>()); this.setRunningAgents(new LinkedList<RunningAgentInterface>());
} }
public RunningScriptSampler(AgentMessengerImpl agentMessenger, public RunningScriptSampler(
Collection<? extends RunningAgentInterface> runningAgents) { Collection<? extends RunningAgentInterface> runningAgents) {
this(); this();
this.getRunningAgents().addAll(runningAgents); this.getRunningAgents().addAll(runningAgents);
@ -70,10 +57,7 @@ public class RunningScriptSampler {
if (runningAgent.isBreakDown()) { if (runningAgent.isBreakDown()) {
continue; continue;
} }
TestBriefStatusModel testBriefStatusModel = this TestBriefStatusModel testBriefStatusModel = runningAgent.briefAll();
.getAgentMessenger().scriptBriefAll(
runningAgent.getAgent(),
runningAgent.getAgentRunId());
addScriptResultModelStatistics(testBriefStatusModel); addScriptResultModelStatistics(testBriefStatusModel);
} }

View File

@ -40,8 +40,8 @@ public class Test_RunningScriptSampler extends TestBase_MakeUpTestPlan {
TestPlan testPlanInRunning = fetchTestPlan(); TestPlan testPlanInRunning = fetchTestPlan();
TestPlanScript testPlanScript = testPlanInRunning TestPlanScript testPlanScript = testPlanInRunning
.extracSpecifiedScript(getScriptId()); .extracSpecifiedScript(getScriptId());
this.setRunningScriptSampler(new RunningScriptSampler(this this.setRunningScriptSampler(new RunningScriptSampler(testPlanScript
.getAgentMessenger(), testPlanScript.getRunningAgentsDB())); .getRunningAgentsDB()));
} }
@After @After