-
Notifications
You must be signed in to change notification settings - Fork 411
/
messaging-dump-cluster-database-CJOC.groovy
163 lines (140 loc) · 6.01 KB
/
messaging-dump-cluster-database-CJOC.groovy
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Does all the checks that the messaging API performs prior to getting and sending any message to/from all the masters
* Dumps information related to the cluster messaging database.
* Only to be executer on CJOC.
*/
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap;
import com.cloudbees.opscenter.context.Messaging;
import com.cloudbees.opscenter.context.Messaging.OutboxEntry;
import com.cloudbees.opscenter.server.messaging.Transport;
import com.cloudbees.opscenter.server.model.ConnectedMaster;
import hudson.ExtensionList;
import hudson.model.AsyncPeriodicWork;
import hudson.model.PeriodicWork;
import hudson.remoting.Channel;
import jenkins.model.Jenkins;
Jenkins jenkins = Jenkins.getInstance();
out.println("InstanceId: " + jenkins.getLegacyInstanceId());
Transport transport = getTransport();
try {
for (ConnectedMaster m : jenkins.getAllItems(ConnectedMaster.class)) {
String instanceId = m.getLegacyInstanceId();
out.println(" " + m.getFullName() + "(" + instanceId + "):");
out.println(" offline: " + m.isOffline());
Channel channel = m.getChannel();
out.println(" channel: " + channel);
if (channel != null) {
out.println(" channelClossing: " + channel.isClosingOrClosed());
} else {
continue;
}
out.println(" capabilities: " + m.checkCapability(Messaging.class));
Method method;
try {
out.println(" batchSource: " + transport.getBatchSource(channel));
} catch (Exception e) {
out.println(" Error batchSource: " + e.toString());
out.println(" batchSource: " + Messaging.batchSource());
}
try {
out.println(" batchSink: " + transport.getBatchSink(channel));
} catch (Exception e) {
out.println(" Error batchSink: " + e.toString());
out.println(" batchSink: " + Messaging.batchSink());
}
try {
out.println(" reliableMessageTransport: " + transport.getReliableMessageTransport(channel));
} catch (Exception e) {
out.println(" Error reliableMessageTransport: " + e.toString());
out.println(" reliableMessageTransport: " + Messaging.reliableMessageTransport());
}
}
} catch (Exception e) {
e.printStackTrace(out);
}
final ClassLoader oldContext = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(Jenkins.getInstance().getPluginManager().uberClassLoader);
Map<ConnectedMaster, Map<Class<?>, Map<String, List<Object>>>> offlineBuffer;
ConcurrentMap<String, Long> maxPull;
ConcurrentMap<String, Long> minPush;
ConcurrentNavigableMap<String, Messaging.OutboxEntry<?>> outbox;
maxPull = transport.maxPull;
minPush = transport.minPush;
outbox = transport.outbox
offlineBuffer = transport.offlineBuffer
try {
out.println("maxPulls:");
Set<Entry<String, Long>> entrySet = maxPull.entrySet();
for (Entry<String, Long> entry : entrySet) {
out.println(" - " + entry.getKey() + ": " + entry.getValue());
}
} catch (Exception e) {
out.println("Could not get maxPulls information");
e.printStackTrace(out);
}
try {
out.println("minPush:");
Set<Entry<String, Long>> entrySet = minPush.entrySet();
for (Entry<String, Long> entry : entrySet) {
out.println(" - " + entry.getKey() + ": " + entry.getValue());
}
} catch (Exception e) {
out.println("Could not get minPush information");
e.printStackTrace(out);
}
try {
out.println("outbox:");
Set<Entry<String, OutboxEntry<?>>> entrySet = outbox.entrySet();
for (Entry<String, OutboxEntry<?>> entry : entrySet) {
OutboxEntry<?> value = entry.getValue();
out.println(" - " + entry.getKey() + "- source:" + value.getAddress() +
" - destination:" + value.getDestinationId() +
" - expiry:" + new Date(value.getExpiry()) +
" - class:" + value.getClazzName());
}
} catch (Exception e) {
out.println("Could not get minPulls information");
e.printStackTrace(out);
}
try {
Set<Entry<ConnectedMaster, Map<Class<?>, Map<String, List<Object>>>>> entrySet = offlineBuffer.entrySet();
out.println("offlineBuffer: " + offlineBuffer.size());
for (Entry<ConnectedMaster, Map<Class<?>, Map<String, List<Object>>>> entry : entrySet) {
Map<Class<?>, Map<String, List<Object>>> messagesMap = entry.getValue();
ConnectedMaster key = entry.getKey();
out.println(" " + key.getFullDisplayName() + "(" + key.getLegacyInstanceId() + ") - " + messagesMap.size());
for (Entry<Class<?>, Map<String, List<Object>>> messages : messagesMap.entrySet()) {
Map<String, List<Object>> value = messages.getValue();
out.println(" " + messages.getKey() + ":" + value.size());
Set<Entry<String, List<Object>>> messages2 = value.entrySet();
for (Entry<String, List<Object>> message : messages2) {
out.println(" " + message.getKey() + ":" + messages.getValue());
}
}
}
} catch (Exception e) {
out.println("Could not get minPulls information");
e.printStackTrace(out);
}
} finally {
Thread.currentThread().setContextClassLoader(oldContext);
}
Transport getTransport() {
ExtensionList<PeriodicWork> all = AsyncPeriodicWork.all();
for (PeriodicWork periodicWork : all) {
if (periodicWork instanceof Transport) {
return (Transport) periodicWork;
}
}
return null;
}