use of com.vip.saturn.job.console.domain.JobStatus in project Saturn by vipshop.
the class MarathonServiceImpl method deleteContainerScaleJob.
@Override
public void deleteContainerScaleJob(String namespace, String taskId, String jobName) throws SaturnJobConsoleException {
// disable job, and delete it
// wait 5s to disable job at most
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
try {
String jobNodePath = JobNodePath.getJobNodePath(jobName);
if (curatorFrameworkOp.checkExists(jobNodePath)) {
String enabledNodePath = JobNodePath.getConfigNodePath(jobName, "enabled");
String enabledStr = curatorFrameworkOp.getData(enabledNodePath);
Boolean enabled = Boolean.valueOf(enabledStr);
if (enabled) {
curatorFrameworkOp.update(enabledNodePath, false);
}
long waitStopTime = 5000L;
while (waitStopTime > 0L) {
Thread.sleep(100);
waitStopTime -= 100;
JobStatus jobStatus = jobService.getJobStatus(namespace, jobName);
if (JobStatus.STOPPED.equals(jobStatus)) {
jobService.removeJob(namespace, jobName);
deleteScaleJobNodePath(curatorFrameworkOp, taskId, jobName);
return;
}
}
throw new SaturnJobConsoleException("The job is not stopped, cannot be deleted, please retry later");
} else {
deleteScaleJobNodePath(curatorFrameworkOp, taskId, jobName);
}
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e.getMessage(), e);
}
}
Aggregations