Skip to content

Commit

Permalink
#483 code review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kfchu committed Sep 7, 2018
1 parent 68d46fa commit 33e47e9
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Maps;
import com.vip.saturn.job.basic.JobScheduler;
import com.vip.saturn.job.exception.JobException;
import com.vip.saturn.job.internal.config.ConfigurationNode;
import com.vip.saturn.job.internal.config.JobConfiguration;
import com.vip.saturn.job.internal.storage.JobNodePath;
Expand Down Expand Up @@ -34,6 +35,7 @@
public class InitNewJobService {

private static final Logger log = LoggerFactory.getLogger(InitNewJobService.class);
private static final String ERR_MSG_JOB_IS_ON_DELETING = "the job is on deleting";

private SaturnExecutorService saturnExecutorService;
private String executorName;
Expand Down Expand Up @@ -125,16 +127,16 @@ public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exc
log.info("new job: {} 's jobClass created event received", jobName);

if (!jobNames.contains(jobName)) {
if (initJobScheduler(jobName)) {
try {
initJobScheduler(jobName);
jobNames.add(jobName);
log.info("the job {} initialize successfully", jobName);
} else {
log.warn("the job {} initialize fail", jobName);
String alarmMessage = "job:" + jobName + " init fail";
} catch (JobException e) {
String alarmMessage = String.format("job [%s] initialize fail: %s", jobName, e.getMessage());
log.warn(alarmMessage);
String namespace = regCenter.getNamespace();
AlarmUtils.raiseAlarm(constructAlarmInfo(namespace, jobName, executorName, alarmMessage),
namespace);
log.info("alarm raised for job:[{}] at namespace:[{}] init fail", jobName, namespace);
}
} else {
log.warn("the job {} is unnecessary to initialize, because it's already existing", jobName);
Expand Down Expand Up @@ -162,27 +164,28 @@ public Map<String, Object> constructAlarmInfo(String namespace, String jobName,
return alarmInfo;
}

private boolean initJobScheduler(String jobName) {
private void initJobScheduler(String jobName) {
try {
log.info("[{}] msg=add new job {} - {}", jobName, executorName, jobName);
JobConfiguration jobConfig = new JobConfiguration(regCenter, jobName);
if (jobConfig.getSaturnJobClass() == null) {
log.warn("[{}] msg={} - {} the saturnJobClass is null, jobType is {}", jobConfig, executorName,
jobName, jobConfig.getJobType());
return false;
String errorMsg = String
.format("the saturnJobClass is null, jobType is [%s]", jobConfig.getJobType());
log.warn("[{}] msg={} - {}", jobName, executorName, errorMsg);
throw new JobException(errorMsg);
}
if (jobConfig.isDeleting()) {
log.warn("[{}] msg={} - {} the job is on deleting", jobName, executorName, jobName);
log.warn("[{}] msg={} - {}", jobName, executorName, ERR_MSG_JOB_IS_ON_DELETING);
String serverNodePath = JobNodePath.getServerNodePath(jobName, executorName);
regCenter.remove(serverNodePath);
return false;
throw new JobException(ERR_MSG_JOB_IS_ON_DELETING);
}
JobScheduler scheduler = new JobScheduler(regCenter, jobConfig);
scheduler.setSaturnExecutorService(saturnExecutorService);
return scheduler.init();
scheduler.init();
} catch (Exception e) {
log.error(e.getMessage(), e);
return false;
throw new JobException(e);
}
}

Expand Down

0 comments on commit 33e47e9

Please sign in to comment.