Search in sources :

Example 1 with CuratorRepository

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository in project Saturn by vipshop.

the class ReuseUtils method reuse.

public static void reuse(String namespace, RegistryCenterService registryCenterService, CuratorRepository curatorRepository, ReuseCallBackWithoutReturn callBack) throws SaturnJobConsoleException {
    try {
        RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
        if (registryCenterConfiguration == null) {
            throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace));
        }
        RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
        if (registryCenterClient != null && registryCenterClient.isConnected()) {
            CuratorFramework curatorClient = registryCenterClient.getCuratorClient();
            CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorClient);
            ThreadLocalCuratorClient.setCuratorClient(curatorClient);
            callBack.call(curatorFrameworkOp);
        } else {
            throw new SaturnJobConsoleException("Connect zookeeper failed");
        }
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Throwable t) {
        log.error(t.getMessage(), t);
        throw new SaturnJobConsoleException(t);
    } finally {
        ThreadLocalCuratorClient.clear();
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 2 with CuratorRepository

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository in project Saturn by vipshop.

the class ReuseUtils method reuse.

public static <T> T reuse(String namespace, RegistryCenterService registryCenterService, CuratorRepository curatorRepository, ReuseCallBack<T> callBack) throws SaturnJobConsoleException {
    try {
        RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
        if (registryCenterConfiguration == null) {
            throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace));
        }
        RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
        if (registryCenterClient != null && registryCenterClient.isConnected()) {
            CuratorFramework curatorClient = registryCenterClient.getCuratorClient();
            CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorClient);
            ThreadLocalCuratorClient.setCuratorClient(curatorClient);
            return callBack.call(curatorFrameworkOp);
        } else {
            throw new SaturnJobConsoleException("Connect zookeeper failed");
        }
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Throwable t) {
        log.error(t.getMessage(), t);
        throw new SaturnJobConsoleException(t);
    } finally {
        ThreadLocalCuratorClient.clear();
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 3 with CuratorRepository

use of com.vip.saturn.job.console.repository.zookeeper.CuratorRepository in project Saturn by vipshop.

the class RestApiServiceImpl method runDownStream.

@Override
public List<BatchJobResult> runDownStream(final String namespace, final String jobName, final Map<String, Object> triggeredData) throws SaturnJobConsoleException {
    return ReuseUtils.reuse(namespace, jobName, registryCenterService, curatorRepository, new ReuseCallBack<List<BatchJobResult>>() {

        @Override
        public List<BatchJobResult> call(CuratorRepository.CuratorFrameworkOp curatorFrameworkOp) throws SaturnJobConsoleException {
            JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
            if (jobConfig == null) {
                throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), "不能触发该作业(" + jobName + ")的下游,因为该作业不存在");
            }
            List<BatchJobResult> batchJobResultList = new ArrayList<>();
            String downStream = jobConfig.getDownStream();
            if (StringUtils.isBlank(downStream)) {
                return batchJobResultList;
            }
            // Maybe should validate downStream, but it seems unnecessary, because it's validated when add/copy/import/update job
            String[] split = downStream.split(",");
            for (String childName : split) {
                String childNameTrim = childName.trim();
                if (childNameTrim.isEmpty()) {
                    continue;
                }
                BatchJobResult batchJobResult = new BatchJobResult();
                batchJobResult.setJobName(childNameTrim);
                try {
                    runJobAtOnce(namespace, childNameTrim, triggeredData);
                    batchJobResult.setSuccess(true);
                } catch (SaturnJobConsoleException e) {
                    batchJobResult.setSuccess(false);
                    batchJobResult.setMessage(e.getMessage());
                } finally {
                    batchJobResultList.add(batchJobResult);
                }
            }
            return batchJobResultList;
        }
    });
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)3 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 RegistryCenterClient (com.vip.saturn.job.console.domain.RegistryCenterClient)2 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)1 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)1