Search in sources :

Example 21 with RequestResult

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

the class ZkTreeController method convertFileToZkTree.

@RequestMapping(value = "convertFileToZkTree", method = RequestMethod.POST)
public RequestResult convertFileToZkTree(MultipartHttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        Iterator<String> fileNames = request.getFileNames();
        MultipartFile file = null;
        while (fileNames.hasNext()) {
            if (file != null) {
                requestResult.setSuccess(false);
                requestResult.setMessage("仅支持单文件导入");
                return requestResult;
            }
            file = request.getFile(fileNames.next());
        }
        if (file == null) {
            requestResult.setSuccess(false);
            requestResult.setMessage("请选择导入的文件");
            return requestResult;
        }
        String originalFilename = file.getOriginalFilename();
        if (originalFilename == null || !originalFilename.endsWith(".json")) {
            requestResult.setSuccess(false);
            requestResult.setMessage("仅支持.json文件导入");
            return requestResult;
        }
        ZkTree zkTree = zkTreeService.convertInputStreamToZkTree(file.getInputStream());
        requestResult.setObj(zkTree);
        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 : ZkTree(com.vip.saturn.job.console.domain.ZkTree) RequestResult(com.vip.saturn.job.console.domain.RequestResult) MultipartFile(org.springframework.web.multipart.MultipartFile) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with RequestResult

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

the class HttpClientUtils method toGuiResponseEntity.

public static GuiResponseEntity toGuiResponseEntity(ResponseEntity responseEntity) {
    RequestResult requestResult = new Gson().fromJson(responseEntity.getEntity(), RequestResult.class);
    GuiResponseEntity guiResponseEntity = new GuiResponseEntity();
    guiResponseEntity.setStatusCode(responseEntity.getStatusCode());
    guiResponseEntity.setRequestResult(requestResult);
    return guiResponseEntity;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) Gson(com.google.gson.Gson)

Example 23 with RequestResult

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

the class ExecutorServiceImpl method addJobs.

@Override
public RequestResult addJobs(JobConfig jobConfig) {
    RequestResult requestResult = new RequestResult();
    requestResult.setMessage("");
    requestResult.setSuccess(true);
    try {
        CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
        String jobName = jobConfig.getJobName();
        if (!curatorFrameworkOp.checkExists(JobNodePath.getConfigNodePath(jobName))) {
            int maxJobNum = getMaxJobNum();
            if (jobIncExceeds(maxJobNum, 1)) {
                requestResult.setSuccess(false);
                String errorMsg = String.format("总作业数超过最大限制(%d),作业名%s创建失败", maxJobNum, jobName);
                requestResult.setMessage(errorMsg);
            } else {
                if (jobConfig.getIsCopyJob()) {
                    // 复制作业
                    jobOperationService.copyAndPersistJob(jobConfig, curatorFrameworkOp);
                } else {
                    // 新增作业
                    jobOperationService.persistJob(jobConfig, curatorFrameworkOp);
                }
            }
        } else {
            requestResult.setSuccess(false);
            requestResult.setMessage("作业名" + jobName + "已经存在");
        }
    } catch (Throwable t) {
        log.error(t.getMessage(), t);
        requestResult.setSuccess(false);
        requestResult.setMessage(t.getMessage());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)

Example 24 with RequestResult

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

the class RegistryCenterServiceImpl method refreshRegCenter.

@Override
public RequestResult refreshRegCenter() {
    RequestResult result = new RequestResult();
    if (refreshingRegCenter.compareAndSet(false, true)) {
        try {
            log.info("begin to refresh registry center");
            refreshAll();
            result.setSuccess(true);
        } catch (Throwable t) {
            log.error(t.getMessage(), t);
            result.setSuccess(false);
            result.setMessage(ExceptionUtils.getMessage(t));
        } finally {
            log.info("end refresh registry center");
            refreshingRegCenter.set(false);
        }
    } else {
        result.setSuccess(false);
        result.setMessage("refreshing, try it later!");
    }
    return result;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult)

Example 25 with RequestResult

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

the class ContainerController method addContainerScaleJob.

@RequestMapping(value = "/addContainerScaleJob", method = RequestMethod.POST)
public RequestResult addContainerScaleJob(String taskId, String jobDesc, Integer instances, String timeZone, String cron, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (taskId == null) {
            throw new SaturnJobConsoleException("The taskId cannot be null");
        }
        if (jobDesc == null) {
            throw new SaturnJobConsoleException("The jobDesc cannot be null");
        }
        if (instances == null || instances < 0) {
            throw new SaturnJobConsoleException("Please input the positive instances");
        }
        if (timeZone == null || timeZone.trim().length() == 0) {
            throw new SaturnJobConsoleException("The timeZone cannot be null or empty");
        }
        if (cron == null || cron.trim().length() == 0) {
            throw new SaturnJobConsoleException("The cron cannot be null or empty");
        }
        try {
            CronExpression.validateExpression(cron);
        } catch (ParseException e) {
            throw new SaturnJobConsoleException("The cron is not valid, " + e.toString());
        }
        containerService.addContainerScaleJob(taskId, jobDesc, instances, timeZone, cron);
        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) ParseException(java.text.ParseException) 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