parent
0f9e403731
commit
92b1f36356
|
@ -1,7 +1,5 @@
|
|||
package org.bench4q.master.domain.entity;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
@ -9,17 +7,10 @@ import javax.persistence.GenerationType;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.service.AgentService;
|
||||
import org.bench4q.master.domain.transaction.Transaction;
|
||||
import org.bench4q.master.domain.transaction.exception.AgentRunException;
|
||||
import org.bench4q.master.domain.transaction.impl.AgentDistribute;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.ApplicationContextHelper;
|
||||
import org.bench4q.master.infrastructure.communication.AgentMessenger;
|
||||
import org.bench4q.share.models.agent.RunScenarioModel;
|
||||
import org.bench4q.share.models.agent.RunScenarioResultModel;
|
||||
import org.python.antlr.PythonParser.return_stmt_return;
|
||||
|
||||
@Entity
|
||||
@Table(name = "agent")
|
||||
|
@ -110,107 +101,4 @@ public class Agent {
|
|||
|
||||
}
|
||||
|
||||
public class AgentDistribute implements Transaction {
|
||||
|
||||
private String agentHostName;
|
||||
private int agentPort;
|
||||
private RunScenarioModel runScenarioModel;
|
||||
private AgentService agentService;
|
||||
private AgentMessenger agentMessenger;
|
||||
private Logger logger = Logger.getLogger(AgentDistribute.class);
|
||||
|
||||
private String getAgentHostName() {
|
||||
return agentHostName;
|
||||
}
|
||||
|
||||
private void setAgentHostName(String agentHostName) {
|
||||
this.agentHostName = agentHostName;
|
||||
}
|
||||
|
||||
private int getAgentPort() {
|
||||
return agentPort;
|
||||
}
|
||||
|
||||
private void setAgentPort(int agentPort) {
|
||||
this.agentPort = agentPort;
|
||||
}
|
||||
|
||||
private RunScenarioModel getRunScenarioModel() {
|
||||
return runScenarioModel;
|
||||
}
|
||||
|
||||
private void setRunScenarioModel(RunScenarioModel runScenarioModel) {
|
||||
this.runScenarioModel = runScenarioModel;
|
||||
}
|
||||
|
||||
private AgentService getAgentService() {
|
||||
return agentService;
|
||||
}
|
||||
|
||||
private void setAgentService(AgentService agentService) {
|
||||
this.agentService = agentService;
|
||||
}
|
||||
|
||||
public AgentMessenger getAgentMessenger() {
|
||||
return agentMessenger;
|
||||
}
|
||||
|
||||
public void setAgentMessenger(AgentMessenger agentMessenger) {
|
||||
this.agentMessenger = agentMessenger;
|
||||
}
|
||||
|
||||
public AgentDistribute(String agentHostName, int port,
|
||||
RunScenarioModel runScenarioModel) {
|
||||
this.setAgentHostName(agentHostName);
|
||||
this.setAgentPort(port);
|
||||
this.setRunScenarioModel(runScenarioModel);
|
||||
this.setAgentService(ApplicationContextHelper.getContext().getBean(
|
||||
AgentService.class));
|
||||
this.setAgentMessenger(ApplicationContextHelper.getContext()
|
||||
.getBean(AgentMessenger.class));
|
||||
}
|
||||
|
||||
public Object execute() throws AgentRunException {
|
||||
try {
|
||||
if (!this.getAgentService().getLoadFromAgent(
|
||||
this.getAgentHostName(),
|
||||
this.getRunScenarioModel().getPoolSize())) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
if (!isValidRunScenarioModel(runScenarioModel)) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
RunScenarioResultModel ret = this.getAgentMessenger()
|
||||
.runWithoutParams(
|
||||
buildAgent(this.getAgentHostName(),
|
||||
this.getAgentPort()),
|
||||
this.getRunScenarioModel());
|
||||
if (ret == null) {
|
||||
throw new AgentRunException();
|
||||
}
|
||||
return ret;
|
||||
} catch (IOException e) {
|
||||
this.logger.error(ExceptionLog.getStackTrace(e).toString());
|
||||
throw new AgentRunException();
|
||||
}
|
||||
}
|
||||
|
||||
private Agent buildAgent(String hostName, int port) {
|
||||
Agent agent = new Agent();
|
||||
agent.setHostName(hostName);
|
||||
agent.setPort(port);
|
||||
return agent;
|
||||
}
|
||||
|
||||
private boolean isValidRunScenarioModel(
|
||||
RunScenarioModel runScenarioModel) {
|
||||
return runScenarioModel == null ? false : true;
|
||||
}
|
||||
|
||||
public void rollBack() {
|
||||
this.getAgentService().backLoadToAgent(this.getAgentHostName(),
|
||||
this.getRunScenarioModel().getPoolSize());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue