in manager/dm-agent/src/main/java/org/apache/doris/manager/agent/service/HeartBeatService.java [118:180]
private HeartBeatResult executeContextTask(HeartBeatContext ctx) {
List<HeartBeatEventResult> eventResults = new ArrayList<>();
List<InstanceStateResult> insStateResults = new ArrayList<>();
//TODO find from cache before
for (HeartBeatEventInfo eventInfo : ctx.getEvents()) {
log.info("handle event {}: resource:{} type:{} stage:{}", eventInfo.getEventId(),
eventInfo.getResourceType(), eventInfo.getEventStage(), eventInfo.getEventStage());
// get result from cache if it has been executed
long eventId = eventInfo.getEventId();
if (cacheResults.containsKey(eventId)) {
HeartBeatEventResult cr = cacheResults.get(eventId);
log.info("result is in cache, event {}, stage {}, result type {}", cr.getEventId(),
cr.getEventStage(), cr.getResultType());
if (cr.getResultType() == HeartBeatEventResultType.PROCESSING
&& eventInfo.getEventStage() < cr.getEventStage()) {
log.info("return result from result cache");
eventResults.add(cr);
continue;
} else if (cr.getResultType() == HeartBeatEventResultType.SUCCESS
&& cr.getEventStage() == cr.getEventStage()) {
log.info("return result form result cache");
eventResults.add(cr);
continue;
}
}
HeartBeatEventResult result = heartbeatEventHandler.handHeartBeatEvent(eventInfo);
if (result != null) {
eventResults.add(result);
}
}
for (InstanceInfo instanceInfo : ctx.getInstanceInfos()) {
log.info("check module {} instance {} state", instanceInfo.getModuleName(), instanceInfo.getInstanceId());
InstanceStateResult stateResult = new InstanceStateResult(instanceInfo);
try {
instanceOpera.checkInstanceProcessState(instanceInfo.getModuleName(), instanceInfo.getInstallDir(),
instanceInfo.getHttpPort());
stateResult.setState(ModelControlState.RUNNING);
} catch (InstanceNotInstallException e) {
log.error("{} instance check exception {}", instanceInfo.getModuleName(), e.getMessage());
// maybe instance has noe be installed
stateResult.setState(ModelControlState.INIT);
stateResult.setErrMsg(e.getMessage());
} catch (InstanceNotRunningException | InstanceServiceException e) {
log.error("{} instance check exception {}", instanceInfo.getModuleName(), e.getMessage());
stateResult.setState(ModelControlState.STOPPED);
stateResult.setErrMsg(e.getMessage());
}
insStateResults.add(stateResult);
}
HeartBeatResult res = new HeartBeatResult();
res.setEventResults(eventResults);
res.setStateResults(insStateResults);
return res;
}