Search in sources :

Example 56 with SaturnJobConsoleHttpException

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

the class JobServiceImpl method saveCronToDb.

private void saveCronToDb(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String newCustomContextStr, String newCron, String updatedBy) throws SaturnJobConsoleException {
    String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
    JobConfig4DB jobConfig4DB = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (jobConfig4DB == null) {
        String errorMsg = "在DB找不到该作业的配置, namespace:" + namespace + " jobName:" + jobName;
        log.error(errorMsg);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMsg);
    }
    JobConfig4DB newJobConfig4DB = new JobConfig4DB();
    SaturnBeanUtils.copyProperties(jobConfig4DB, newJobConfig4DB);
    if (newCustomContextStr != null) {
        newJobConfig4DB.setCustomContext(newCustomContextStr);
    }
    if (newCron != null) {
        newJobConfig4DB.setCron(newCron);
    }
    currentJobConfigService.updateNewAndSaveOld2History(newJobConfig4DB, jobConfig4DB, updatedBy);
}
Also used : JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 57 with SaturnJobConsoleHttpException

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

the class RegistryCenterServiceImpl method createNamespace.

@Transactional(rollbackFor = { Exception.class })
@Override
public void createNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
    String namespace = namespaceDomainInfo.getNamespace();
    String zkClusterKey = namespaceDomainInfo.getZkCluster();
    ZkCluster currentCluster = 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);
        // refresh
        notifyRefreshRegCenter();
    } 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) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 58 with SaturnJobConsoleHttpException

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

the class RegistryCenterServiceImpl method updateNamespace.

@Override
public void updateNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
    String namespace = namespaceDomainInfo.getNamespace();
    if (!checkNamespaceExists(namespace)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), ERR_MSG_NS_NOT_FOUND);
    }
    try {
        // 创建 namespaceInfo
        NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
        namespaceInfoService.update(namespaceInfo);
        // refresh
        notifyRefreshRegCenter();
    } 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 : SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) NamespaceInfo(com.vip.saturn.job.console.mybatis.entity.NamespaceInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 59 with SaturnJobConsoleHttpException

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

the class DashboardRefreshRestApiController method dashboardRefresh.

/**
 * 根据ZK集群key,刷新该集群的dashboard信息
 */
@Audit(type = AuditType.REST)
@RequestMapping(value = "/dashboard/refresh", method = { RequestMethod.POST, RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> dashboardRefresh(String zkClusterKey, HttpServletRequest request) throws SaturnJobConsoleException {
    try {
        checkMissingParameter("zkClusterKey", zkClusterKey);
        long beforeRefresh = System.currentTimeMillis();
        statisticsRefreshService.refresh(zkClusterKey, true);
        long afterRefresh = System.currentTimeMillis();
        long takeTime = afterRefresh - beforeRefresh;
        return new ResponseEntity<Object>(takeTime, 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) 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 60 with SaturnJobConsoleHttpException

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

the class JobOperationRestApiController method constructJobConfigOfUpdate.

private JobConfig constructJobConfigOfUpdate(String namespace, String jobName, Map<String, Object> reqParams) throws SaturnJobConsoleException {
    checkMissingParameter("namespace", namespace);
    checkMissingParameter("jobName", jobName);
    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(jobName);
    jobConfig.setDescription(checkAndGetParametersValueAsString(reqParams, "description", false));
    jobConfig.setChannelName(checkAndGetParametersValueAsString(configParams, "channelName", false));
    jobConfig.setCron(checkAndGetParametersValueAsString(configParams, "cron", false));
    jobConfig.setJobParameter(checkAndGetParametersValueAsString(configParams, "jobParameter", false));
    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", false));
    jobConfig.setShardingTotalCount(checkAndGetParametersValueAsInteger(configParams, "shardingTotalCount", false));
    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.setRerun(checkAndGetParametersValueAsBoolean(configParams, "rerun", false));
    jobConfig.setFailover(checkAndGetParametersValueAsBoolean(configParams, "failover", 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