MaintenanceTaskHealthCheck.java
3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.apache.sling.hc.api.HealthCheck
* org.apache.sling.hc.api.Result
* org.apache.sling.hc.api.ResultLog
* org.apache.sling.hc.util.FormattingResultLog
*/
package com.adobe.granite.maintenance.impl;
import com.adobe.granite.maintenance.MaintenanceTaskInfo;
import com.adobe.granite.maintenance.MaintenanceTaskManager;
import org.apache.sling.hc.api.HealthCheck;
import org.apache.sling.hc.api.Result;
import org.apache.sling.hc.api.ResultLog;
import org.apache.sling.hc.util.FormattingResultLog;
public class MaintenanceTaskHealthCheck
implements HealthCheck {
private final MaintenanceTaskManager mtManager;
private final String taskName;
private final MaintenanceTaskInfo.TaskSchedule schedule;
public MaintenanceTaskHealthCheck(MaintenanceTaskManager manager, MaintenanceTaskInfo.TaskSchedule windowSchedule, String name) {
this.mtManager = manager;
this.taskName = name;
this.schedule = windowSchedule;
}
public Result execute() {
FormattingResultLog resultLog = new FormattingResultLog();
MaintenanceTaskInfo info = this.mtManager.getMaintenanceTaskInfo(this.taskName);
if (info == null) {
resultLog.critical("Maintenance task with name '" + this.taskName + "' does not exist.", new Object[0]);
resultLog.debug(this.taskName + "[Check {0} in the Maintenance section of the Operations Dashboard.](/libs/granite/operations/content/maintenance.html)", new Object[0]);
return new Result((ResultLog)resultLog);
}
String hintMessage = info.getTitle() + "[Check {0} in the Maintenance section of the Operations Dashboard.](/libs/granite/operations/content/maintenance.html)";
if (info.isRunning()) {
resultLog.info("Maintenance task with name '" + this.taskName + "' is currently running.", new Object[0]);
return new Result((ResultLog)resultLog);
}
switch (info.getLastRunState()) {
case FAILED: {
resultLog.critical("Maintenance task with name '" + this.taskName + "' failed in the last run.", new Object[0]);
resultLog.debug(hintMessage, new Object[0]);
return new Result((ResultLog)resultLog);
}
case SUCCEEDED: {
if (info.getSuggestedSchedule() != null) {
if (this.schedule == null) {
resultLog.critical("Maintenance task with name '" + this.taskName + "' is not scheduled.", new Object[0]);
resultLog.debug(hintMessage, new Object[0]);
return new Result((ResultLog)resultLog);
}
int ord1 = info.getSuggestedSchedule().ordinal();
int ord2 = this.schedule.ordinal();
if (ord2 > ord1) {
resultLog.warn("Maintenance task with name '" + this.taskName + "' is scheduled " + this.schedule.name() + " but should be scheduled " + info.getSuggestedSchedule().name() + ".", new Object[0]);
resultLog.debug(hintMessage, new Object[0]);
return new Result((ResultLog)resultLog);
}
}
resultLog.info("Maintenance task with name '" + this.taskName + "' succeeded in the last run.", new Object[0]);
return new Result((ResultLog)resultLog);
}
case STOPPED: {
resultLog.critical("Maintenance task with name '" + this.taskName + "' has been stopped in the last run.", new Object[0]);
resultLog.debug(hintMessage, new Object[0]);
return new Result((ResultLog)resultLog);
}
}
resultLog.critical("Maintenance task with name '" + this.taskName + "' has never run.", new Object[0]);
resultLog.debug(hintMessage, new Object[0]);
return new Result((ResultLog)resultLog);
}
}