Skip to content

Commit

Permalink
#483 code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kfchu committed Sep 12, 2018
1 parent ac03646 commit fa2fee9
Showing 1 changed file with 21 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,17 @@
public class InitNewJobService {

private static final Logger log = LoggerFactory.getLogger(InitNewJobService.class);

/**
* record the alarm message hashcode, permanently saved, used for just raising alarm one time for one type exception
*/
private static final ConcurrentMap<String, ConcurrentMap<String, Set<Integer>>> JOB_INIT_FAILED_RECORDS = new ConcurrentHashMap<>();
private SaturnExecutorService saturnExecutorService;
private String executorName;
private CoordinatorRegistryCenter regCenter;

private TreeCache treeCache;
private ExecutorService executorService;

private List<String> jobNames = new ArrayList<>();

/**
* record the alarm message hashcode, permanently saved, used for just raising alarm one time for one type exception
*/
private static final ConcurrentMap<String, ConcurrentMap<String, Set<Integer>>> JOB_INIT_FAILED_RECORDS = new ConcurrentHashMap<>();

public InitNewJobService(SaturnExecutorService saturnExecutorService) {
this.saturnExecutorService = saturnExecutorService;
this.executorName = saturnExecutorService.getExecutorName();
Expand Down Expand Up @@ -159,24 +155,6 @@ public Map<String, Object> constructAlarmInfo(String namespace, String jobName,
return alarmInfo;
}

private void raiseAlarmForJobInitFailed(String jobName, JobInitAlarmException jobInitAlarmException) {
String message = jobInitAlarmException.getMessage();
int messageHashCode = message.hashCode();
Set<Integer> records = JOB_INIT_FAILED_RECORDS.get(executorName).get(jobName);
if (!records.contains(messageHashCode)) {
try {
String namespace = regCenter.getNamespace();
AlarmUtils.raiseAlarm(constructAlarmInfo(namespace, jobName, executorName, message), namespace);
records.add(messageHashCode);
} catch (Exception e) {
log.error("exception throws during raise alarm for job init fail", e);
}
} else {
log.info(SaturnConstant.LOG_FORMAT, jobName,
"job initialize failed but will not raise alarm as such kind of alarm already been raise before");
}
}

private boolean initJobScheduler(String jobName) {
try {
log.info(SaturnConstant.LOG_FORMAT, jobName, "start to initialize the new job");
Expand Down Expand Up @@ -210,6 +188,23 @@ private boolean initJobScheduler(String jobName) {
return false;
}

private void raiseAlarmForJobInitFailed(String jobName, JobInitAlarmException jobInitAlarmException) {
String message = jobInitAlarmException.getMessage();
int messageHashCode = message.hashCode();
Set<Integer> records = JOB_INIT_FAILED_RECORDS.get(executorName).get(jobName);
if (!records.contains(messageHashCode)) {
try {
String namespace = regCenter.getNamespace();
AlarmUtils.raiseAlarm(constructAlarmInfo(namespace, jobName, executorName, message), namespace);
records.add(messageHashCode);
} catch (Exception e) {
log.error("exception throws during raise alarm for job init fail", e);
}
} else {
log.info(SaturnConstant.LOG_FORMAT, jobName,
"job initialize failed but will not raise alarm as such kind of alarm already been raise before");
}
}
}

public static boolean containsJobInitFailedRecord(String executorName, String jobName, String message) {
Expand Down

0 comments on commit fa2fee9

Please sign in to comment.