Search in sources :

Example 26 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobController method migrateJobNewTask.

@RequestMapping(value = "migrateJobNewTask", method = RequestMethod.POST)
public RequestResult migrateJobNewTask(final String jobName, final String newTask, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (jobName == null) {
            throw new SaturnJobConsoleException("The jobName cannot be null");
        }
        if (newTask == null) {
            throw new SaturnJobConsoleException("The new task cannot be null");
        }
        if (jobName.trim().length() == 0) {
            throw new SaturnJobConsoleException("The jobName cannot be empty string");
        }
        if (newTask.trim().length() == 0) {
            throw new SaturnJobConsoleException("The new task cannot be empty string");
        }
        jobDimensionService.migrateJobNewTask(jobName.trim(), newTask.trim());
        requestResult.setSuccess(true);
    } catch (Exception e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobOperationController method batchToggleJobEnabledState.

@RequestMapping(value = "batchToggleJobEnabledState", method = RequestMethod.POST)
public RequestResult batchToggleJobEnabledState(HttpServletRequest request, String jobNames, Boolean state, Boolean confirmed) {
    RequestResult requestResult = new RequestResult();
    if (state == null) {
        requestResult.setSuccess(false);
        requestResult.setMessage("更改的状态有误。");
        return requestResult;
    }
    String[] jobNameArr = jobNames.split(",");
    if (jobNameArr == null || jobNameArr.length == 0) {
        requestResult.setSuccess(false);
        requestResult.setMessage("没有选中任何要操作的作业。");
        return requestResult;
    }
    if (confirmed != null && !confirmed) {
        for (String jobName : jobNameArr) {
            if (jobName != null && jobName.trim().length() > 0) {
                jobName = jobName.trim();
                try {
                    if (state) {
                        // 启用时,检查其依赖的作业是否已经启动
                        List<JobConfig> dependentJobsStatus = jobDimensionService.getDependentJobsStatus(jobName);
                        if (dependentJobsStatus != null) {
                            String unableJobs = "";
                            for (JobConfig jobConfig : dependentJobsStatus) {
                                if (!jobConfig.getEnabled()) {
                                    unableJobs += jobConfig.getJobName() + ",";
                                }
                            }
                            if (!unableJobs.equals("")) {
                                requestResult.setSuccess(false);
                                requestResult.setMessage("有作业依赖的作业还没启用,是否继续批量启用作业?");
                                requestResult.setObj("confirmDependencies");
                                return requestResult;
                            }
                        }
                    } else {
                        // 禁用时,检查依赖它的作业是否已经禁用
                        List<JobConfig> dependedJobsStatus = jobDimensionService.getDependedJobsStatus(jobName);
                        if (dependedJobsStatus != null) {
                            String enableJobs = "";
                            for (JobConfig jobConfig : dependedJobsStatus) {
                                if (jobConfig.getEnabled()) {
                                    enableJobs += jobConfig.getJobName();
                                }
                            }
                            if (!enableJobs.equals("")) {
                                requestResult.setSuccess(false);
                                requestResult.setMessage("有作业被依赖的作业还没禁用,是否继续批量禁用作业?");
                                requestResult.setObj("confirmDependencies");
                                return requestResult;
                            }
                        }
                    }
                } catch (SaturnJobConsoleException e) {
                    requestResult.setSuccess(false);
                    requestResult.setMessage(e.getMessage());
                    return requestResult;
                } catch (Exception e) {
                    requestResult.setSuccess(false);
                    requestResult.setMessage(e.toString());
                    return requestResult;
                }
            }
        }
    }
    StringBuilder messageSbf = new StringBuilder();
    for (String jobName : jobNameArr) {
        try {
            Boolean isJobEnabled = jobDimensionService.isJobEnabled(jobName);
            if (isJobEnabled == state) {
                if (state) {
                    messageSbf.append("作业【" + jobName + "】已经是启动状态,");
                } else {
                    messageSbf.append("作业【" + jobName + "】已经是禁用状态,");
                }
            }
            JobStatus js = jobDimensionService.getJobStatus(jobName);
            // enabled job
            if (state) {
                if (JobStatus.STOPPED.equals(js)) {
                    jobOperationService.setJobEnabledState(jobName, state);
                } else {
                    messageSbf.append("作业【" + jobName + "】不处于stopped状态,不能启用,");
                }
            } else {
                if (JobStatus.RUNNING.equals(js) || JobStatus.READY.equals(js)) {
                    jobOperationService.setJobEnabledState(jobName, state);
                } else {
                    messageSbf.append("作业【" + jobName + "】不处于running或ready状态,不能禁用,");
                }
            }
        } catch (Exception e) {
            messageSbf.append("操作作业【" + jobName + "】出现内部错误,");
            continue;
        }
    }
    if (messageSbf.length() == 0) {
        requestResult.setSuccess(true);
        return requestResult;
    } else {
        requestResult.setSuccess(false);
        // 去掉最后一个逗号
        requestResult.setMessage(messageSbf.substring(0, messageSbf.length() - 1));
        return requestResult;
    }
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) HistoryJobConfig(com.vip.saturn.job.console.mybatis.entity.HistoryJobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobOperationRestApiController method run.

@RequestMapping(value = "/{namespace}/jobs/{jobName}/run", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> run(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
    try {
        checkMissingParameter("namespace", namespace);
        checkMissingParameter("jobName", jobName);
        restApiService.runJobAtOnce(namespace, jobName);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobOperationRestApiController method create.

@RequestMapping(value = "/{namespace}/jobs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> create(@PathVariable("namespace") String namespace, @RequestBody Map<String, Object> reqParams) throws SaturnJobConsoleException {
    try {
        JobConfig jobConfig = constructJobConfig(namespace, reqParams);
        restApiService.createJob(namespace, jobConfig);
        return new ResponseEntity<>(HttpStatus.CREATED);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) JobConfig(com.vip.saturn.job.console.domain.JobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobOperationRestApiController method enable.

@RequestMapping(value = { "/{namespace}/{jobName}/enable", "/{namespace}/jobs/{jobName}/enable" }, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> enable(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
    HttpHeaders httpHeaders = new HttpHeaders();
    try {
        checkMissingParameter("namespace", namespace);
        checkMissingParameter("jobName", jobName);
        restApiService.enableJob(namespace, jobName);
        return new ResponseEntity<>(httpHeaders, HttpStatus.OK);
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)190 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)56 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)56 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)39 RequestResult (com.vip.saturn.job.console.domain.RequestResult)31 ParseException (java.text.ParseException)28 ResponseEntity (org.springframework.http.ResponseEntity)26 Transactional (org.springframework.transaction.annotation.Transactional)23 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)22 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)22 IOException (java.io.IOException)19 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 StatusLine (org.apache.http.StatusLine)18 HttpEntity (org.apache.http.HttpEntity)16 Audit (com.vip.saturn.job.console.aop.annotation.Audit)13 JobConfig (com.vip.saturn.job.console.domain.JobConfig)11 HttpHeaders (org.springframework.http.HttpHeaders)11 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)8 ArrayList (java.util.ArrayList)8