Search in sources :

Example 11 with CurrentJobConfig

use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig 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 12 with CurrentJobConfig

use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig 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)

Example 13 with CurrentJobConfig

use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.

the class JobOperationServiceImpl method setJobEnabledState.

@Transactional
@Override
public void setJobEnabledState(String jobName, boolean state) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
    String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
    CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (oldCurrentJobConfig != null) {
        oldCurrentJobConfig.setEnabled(state);
        oldCurrentJobConfig.setLastUpdateTime(new Date());
        try {
            currentJobConfigService.updateByPrimaryKey(oldCurrentJobConfig);
        } 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);
        }
    } else {
        log.warn("job:{} not existed in db", jobName);
    }
    curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, "enabled"), state);
}
Also used : CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp) 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) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)13 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)10 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)8 ParseException (java.text.ParseException)7 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)2 JobSettings (com.vip.saturn.job.console.domain.JobSettings)1 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)1 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)1 CuratorTransactionOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp.CuratorTransactionOp)1 BooleanWrapper (com.vip.saturn.job.console.utils.BooleanWrapper)1 HashMap (java.util.HashMap)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1