Search in sources :

Example 31 with SaturnJobConsoleHttpException

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

the class RegistryCenterServiceImpl method getNamespace.

@Override
public NamespaceDomainInfo getNamespace(String namespace) throws SaturnJobConsoleException {
    if (namespaceInfoService.selectByNamespace(namespace) == null) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    String zkClusterKey = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
    if (StringUtils.isBlank(zkClusterKey)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), ERR_MSG_NS_NOT_FOUND);
    }
    NamespaceDomainInfo namespaceDomainInfo = new NamespaceDomainInfo();
    namespaceDomainInfo.setNamespace(namespace);
    namespaceDomainInfo.setZkCluster(zkClusterKey);
    return namespaceDomainInfo;
}
Also used : NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 32 with SaturnJobConsoleHttpException

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

the class NamespaceAndJobServiceImpl method createNamespaceAndCloneJobs.

@Override
public void createNamespaceAndCloneJobs(String srcNamespace, String namespace, String zkClusterName, String createBy) throws SaturnJobConsoleException {
    logger.info("start createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
    NamespaceZkClusterMapping mapping = namespaceZkClusterMappingRepository.selectByNamespace(srcNamespace);
    if (mapping == null) {
        throw new SaturnJobConsoleException("no zkCluster mapping is not found");
    }
    NamespaceDomainInfo namespaceInfo = new NamespaceDomainInfo();
    namespaceInfo.setNamespace(namespace);
    namespaceInfo.setZkCluster(zkClusterName);
    namespaceInfo.setContent("");
    try {
        registryCenterService.createNamespace(namespaceInfo);
        registryCenterService.refreshRegistryCenterForNamespace(zkClusterName, srcNamespace);
    } catch (SaturnJobConsoleHttpException e) {
        if (StringUtils.equals(String.format(ERR_MSG_NS_ALREADY_EXIST, namespace), e.getMessage())) {
            logger.warn("namespace already exists, ignore this exception and move on");
        } else {
            throw e;
        }
    }
    namespaceService.importJobsFromNamespaceToNamespace(srcNamespace, namespace, createBy);
    logger.info("finish createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 33 with SaturnJobConsoleHttpException

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

the class ExecutorServiceImpl method deleteJobFromDb.

private void deleteJobFromDb(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String jobName) throws SaturnJobConsoleHttpException {
    String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
    CurrentJobConfig currentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (currentJobConfig == null) {
        log.warn("currentJobConfig from db does not exists,namespace and jobName is:" + namespace + " " + jobName);
        return;
    }
    try {
        currentJobConfigService.deleteByPrimaryKey(currentJobConfig.getId());
    } catch (Exception e) {
        log.error("exception is thrown during delete job config from db", e);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 34 with SaturnJobConsoleHttpException

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

the class JobOperationServiceImpl method saveCronToDb.

private void saveCronToDb(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String newCustomContextStr, String newCron) throws SaturnJobConsoleException, SaturnJobConsoleHttpException {
    String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
    CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (oldCurrentJobConfig == null) {
        String errorMsg = "在DB找不到该作业的配置, namespace:" + namespace + " jobname:" + jobName;
        log.error(errorMsg);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), errorMsg);
    }
    CurrentJobConfig newCurrentJobConfig = mapper.map(oldCurrentJobConfig, CurrentJobConfig.class);
    if (newCustomContextStr != null) {
        newCurrentJobConfig.setCustomContext(newCustomContextStr);
    }
    if (newCron != null) {
        newCurrentJobConfig.setCron(newCron);
    }
    try {
        currentJobConfigService.updateConfigAndSave2History(newCurrentJobConfig, oldCurrentJobConfig, null);
    } catch (Exception e) {
        log.error("exception is thrown during change job state in db", e);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 35 with SaturnJobConsoleHttpException

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

the class JobOperationServiceImpl method saveJobConfigToDb.

private void saveJobConfigToDb(JobConfig jobConfig, CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
    String jobName = jobConfig.getJobName();
    String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
    CurrentJobConfig oldJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (oldJobConfig != null) {
        log.warn("when create a new job, a jobConfig with the same name from db exists, will delete it first. namespace:{} and jobName:{}", namespace, jobName);
        try {
            currentJobConfigService.deleteByPrimaryKey(oldJobConfig.getId());
        } catch (Exception e) {
            log.error("exception is thrown during delete job config in db", e);
            throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "创建作业时,数据库存在已经存在该作业的相关配置!并且清理该配置的时候失败", e);
        }
    }
    CurrentJobConfig currentJobConfig = new CurrentJobConfig();
    mapper.map(jobConfig, currentJobConfig);
    currentJobConfig.setCreateTime(new Date());
    currentJobConfig.setLastUpdateTime(new Date());
    currentJobConfig.setNamespace(namespace);
    try {
        currentJobConfigService.create(currentJobConfig);
    } catch (Exception e) {
        log.error("exception is thrown during creating job config in db", e);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
    }
}
Also used : CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) ParseException(java.text.ParseException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

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