Skip to content

Commit 6dfdcb4

Browse files
committed
Simplified find statistics task
1 parent efeb382 commit 6dfdcb4

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

op/console/src/main/java/org/jboss/hal/op/task/FindStatisticsEnabledAttributes.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
package org.jboss.hal.op.task;
1717

1818
import java.util.EnumSet;
19-
import java.util.Set;
2019

2120
import org.jboss.elemento.logger.Logger;
21+
import org.jboss.hal.dmr.ModelNode;
2222
import org.jboss.hal.dmr.Operation;
2323
import org.jboss.hal.dmr.Property;
2424
import org.jboss.hal.dmr.dispatch.Dispatcher;
@@ -30,9 +30,7 @@
3030

3131
import elemental2.promise.Promise;
3232

33-
import static java.util.Collections.emptySet;
3433
import static java.util.Collections.singleton;
35-
import static java.util.stream.Collectors.toSet;
3634
import static org.jboss.hal.dmr.ModelDescriptionConstants.ATTRIBUTES_ONLY;
3735
import static org.jboss.hal.dmr.ModelDescriptionConstants.INCLUDE_RUNTIME;
3836
import static org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION;
@@ -52,31 +50,30 @@ class FindStatisticsEnabledAttributes {
5250

5351
void find(AddressTemplate root) {
5452
TraverseContinuation continuation = new TraverseContinuation();
55-
TraverseOperation<Set<String>> readAttributes = (template, context) -> {
53+
TraverseOperation<ModelNode> readAttributes = (template, context) -> {
5654
if (template.fullyQualified()) {
5755
return dispatcher.execute(new Operation.Builder(template.resolve(context), READ_RESOURCE_OPERATION)
5856
.param(ATTRIBUTES_ONLY, true)
5957
.param(INCLUDE_RUNTIME, true)
6058
.build())
61-
.then(result -> {
62-
Set<String> collect = result.asPropertyList().stream()
63-
.map(Property::getName)
64-
.collect(toSet());
65-
return Promise.resolve(collect);
66-
})
59+
.then(result -> Promise.resolve(result.asPropertyList().stream()
60+
.filter(property -> STATISTICS_ENABLED.equals(property.getName()))
61+
.map(Property::getValue)
62+
.findFirst()
63+
.orElse(new ModelNode())))
6764
.catch_(error -> {
6865
logger.error("Failed to read attributes of %s: %s", template, error);
69-
return Promise.resolve(emptySet());
66+
return Promise.resolve(new ModelNode());
7067
});
7168
} else {
72-
return Promise.resolve(emptySet());
69+
return Promise.resolve(new ModelNode());
7370
}
7471
};
7572
modelTree.traverse(continuation, root, singleton("/core-service"),
7673
EnumSet.noneOf(TraverseType.class), readAttributes,
77-
(template, attributes, context) -> {
78-
if (template.fullyQualified() && attributes.contains(STATISTICS_ENABLED)) {
79-
logger.info("Found statistics enabled attribute for %s", template);
74+
(template, statisticsEnabled, context) -> {
75+
if (template.fullyQualified() && statisticsEnabled.isDefined()) {
76+
logger.info("Found statistics enabled attribute for %s: %s", template, statisticsEnabled.asString());
8077
}
8178
})
8279
.then(context -> {

0 commit comments

Comments
 (0)