/
ProcessGroupStatus.java
591 lines (492 loc) · 23.1 KB
/
ProcessGroupStatus.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.controller.status;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.apache.nifi.registry.flow.VersionedFlowState;
/**
*/
public class ProcessGroupStatus implements Cloneable {
private String id;
private String name;
private VersionedFlowState versionedFlowState;
private Integer inputCount;
private Long inputContentSize;
private Integer outputCount;
private Long outputContentSize;
private Integer activeThreadCount;
private Integer terminatedThreadCount;
private Integer queuedCount;
private Long queuedContentSize;
private Long bytesRead;
private Long bytesWritten;
private int flowFilesReceived;
private long bytesReceived;
private int flowFilesSent;
private long bytesSent;
private int flowFilesTransferred;
private long bytesTransferred;
private Collection<ConnectionStatus> connectionStatus = new ArrayList<>();
private Collection<ProcessorStatus> processorStatus = new ArrayList<>();
private Collection<ProcessGroupStatus> processGroupStatus = new ArrayList<>();
private Collection<RemoteProcessGroupStatus> remoteProcessGroupStatus = new ArrayList<>();
private Collection<PortStatus> inputPortStatus = new ArrayList<>();
private Collection<PortStatus> outputPortStatus = new ArrayList<>();
public String getId() {
return id;
}
public void setId(final String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public VersionedFlowState getVersionedFlowState() {
return versionedFlowState;
}
public void setVersionedFlowState(VersionedFlowState versionedFlowState) {
this.versionedFlowState = versionedFlowState;
}
public Integer getInputCount() {
return inputCount;
}
public void setInputCount(final Integer inputCount) {
this.inputCount = inputCount;
}
public Long getInputContentSize() {
return inputContentSize;
}
public void setInputContentSize(final Long inputContentSize) {
this.inputContentSize = inputContentSize;
}
public Integer getOutputCount() {
return outputCount;
}
public void setOutputCount(final Integer outputCount) {
this.outputCount = outputCount;
}
public Long getOutputContentSize() {
return outputContentSize;
}
public void setOutputContentSize(final Long outputContentSize) {
this.outputContentSize = outputContentSize;
}
public Long getBytesRead() {
return bytesRead;
}
public void setBytesRead(final Long bytesRead) {
this.bytesRead = bytesRead;
}
public Long getBytesWritten() {
return bytesWritten;
}
public void setBytesWritten(final Long bytesWritten) {
this.bytesWritten = bytesWritten;
}
public Integer getQueuedCount() {
return this.queuedCount;
}
public void setQueuedCount(final Integer queuedCount) {
this.queuedCount = queuedCount;
}
public Long getQueuedContentSize() {
return queuedContentSize;
}
public void setQueuedContentSize(final Long queuedContentSize) {
this.queuedContentSize = queuedContentSize;
}
public Integer getActiveThreadCount() {
return activeThreadCount;
}
public void setActiveThreadCount(final Integer activeThreadCount) {
this.activeThreadCount = activeThreadCount;
}
public Integer getTerminatedThreadCount() {
return terminatedThreadCount;
}
public void setTerminatedThreadCount(Integer terminatedThreadCount) {
this.terminatedThreadCount = terminatedThreadCount;
}
public Collection<ConnectionStatus> getConnectionStatus() {
return connectionStatus;
}
public void setConnectionStatus(final Collection<ConnectionStatus> connectionStatus) {
this.connectionStatus = connectionStatus;
}
public Collection<ProcessorStatus> getProcessorStatus() {
return processorStatus;
}
public void setProcessorStatus(final Collection<ProcessorStatus> processorStatus) {
this.processorStatus = processorStatus;
}
public Collection<ProcessGroupStatus> getProcessGroupStatus() {
return processGroupStatus;
}
public void setProcessGroupStatus(final Collection<ProcessGroupStatus> processGroupStatus) {
this.processGroupStatus = processGroupStatus;
}
public Collection<PortStatus> getInputPortStatus() {
return inputPortStatus;
}
public void setInputPortStatus(Collection<PortStatus> inputPortStatus) {
this.inputPortStatus = inputPortStatus;
}
public Collection<PortStatus> getOutputPortStatus() {
return outputPortStatus;
}
public void setOutputPortStatus(Collection<PortStatus> outputPortStatus) {
this.outputPortStatus = outputPortStatus;
}
public Collection<RemoteProcessGroupStatus> getRemoteProcessGroupStatus() {
return remoteProcessGroupStatus;
}
public void setRemoteProcessGroupStatus(final Collection<RemoteProcessGroupStatus> remoteProcessGroupStatus) {
this.remoteProcessGroupStatus = remoteProcessGroupStatus;
}
public int getFlowFilesReceived() {
return flowFilesReceived;
}
public void setFlowFilesReceived(final int flowFilesReceived) {
this.flowFilesReceived = flowFilesReceived;
}
public long getBytesReceived() {
return bytesReceived;
}
public void setBytesReceived(final long bytesReceived) {
this.bytesReceived = bytesReceived;
}
public int getFlowFilesSent() {
return flowFilesSent;
}
public void setFlowFilesSent(final int flowFilesSent) {
this.flowFilesSent = flowFilesSent;
}
public long getBytesSent() {
return bytesSent;
}
public void setBytesSent(final long bytesSent) {
this.bytesSent = bytesSent;
}
public int getFlowFilesTransferred() {
return flowFilesTransferred;
}
public void setFlowFilesTransferred(int flowFilesTransferred) {
this.flowFilesTransferred = flowFilesTransferred;
}
public long getBytesTransferred() {
return bytesTransferred;
}
public void setBytesTransferred(long bytesTransferred) {
this.bytesTransferred = bytesTransferred;
}
@Override
public ProcessGroupStatus clone() {
final ProcessGroupStatus clonedObj = new ProcessGroupStatus();
clonedObj.id = id;
clonedObj.name = name;
clonedObj.outputContentSize = outputContentSize;
clonedObj.outputCount = outputCount;
clonedObj.inputContentSize = inputContentSize;
clonedObj.inputCount = inputCount;
clonedObj.activeThreadCount = activeThreadCount;
clonedObj.terminatedThreadCount = terminatedThreadCount;
clonedObj.queuedContentSize = queuedContentSize;
clonedObj.queuedCount = queuedCount;
clonedObj.bytesRead = bytesRead;
clonedObj.bytesWritten = bytesWritten;
clonedObj.flowFilesReceived = flowFilesReceived;
clonedObj.bytesReceived = bytesReceived;
clonedObj.flowFilesSent = flowFilesSent;
clonedObj.bytesSent = bytesSent;
clonedObj.flowFilesTransferred = flowFilesTransferred;
clonedObj.bytesTransferred = bytesTransferred;
if (connectionStatus != null) {
final Collection<ConnectionStatus> statusList = new ArrayList<>();
clonedObj.setConnectionStatus(statusList);
for (final ConnectionStatus status : connectionStatus) {
statusList.add(status.clone());
}
}
if (processorStatus != null) {
final Collection<ProcessorStatus> statusList = new ArrayList<>();
clonedObj.setProcessorStatus(statusList);
for (final ProcessorStatus status : processorStatus) {
statusList.add(status.clone());
}
}
if (inputPortStatus != null) {
final Collection<PortStatus> statusList = new ArrayList<>();
clonedObj.setInputPortStatus(statusList);
for (final PortStatus status : inputPortStatus) {
statusList.add(status.clone());
}
}
if (outputPortStatus != null) {
final Collection<PortStatus> statusList = new ArrayList<>();
clonedObj.setOutputPortStatus(statusList);
for (final PortStatus status : outputPortStatus) {
statusList.add(status.clone());
}
}
if (processGroupStatus != null) {
final Collection<ProcessGroupStatus> statusList = new ArrayList<>();
clonedObj.setProcessGroupStatus(statusList);
for (final ProcessGroupStatus status : processGroupStatus) {
statusList.add(status.clone());
}
}
if (remoteProcessGroupStatus != null) {
final Collection<RemoteProcessGroupStatus> statusList = new ArrayList<>();
clonedObj.setRemoteProcessGroupStatus(statusList);
for (final RemoteProcessGroupStatus status : remoteProcessGroupStatus) {
statusList.add(status.clone());
}
}
return clonedObj;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("ProcessGroupStatus [id=");
builder.append(id);
builder.append(", inputCount=");
builder.append(inputCount);
builder.append(", inputBytes=");
builder.append(inputContentSize);
builder.append(", outputCount=");
builder.append(outputCount);
builder.append(", outputBytes=");
builder.append(outputContentSize);
builder.append(", activeThreadCount=");
builder.append(activeThreadCount);
builder.append(", terminatedThreadCount=");
builder.append(terminatedThreadCount);
builder.append(", flowFilesTransferred=");
builder.append(flowFilesTransferred);
builder.append(", bytesTransferred=");
builder.append(bytesTransferred);
builder.append(", flowFilesReceived=");
builder.append(flowFilesReceived);
builder.append(", bytesReceived=");
builder.append(bytesReceived);
builder.append(", flowFilesSent=");
builder.append(flowFilesSent);
builder.append(", bytesSent=");
builder.append(bytesSent);
builder.append(",\n\tconnectionStatus=");
for (final ConnectionStatus status : connectionStatus) {
builder.append("\n\t\t");
builder.append(status);
}
builder.append(",\n\tprocessorStatus=");
for (final ProcessorStatus status : processorStatus) {
builder.append("\n\t\t");
builder.append(status);
}
builder.append(",\n\tprocessGroupStatus=");
for (final ProcessGroupStatus status : processGroupStatus) {
builder.append("\n\t\t");
builder.append(status);
}
builder.append(",\n\tremoteProcessGroupStatus=");
for (final RemoteProcessGroupStatus status : remoteProcessGroupStatus) {
builder.append("\n\t\t");
builder.append(status);
}
builder.append(",\n\tinputPortStatus=");
for (final PortStatus status : inputPortStatus) {
builder.append("\n\t\t");
builder.append(status);
}
builder.append(",\n\toutputPortStatus=");
for (final PortStatus status : outputPortStatus) {
builder.append("\n\t\t");
builder.append(status);
}
builder.append("]");
return builder.toString();
}
public static void merge(final ProcessGroupStatus target, final ProcessGroupStatus toMerge) {
if (target == null || toMerge == null) {
return;
}
target.setInputCount(target.getInputCount() + toMerge.getInputCount());
target.setInputContentSize(target.getInputContentSize() + toMerge.getInputContentSize());
target.setOutputCount(target.getOutputCount() + toMerge.getOutputCount());
target.setOutputContentSize(target.getOutputContentSize() + toMerge.getOutputContentSize());
target.setQueuedCount(target.getQueuedCount() + toMerge.getQueuedCount());
target.setQueuedContentSize(target.getQueuedContentSize() + toMerge.getQueuedContentSize());
target.setBytesRead(target.getBytesRead() + toMerge.getBytesRead());
target.setBytesWritten(target.getBytesWritten() + toMerge.getBytesWritten());
target.setActiveThreadCount(target.getActiveThreadCount() + toMerge.getActiveThreadCount());
target.setTerminatedThreadCount(target.getTerminatedThreadCount() + toMerge.getTerminatedThreadCount());
target.setFlowFilesTransferred(target.getFlowFilesTransferred() + toMerge.getFlowFilesTransferred());
target.setBytesTransferred(target.getBytesTransferred() + toMerge.getBytesTransferred());
target.setFlowFilesReceived(target.getFlowFilesReceived() + toMerge.getFlowFilesReceived());
target.setBytesReceived(target.getBytesReceived() + toMerge.getBytesReceived());
target.setFlowFilesSent(target.getFlowFilesSent() + toMerge.getFlowFilesSent());
target.setBytesSent(target.getBytesSent() + toMerge.getBytesSent());
// if the versioned flow state to merge is sync failure allow it to take precedence.
if (VersionedFlowState.SYNC_FAILURE.equals(toMerge.getVersionedFlowState())) {
target.setVersionedFlowState(VersionedFlowState.SYNC_FAILURE);
}
// connection status
// sort by id
final Map<String, ConnectionStatus> mergedConnectionMap = new HashMap<>();
for (final ConnectionStatus status : target.getConnectionStatus()) {
mergedConnectionMap.put(status.getId(), status);
}
for (final ConnectionStatus statusToMerge : toMerge.getConnectionStatus()) {
ConnectionStatus merged = mergedConnectionMap.get(statusToMerge.getId());
if (merged == null) {
mergedConnectionMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merged.setQueuedCount(merged.getQueuedCount() + statusToMerge.getQueuedCount());
merged.setQueuedBytes(merged.getQueuedBytes() + statusToMerge.getQueuedBytes());
merged.setInputCount(merged.getInputCount() + statusToMerge.getInputCount());
merged.setInputBytes(merged.getInputBytes() + statusToMerge.getInputBytes());
merged.setOutputCount(merged.getOutputCount() + statusToMerge.getOutputCount());
merged.setOutputBytes(merged.getOutputBytes() + statusToMerge.getOutputBytes());
}
target.setConnectionStatus(mergedConnectionMap.values());
// processor status
final Map<String, ProcessorStatus> mergedProcessorMap = new HashMap<>();
for (final ProcessorStatus status : target.getProcessorStatus()) {
mergedProcessorMap.put(status.getId(), status);
}
for (final ProcessorStatus statusToMerge : toMerge.getProcessorStatus()) {
ProcessorStatus merged = mergedProcessorMap.get(statusToMerge.getId());
if (merged == null) {
mergedProcessorMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merged.setActiveThreadCount(merged.getActiveThreadCount() + statusToMerge.getActiveThreadCount());
merged.setTerminatedThreadCount(merged.getTerminatedThreadCount() + statusToMerge.getTerminatedThreadCount());
merged.setBytesRead(merged.getBytesRead() + statusToMerge.getBytesRead());
merged.setBytesWritten(merged.getBytesWritten() + statusToMerge.getBytesWritten());
merged.setInputBytes(merged.getInputBytes() + statusToMerge.getInputBytes());
merged.setInputCount(merged.getInputCount() + statusToMerge.getInputCount());
merged.setInvocations(merged.getInvocations() + statusToMerge.getInvocations());
merged.setOutputBytes(merged.getOutputBytes() + statusToMerge.getOutputBytes());
merged.setOutputCount(merged.getOutputCount() + statusToMerge.getOutputCount());
merged.setProcessingNanos(merged.getProcessingNanos() + statusToMerge.getProcessingNanos());
merged.setFlowFilesRemoved(merged.getFlowFilesRemoved() + statusToMerge.getFlowFilesRemoved());
// if the status to merge is invalid allow it to take precedence. whether the
// processor run status is disabled/stopped/running is part of the flow configuration
// and should not differ amongst nodes. however, whether a processor is invalid
// can be driven by environmental conditions. this check allows any of those to
// take precedence over the configured run status.
if (RunStatus.Validating.equals(statusToMerge.getRunStatus())) {
merged.setRunStatus(RunStatus.Validating);
} else if (RunStatus.Invalid.equals(statusToMerge.getRunStatus())) {
merged.setRunStatus(RunStatus.Invalid);
}
}
target.setProcessorStatus(mergedProcessorMap.values());
// input ports
final Map<String, PortStatus> mergedInputPortMap = new HashMap<>();
for (final PortStatus status : target.getInputPortStatus()) {
mergedInputPortMap.put(status.getId(), status);
}
for (final PortStatus statusToMerge : toMerge.getInputPortStatus()) {
PortStatus merged = mergedInputPortMap.get(statusToMerge.getId());
if (merged == null) {
mergedInputPortMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merged.setInputBytes(merged.getInputBytes() + statusToMerge.getInputBytes());
merged.setInputCount(merged.getInputCount() + statusToMerge.getInputCount());
merged.setOutputBytes(merged.getOutputBytes() + statusToMerge.getOutputBytes());
merged.setOutputCount(merged.getOutputCount() + statusToMerge.getOutputCount());
merged.setActiveThreadCount(merged.getActiveThreadCount() + statusToMerge.getActiveThreadCount());
if (statusToMerge.isTransmitting() != null && statusToMerge.isTransmitting()) {
merged.setTransmitting(true);
}
// should be unnecessary here since ports run status should not be affected by
// environmental conditions but doing so in case that changes
if (RunStatus.Invalid.equals(statusToMerge.getRunStatus())) {
merged.setRunStatus(RunStatus.Invalid);
}
}
target.setInputPortStatus(mergedInputPortMap.values());
// output ports
final Map<String, PortStatus> mergedOutputPortMap = new HashMap<>();
for (final PortStatus status : target.getOutputPortStatus()) {
mergedOutputPortMap.put(status.getId(), status);
}
for (final PortStatus statusToMerge : toMerge.getOutputPortStatus()) {
PortStatus merged = mergedOutputPortMap.get(statusToMerge.getId());
if (merged == null) {
mergedOutputPortMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merged.setInputBytes(merged.getInputBytes() + statusToMerge.getInputBytes());
merged.setInputCount(merged.getInputCount() + statusToMerge.getInputCount());
merged.setOutputBytes(merged.getOutputBytes() + statusToMerge.getOutputBytes());
merged.setOutputCount(merged.getOutputCount() + statusToMerge.getOutputCount());
merged.setActiveThreadCount(merged.getActiveThreadCount() + statusToMerge.getActiveThreadCount());
if (statusToMerge.isTransmitting() != null && statusToMerge.isTransmitting()) {
merged.setTransmitting(true);
}
// should be unnecessary here since ports run status not should be affected by
// environmental conditions but doing so in case that changes
if (RunStatus.Invalid.equals(statusToMerge.getRunStatus())) {
merged.setRunStatus(RunStatus.Invalid);
}
}
target.setOutputPortStatus(mergedOutputPortMap.values());
// child groups
final Map<String, ProcessGroupStatus> mergedGroupMap = new HashMap<>();
for (final ProcessGroupStatus status : target.getProcessGroupStatus()) {
mergedGroupMap.put(status.getId(), status);
}
for (final ProcessGroupStatus statusToMerge : toMerge.getProcessGroupStatus()) {
ProcessGroupStatus merged = mergedGroupMap.get(statusToMerge.getId());
if (merged == null) {
mergedGroupMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
merge(merged, statusToMerge);
}
target.setOutputPortStatus(mergedOutputPortMap.values());
// remote groups
final Map<String, RemoteProcessGroupStatus> mergedRemoteGroupMap = new HashMap<>();
for (final RemoteProcessGroupStatus status : target.getRemoteProcessGroupStatus()) {
mergedRemoteGroupMap.put(status.getId(), status);
}
for (final RemoteProcessGroupStatus statusToMerge : toMerge.getRemoteProcessGroupStatus()) {
RemoteProcessGroupStatus merged = mergedRemoteGroupMap.get(statusToMerge.getId());
if (merged == null) {
mergedRemoteGroupMap.put(statusToMerge.getId(), statusToMerge.clone());
continue;
}
// NOTE - active/inactive port counts are not merged since that state is considered part of the flow (like runStatus)
merged.setReceivedContentSize(merged.getReceivedContentSize() + statusToMerge.getReceivedContentSize());
merged.setReceivedCount(merged.getReceivedCount() + statusToMerge.getReceivedCount());
merged.setSentContentSize(merged.getSentContentSize() + statusToMerge.getSentContentSize());
merged.setSentCount(merged.getSentCount() + statusToMerge.getSentCount());
merged.setActiveThreadCount(merged.getActiveThreadCount() + statusToMerge.getActiveThreadCount());
}
target.setRemoteProcessGroupStatus(mergedRemoteGroupMap.values());
}
}