Search in sources :

Example 26 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.

the class ContainerController method addContainer.

@RequestMapping(value = "/addContainer", method = RequestMethod.POST)
@ResponseBody
public RequestResult addContainer(AddContainerModel addContainerModel, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (addContainerModel.getContainerToken() == null) {
            throw new SaturnJobConsoleException("Please input container token");
        }
        containerService.checkContainerTokenNotNull(addContainerModel.getContainerToken());
        containerService.saveOrUpdateContainerTokenIfNecessary(addContainerModel.getContainerToken());
        ContainerConfig containerConfig = new ContainerConfig();
        containerConfig.setTaskId(addContainerModel.getTaskId());
        containerConfig.setCmd(addContainerModel.getCmd());
        containerConfig.setCpus(addContainerModel.getCpus());
        containerConfig.setMem(addContainerModel.getMem());
        containerConfig.setInstances(addContainerModel.getInstances());
        containerConfig.setConstraints(addContainerModel.getConstraints());
        containerConfig.setEnv(addContainerModel.getEnv());
        containerConfig.setPrivileged(addContainerModel.getPrivileged() == null ? false : addContainerModel.getPrivileged());
        containerConfig.setForcePullImage(addContainerModel.getForcePullImage() == null ? true : addContainerModel.getForcePullImage());
        containerConfig.setParameters(addContainerModel.getParameters());
        containerConfig.setVolumes(addContainerModel.getVolumes());
        containerConfig.setImage(addContainerModel.getImage());
        containerConfig.setCreateTime(System.currentTimeMillis());
        String imageNew = "";
        String vipSaturnDcosRegistryUri = SaturnEnvProperties.VIP_SATURN_DCOS_REGISTRY_URI;
        if (vipSaturnDcosRegistryUri == null || vipSaturnDcosRegistryUri.trim().length() == 0) {
            String errorMsg = "VIP_SATURN_DCOS_REGISTRY_URI is not configured";
            requestResult.setSuccess(false);
            requestResult.setMessage(errorMsg);
            return requestResult;
        } else {
            if (vipSaturnDcosRegistryUri.startsWith("http://")) {
                String tmp = vipSaturnDcosRegistryUri.substring("http://".length());
                while (tmp.endsWith("/")) {
                    tmp = tmp.substring(0, tmp.length() - 1);
                }
                imageNew = tmp + "/" + addContainerModel.getImage();
            } else if (vipSaturnDcosRegistryUri.startsWith("https://")) {
                String tmp = vipSaturnDcosRegistryUri.substring("https://".length());
                while (tmp.endsWith("/")) {
                    tmp = tmp.substring(0, tmp.length() - 1);
                }
                imageNew = tmp + "/" + addContainerModel.getImage();
            }
        }
        containerConfig.setImage(imageNew);
        if (containerConfig.getEnv() == null) {
            containerConfig.setEnv(new HashMap<String, String>());
        }
        if (!containerConfig.getEnv().containsKey(SaturnEnvProperties.NAME_VIP_SATURN_ZK_CONNECTION)) {
            containerConfig.getEnv().put(SaturnEnvProperties.NAME_VIP_SATURN_ZK_CONNECTION, getCurrentZkAddr(request.getSession()));
        }
        containerService.addContainer(containerConfig);
        requestResult.setSuccess(true);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
    }
    return requestResult;
}
Also used : ContainerConfig(com.vip.saturn.job.console.domain.container.ContainerConfig) RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 27 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.

the class ContainerController method saveOrUpdateContainerToken.

@RequestMapping(value = "saveOrUpdateContainerToken", method = RequestMethod.POST)
public RequestResult saveOrUpdateContainerToken(ContainerToken containerToken, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (containerToken == null) {
            throw new SaturnJobConsoleException("Please input container token");
        }
        containerService.checkContainerTokenNotNull(containerToken);
        containerService.saveOrUpdateContainerToken(containerToken);
        requestResult.setSuccess(true);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.

the class ContainerController method getContainerDetail.

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

Example 29 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult 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 30 with RequestResult

use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.

the class ContainerController method enableContainerScaleJob.

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

Aggregations

RequestResult (com.vip.saturn.job.console.domain.RequestResult)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)45 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)38 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 ParseException (java.text.ParseException)11 IOException (java.io.IOException)3 ExecutorProvided (com.vip.saturn.job.console.domain.ExecutorProvided)2 ExportJobConfigPageStatus (com.vip.saturn.job.console.domain.ExportJobConfigPageStatus)2 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)2 JobMigrateInfo (com.vip.saturn.job.console.domain.JobMigrateInfo)2 SystemConfig (com.vip.saturn.job.console.mybatis.entity.SystemConfig)2 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 Gson (com.google.gson.Gson)1 JobBriefInfo (com.vip.saturn.job.console.domain.JobBriefInfo)1 JobConfig (com.vip.saturn.job.console.domain.JobConfig)1 MoveNamespaceBatchStatus (com.vip.saturn.job.console.domain.MoveNamespaceBatchStatus)1 NamespaceZkClusterMappingVo (com.vip.saturn.job.console.domain.NamespaceZkClusterMappingVo)1 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)1 SaturnJunkData (com.vip.saturn.job.console.domain.SaturnJunkData)1