Search in sources :

Example 6 with SaturnJobConsoleException

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

the class ExecutorServiceImpl method shardAllAtOnce.

@Override
public RequestResult shardAllAtOnce() throws SaturnJobConsoleException {
    try {
        RequestResult requestResult = new RequestResult();
        CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
        String shardAllAtOnceNodePath = ExecutorNodePath.getExecutorShardingNodePath("shardAllAtOnce");
        if (curatorFrameworkOp.checkExists(shardAllAtOnceNodePath)) {
            curatorFrameworkOp.deleteRecursive(shardAllAtOnceNodePath);
        }
        curatorFrameworkOp.create(shardAllAtOnceNodePath);
        requestResult.setMessage("");
        requestResult.setSuccess(true);
        return requestResult;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    }
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)

Example 7 with SaturnJobConsoleException

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

the class JobConfigInitializationServiceImpl method exportAllToDb.

@Override
public void exportAllToDb(final String userName) throws SaturnJobConsoleException {
    final ExportJobConfigPageStatus exportJobConfigPageStatus = new ExportJobConfigPageStatus();
    temporarySharedStatusService.delete(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS);
    temporarySharedStatusService.create(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            log.info("start to export all to db");
            try {
                log.info("start to delete all from table job_config");
                deleteAll();
                log.info("delete all from table job_config successfully");
                Collection<ZkCluster> zkClusters = registryCenterService.getZkClusterList();
                if (zkClusters != null) {
                    for (ZkCluster tmp : zkClusters) {
                        exportToDbByZkCluster(userName, tmp, exportJobConfigPageStatus);
                    }
                }
                exportJobConfigPageStatus.setSuccess(true);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                exportJobConfigPageStatus.setSuccess(false);
            } finally {
                exportJobConfigPageStatus.setExported(true);
                temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
            }
        }
    });
}
Also used : ExportJobConfigPageStatus(com.vip.saturn.job.console.domain.ExportJobConfigPageStatus) Collection(java.util.Collection) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 8 with SaturnJobConsoleException

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

the class JobConfigInitializationServiceImpl method exportToDbByZkCluster.

private void exportToDbByZkCluster(String userName, ZkCluster tmp, ExportJobConfigPageStatus exportJobConfigPageStatus) throws SaturnJobConsoleException {
    log.info(" start to export db by single zkCluster, zkCluster Addr is :{}", tmp.getZkAddr());
    ZkCluster zkCluster = tmp;
    ArrayList<RegistryCenterConfiguration> oldRccs = zkCluster.getRegCenterConfList();
    ArrayList<RegistryCenterConfiguration> rccs = new ArrayList<RegistryCenterConfiguration>(oldRccs);
    for (RegistryCenterConfiguration rcc : rccs) {
        List<String> jobNames = getAllUnSystemJobs(rcc.getNamespace(), zkCluster.getCuratorFramework());
        for (String jobName : jobNames) {
            try {
                JobSettings jobSettings = getJobSettings(jobName, rcc, zkCluster.getCuratorFramework());
                CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
                current.setCreateBy(userName);
                current.setCreateTime(new Date());
                current.setLastUpdateBy(userName);
                current.setLastUpdateTime(new Date());
                current.setNamespace(rcc.getNamespace());
                currentJobConfigService.create(current);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new SaturnJobConsoleException(e.getMessage());
            }
        }
        exportJobConfigPageStatus.setSuccessJobNum(exportJobConfigPageStatus.getSuccessJobNum() + jobNames.size());
        exportJobConfigPageStatus.setSuccessNamespaceNum(exportJobConfigPageStatus.getSuccessNamespaceNum() + 1);
        temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
    }
    log.info("export db by single zkCluster successfully, zkCluster Addr is :{}", tmp.getZkAddr());
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) JobSettings(com.vip.saturn.job.console.domain.JobSettings) CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Date(java.util.Date) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 9 with SaturnJobConsoleException

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

the class JobDimensionServiceImpl method savePreferListToDb.

private void savePreferListToDb(String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, String newJobConfigPreferList) throws SaturnJobConsoleException, SaturnJobConsoleHttpException {
    String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
    CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (oldCurrentJobConfig == null) {
        log.error("找不到该作业的配置,namespace jobname is:" + namespace + " " + jobName);
        return;
    }
    CurrentJobConfig newCurrentJobConfig = mapper.map(oldCurrentJobConfig, CurrentJobConfig.class);
    newCurrentJobConfig.setPreferList(newJobConfigPreferList);
    try {
        currentJobConfigService.updateConfigAndSave2History(newCurrentJobConfig, oldCurrentJobConfig, null);
    } catch (Exception e) {
        log.error("exception is thrown during change perfer list 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 10 with SaturnJobConsoleException

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

the class JobOperationServiceImpl method updateJobCron.

@Transactional
@Override
public void updateJobCron(String jobName, String cron, Map<String, String> customContext) throws SaturnJobConsoleException {
    String cron0 = cron;
    if (cron0 != null && !cron0.trim().isEmpty()) {
        try {
            cron0 = cron0.trim();
            CronExpression.validateExpression(cron0);
        } catch (ParseException e) {
            throw new SaturnJobConsoleException("The cron expression is valid: " + cron);
        }
    } else {
        cron0 = "";
    }
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
    if (curatorFrameworkOp.checkExists(JobNodePath.getConfigNodePath(jobName))) {
        String newCustomContextStr = null;
        String newCron = null;
        String oldCustomContextStr = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "customContext"));
        Map<String, String> oldCustomContextMap = toCustomContext(oldCustomContextStr);
        if (customContext != null && !customContext.isEmpty()) {
            oldCustomContextMap.putAll(customContext);
            newCustomContextStr = toCustomContext(oldCustomContextMap);
            if (newCustomContextStr.getBytes().length > 1024 * 1024) {
                throw new SaturnJobConsoleException("The all customContext is out of zk limit memory(1M)");
            }
        }
        String oldCron = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "cron"));
        if (cron0 != null && oldCron != null && !cron0.equals(oldCron.trim())) {
            newCron = cron0;
        }
        if (newCustomContextStr != null || newCron != null) {
            saveCronToDb(jobName, curatorFrameworkOp, newCustomContextStr, newCron);
        }
        if (newCustomContextStr != null) {
            curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, "customContext"), newCustomContextStr);
        }
        if (newCron != null) {
            curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, "cron"), newCron);
        }
    } else {
        throw new SaturnJobConsoleException("The job is not found: " + jobName);
    }
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ParseException(java.text.ParseException) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp) Transactional(org.springframework.transaction.annotation.Transactional)

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