Search in sources :

Example 1 with ContainerScaleJobVo

use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.

the class ContainerServiceImpl method removeContainer.

@Override
public void removeContainer(String taskId) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
    ContainerToken containerToken = getContainerToken();
    String dcosTaskIdNodePath = ContainerNodePath.getDcosTaskIdNodePath(taskId);
    if (!curatorFrameworkOp.checkExists(dcosTaskIdNodePath)) {
        throw new SaturnJobConsoleException("The taskId already exists");
    }
    List<ContainerScaleJobVo> containerScaleJobVos = getContainerScaleJobVos(taskId);
    List<String> allUnSystemJobs = jobDimensionService.getAllUnSystemJobs(curatorFrameworkOp);
    for (String job : allUnSystemJobs) {
        String preferListNodePath = JobNodePath.getConfigNodePath(job, "preferList");
        if (curatorFrameworkOp.checkExists(preferListNodePath)) {
            String preferList = curatorFrameworkOp.getData(preferListNodePath);
            if (preferList != null) {
                String[] split = preferList.trim().split(",");
                for (String tmp : split) {
                    if (tmp.trim().equals("@" + taskId)) {
                        throw new SaturnJobConsoleException("Cannot destroy the container, because it's binding a job");
                    }
                }
            }
        }
    }
    for (ContainerScaleJobVo containerScaleJobVo : containerScaleJobVos) {
        deleteContainerScaleJob(taskId, containerScaleJobVo.getJobName());
    }
    getContainerRestService().destroy(containerToken, taskId);
    curatorFrameworkOp.deleteRecursive(dcosTaskIdNodePath);
}
Also used : ContainerScaleJobVo(com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 2 with ContainerScaleJobVo

use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.

the class ContainerServiceImpl method getContainerScaleJobVos.

@Override
public List<ContainerScaleJobVo> getContainerScaleJobVos(String taskId) throws SaturnJobConsoleException {
    List<ContainerScaleJobVo> containerScaleJobVos = new ArrayList<>();
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
    String dcosTaskScaleJobsNodePath = ContainerNodePath.getDcosTaskScaleJobsNodePath(taskId);
    if (curatorFrameworkOp.checkExists(dcosTaskScaleJobsNodePath)) {
        List<String> jobs = curatorFrameworkOp.getChildren(dcosTaskScaleJobsNodePath);
        if (jobs != null) {
            for (String job : jobs) {
                ContainerScaleJobVo containerScaleJobVo = getContainerScaleJobVo(taskId, job);
                if (containerScaleJobVo != null) {
                    containerScaleJobVos.add(containerScaleJobVo);
                }
            }
        }
    }
    Collections.sort(containerScaleJobVos, new Comparator<ContainerScaleJobVo>() {

        @Override
        public int compare(ContainerScaleJobVo o1, ContainerScaleJobVo o2) {
            return o1.getJobName().compareTo(o2.getJobName());
        }
    });
    return containerScaleJobVos;
}
Also used : ContainerScaleJobVo(com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)

Example 3 with ContainerScaleJobVo

use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.

the class ContainerServiceImpl method getContainerScaleJobVo.

@Override
public ContainerScaleJobVo getContainerScaleJobVo(String taskId, String jobName) throws SaturnJobConsoleException {
    ContainerScaleJobVo containerScaleJobVo = null;
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
    try {
        ContainerScaleJob containerScaleJob = getContainerScaleJob(curatorFrameworkOp, taskId, jobName);
        ContainerScaleJobConfig containerScaleJobConfig = containerScaleJob.getContainerScaleJobConfig();
        containerScaleJobVo = new ContainerScaleJobVo();
        containerScaleJobVo.setJobName(containerScaleJobConfig.getJobName());
        containerScaleJobVo.setJobDesc(containerScaleJobConfig.getJobDesc());
        if (containerScaleJobConfig.getInstances() != null) {
            containerScaleJobVo.setInstances(containerScaleJobConfig.getInstances().toString());
        }
        if (containerScaleJobConfig.getTimeZone() == null) {
            containerScaleJobVo.setTimeZone(SaturnConstants.TIME_ZONE_ID_DEFAULT);
        } else {
            containerScaleJobVo.setTimeZone(containerScaleJobConfig.getTimeZone());
        }
        containerScaleJobVo.setCron(containerScaleJobConfig.getCron());
        containerScaleJobVo.setEnabled(containerScaleJob.getEnabled().toString());
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    }
    return containerScaleJobVo;
}
Also used : ContainerScaleJobVo(com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo) 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)

Example 4 with ContainerScaleJobVo

use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.

the class ContainerController method getContainerScaleJob.

@RequestMapping(value = "/getContainerScaleJobVo", method = RequestMethod.GET)
public RequestResult getContainerScaleJob(String taskId, String jobName, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (taskId == null) {
            throw new SaturnJobConsoleException("The taskId cannot be null");
        }
        if (jobName == null) {
            throw new SaturnJobConsoleException("The jobName cannot be null");
        }
        ContainerScaleJobVo containerScaleJob = containerService.getContainerScaleJobVo(taskId, jobName);
        requestResult.setSuccess(true);
        requestResult.setObj(containerScaleJob);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
    }
    return requestResult;
}
Also used : ContainerScaleJobVo(com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo) RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ContainerScaleJobVo

use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.

the class MarathonServiceImpl method getContainerScaleJobVo.

@Override
public ContainerScaleJobVo getContainerScaleJobVo(String namespace, String taskId, String jobName) throws SaturnJobConsoleException {
    ContainerScaleJobVo containerScaleJobVo = null;
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    try {
        ContainerScaleJob containerScaleJob = getContainerScaleJob(curatorFrameworkOp, taskId, jobName);
        ContainerScaleJobConfig containerScaleJobConfig = containerScaleJob.getContainerScaleJobConfig();
        containerScaleJobVo = new ContainerScaleJobVo();
        containerScaleJobVo.setJobName(containerScaleJobConfig.getJobName());
        containerScaleJobVo.setJobDesc(containerScaleJobConfig.getJobDesc());
        if (containerScaleJobConfig.getInstances() != null) {
            containerScaleJobVo.setInstances(containerScaleJobConfig.getInstances().toString());
        }
        if (containerScaleJobConfig.getTimeZone() == null) {
            containerScaleJobVo.setTimeZone(SaturnConstants.TIME_ZONE_ID_DEFAULT);
        } else {
            containerScaleJobVo.setTimeZone(containerScaleJobConfig.getTimeZone());
        }
        containerScaleJobVo.setCron(containerScaleJobConfig.getCron());
        containerScaleJobVo.setEnabled(containerScaleJob.getEnabled().toString());
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    }
    return containerScaleJobVo;
}
Also used : ContainerScaleJobVo(com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo) 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

ContainerScaleJobVo (com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo)7 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)5 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)5 RequestResult (com.vip.saturn.job.console.domain.RequestResult)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1