mirror of
https://github.com/scxwhite/hera.git
synced 2025-05-02 23:30:48 +08:00
fix npe
This commit is contained in:
parent
fb534b03e2
commit
7fe633e283
@ -106,6 +106,7 @@ public class Master {
|
||||
HeraLog.info("refresh hostGroup cache");
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isTaskLimit() {
|
||||
return masterRunJob.isTaskLimit();
|
||||
}
|
||||
@ -251,6 +252,7 @@ public class Master {
|
||||
|
||||
/**
|
||||
* 拓扑排序
|
||||
*
|
||||
* @param jobDetails
|
||||
* @return
|
||||
*/
|
||||
@ -261,18 +263,19 @@ public class Master {
|
||||
Map<Integer, Set<Integer>> downStreamJobInfo = Maps.newHashMap();
|
||||
for (HeraJob heraJob : jobDetails) {
|
||||
jobInfo.put(heraJob.getId(), heraJob);
|
||||
HashSet<String> depList = Sets.newHashSet(Splitter.on(",").split(heraJob.getDependencies()));
|
||||
for (String dep : depList) {
|
||||
if (!Strings.isNullOrEmpty(dep)) {
|
||||
Set<Integer> downStreamJobList = downStreamJobInfo.get(Integer.valueOf(dep));
|
||||
if (downStreamJobList == null) {
|
||||
downStreamJobList = Sets.newHashSet();
|
||||
if (heraJob.getDependencies() != null) {
|
||||
HashSet<String> depList = Sets.newHashSet(Splitter.on(",").split(heraJob.getDependencies()));
|
||||
for (String dep : depList) {
|
||||
if (!Strings.isNullOrEmpty(dep)) {
|
||||
Set<Integer> downStreamJobList = downStreamJobInfo.get(Integer.valueOf(dep));
|
||||
if (downStreamJobList == null) {
|
||||
downStreamJobList = Sets.newHashSet();
|
||||
}
|
||||
downStreamJobList.add(heraJob.getId());
|
||||
downStreamJobInfo.put(Integer.valueOf(dep), downStreamJobList);
|
||||
}
|
||||
downStreamJobList.add(heraJob.getId());
|
||||
downStreamJobInfo.put(Integer.valueOf(dep), downStreamJobList);
|
||||
}
|
||||
}
|
||||
|
||||
if (!downStreamJobInfo.containsKey(heraJob.getId())) {
|
||||
downStreamJobInfo.put(heraJob.getId(), Sets.newHashSet());
|
||||
}
|
||||
@ -446,7 +449,7 @@ public class Master {
|
||||
heraAction.setDependencies(null);
|
||||
heraAction.setReadyDependency(null);
|
||||
heraAction.setHostGroupId(heraJob.getHostGroupId());
|
||||
heraAction.setBatchId(getBatchIdFromActionIdPeriod(actionId,heraJob.getCronPeriod(),heraJob.getCronInterval())); //批次号
|
||||
heraAction.setBatchId(getBatchIdFromActionIdPeriod(actionId, heraJob.getCronPeriod(), heraJob.getCronInterval())); //批次号
|
||||
heraActionList.add(heraAction);
|
||||
}
|
||||
return heraActionList;
|
||||
@ -566,7 +569,7 @@ public class Master {
|
||||
actionNew.setJobId(heraJob.getId());
|
||||
actionNew.setAuto(heraJob.getAuto());
|
||||
actionNew.setHostGroupId(heraJob.getHostGroupId());
|
||||
actionNew.setBatchId(getBatchIdFromActionIdPeriod(actionId,heraJob.getCronPeriod(),heraJob.getCronInterval()));//批次号
|
||||
actionNew.setBatchId(getBatchIdFromActionIdPeriod(actionId, heraJob.getCronPeriod(), heraJob.getCronInterval()));//批次号
|
||||
masterContext.getHeraJobActionService().insert(actionNew, nowAction);
|
||||
actionMap.put(actionNew.getId(), actionNew);
|
||||
insertList.add(actionNew);
|
||||
@ -579,7 +582,6 @@ public class Master {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean scanQueue(BlockingQueue<JobElement> queue) throws InterruptedException {
|
||||
if (!queue.isEmpty()) {
|
||||
JobElement jobElement = queue.take();
|
||||
@ -1032,52 +1034,53 @@ public class Master {
|
||||
|
||||
/**
|
||||
* 输出批次号
|
||||
*
|
||||
* @param actionId
|
||||
* @param cronPeriod 周期
|
||||
* @param cronPeriod 周期
|
||||
* @param cronInterval 间隔
|
||||
* @return 批次号;示例actionId=20190102112233,cronPeriod=day,cronInterval=-1,则批次号=2019-01-01
|
||||
*/
|
||||
public String getBatchIdFromActionIdPeriod(Long actionId,String cronPeriod,int cronInterval) {
|
||||
cronPeriod=cronPeriod.toLowerCase();
|
||||
if(cronPeriod.equals("other")){
|
||||
return actionId.toString();
|
||||
}else{
|
||||
String dmStr=actionId.toString().substring(0, 14);
|
||||
Date currDate = HeraDateTool.StringToDate(dmStr, "yyyyMMddHHmmss");
|
||||
Calendar cal=Calendar.getInstance();
|
||||
cal.setTime(currDate);
|
||||
String outDateStr;
|
||||
SimpleDateFormat outDateFormat = new SimpleDateFormat(TimeFormatConstant.YYYY_MM_DD_HH_MM_SS);
|
||||
if(cronPeriod.equals("year")){
|
||||
cal.add(Calendar.YEAR, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0,4);
|
||||
}else if(cronPeriod.equals("month")){
|
||||
cal.add(Calendar.MONTH, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0,7);
|
||||
}else if(cronPeriod.equals("day")){
|
||||
cal.add(Calendar.DATE, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0,10);
|
||||
}else if(cronPeriod.equals("hour")){
|
||||
cal.add(Calendar.HOUR, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0,13);
|
||||
}else if(cronPeriod.equals("minute")){
|
||||
cal.add(Calendar.MINUTE, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0,16);
|
||||
}else if(cronPeriod.equals("second")){
|
||||
cal.add(Calendar.SECOND, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0,19);
|
||||
}else{//未知,使用秒方案
|
||||
cal.add(Calendar.SECOND, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0,19);
|
||||
}
|
||||
}
|
||||
public String getBatchIdFromActionIdPeriod(Long actionId, String cronPeriod, int cronInterval) {
|
||||
cronPeriod = cronPeriod.toLowerCase();
|
||||
if (cronPeriod.equals("other")) {
|
||||
return actionId.toString();
|
||||
} else {
|
||||
String dmStr = actionId.toString().substring(0, 14);
|
||||
Date currDate = HeraDateTool.StringToDate(dmStr, "yyyyMMddHHmmss");
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(currDate);
|
||||
String outDateStr;
|
||||
SimpleDateFormat outDateFormat = new SimpleDateFormat(TimeFormatConstant.YYYY_MM_DD_HH_MM_SS);
|
||||
if (cronPeriod.equals("year")) {
|
||||
cal.add(Calendar.YEAR, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0, 4);
|
||||
} else if (cronPeriod.equals("month")) {
|
||||
cal.add(Calendar.MONTH, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0, 7);
|
||||
} else if (cronPeriod.equals("day")) {
|
||||
cal.add(Calendar.DATE, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0, 10);
|
||||
} else if (cronPeriod.equals("hour")) {
|
||||
cal.add(Calendar.HOUR, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0, 13);
|
||||
} else if (cronPeriod.equals("minute")) {
|
||||
cal.add(Calendar.MINUTE, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0, 16);
|
||||
} else if (cronPeriod.equals("second")) {
|
||||
cal.add(Calendar.SECOND, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0, 19);
|
||||
} else {//未知,使用秒方案
|
||||
cal.add(Calendar.SECOND, cronInterval);
|
||||
outDateStr = outDateFormat.format(cal.getTime());
|
||||
return outDateStr.substring(0, 19);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user