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