Skip to content

Commit

Permalink
#526 fix shutdown problem, when job is the disabled SHELL_JOB
Browse files Browse the repository at this point in the history
  • Loading branch information
heziai committed Oct 23, 2018
1 parent 188c0a9 commit 0c7df1c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.vip.saturn.job.executor.SaturnExecutorService;
import com.vip.saturn.job.internal.config.ConfigurationService;
import com.vip.saturn.job.internal.config.JobType;
import com.vip.saturn.job.internal.control.ReportService;
import com.vip.saturn.job.internal.execution.ExecutionContextService;
import com.vip.saturn.job.internal.execution.ExecutionNode;
Expand Down Expand Up @@ -95,7 +96,15 @@ public void shutdown() {
jobScheduler.shutdownExecutorService();
// 检查调度器任务是否完成,如果没有,中止业务
if (!scheduler.isTerminated()) {
abort();
if (configService.isShellJob() && !configService.isJobEnabled()) {
// 如果Shell作业业务进程有子进程,我们可能不能完全中止其子进程。
// 所以,对于禁用的Shell作业,不中止业务。因为,作业处于禁用状态,说明是人为介入的可控状态。
// 另外,在该Executor再次启动该作业前,会检查该作业是否正在运行,如果正在运行并且仍然处于禁用状态,则会相应的持久化相关状态到zk,防止重入;如果正在运行并且已经处于启用状态,则会中止其进程。
LogUtils.warn(log, jobName, "the job is the disabled {}, will not be aborted",
JobType.SHELL_JOB.name());
} else {
abort();
}
}
}
}
Expand Down Expand Up @@ -207,8 +216,7 @@ private boolean checkIfZkLostAfterExecution(final Integer item) {
if (ephemeralOwner != sessionId) {
LogUtils.info(log, jobName,
"item={} 's running node doesn't belong to current zk, node sessionid is {}, current zk "
+ "sessionid is {}",
item, ephemeralOwner, sessionId);
+ "sessionid is {}", item, ephemeralOwner, sessionId);
return false;
} else {
return true;
Expand All @@ -219,7 +227,8 @@ private boolean checkIfZkLostAfterExecution(final Integer item) {

return false;
} catch (Throwable e) {
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()), e);
LogUtils.error(log, jobName, String.format(SaturnConstant.LOG_FORMAT_FOR_STRING, jobName, e.getMessage()),
e);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vip.saturn.job.executor;

import com.vip.saturn.job.basic.JobTypeManager;
import com.vip.saturn.job.internal.config.JobType;
import com.vip.saturn.job.java.SaturnJavaJob;
import com.vip.saturn.job.shell.SaturnScriptJob;
import com.vip.saturn.job.utils.LocalHostService;
Expand Down Expand Up @@ -69,8 +70,8 @@ public void initAfter() {

@Override
public void registerJobType() {
JobTypeManager.getInstance().registerHandler("JAVA_JOB", SaturnJavaJob.class);
JobTypeManager.getInstance().registerHandler("SHELL_JOB", SaturnScriptJob.class);
JobTypeManager.getInstance().registerHandler(JobType.JAVA_JOB.name(), SaturnJavaJob.class);
JobTypeManager.getInstance().registerHandler(JobType.SHELL_JOB.name(), SaturnScriptJob.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ public boolean isEnabledReport() {
return isEnabledReportInJobConfig;
}
// if isEnabledReportInJobConfig == null, 如果作业类型是JAVA或者Shell,默认上报
if ("JAVA_JOB".equals(jobConfiguration.getJobType()) || "SHELL_JOB".equals(jobConfiguration.getJobType())) {
if (JobType.JAVA_JOB.name().equals(jobConfiguration.getJobType()) || JobType.SHELL_JOB.name()
.equals(jobConfiguration.getJobType())) {
return true;
}

Expand Down Expand Up @@ -416,8 +417,8 @@ private Map<String, String> toCustomContext(String customContextStr) {
return Maps.newHashMap();
}

public String getRawJobType() {
return jobConfiguration.getJobType();
public boolean isShellJob() {
return JobType.SHELL_JOB.name().equals(jobConfiguration.getJobType());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

public enum JobType {

JAVA_JOB("JAVA_JOB"),
SHELL_JOB("SHELL_JOB"),
MSG_JOB("MSG_JOB"),
UNKOWN_JOB("UNKOWN_JOB");
JAVA_JOB, SHELL_JOB, MSG_JOB, UNKOWN_JOB;

private String name;

JobType(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.vip.saturn.job.basic.SaturnConstant;
import com.vip.saturn.job.executor.SaturnExecutorsNode;
import com.vip.saturn.job.internal.config.ConfigurationNode;
import com.vip.saturn.job.internal.config.JobType;
import com.vip.saturn.job.internal.execution.ExecutionNode;
import com.vip.saturn.job.internal.storage.JobNodePath;
import com.vip.saturn.job.reg.base.CoordinatorRegistryCenter;
Expand Down Expand Up @@ -396,7 +397,7 @@ public static void checkOneExistJob(final CoordinatorRegistryCenter regCenter, f
String jobTypePath = JobNodePath.getNodeFullPath(jobName, ConfigurationNode.JOB_TYPE);
String jobType = regCenter.get(jobTypePath);
// 只检查Shell作业
if (!"SHELL_JOB".equals(jobType)) {
if (!JobType.SHELL_JOB.name().equals(jobType)) {
LogUtils.info(log, jobName, "{} is not shell job ,igore checking ", jobName);
return;
}
Expand Down

0 comments on commit 0c7df1c

Please sign in to comment.