...
|
...
|
@@ -11,14 +11,14 @@ import java.util.Map; |
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.curator.framework.CuratorFramework;
|
|
|
import org.apache.zookeeper.CreateMode;
|
|
|
import org.apache.zookeeper.data.Stat;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yoho.jobs.common.domain.ConstantEnum;
|
|
|
import com.yoho.jobs.common.domain.JobInfo;
|
|
|
import com.yoho.jobs.server.domain.ConstantEnum;
|
|
|
import com.yoho.jobs.common.jobopt.JobRegisterService;
|
|
|
import com.yoho.jobs.server.domain.ScheduleJobInfo;
|
|
|
import com.yoho.jobs.server.scheduler.Container;
|
|
|
import com.yoho.jobs.server.scheduler.JobService;
|
...
|
...
|
@@ -34,6 +34,8 @@ public class JobServiceImpl implements JobService { |
|
|
|
|
|
private CuratorFramework client;
|
|
|
|
|
|
private JobRegisterService jobRegisterService;
|
|
|
|
|
|
/*
|
|
|
* (non-Javadoc)
|
|
|
*
|
...
|
...
|
@@ -129,23 +131,27 @@ public class JobServiceImpl implements JobService { |
|
|
this.client = client;
|
|
|
}
|
|
|
|
|
|
public JobRegisterService getJobRegisterService() {
|
|
|
return jobRegisterService;
|
|
|
}
|
|
|
|
|
|
public void setJobRegisterService(JobRegisterService jobRegisterService) {
|
|
|
this.jobRegisterService = jobRegisterService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void createJob(JobInfo jobInfo) throws Exception {
|
|
|
if (logger.isDebugEnabled()) {
|
|
|
logger.debug("begin to create job , job is {}", jobInfo);
|
|
|
}
|
|
|
|
|
|
if (!checkJobExist(jobInfo)) {
|
|
|
String message = "the job already exist in zk,plz check it ,jobinfo is " + jobInfo;
|
|
|
logger.error("the job already exits in zk,plz check it ,jobinfo is {}", jobInfo);
|
|
|
throw new Exception(message);
|
|
|
} else {
|
|
|
String jobPath = JOBINFO_PATH + "/" + jobInfo.getModule() + "/jobinfo/" + jobInfo.getJobName();
|
|
|
jobInfo.setOperator(ConstantEnum.JobOperatorEnum.CREATE.getValue());
|
|
|
jobInfo.setStatus(ConstantEnum.JobStatusEnum.STOPPING.getValue());
|
|
|
client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(jobPath,
|
|
|
JSON.toJSONString(jobInfo).getBytes(Charset.forName("UTF-8")));
|
|
|
}
|
|
|
jobInfo.setOperator(ConstantEnum.JobOperatorEnum.CREATE.getValue());
|
|
|
jobInfo.setStatus(ConstantEnum.JobStatusEnum.STOPPING.getValue());
|
|
|
jobRegisterService.registJob(jobInfo);
|
|
|
ScheduleJobInfo scheduleJobInfo = new ScheduleJobInfo();
|
|
|
scheduleJobInfo.setFuture(null);
|
|
|
scheduleJobInfo.setJobInfo(jobInfo);
|
|
|
scheduleJobInfo.setScheduler(null);
|
|
|
Container.CONTAINER.addJobInfo(jobInfo.getModule(), scheduleJobInfo);
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -155,7 +161,7 @@ public class JobServiceImpl implements JobService { |
|
|
logger.debug("begin to startJob job , job is {}", jobInfo);
|
|
|
}
|
|
|
|
|
|
if (!checkJobExist(jobInfo)) {
|
|
|
if (!jobRegisterService.checkJobExist(jobInfo)) {
|
|
|
// 不存在
|
|
|
String message = "job not exist, job is " + jobInfo;
|
|
|
logger.error(message);
|
...
|
...
|
@@ -184,7 +190,7 @@ public class JobServiceImpl implements JobService { |
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!checkJobExist(jobInfo)) {
|
|
|
if (!jobRegisterService.checkJobExist(jobInfo)) {
|
|
|
String message = "job not exist, job is " + jobInfo;
|
|
|
logger.error(message);
|
|
|
throw new Exception(message);
|
...
|
...
|
@@ -205,7 +211,7 @@ public class JobServiceImpl implements JobService { |
|
|
public void updateJob(JobInfo jobInfo) throws Exception {
|
|
|
|
|
|
String jobPath = JOBINFO_PATH + "/" + jobInfo.getModule() + "/jobinfo/" + jobInfo.getJobName();
|
|
|
if (!checkJobExist(jobInfo)) {
|
|
|
if (!jobRegisterService.checkJobExist(jobInfo)) {
|
|
|
// 当任务不存在时,create之
|
|
|
jobInfo.setOperator(ConstantEnum.JobOperatorEnum.CREATE.getValue());
|
|
|
createJob(jobInfo);
|
...
|
...
|
@@ -228,7 +234,7 @@ public class JobServiceImpl implements JobService { |
|
|
if (logger.isDebugEnabled()) {
|
|
|
logger.debug("begin to retryJob job , job is {}", jobInfo);
|
|
|
}
|
|
|
if (!checkJobExist(jobInfo)) {
|
|
|
if (!jobRegisterService.checkJobExist(jobInfo)) {
|
|
|
String message = "job not exist, job is " + jobInfo;
|
|
|
logger.error(message);
|
|
|
throw new Exception(message);
|
...
|
...
|
@@ -240,13 +246,4 @@ public class JobServiceImpl implements JobService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private boolean checkJobExist(JobInfo jobInfo) throws Exception {
|
|
|
String jobPath = JOBINFO_PATH + "/" + jobInfo.getModule() + "/jobinfo/" + jobInfo.getJobName();
|
|
|
Stat stat = client.checkExists().forPath(jobPath);
|
|
|
if (stat == null) {
|
|
|
return false;
|
|
|
} else {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|