ReplicationQueueHealthCheck.java
5.92 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.replication.Agent
* com.day.cq.replication.AgentManager
* com.day.cq.replication.ReplicationQueue
* com.day.cq.replication.ReplicationQueue$Entry
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.PropertyUnbounded
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.ReferencePolicy
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.osgi.PropertiesUtil
* org.apache.sling.hc.api.HealthCheck
* org.apache.sling.hc.api.Result
* org.apache.sling.hc.api.ResultLog
* org.apache.sling.hc.util.FormattingResultLog
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.replication.hc.impl;
import com.day.cq.replication.Agent;
import com.day.cq.replication.AgentManager;
import com.day.cq.replication.ReplicationQueue;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
@Component(metatype=1, label="Adobe Granite Replication Queue Health Check", description="This health check checks the replication queue.")
@Properties(value={@Property(name="hc.name", value={"Replication Queue"}, label="Name", description="Name of the health check."), @Property(name="hc.tags", unbounded=PropertyUnbounded.ARRAY, label="Tags", description="Tags for the health check."), @Property(name="hc.mbean.name", value={"replicationQueue"}, label="MBean Name", description="Name of the JMX mbean to register for this check.")})
@Service(value={HealthCheck.class})
public class ReplicationQueueHealthCheck
implements HealthCheck {
private static final Logger log = LoggerFactory.getLogger(ReplicationQueueHealthCheck.class);
private static final int DEFAULT_NUMBER_OF_RETRIES_ALLOWED = 3;
private int numberOfRetriesAllowed;
@Property(intValue={3}, label="Number of Allowed Retries", description="This is the number of allowed retries for an entry.")
private static final String NUMBER_OF_RETRIES_ALLOWED = "numberOfRetriesAllowed";
@Reference(policy=ReferencePolicy.DYNAMIC)
private volatile AgentManager agentManager;
@Activate
public void activate(Map<String, Object> properties) {
this.numberOfRetriesAllowed = PropertiesUtil.toInteger((Object)properties.get("numberOfRetriesAllowed"), (int)3);
log.info("Activated, numberOfRetriesAllowed={}", (Object)this.numberOfRetriesAllowed);
}
public Result execute() {
FormattingResultLog resultLog = new FormattingResultLog();
int failures = 0;
Map agents = this.agentManager.getAgents();
if (agents != null && agents.size() > 0) {
for (Map.Entry s : agents.entrySet()) {
String name = (String)s.getKey();
Agent agent = (Agent)s.getValue();
try {
if (agent.isEnabled()) {
ReplicationQueue q = agent.getQueue();
List entries = q.entries();
if (entries != null && entries.size() > 0) {
ReplicationQueue.Entry top = (ReplicationQueue.Entry)entries.get(0);
if (top.getNumProcessed() <= this.numberOfRetriesAllowed) {
resultLog.debug("Agent: [{}], first item: [{}], number of retries: {}", new Object[]{name, top.getId(), top.getNumProcessed()});
continue;
}
resultLog.warn("Agent: [{}], first item: [{}], number of retries: {}, expected number of retries <= {}", new Object[]{name, top.getId(), top.getNumProcessed(), this.numberOfRetriesAllowed});
++failures;
continue;
}
resultLog.debug("No items in queue for agent [{}]", new Object[]{name});
continue;
}
resultLog.debug("Agent is disabled [{}]", new Object[]{name});
}
catch (Exception e) {
resultLog.warn("Exception while inspecting replication agent [{}]: {}", new Object[]{name, e});
}
}
} else {
resultLog.debug("No replication agents configured", new Object[0]);
}
resultLog.info("[Click here to inspect the replication agent configurations and queues.](/etc/replication.html)", new Object[0]);
if (failures > 0) {
resultLog.info("[Go to the 'Log Messages' section of the Diagnosis page and check for replication specific log entries.](/libs/granite/operations/content/diagnosis/tool.html/_granite_logmessages)", new Object[0]);
}
return new Result((ResultLog)resultLog);
}
protected void bindAgentManager(AgentManager agentManager) {
this.agentManager = agentManager;
}
protected void unbindAgentManager(AgentManager agentManager) {
if (this.agentManager == agentManager) {
this.agentManager = null;
}
}
}