Search in sources :

Example 1 with JobStatus

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);
    }
}
Also used : JobStatus(com.vip.saturn.job.console.domain.JobStatus) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Aggregations

JobStatus (com.vip.saturn.job.console.domain.JobStatus)1 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)1 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)1