-
Notifications
You must be signed in to change notification settings - Fork 131
/
PoolCostMsgHandler.java
289 lines (246 loc) · 9.8 KB
/
PoolCostMsgHandler.java
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package org.dcache.services.info.gathers.poolmanager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Map;
import diskCacheV111.pools.PoolCostInfo;
import diskCacheV111.pools.PoolCostInfo.NamedPoolQueueInfo;
import diskCacheV111.pools.PoolCostInfo.PoolQueueInfo;
import diskCacheV111.pools.PoolCostInfo.PoolSpaceInfo;
import diskCacheV111.vehicles.CostModulePoolInfoTable;
import dmg.cells.nucleus.UOID;
import org.dcache.services.info.base.FloatingPointStateValue;
import org.dcache.services.info.base.IntegerStateValue;
import org.dcache.services.info.base.StatePath;
import org.dcache.services.info.base.StateUpdate;
import org.dcache.services.info.base.StateUpdateManager;
import org.dcache.services.info.base.StringStateValue;
import org.dcache.services.info.gathers.CellMessageHandlerSkel;
import org.dcache.services.info.gathers.MessageMetadataRepository;
import org.dcache.services.info.stateInfo.SpaceInfo;
/**
* This class processing incoming CellMessages that contain CostModulePoolInfoTable
*
* @author Paul Millar <paul.millar@desy.de>
*/
public class PoolCostMsgHandler extends CellMessageHandlerSkel
{
private static final Logger LOGGER = LoggerFactory.getLogger(PoolCostMsgHandler.class);
public PoolCostMsgHandler(StateUpdateManager sum,
MessageMetadataRepository<UOID> msgMetaRepo)
{
super(sum, msgMetaRepo);
}
@Override
public void process(Object msgPayload, long msgDeliveryPeriod)
{
long metricLifetime = (long) (msgDeliveryPeriod * 2.5); // Give metrics a lifetime of 2.5* message deliver period
if (!(msgPayload instanceof CostModulePoolInfoTable)) {
LOGGER.error("received non-CostModulePoolInfoTable object in message");
return;
}
CostModulePoolInfoTable poolInfoTbl = (CostModulePoolInfoTable) msgPayload;
Collection<PoolCostInfo> poolInfos = poolInfoTbl.poolInfos();
if (poolInfos.size() > 0) {
StateUpdate update = buildUpdate(poolInfos, metricLifetime);
applyUpdates(update);
}
}
/**
* Build a StateUpdate for the supplied collection of pool information
* @param poolInfos a collection of informaiton about the pools
* @param metricLifetime the duration metrics should remain
* @return a StateUpdate that updates the state
*/
private StateUpdate buildUpdate(Collection<PoolCostInfo> poolInfos,
long metricLifetime)
{
StatePath poolsPath = new StatePath("pools");
StateUpdate update = new StateUpdate();
for (PoolCostInfo thisPoolInfo : poolInfos) {
String poolName = thisPoolInfo.getPoolName();
StatePath pathToThisPool = poolsPath.newChild(poolName);
StatePath pathToQueues = pathToThisPool.newChild("queues");
/*
* Add all the standard queues
*/
addTapeQueueInfo(update, pathToQueues, "store", thisPoolInfo.getStoreQueue(), metricLifetime);
addTapeQueueInfo(update, pathToQueues, "restore", thisPoolInfo.getRestoreQueue(), metricLifetime);
addQueueInfo(update, pathToQueues, "mover", thisPoolInfo.getMoverQueue(), metricLifetime);
addQueueInfo(update, pathToQueues, "p2p-queue", thisPoolInfo.getP2pQueue(), metricLifetime);
addQueueInfo(update, pathToQueues, "p2p-clientqueue", thisPoolInfo.getP2pClientQueue(), metricLifetime);
/*
* Add the "extra" named queues
*/
addNamedQueues(update, pathToQueues, thisPoolInfo, metricLifetime);
/*
* Add information about our default queue's name, if we have one.
*/
String defaultQueue = thisPoolInfo.getDefaultQueueName();
if (defaultQueue != null) {
update.appendUpdate(pathToQueues.newChild("default-queue"),
new StringStateValue(defaultQueue, metricLifetime));
}
/**
* Add information about this pool's space utilisation.
*/
addSpaceInfo(update, pathToThisPool.newChild("space"), thisPoolInfo.getSpaceInfo(), metricLifetime);
}
return update;
}
/**
* Add information about a specific queue to a pool's portion of dCache state.
* The state tree looks like:
*
* <pre>
* [dCache]
* |
* +--[pools]
* | |
* | +--[<poolName>]
* | | |
* | | +--[queues]
* | | | |
* | | | +--[<queueName1>]
* | | | | |
* | | | | +--active: nnn
* | | | | +--max-active: nnn
* | | | | +--queued: nnn
* | | | |
* | | | +--[<queueName2>]
* </pre>
*
* @param pathToQueues the StatePath pointing to queues (e.g.,
* "pools.mypool_1.queues")
* @param queueName the name of the queue.
*/
private void addQueueInfo(StateUpdate stateUpdate, StatePath pathToQueues,
String queueName, PoolQueueInfo info, long lifetime)
{
StatePath queuePath = pathToQueues.newChild(queueName);
stateUpdate.appendUpdate(queuePath.newChild("active"),
new IntegerStateValue(info.getActive(), lifetime));
stateUpdate.appendUpdate(queuePath.newChild("max-active"),
new IntegerStateValue(info.getMaxActive(), lifetime));
stateUpdate.appendUpdate(queuePath.newChild("queued"),
new IntegerStateValue(info.getQueued(), lifetime));
}
/**
* Add information about a specific tape queue to a pool's portion of dCache state.
* The state tree looks like:
*
* <pre>
* [dCache]
* |
* +--[pools]
* | |
* | +--[<poolName>]
* | | |
* | | +--[queues]
* | | | |
* | | | +--[<queueName1>]
* | | | | |
* | | | | +--active: nnn
* | | | | +--queued: nnn
* | | | |
* | | | +--[<queueName2>]
* </pre>
*
* The difference to regular queues is that tape queues to not have a public maximum
* value for active tasks (specific providers may have one, but this is internal to
* a provider).
*
* @param pathToQueues the StatePath pointing to queues (e.g.,
* "pools.mypool_1.queues")
* @param queueName the name of the queue.
*/
private void addTapeQueueInfo(StateUpdate stateUpdate, StatePath pathToQueues,
String queueName, PoolQueueInfo info, long lifetime)
{
StatePath queuePath = pathToQueues.newChild(queueName);
stateUpdate.appendUpdate(queuePath.newChild("active"),
new IntegerStateValue(info.getActive(), lifetime));
stateUpdate.appendUpdate(queuePath.newChild("queued"),
new IntegerStateValue(info.getQueued(), lifetime));
}
/**
* Adds information from a pool's PoolSpaceInfo object.
* We add this into the state in the following way:
*
* <pre>
* [dCache]
* |
* +--[pools]
* | |
* | +--[<poolName>]
* | | |
* | | +--[space]
* | | | |
* | | | +--total: nnn
* | | | +--free: nnn
* | | | +--precious: nnn
* | | | +--removable: nnn
* | | | +--pinned: nnn
* | | | +--used: nnn
* | | | +--gap: nnn
* | | | +--break-even: nnn
* | | | +--LRU-seconds: nnn
* </pre>
*
* @param stateUpdate the StateUpdate we will append
* @param path the StatePath pointing to the space branch
* @param info the space information to include.
*/
private void addSpaceInfo(StateUpdate stateUpdate, StatePath pathToSpace,
PoolSpaceInfo info, long lifetime)
{
SpaceInfo si = new SpaceInfo(info);
si.addMetrics(stateUpdate, pathToSpace, lifetime);
stateUpdate.appendUpdate(pathToSpace.newChild("gap"),
new IntegerStateValue(info.getGap(), lifetime));
stateUpdate.appendUpdate(pathToSpace.newChild("break-even"),
new FloatingPointStateValue(info.getBreakEven(), lifetime));
stateUpdate.appendUpdate(pathToSpace.newChild("LRU-seconds"),
new IntegerStateValue(info.getLRUSeconds(), lifetime));
}
/**
* Add information about all "named" queues. The available information is the
* same as with regular queues, but there are arbirary number of these. The
* information is presented underneath the named-queues branch of the queues
* branch:
*
* <pre>
* [dCache]
* |
* +--[pools]
* | |
* | +--[<poolName>]
* | | |
* | | +--[queues]
* | | | |
* | | | +--[named-queues]
* | | | | |
* | | | | +--[<namedQueue1>]
* | | | | | |
* | | | | | +--active: nnn
* | | | | | +--max-active: nnn
* </pre>
*
* @param update the StateUpdate we are appending to
* @param pathToQueues the StatePath pointing to [queues] above
* @param thisPoolInfo the information about this pool.
*/
private void addNamedQueues(StateUpdate update, StatePath pathToQueues,
PoolCostInfo thisPoolInfo, long lifetime)
{
Map<String, NamedPoolQueueInfo> namedQueuesInfo = thisPoolInfo.getExtendedMoverHash();
if (namedQueuesInfo == null) {
return;
}
StatePath pathToNamedQueues = pathToQueues.newChild("named-queues");
for (NamedPoolQueueInfo thisNamedQueueInfo : namedQueuesInfo.values()) {
addQueueInfo(update, pathToNamedQueues, thisNamedQueueInfo.getName(),
thisNamedQueueInfo, lifetime);
}
}
}