use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig 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.mybatis.entity.CurrentJobConfig 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.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobDimensionServiceImpl method updateJobSettings.
@Transactional
@Override
public String updateJobSettings(final JobSettings jobSettings, RegistryCenterConfiguration configInSession) {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
// Modify JobSettings.updateFields() sync, if the update fields changed.
jobSettings.setDefaultValues();
BooleanWrapper bw = new BooleanWrapper(false);
CuratorTransactionOp curatorTransactionOp = null;
try {
curatorTransactionOp = curatorFrameworkOp.inTransaction().replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobMode"), jobSettings.getJobMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "shardingTotalCount"), jobSettings.getShardingTotalCount(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "loadLevel"), jobSettings.getLoadLevel(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobDegree"), jobSettings.getJobDegree(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "enabledReport"), jobSettings.getEnabledReport(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeZone"), StringUtils.trim(jobSettings.getTimeZone()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "cron"), StringUtils.trim(jobSettings.getCron()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "pausePeriodDate"), jobSettings.getPausePeriodDate(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "pausePeriodTime"), jobSettings.getPausePeriodTime(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "shardingItemParameters"), jobSettings.getShardingItemParameters(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "jobParameter"), jobSettings.getJobParameter(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "processCountIntervalSeconds"), jobSettings.getProcessCountIntervalSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeout4AlarmSeconds"), jobSettings.getTimeout4AlarmSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "timeoutSeconds"), jobSettings.getTimeoutSeconds(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "dependencies"), jobSettings.getDependencies(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "groups"), jobSettings.getGroups(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "description"), jobSettings.getDescription(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "channelName"), StringUtils.trim(jobSettings.getChannelName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "queueName"), StringUtils.trim(jobSettings.getQueueName()), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "showNormalLog"), jobSettings.getShowNormalLog(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "preferList"), jobSettings.getPreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "useDispreferList"), jobSettings.getUseDispreferList(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "failover"), jobSettings.getFailover(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "localMode"), jobSettings.getLocalMode(), bw).replaceIfchanged(JobNodePath.getConfigNodePath(jobSettings.getJobName(), "useSerial"), jobSettings.getUseSerial(), bw);
if (jobSettings.getEnabledReport() != null && !jobSettings.getEnabledReport()) {
// 当enabledReport关闭上报时,要清理execution节点
log.info("the switch of enabledReport set to false, now deleteJob the execution zk node");
String executionNodePath = JobNodePath.getExecutionNodePath(jobSettings.getJobName());
if (curatorFrameworkOp.checkExists(executionNodePath)) {
curatorFrameworkOp.deleteRecursive(executionNodePath);
}
}
} catch (Exception e) {
log.error("update settings to zk failed: {}", e.getMessage());
log.error(e.getMessage(), e);
return e.getMessage();
}
try {
CurrentJobConfig jobconfig = currentJobConfigService.findConfigByNamespaceAndJobName(configInSession.getNamespace(), jobSettings.getJobName());
// config not exists, save it to current config.
if (jobconfig == null) {
CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
current.setNamespace(configInSession.getNamespace());
current.setCreateTime(new Date());
current.setLastUpdateTime(new Date());
currentJobConfigService.create(current);
} else if (bw.isValue()) {
// config changed, update current config and save a copy to history config.
currentJobConfigService.updateConfigAndSave2History(jobconfig, jobSettings, null);
}
if (curatorTransactionOp != null) {
curatorTransactionOp.commit();
}
} catch (Exception e) {
log.error("update settings to db failed: {}", e.getMessage());
log.error(e.getMessage(), e);
return e.getMessage();
}
return null;
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class NamespaceZkClusterMappingServiceImpl method moveNamespaceTo.
@Transactional(rollbackFor = { SaturnJobConsoleException.class })
@Override
public void moveNamespaceTo(String namespace, String zkClusterKeyNew, String lastUpdatedBy, boolean updateDBOnly) throws SaturnJobConsoleException {
try {
log.info("start move {} to {}", namespace, zkClusterKeyNew);
if (updateDBOnly) {
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
} else {
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey != null && zkClusterKey.equals(zkClusterKeyNew)) {
// see
throw new SaturnJobConsoleException("The namespace(" + namespace + ") is in " + zkClusterKey);
// moveNamespaceBatchTo
// before
// modify
}
ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKeyNew);
if (zkCluster == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " is not exists");
}
if (zkCluster.isOffline()) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
String zkAddr = zkCluster.getZkAddr();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.connectOnly(zkAddr, null);
if (curatorFrameworkOp == null) {
throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
}
CuratorFramework curatorFramework = curatorFrameworkOp.getCuratorFramework();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOpByNamespace = registryCenterService.connectOnly(zkAddr, namespace);
CuratorFramework curatorFrameworkByNamespace = curatorFrameworkOpByNamespace.getCuratorFramework();
try {
String namespaceNodePath = "/" + namespace;
if (curatorFramework.checkExists().forPath(namespaceNodePath) != null) {
curatorFramework.delete().deletingChildrenIfNeeded().forPath(namespaceNodePath);
}
String jobsNodePath = namespaceNodePath + JobNodePath.get$JobsNodePath();
curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(jobsNodePath);
List<CurrentJobConfig> configs = currentJobConfigService.findConfigsByNamespace(namespace);
log.info("get configs success, {}", namespace);
if (configs != null) {
for (CurrentJobConfig jobConfig : configs) {
jobOperationService.persistJobFromDB(jobConfig, curatorFrameworkOpByNamespace);
log.info("move {}-{} to zk success", namespace, jobConfig.getJobName());
}
}
} finally {
curatorFramework.close();
curatorFrameworkByNamespace.close();
}
log.info("move {} to zk {} success", namespace, zkClusterKeyNew);
namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
log.info("update mapping table success, {}-{}", namespace, zkClusterKeyNew);
}
} catch (SaturnJobConsoleException e) {
log.error(e.getMessage(), e);
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
} finally {
log.info("end move {} to {}", namespace, zkClusterKeyNew);
}
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig 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);
}
}
Aggregations