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();
}
}
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();
}
}
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;
}
});
}
Aggregations