Search in sources :

Example 6 with ContainerScaleJobVo

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

the class MarathonServiceImpl method getContainerScaleJobVos.

private List<ContainerScaleJobVo> getContainerScaleJobVos(String namespace, String taskId, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
    List<ContainerScaleJobVo> containerScaleJobVos = new ArrayList<>();
    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(namespace, 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)

Example 7 with ContainerScaleJobVo

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

the class MarathonServiceImpl method removeContainer.

@Override
public void removeContainer(String namespace, String taskId) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    String dcosTaskIdNodePath = ContainerNodePath.getDcosTaskIdNodePath(taskId);
    if (!curatorFrameworkOp.checkExists(dcosTaskIdNodePath)) {
        throw new SaturnJobConsoleException("The taskId already exists");
    }
    List<ContainerScaleJobVo> containerScaleJobVos = getContainerScaleJobVos(namespace, taskId, curatorFrameworkOp);
    List<String> allUnSystemJobs = jobService.getUnSystemJobNames(namespace);
    for (String job : allUnSystemJobs) {
        String preferListNodePath = JobNodePath.getConfigNodePath(job, "preferList");
        if (curatorFrameworkOp.checkExists(preferListNodePath)) {
            String preferList = curatorFrameworkOp.getData(preferListNodePath);
            if (null == preferList) {
                continue;
            }
            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(namespace, taskId, containerScaleJobVo.getJobName());
    }
    ContainerToken containerToken = getContainerToken(namespace);
    MarathonRestClient.destroy(containerToken.getUserName(), containerToken.getPassword(), 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)

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