let the HA's breakdown and restoration rely on the ScriptLoadCommand
This commit is contained in:
parent
13cd25a927
commit
c30febb54e
|
@ -1,5 +1,7 @@
|
|||
package org.bench4q.master.api.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -13,7 +15,7 @@ public class RunningAgentModel {
|
|||
private int loadInUse;
|
||||
private int scriptId;
|
||||
private UUID agentRunId;
|
||||
private UUID substituteRunId;
|
||||
private List<UUID> substituteRunIds;
|
||||
|
||||
@XmlElement
|
||||
public Agent getAgent() {
|
||||
|
@ -51,12 +53,15 @@ public class RunningAgentModel {
|
|||
this.agentRunId = agentRunId;
|
||||
}
|
||||
|
||||
public UUID getSubstituteRunId() {
|
||||
return substituteRunId;
|
||||
public RunningAgentModel() {
|
||||
this.setSubstituteRunIds(new ArrayList<UUID>());
|
||||
}
|
||||
|
||||
public void setSubstituteRunId(UUID substituteRunId) {
|
||||
this.substituteRunId = substituteRunId;
|
||||
public List<UUID> getSubstituteRunIds() {
|
||||
return substituteRunIds;
|
||||
}
|
||||
|
||||
public void setSubstituteRunIds(List<UUID> substituteRunIds) {
|
||||
this.substituteRunIds = substituteRunIds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package org.bench4q.master.entity.db;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "agent")
|
||||
public class Report {
|
||||
private int id;
|
||||
private TestPlan testPlan;
|
||||
private String savePath;
|
||||
private Date createDatetime;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "testPlanId", nullable = false)
|
||||
public TestPlan getTestPlan() {
|
||||
return testPlan;
|
||||
}
|
||||
|
||||
public void setTestPlan(TestPlan testPlan) {
|
||||
this.testPlan = testPlan;
|
||||
}
|
||||
|
||||
@Column(name = "savePath", nullable = false)
|
||||
public String getSavePath() {
|
||||
return savePath;
|
||||
}
|
||||
|
||||
public void setSavePath(String savePath) {
|
||||
this.savePath = savePath;
|
||||
}
|
||||
|
||||
@Column(name = "createDatetime", nullable = false)
|
||||
public Date getCreateDatetime() {
|
||||
return createDatetime;
|
||||
}
|
||||
|
||||
public void setCreateDatetime(Date createDatetime) {
|
||||
this.createDatetime = createDatetime;
|
||||
}
|
||||
}
|
|
@ -2,16 +2,19 @@ package org.bench4q.master.service;
|
|||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.communication.HttpRequester;
|
||||
import org.bench4q.master.communication.HttpRequester.HttpResponse;
|
||||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
||||
import org.bench4q.master.communication.agent.RunScenarioResultModel;
|
||||
import org.bench4q.master.communication.agent.StopTestModel;
|
||||
import org.bench4q.master.communication.agent.TestBriefStatusModel;
|
||||
|
@ -248,12 +251,12 @@ public class AgentService {
|
|||
}
|
||||
}
|
||||
|
||||
public RunScenarioResultModel run(Agent agent, String scriptContent)
|
||||
throws IOException {
|
||||
public RunScenarioResultModel run(Agent agent,
|
||||
RunScenarioModel runScenarioModel) throws IOException {
|
||||
try {
|
||||
HttpResponse httpResponse = this.httpRequester.sendPostXml(
|
||||
agent.getHostName() + ":" + PORT + "/test/run",
|
||||
scriptContent, null);
|
||||
marshalRunScenarioModel(runScenarioModel), null);
|
||||
return extractRunSenarioResultModel(httpResponse.getContent());
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -261,6 +264,16 @@ public class AgentService {
|
|||
}
|
||||
}
|
||||
|
||||
private String marshalRunScenarioModel(RunScenarioModel runScenarioModel)
|
||||
throws JAXBException {
|
||||
Marshaller marshaller;
|
||||
marshaller = JAXBContext.newInstance(runScenarioModel.getClass())
|
||||
.createMarshaller();
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
marshaller.marshal(runScenarioModel, stringWriter);
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
private RunScenarioResultModel extractRunSenarioResultModel(
|
||||
String responseContent) throws JAXBException {
|
||||
RunScenarioResultModel resultModel = new RunScenarioResultModel();
|
||||
|
|
|
@ -7,8 +7,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.api.model.RunningAgentModel;
|
||||
import org.bench4q.master.communication.AgentStateService;
|
||||
import org.bench4q.master.communication.agent.RunScenarioModel;
|
||||
import org.bench4q.master.communication.agent.ServerStatusModel;
|
||||
import org.bench4q.master.entity.db.Agent;
|
||||
import org.bench4q.master.service.AgentService;
|
||||
|
@ -30,6 +32,8 @@ public class HighAvailableAgentPool {
|
|||
private Map<String, ServerStatusModel> agentStatusOfPreviousBeatMap;
|
||||
private Map<UUID, AgentRunBlotter> agentRunBlotters;
|
||||
private long maxLoadOfHAPool;
|
||||
private static Logger logger = Logger
|
||||
.getLogger(HighAvailableAgentPool.class);
|
||||
|
||||
public List<Agent> getHighAvailablePool() {
|
||||
return this.highAvailablePool;
|
||||
|
@ -145,48 +149,60 @@ public class HighAvailableAgentPool {
|
|||
|
||||
private void substituteOnBoard(AgentRunBlotter deadAgentBlotter,
|
||||
UUID deadRunId) {
|
||||
System.out.println("enter substituteOnBoard");
|
||||
Agent subAgent = this.getAgentWithEnoughLoadInIdel(deadAgentBlotter
|
||||
.getRunningAgentModel().getLoadInUse());
|
||||
RunningAgentModel substituteRunModel = deadAgentBlotter
|
||||
.getRunningAgentModel();
|
||||
String content = this.scriptService
|
||||
.getScriptContentByScriptId(deadAgentBlotter
|
||||
.getRunningAgentModel().getScriptId());
|
||||
if (content == null) {
|
||||
return;
|
||||
}
|
||||
UUID substituteRunId;
|
||||
logger.info("enter substituteOnBoard");
|
||||
try {
|
||||
// TODO: if this runs wrongly, will it be? it's the matter of HA
|
||||
// Maybe, it's not possible
|
||||
substituteRunId = this.agentService.run(subAgent, content)
|
||||
.getRunId();
|
||||
System.out.println("substitute hostname is : "
|
||||
+ subAgent.getHostName());
|
||||
TestPlanContext testPlanContext = this.testPlanContainer
|
||||
.queryTestPlanContext(deadAgentBlotter.getTestPlanId());
|
||||
if (testPlanContext == null) {
|
||||
Agent subAgent = this.getAgentWithEnoughLoadInIdel(deadAgentBlotter
|
||||
.getRunningAgentModel().getLoadInUse());
|
||||
if (subAgent == null) {
|
||||
|
||||
}
|
||||
RunningAgentModel substituteRunModel = deadAgentBlotter
|
||||
.getRunningAgentModel();
|
||||
RunScenarioModel runScenarioModel = this.getScriptService()
|
||||
.getRunSceniroModelByScriptId(
|
||||
deadAgentBlotter.getRunningAgentModel()
|
||||
.getScriptId());
|
||||
if (runScenarioModel == null) {
|
||||
logger.error("When substitute want to be on board, the runscenarioModel is null!");
|
||||
return;
|
||||
}
|
||||
substituteRunModel.setAgent(subAgent);
|
||||
substituteRunModel.setAgentRunId(substituteRunId);
|
||||
this.agentRunBlotters.put(
|
||||
substituteRunId,
|
||||
buildAgentRunBlotter(substituteRunModel,
|
||||
deadAgentBlotter.getTestPlanId()));
|
||||
|
||||
testPlanContext.getRunningScriptMap()
|
||||
.get(deadAgentBlotter.getRunningAgentModel().getScriptId())
|
||||
.getRunningAgents().add(substituteRunModel);
|
||||
deadAgentBlotter.getRunningAgentModel().setSubstituteRunId(
|
||||
substituteRunId);
|
||||
runScenarioModel.setPoolSize(deadAgentBlotter
|
||||
.getRunningAgentModel().getLoadInUse());
|
||||
|
||||
UUID substituteRunId = this.agentService.run(subAgent,
|
||||
runScenarioModel).getRunId();
|
||||
|
||||
completeSubstituteInfo(deadAgentBlotter, subAgent,
|
||||
substituteRunModel, substituteRunId);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.error(e.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
private void completeSubstituteInfo(AgentRunBlotter deadAgentBlotter,
|
||||
Agent subAgent, RunningAgentModel substituteRunModel,
|
||||
UUID substituteRunId) {
|
||||
TestPlanContext testPlanContext = this.testPlanContainer
|
||||
.queryTestPlanContext(deadAgentBlotter.getTestPlanId());
|
||||
if (testPlanContext == null) {
|
||||
return;
|
||||
}
|
||||
substituteRunModel.setAgent(subAgent);
|
||||
substituteRunModel.setAgentRunId(substituteRunId);
|
||||
|
||||
this.agentRunBlotters.put(
|
||||
substituteRunId,
|
||||
buildAgentRunBlotter(substituteRunModel,
|
||||
deadAgentBlotter.getTestPlanId()));
|
||||
|
||||
testPlanContext.getRunningScriptMap()
|
||||
.get(deadAgentBlotter.getRunningAgentModel().getScriptId())
|
||||
.getRunningAgents().add(substituteRunModel);
|
||||
deadAgentBlotter.getRunningAgentModel().getSubstituteRunIds()
|
||||
.add(substituteRunId);
|
||||
}
|
||||
|
||||
public static AgentRunBlotter buildAgentRunBlotter(
|
||||
RunningAgentModel runningAgentModel, UUID testPlanId) {
|
||||
AgentRunBlotter agentRunBlotter = new AgentRunBlotter();
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package org.bench4q.master.testPlan.loadcommand;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.api.model.RunningAgentModel;
|
||||
|
@ -199,8 +196,7 @@ public class ScriptLoadCommand implements LoadCommand {
|
|||
runScenarioModel.getPoolSize())) {
|
||||
return null;
|
||||
}
|
||||
return this.getAgentService().run(agent,
|
||||
this._marshalRunScenarioModelToString(runScenarioModel));
|
||||
return this.getAgentService().run(agent, runScenarioModel);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -208,16 +204,6 @@ public class ScriptLoadCommand implements LoadCommand {
|
|||
}
|
||||
}
|
||||
|
||||
private String _marshalRunScenarioModelToString(
|
||||
RunScenarioModel runScenarioModel) throws JAXBException {
|
||||
Marshaller marshaller;
|
||||
marshaller = JAXBContext.newInstance(runScenarioModel.getClass())
|
||||
.createMarshaller();
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
marshaller.marshal(runScenarioModel, stringWriter);
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
private RunningScriptModel buildRunningScriptModel(
|
||||
List<RunningAgentModel> runningAgentModels, int scriptId) {
|
||||
RunningScriptModel result = new RunningScriptModel();
|
||||
|
|
Loading…
Reference in New Issue