use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobDimensionServiceImpl method getAllUnSystemJobs.
private List<String> getAllUnSystemJobs(Map<String, CurrentJobConfig> jobConfigMap) throws SaturnJobConsoleException {
List<String> allJobs = new ArrayList<String>();
for (CurrentJobConfig jobConfig : jobConfigMap.values()) {
allJobs.add(jobConfig.getJobName());
}
Collections.sort(allJobs);
Iterator<String> iterator = allJobs.iterator();
while (iterator.hasNext()) {
String job = iterator.next();
CurrentJobConfig jobConfig = jobConfigMap.get(job);
if (StringUtils.isNotBlank(jobConfig.getJobMode())) {
if (jobConfig.getJobMode().startsWith(JobMode.SYSTEM_PREFIX)) {
iterator.remove();
}
}
}
return allJobs;
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobDimensionServiceImpl method getJobConfigsFromDB.
private Map<String, CurrentJobConfig> getJobConfigsFromDB(String namespace) {
Map<String, CurrentJobConfig> result = new HashMap<String, CurrentJobConfig>();
List<CurrentJobConfig> jobConfigs = currentJobConfigService.findConfigsByNamespace(namespace);
if (CollectionUtils.isEmpty(jobConfigs)) {
return result;
}
for (CurrentJobConfig jobConfig : jobConfigs) {
result.put(jobConfig.getJobName(), jobConfig);
}
return result;
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobDimensionServiceImpl method genJobBriefInfo4tree.
private JobBriefInfo genJobBriefInfo4tree(String jobName, Map<String, CurrentJobConfig> jobConfigs) {
if (jobConfigs.containsKey(jobName)) {
CurrentJobConfig jobConfig = jobConfigs.get(jobName);
JobBriefInfo jobBriefInfo = new JobBriefInfo();
jobBriefInfo.setJobName(jobName);
jobBriefInfo.setDescription(jobConfig.getDescription());
jobBriefInfo.setJobClass(jobConfig.getJobClass());
jobBriefInfo.setJobType(JobType.getJobType(jobConfig.getJobType()));
if (JobType.UNKOWN_JOB.equals(jobBriefInfo.getJobType())) {
if (jobBriefInfo.getJobClass() != null && jobBriefInfo.getJobClass().indexOf("SaturnScriptJob") != -1) {
jobBriefInfo.setJobType(JobType.SHELL_JOB);
} else {
jobBriefInfo.setJobType(JobType.JAVA_JOB);
}
}
return jobBriefInfo;
}
return null;
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobDimensionServiceImpl method getJobSettings.
private JobSettings getJobSettings(final String jobName, CuratorRepository.CuratorFrameworkOp curatorFrameworkOp, RegistryCenterConfiguration configInSession, boolean isJobConfigOnly) {
JobSettings result = new JobSettings();
result.setJobName(jobName);
result.setJobType(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "jobType")));
result.setJobClass(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "jobClass")));
// 兼容旧版没有msg_job。
if (StringUtils.isBlank(result.getJobType())) {
if (result.getJobClass().indexOf("script") > 0) {
result.setJobType(JobType.SHELL_JOB.name());
} else {
result.setJobType(JobType.JAVA_JOB.name());
}
}
result.setShardingTotalCount(Integer.parseInt(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "shardingTotalCount"))));
String timeZone = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "timeZone"));
if (Strings.isNullOrEmpty(timeZone)) {
result.setTimeZone(SaturnConstants.TIME_ZONE_ID_DEFAULT);
} else {
result.setTimeZone(timeZone);
}
result.setTimeZonesProvided(Arrays.asList(TimeZone.getAvailableIDs()));
result.setCron(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "cron")));
result.setPausePeriodDate(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "pausePeriodDate")));
result.setPausePeriodTime(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "pausePeriodTime")));
result.setShardingItemParameters(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "shardingItemParameters")));
result.setJobParameter(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "jobParameter")));
result.setProcessCountIntervalSeconds(Integer.parseInt(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "processCountIntervalSeconds"))));
String timeout4AlarmSecondsStr = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "timeout4AlarmSeconds"));
if (Strings.isNullOrEmpty(timeout4AlarmSecondsStr)) {
result.setTimeout4AlarmSeconds(0);
} else {
result.setTimeout4AlarmSeconds(Integer.parseInt(timeout4AlarmSecondsStr));
}
result.setTimeoutSeconds(Integer.parseInt(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "timeoutSeconds"))));
String lv = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "loadLevel"));
if (Strings.isNullOrEmpty(lv)) {
result.setLoadLevel(1);
} else {
result.setLoadLevel(Integer.parseInt(lv));
}
String jobDegree = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "jobDegree"));
if (Strings.isNullOrEmpty(jobDegree)) {
result.setJobDegree(0);
} else {
result.setJobDegree(Integer.parseInt(jobDegree));
}
result.setEnabled(// 默认是禁用的
Boolean.valueOf(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "enabled"))));
result.setPreferList(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "preferList")));
if (!isJobConfigOnly) {
result.setPreferListProvided(getAllExecutors(jobName));
}
String useDispreferList = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "useDispreferList"));
if (Strings.isNullOrEmpty(useDispreferList)) {
result.setUseDispreferList(null);
} else {
result.setUseDispreferList(Boolean.valueOf(useDispreferList));
}
result.setLocalMode(Boolean.valueOf(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "localMode"))));
result.setDependencies(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "dependencies")));
result.setGroups(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "groups")));
try {
List<String> allUnSystemJobs = getAllUnSystemJobs(curatorFrameworkOp);
if (allUnSystemJobs != null) {
allUnSystemJobs.remove(jobName);
result.setDependenciesProvided(allUnSystemJobs);
}
} catch (SaturnJobConsoleException e) {
log.error(e.getMessage(), e);
}
result.setDescription(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "description")));
result.setJobMode(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "jobMode")));
result.setUseSerial(Boolean.valueOf(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "useSerial"))));
result.setQueueName(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "queueName")));
result.setChannelName(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "channelName")));
if (curatorFrameworkOp.checkExists(JobNodePath.getConfigNodePath(jobName, "showNormalLog")) == false) {
curatorFrameworkOp.create(JobNodePath.getConfigNodePath(jobName, "showNormalLog"));
}
String enabledReport = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "enabledReport"));
Boolean enabledReportValue = Boolean.valueOf(enabledReport);
if (Strings.isNullOrEmpty(enabledReport)) {
enabledReportValue = true;
}
result.setEnabledReport(enabledReportValue);
result.setShowNormalLog(Boolean.valueOf(curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "showNormalLog"))));
if (!isJobConfigOnly) {
try {
CurrentJobConfig jobconfig = currentJobConfigService.findConfigByNamespaceAndJobName(configInSession.getNamespace(), result.getJobName());
// config not exists, save it to current config.
if (jobconfig == null) {
CurrentJobConfig current = mapper.map(result, CurrentJobConfig.class);
current.setCreateTime(new Date());
current.setLastUpdateTime(new Date());
current.setNamespace(configInSession.getNamespace());
currentJobConfigService.create(current);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
return result;
}
use of com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig in project Saturn by vipshop.
the class JobDimensionServiceImpl method getAllJobsBriefInfo.
@Override
public Collection<JobBriefInfo> getAllJobsBriefInfo(String sessionBsKey, String namespace) {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
Map<String, CurrentJobConfig> jobConfigs = getJobConfigsFromDB(namespace);
List<String> jobNames = new ArrayList<>();
try {
jobNames = getAllUnSystemJobs(jobConfigs);
} catch (SaturnJobConsoleException e) {
log.error(e.getMessage(), e);
}
List<JobBriefInfo> result = new ArrayList<>(jobNames.size());
for (String jobName : jobNames) {
try {
if (jobConfigs.containsKey(jobName)) {
CurrentJobConfig currentJobConfig = jobConfigs.get(jobName);
JobBriefInfo jobBriefInfo = genJobBriefInfo4tree(jobName, jobConfigs);
jobBriefInfo.setIsJobEnabled(currentJobConfig.getEnabled());
jobBriefInfo.setStatus(getJobStatus(jobName, curatorFrameworkOp, currentJobConfig.getEnabled()));
jobBriefInfo.setJobParameter(currentJobConfig.getJobParameter());
jobBriefInfo.setShardingItemParameters(currentJobConfig.getShardingItemParameters());
jobBriefInfo.setQueueName(currentJobConfig.getQueueName());
jobBriefInfo.setChannelName(currentJobConfig.getChannelName());
jobBriefInfo.setLoadLevel(String.valueOf(currentJobConfig.getLoadLevel()));
String jobDegree = currentJobConfig.getJobDegree() == null ? "0" : String.valueOf(currentJobConfig.getJobDegree());
jobBriefInfo.setJobDegree(jobDegree);
jobBriefInfo.setShardingTotalCount(String.valueOf(currentJobConfig.getShardingTotalCount()));
if (currentJobConfig.getTimeout4AlarmSeconds() == null) {
jobBriefInfo.setTimeout4AlarmSeconds(0);
} else {
jobBriefInfo.setTimeout4AlarmSeconds(currentJobConfig.getTimeout4AlarmSeconds());
}
jobBriefInfo.setTimeoutSeconds(currentJobConfig.getTimeoutSeconds());
jobBriefInfo.setPausePeriodDate(currentJobConfig.getPausePeriodDate());
jobBriefInfo.setPausePeriodTime(currentJobConfig.getPausePeriodTime());
jobBriefInfo.setShowNormalLog(currentJobConfig.getShowNormalLog());
jobBriefInfo.setLocalMode(currentJobConfig.getLocalMode());
jobBriefInfo.setUseSerial(currentJobConfig.getUseSerial());
jobBriefInfo.setUseDispreferList(currentJobConfig.getUseDispreferList());
jobBriefInfo.setProcessCountIntervalSeconds(currentJobConfig.getProcessCountIntervalSeconds());
jobBriefInfo.setGroups(currentJobConfig.getGroups());
String preferList = currentJobConfig.getPreferList();
jobBriefInfo.setPreferList(preferList);
if (!Strings.isNullOrEmpty(preferList)) {
String containerTaskIdsNodePath = ContainerNodePath.getDcosTasksNodePath();
List<String> containerTaskIds = curatorFrameworkOp.getChildren(containerTaskIdsNodePath);
jobBriefInfo.setMigrateEnabled(isMigrateEnabled(preferList, containerTaskIds));
} else {
jobBriefInfo.setMigrateEnabled(false);
}
String timeZone = currentJobConfig.getTimeZone();
if (Strings.isNullOrEmpty(timeZone)) {
jobBriefInfo.setTimeZone(SaturnConstants.TIME_ZONE_ID_DEFAULT);
} else {
jobBriefInfo.setTimeZone(timeZone);
}
jobBriefInfo.setCron(currentJobConfig.getCron());
updateJobBriefInfoStatus(curatorFrameworkOp, jobName, jobBriefInfo);
result.add(jobBriefInfo);
}
} catch (Exception e) {
log.error("加载作业{}时出现异常:", jobName, e);
continue;
}
}
Collections.sort(result);
return result;
}
Aggregations