Search in sources :

Example 16 with SaturnJobConsoleHttpException

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

the class RestApiServiceImpl method createNamespace.

@Transactional(rollbackFor = { Exception.class })
@Override
public void createNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
    String namespace = namespaceDomainInfo.getNamespace();
    String zkClusterKey = namespaceDomainInfo.getZkCluster();
    ZkCluster currentCluster = registryCenterService.getZkCluster(zkClusterKey);
    if (currentCluster == null) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, "not found zkcluster" + zkClusterKey));
    }
    if (checkNamespaceExists(namespace)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_NS_ALREADY_EXIST, namespace));
    }
    try {
        // 创建 namespaceInfo
        NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
        namespaceInfoService.create(namespaceInfo);
        // 创建 zkcluster 和 namespaceInfo 关系
        namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, NAMESPACE_CREATOR_NAME);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, e.getMessage()));
    }
}
Also used : ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) NamespaceInfo(com.vip.saturn.job.console.mybatis.entity.NamespaceInfo) ReportAlarmException(com.vip.saturn.job.integrate.exception.ReportAlarmException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with SaturnJobConsoleHttpException

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

the class NamespaceAndJobRestApiController method create.

@Audit(type = AuditType.REST)
@RequestMapping(value = "/namespaces/createNamespaceAndImportJobs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> create(@RequestBody Map<String, Object> reqParams, HttpServletRequest request) throws SaturnJobConsoleException {
    try {
        String namespace = checkAndGetParametersValueAsString(reqParams, "namespace", true);
        if (StringUtils.isBlank(namespace)) {
            throw new SaturnJobConsoleException("namespace is empty");
        }
        String zkClusterName = checkAndGetParametersValueAsString(reqParams, "zkCluster", true);
        if (StringUtils.isBlank(zkClusterName)) {
            throw new SaturnJobConsoleException("zkCluster is empty");
        }
        String srcNamespace = checkAndGetParametersValueAsString(reqParams, "srcNamespace", true);
        if (StringUtils.isBlank(srcNamespace)) {
            throw new SaturnJobConsoleException("srcNamespace is empty");
        }
        String createBy = checkAndGetParametersValueAsString(reqParams, "createBy", true);
        namespaceAndJobService.createNamespaceAndCloneJobs(srcNamespace, namespace, zkClusterName, createBy);
        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) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Audit(com.vip.saturn.job.console.aop.annotation.Audit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with SaturnJobConsoleHttpException

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

the class ZkDbDiffRestApiController method diff.

@Audit(type = AuditType.REST)
@RequestMapping(value = "/diff", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public ResponseEntity<Object> diff(String zkcluster, HttpServletRequest request) throws SaturnJobConsoleHttpException {
    try {
        checkMissingParameter("zkcluster", zkcluster);
        List<JobDiffInfo> resultList = zkDBDiffService.diffByCluster(zkcluster);
        return new ResponseEntity<Object>(resultList, HttpStatus.OK);
    } catch (Exception e) {
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : JobDiffInfo(com.vip.saturn.job.console.domain.JobDiffInfo) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Audit(com.vip.saturn.job.console.aop.annotation.Audit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with SaturnJobConsoleHttpException

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

the class JobOperationRestApiController method update.

@Audit(type = AuditType.REST)
@RequestMapping(value = "/{namespace}/jobs/{jobName}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> update(@PathVariable("namespace") String namespace, @PathVariable String jobName, @RequestBody Map<String, Object> reqParams) throws SaturnJobConsoleException {
    try {
        JobConfig jobConfig = constructJobConfigOfUpdate(namespace, jobName, reqParams);
        restApiService.updateJob(namespace, jobName, jobConfig);
        return new ResponseEntity<>(HttpStatus.OK);
    } 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) Audit(com.vip.saturn.job.console.aop.annotation.Audit)

Example 20 with SaturnJobConsoleHttpException

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

the class JobOperationRestApiController method constructJobConfigOfCreate.

private JobConfig constructJobConfigOfCreate(String namespace, Map<String, Object> reqParams) throws SaturnJobConsoleException {
    checkMissingParameter("namespace", namespace);
    if (!reqParams.containsKey("jobConfig")) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobConfig", "cannot be blank"));
    }
    JobConfig jobConfig = new JobConfig();
    Map<String, Object> configParams = (Map<String, Object>) reqParams.get("jobConfig");
    jobConfig.setJobName(checkAndGetParametersValueAsString(reqParams, "jobName", true));
    jobConfig.setDescription(checkAndGetParametersValueAsString(reqParams, "description", false));
    jobConfig.setChannelName(checkAndGetParametersValueAsString(configParams, "channelName", false));
    jobConfig.setCron(checkAndGetParametersValueAsString(configParams, "cron", false));
    jobConfig.setJobClass(checkAndGetParametersValueAsString(configParams, "jobClass", false));
    jobConfig.setJobParameter(checkAndGetParametersValueAsString(configParams, "jobParameter", false));
    String jobType = checkAndGetParametersValueAsString(configParams, "jobType", true);
    if (JobType.UNKNOWN_JOB == JobType.getJobType(jobType)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobType", "is malformed"));
    }
    jobConfig.setJobType(jobType);
    jobConfig.setLoadLevel(checkAndGetParametersValueAsInteger(configParams, "loadLevel", false));
    jobConfig.setLocalMode(checkAndGetParametersValueAsBoolean(configParams, "localMode", false));
    jobConfig.setPausePeriodDate(checkAndGetParametersValueAsString(configParams, "pausePeriodDate", false));
    jobConfig.setPausePeriodTime(checkAndGetParametersValueAsString(configParams, "pausePeriodTime", false));
    jobConfig.setPreferList(checkAndGetParametersValueAsString(configParams, "preferList", false));
    jobConfig.setQueueName(checkAndGetParametersValueAsString(configParams, "queueName", false));
    jobConfig.setShardingItemParameters(checkAndGetParametersValueAsString(configParams, "shardingItemParameters", true));
    jobConfig.setShardingTotalCount(checkAndGetParametersValueAsInteger(configParams, "shardingTotalCount", true));
    jobConfig.setTimeout4AlarmSeconds(checkAndGetParametersValueAsInteger(configParams, "timeout4AlarmSeconds", false));
    jobConfig.setUseDispreferList(checkAndGetParametersValueAsBoolean(configParams, "useDispreferList", false));
    jobConfig.setUseSerial(checkAndGetParametersValueAsBoolean(configParams, "useSerial", false));
    jobConfig.setJobDegree(checkAndGetParametersValueAsInteger(configParams, "jobDegree", false));
    jobConfig.setDependencies(checkAndGetParametersValueAsString(configParams, "dependencies", false));
    jobConfig.setTimeZone(checkAndGetParametersValueAsString(configParams, "timeZone", false));
    jobConfig.setTimeoutSeconds(checkAndGetParametersValueAsInteger(configParams, "timeoutSeconds", false));
    jobConfig.setProcessCountIntervalSeconds(checkAndGetParametersValueAsInteger(configParams, "processCountIntervalSeconds", false));
    jobConfig.setGroups(checkAndGetParametersValueAsString(configParams, "groups", false));
    jobConfig.setShowNormalLog(checkAndGetParametersValueAsBoolean(configParams, "showNormalLog", false));
    jobConfig.setFailover(checkAndGetParametersValueAsBoolean(configParams, "failover", false));
    jobConfig.setRerun(checkAndGetParametersValueAsBoolean(configParams, "rerun", false));
    jobConfig.setUpStream(checkAndGetParametersValueAsString(configParams, "upStream", false));
    jobConfig.setDownStream(checkAndGetParametersValueAsString(configParams, "downStream", false));
    return jobConfig;
}
Also used : SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Map(java.util.Map) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Aggregations

SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)68 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)40 ResponseEntity (org.springframework.http.ResponseEntity)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 Test (org.junit.Test)15 HttpHeaders (org.springframework.http.HttpHeaders)13 Audit (com.vip.saturn.job.console.aop.annotation.Audit)12 JobConfig (com.vip.saturn.job.console.domain.JobConfig)10 Matchers.anyString (org.mockito.Matchers.anyString)8 NamespaceDomainInfo (com.vip.saturn.job.console.domain.NamespaceDomainInfo)7 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)5 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)5 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 MvcResult (org.springframework.test.web.servlet.MvcResult)5 Transactional (org.springframework.transaction.annotation.Transactional)5 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)4 AlarmInfo (com.vip.saturn.job.integrate.entity.AlarmInfo)4 ParseException (java.text.ParseException)4 Map (java.util.Map)4 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)3