change high avilable pool heartbeat
This commit is contained in:
parent
e8700549c4
commit
e5e0d86cab
|
@ -192,6 +192,7 @@ public class TestPlan implements IAggregate {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
Logger.getLogger(TestPlan.class).info(
|
||||
this.getTestPlanRunId() + " start to run ");
|
||||
|
@ -256,10 +257,6 @@ public class TestPlan implements IAggregate {
|
|||
scheScheduledExecutorService.scheduleAtFixedRate(new Runnable() {
|
||||
public void run() {
|
||||
if (isFinish()) {
|
||||
getTestResultSave().update(TestPlan.this,
|
||||
createMonitorFinishedResult());
|
||||
getTestResultSave().update(TestPlan.this,
|
||||
createScriptFinishedResult());
|
||||
scheScheduledExecutorService.shutdown();
|
||||
return;
|
||||
}
|
||||
|
@ -275,34 +272,6 @@ public class TestPlan implements IAggregate {
|
|||
|
||||
|
||||
|
||||
private List<Object> createMonitorFinishedResult() {
|
||||
List<Object> resultList = new LinkedList<Object>();
|
||||
if (getMonitors() != null) {
|
||||
for (Monitor monitor : getMonitors()) {
|
||||
List<MonitorResult> monitorResults = monitor
|
||||
.createFinishedResult();
|
||||
if (monitorResults != null) {
|
||||
resultList.addAll(monitorResults);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private List<Object> createScriptFinishedResult() {
|
||||
List<Object> resultList = new LinkedList<Object>();
|
||||
if (getTestPlanScripts() == null) {
|
||||
Logger.getLogger(TestPlan.class).error(
|
||||
"no scripts in testPlan:" + testPlanRunId);
|
||||
|
||||
}
|
||||
for (TestPlanScript testPlanScript : this.getTestPlanScripts()) {
|
||||
resultList.addAll(testPlanScript.createFinishedResult());
|
||||
}
|
||||
return resultList;
|
||||
|
||||
}
|
||||
|
||||
private List<Object> collectResult() {
|
||||
List<Object> resultList = new LinkedList<Object>();
|
||||
|
|
|
@ -18,6 +18,8 @@ import org.bench4q.share.models.master.statistics.ScriptBriefResultModel;
|
|||
@Entity
|
||||
@Table(name = "TestPlanScriptResult")
|
||||
public class TestPlanScriptResult {
|
||||
// private int testPlanId;
|
||||
// private int scriptId,
|
||||
private int id;
|
||||
private TestPlanScript testPlanScript;
|
||||
private String resultContent;
|
||||
|
|
|
@ -49,7 +49,7 @@ public class AgentService {
|
|||
}
|
||||
|
||||
public boolean addAgentToPool(Agent agentWithoutId) {
|
||||
synchronized (this.getAgentRepository().getAddDeleteLock()) {
|
||||
/* synchronized (this.getAgentRepository().getAddDeleteLock()) {*/
|
||||
if (!this.getAgentRepository().attach(
|
||||
Agent.createAgentWithoutId(agentWithoutId))) {
|
||||
return false;
|
||||
|
@ -61,16 +61,17 @@ public class AgentService {
|
|||
}
|
||||
this.getHighAvailablePool().add(agent);
|
||||
return true;
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public boolean removeAgentFromPool(int agentId) {
|
||||
// TODO: check if the agent is idle
|
||||
synchronized (this.getAgentRepository().getAddDeleteLock()) {
|
||||
// synchronized (this.getAgentRepository().getAddDeleteLock()) {
|
||||
this.getHighAvailablePool().remove(
|
||||
getAgentRepository().getEntity(agentId));
|
||||
return this.getAgentRepository().detach(agentId);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
public List<Agent> loadAgentPoolFromDB() {
|
||||
|
|
|
@ -7,7 +7,10 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.domain.RunningAgentInterface;
|
||||
import org.bench4q.master.domain.RunningScriptInterface;
|
||||
|
@ -34,6 +37,7 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
private Map<String, ServerStatusModel> agentStatusOfPreviousBeatMap;
|
||||
private Map<UUID, RunningAgentInterface> agentRunBlotters;
|
||||
private List<UUID> agentRunIdShouldBeSubstitute;
|
||||
private ExecutorService excuExecutorService;
|
||||
private long maxAvailableLoad;
|
||||
private int currentAvailableLoad;
|
||||
static Logger logger = Logger.getLogger(HighAvailablePoolImpl.class);
|
||||
|
@ -86,7 +90,7 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
}
|
||||
|
||||
public synchronized void remove(Agent agent) {
|
||||
this.getPool().put(agent.getHostName(), agent);
|
||||
this.getPool().remove(agent.getHostName());
|
||||
}
|
||||
|
||||
public int getCurrentAvailableLoad() {
|
||||
|
@ -129,6 +133,7 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
this.setCurrentAvailableLoad(0);
|
||||
this.setAgentRunIdShouldBeSubstitute(new LinkedList<UUID>());
|
||||
this.setAgentRepository(agentRepository);
|
||||
this.excuExecutorService = Executors.newCachedThreadPool();
|
||||
initialPool();
|
||||
}
|
||||
|
||||
|
@ -138,12 +143,44 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0,30 */1 * * * *")
|
||||
public synchronized void checkAllHeartBeat() {
|
||||
synchronized (this.getAgentRepository().getAddDeleteLock()) {
|
||||
@Scheduled(cron = "0,30 */2 * * * *")
|
||||
public void checkAllHeartBeat() {
|
||||
long time = System.nanoTime();
|
||||
heartBeatsAndUpdateHAPool();
|
||||
doSubstituteIfRequired();
|
||||
System.out.println("finish heart beat:" + (System.nanoTime() - time));
|
||||
}
|
||||
|
||||
private void heartBeatsAndUpdateHAPool() {
|
||||
Map<Agent, Future<ServerStatusModel>> map = new HashMap<Agent, Future<ServerStatusModel>>();
|
||||
for (Agent agent : this.getPool().values()) {
|
||||
CheckHearBeat checkHearBeat = new CheckHearBeat(agent,
|
||||
agentMessenger);
|
||||
map.put(agent, this.excuExecutorService.submit(checkHearBeat));
|
||||
}
|
||||
this.updateAgentPoolByHeart(map);
|
||||
}
|
||||
|
||||
private synchronized void updateAgentPoolByHeart(
|
||||
Map<Agent, Future<ServerStatusModel>> map) {
|
||||
this.setCurrentAvailableLoad(0);
|
||||
this.setMaxAvailableLoad((long) 0);
|
||||
for (Agent agent : map.keySet()) {
|
||||
ServerStatusModel model;
|
||||
try {
|
||||
model = map.get(agent).get();
|
||||
|
||||
if (model == null) {
|
||||
doForBreakDown(agent);
|
||||
} else {
|
||||
doForHealth(model, agent);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.getAgentRepository().Update(this.getPool().values());
|
||||
}
|
||||
|
||||
private void doSubstituteIfRequired() {
|
||||
|
@ -175,28 +212,6 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
this.setCurrentAvailableLoad(availableLoad);
|
||||
}
|
||||
|
||||
private void heartBeatsAndUpdateHAPool() {
|
||||
this.setCurrentAvailableLoad(0);
|
||||
this.setMaxAvailableLoad((long) 0);
|
||||
for (Agent agent : this.getPool().values()) {
|
||||
checkHeartBeat(agent);
|
||||
}
|
||||
this.getAgentRepository().Update(this.getPool().values());
|
||||
}
|
||||
|
||||
public void checkHeartBeat(Agent agent) {
|
||||
ServerStatusModel model = queryAgentStatus(agent);
|
||||
if (model == null) {
|
||||
doForBreakDown(agent);
|
||||
} else {
|
||||
doForHealth(model, agent);
|
||||
}
|
||||
}
|
||||
|
||||
public ServerStatusModel queryAgentStatus(Agent agent) {
|
||||
return this.getAgentMessenger().getStatus(agent);
|
||||
}
|
||||
|
||||
public void addABlotter(RunningAgentInterface runningAgent) {
|
||||
this.getAgentRunBlotters().put(runningAgent.getAgentRunId(),
|
||||
runningAgent);
|
||||
|
@ -321,4 +336,39 @@ public class HighAvailablePoolImpl extends CurrentLoadSubject implements
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void checkHeartBeat(Agent agent) {
|
||||
ServerStatusModel model = queryAgentStatus(agent);
|
||||
if (model == null) {
|
||||
doForBreakDown(agent);
|
||||
} else {
|
||||
doForHealth(model, agent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerStatusModel queryAgentStatus(Agent agent) {
|
||||
return this.getAgentMessenger().getStatus(agent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CheckHearBeat implements Callable<ServerStatusModel> {
|
||||
private Agent agent;
|
||||
private AgentMessenger agentMessenger;
|
||||
|
||||
private AgentMessenger getAgentMessenger() {
|
||||
return agentMessenger;
|
||||
}
|
||||
|
||||
public CheckHearBeat(Agent agent, AgentMessenger agentMessenger) {
|
||||
this.agent = agent;
|
||||
this.agentMessenger = agentMessenger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerStatusModel call() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return this.getAgentMessenger().getStatus(agent);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver </property>
|
||||
<property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/bench4q_master
|
||||
<property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/bench4q
|
||||
</property>
|
||||
<property name="hibernate.connection.username">root</property>
|
||||
<property name="hibernate.connection.password">123456 </property>
|
||||
|
|
Loading…
Reference in New Issue