// in reverse order of how they should execute, as that is the way adding a Stage.IMMEDIATE step works
// Last to execute is the handler that assembles the overall response from the pieces created by all the other steps
final ReadResourceAssemblyHandler assemblyHandler = new ReadResourceAssemblyHandler(directAttributes, metrics, otherAttributes, directChildren, childResources);
context.addStep(assemblyHandler, queryRuntime ? OperationContext.Stage.VERIFY : OperationContext.Stage.IMMEDIATE);
final ImmutableManagementResourceRegistration registry = context.getResourceRegistration();
final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
// Get the model for this resource.
final ModelNode model = resource.getModel();
final Map<String, Set<String>> childrenByType = registry != null ? getChildAddresses(registry, resource, null): Collections.<String, Set<String>>emptyMap();
if(model.isDefined()) {
// Store direct attributes first
for (String key : model.keys()) {
// In case someone put some garbage in it
if(! childrenByType.containsKey(key)) {
directAttributes.put(key, model.get(key));
}
}
}
// Next, process child resources
for (Map.Entry<String, Set<String>> entry : childrenByType.entrySet()) {
String childType = entry.getKey();
Set<String> children = entry.getValue();
if (children.isEmpty()) {
// Just treat it like an undefined attribute
directAttributes.put(childType, new ModelNode());
} else {
for (String child : children) {
boolean storeDirect = !recursive;
if (recursive) {
PathElement childPE = PathElement.pathElement(childType, child);
PathAddress relativeAddr = PathAddress.pathAddress(childPE);
ImmutableManagementResourceRegistration childReg = registry.getSubModel(relativeAddr);
if(childReg == null) {
throw new OperationFailedException(new ModelNode().set(String.format("no child registry for (%s, %s)", childType, child)));
}
// We only invoke runtime resources if they are remote proxies
if (childReg.isRuntimeOnly() && (!proxies || !childReg.isRemote())) {
storeDirect = true;
} else {
// Add a step to read the child resource
ModelNode rrOp = new ModelNode();
rrOp.get(OP).set(opName);
rrOp.get(OP_ADDR).set(PathAddress.pathAddress(address, childPE).toModelNode());
rrOp.get(RECURSIVE).set(true);
rrOp.get(PROXIES).set(proxies);
rrOp.get(INCLUDE_RUNTIME).set(queryRuntime);
ModelNode rrRsp = new ModelNode();
childResources.put(childPE, rrRsp);
OperationStepHandler rrHandler = childReg.getOperationHandler(relativeAddr, opName);
context.addStep(rrRsp, rrOp, rrHandler, OperationContext.Stage.IMMEDIATE);
}
}
if (storeDirect) {
ModelNode childMap = directChildren.get(childType);