-
Notifications
You must be signed in to change notification settings - Fork 188
/
TaskPerformanceInformation.java
122 lines (101 loc) · 4.18 KB
/
TaskPerformanceInformation.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
/*
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.schema.util.task;
import static java.util.Objects.requireNonNull;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.NotNull;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
/**
* Quickly hacked "API" presenting task performance information.
*
* Use with care. Will change in next midPoint release.
*
* TODO deduplicate with {@link TaskProgressInformation}.
*/
@Experimental
public class TaskPerformanceInformation implements DebugDumpable, Serializable {
private static final Trace LOGGER = TraceManager.getTrace(TaskPerformanceInformation.class);
/**
* Information on the progress in individual parts. Indexed by part URI.
*/
private final Map<String, TaskPartPerformanceInformation> parts = new HashMap<>();
private TaskPerformanceInformation() {
}
/**
* Precondition: the task contains fully retrieved and resolved subtasks.
*/
public static TaskPerformanceInformation fromTaskTree(TaskType task) {
if (TaskWorkStateUtil.isPartitionedMaster(task)) {
return fromPartitionedMaster(task);
} else {
return fromOtherTask(task);
}
}
@NotNull
private static TaskPerformanceInformation fromPartitionedMaster(TaskType task) {
Map<String, TaskPartPerformanceInformation> partsByUri = new HashMap<>();
List<ObjectReferenceType> subtasks = task.getSubtaskRef();
for (ObjectReferenceType subtaskRef : subtasks) {
TaskType subtask = (TaskType)
requireNonNull(subtaskRef.asReferenceValue().getObject(),
() -> "Task " + task + " has unresolved subtask: " + subtaskRef)
.asObjectable();
TaskPerformanceInformation subInfo = fromOtherTask(subtask);
if (subInfo.parts.size() > 1) {
LOGGER.warn("Partitioned task has more than one part - ignoring: {}\n{}", subtask, subInfo.parts);
} else {
partsByUri.putAll(subInfo.parts);
}
}
TaskPerformanceInformation info = new TaskPerformanceInformation();
info.parts.putAll(partsByUri);
return info;
}
/**
* Not a partitioned master.
*/
@NotNull
private static TaskPerformanceInformation fromOtherTask(@NotNull TaskType task) {
TaskPerformanceInformation info = new TaskPerformanceInformation();
StructuredTaskProgressType progress = TaskProgressUtil.getStructuredProgressFromTree(task);
OperationStatsType operationStats = TaskOperationStatsUtil.getOperationStatsFromTree(task, PrismContext.get());
if (operationStats != null && operationStats.getIterativeTaskInformation() != null) {
for (IterativeTaskPartItemsProcessingInformationType part : operationStats.getIterativeTaskInformation().getPart()) {
info.addPart(TaskPartPerformanceInformation.forPart(part, progress));
}
}
return info;
}
private void addPart(TaskPartPerformanceInformation part) {
parts.put(part.getPartIdentifier(), part);
}
public Map<String, TaskPartPerformanceInformation> getParts() {
return parts;
}
@Override
public String toString() {
return "TaskPerformanceInformation{" +
"parts=" + parts +
'}';
}
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.debugDumpLabelLn(sb, getClass().getSimpleName(), indent);
DebugUtil.debugDumpWithLabel(sb, "Parts", parts, indent + 1);
return sb.toString();
}
}