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