...
|
...
|
@@ -2,7 +2,6 @@ package com.yoho.kisjob.reg.persistence.service; |
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
...
|
...
|
@@ -11,12 +10,15 @@ import org.springframework.util.Assert; |
|
|
import com.yoho.kisjob.common.constant.JobException;
|
|
|
import com.yoho.kisjob.common.constant.State;
|
|
|
import com.yoho.kisjob.common.meta.ExecutionMeta;
|
|
|
import com.yoho.kisjob.common.meta.JobMeta;
|
|
|
import com.yoho.kisjob.common.meta.JobType;
|
|
|
import com.yoho.kisjob.common.utils.NodeUtil;
|
|
|
import com.yoho.kisjob.common.utils.RandomUtils;
|
|
|
import com.yoho.kisjob.common.utils.Utils;
|
|
|
import com.yoho.kisjob.reg.persistence.service.jdbc.JdbcService;
|
|
|
import com.yoho.kisjob.reg.persistence.vo.KisJob;
|
|
|
import com.yoho.kisjob.reg.persistence.vo.KisJobInstance;
|
|
|
import com.yoho.kisjob.reg.persistence.vo.KisJobInstanceGroup;
|
|
|
|
|
|
/**
|
|
|
* 定时任务实例持久化服务类。
|
...
|
...
|
@@ -34,6 +36,9 @@ public class JobInstanceService { |
|
|
@Autowired
|
|
|
private JobInstGroupService jobInstGroupService;
|
|
|
|
|
|
@Autowired
|
|
|
private JobMetaService jobMetaService;
|
|
|
|
|
|
public Long addNewInstance(String nodeGroup, String jobName) {
|
|
|
List<KisJob> list = jdbcService.query(new KisJob(nodeGroup, jobName));
|
|
|
Assert.notEmpty(list, "For " + jobName);
|
...
|
...
|
@@ -81,21 +86,37 @@ public class JobInstanceService { |
|
|
condition.setInstanceStatus(State.Running.getCode());
|
|
|
List<KisJobInstance> list = jdbcService.query(condition);
|
|
|
if (Utils.isNotEmpty(list)) {
|
|
|
|
|
|
JobMeta jobMeta = jobMetaService.queryByJobId(jobId);
|
|
|
JobType jobType = jobMeta != null ? jobMeta.getJobType() : null;
|
|
|
for (KisJobInstance jobInstance : list) {
|
|
|
if (NodeUtil.getCurrentNodeIp().equals(jobInstance.getNodeIdentifier())) {
|
|
|
if (NodeUtil.isCurrentNode(jobInstance.getNodeIdentifier())) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
Map<Integer, State> groupStatusMap = jobInstGroupService.queryJobInstanceGroupStatus(jobInstance
|
|
|
.getInstanceId());
|
|
|
for (Map.Entry<Integer, State> entry : groupStatusMap.entrySet()) {
|
|
|
if (entry.getValue() == State.Ready || entry.getValue() == State.Running) {
|
|
|
jobInstGroupService.endExecuteGroup(jobInstance.getInstanceId(), entry.getKey(),
|
|
|
new JobException("Execute group failed for master crashed."));
|
|
|
}
|
|
|
if (jobType == JobType.ElastaicJob) {
|
|
|
updateUncompletedJobInstGroups(jobInstance);
|
|
|
}
|
|
|
|
|
|
updateInstanceResult(jobInstance.getInstanceId(), null, new JobException(
|
|
|
"Execute instance failed for master crashed."));
|
|
|
"Execute instance failed for master %s crashed.", jobInstance.getNodeIdentifier()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void updateUncompletedJobInstGroups(KisJobInstance jobInstance) {
|
|
|
State groupState;
|
|
|
List<KisJobInstanceGroup> groups = jobInstGroupService.queryJobInstanceGroups(new KisJobInstanceGroup(
|
|
|
jobInstance.getInstanceId()));
|
|
|
if (Utils.isNotEmpty(groups)) {
|
|
|
// TODO:暂时先把master上面的分组更新成失败的 这个后续需要优化
|
|
|
for (KisJobInstanceGroup group : groups) {
|
|
|
groupState = State.build(group.getGroupState());
|
|
|
if ((groupState == State.Ready || groupState == State.Running)
|
|
|
&& jobInstance.getNodeIdentifier().equals(group.getNodeIdentifier())) {
|
|
|
jobInstGroupService.endExecuteGroup(jobInstance.getInstanceId(), group.getGroupIndex(),
|
|
|
new JobException("Execute group failed for master %s crashed.", group.getNodeIdentifier()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|