CompositeRrdParser { public RrdResult parse(CompositeResult compositeResult) throws ParserException { int index = 0; RrdResult rrdResult = new RrdResult(); for (ModelNode step : compositeResult) { if (step.isFailure()) { throw new ParserException("Failed step 'step-" + (index + 1) + "' in composite rrd result: " + step .getFailureDescription()); } ModelNode stepResult = step.get(RESULT); if (stepResult.getType() == ModelType.LIST) { for (ModelNode modelNode : stepResult.asList()) { ModelNode result = modelNode.get(RESULT); if (result.isDefined()) { ResourceAddress operationAddress = operationAddress(index); ResourceAddress resultAddress = new ResourceAddress(modelNode.get(ADDRESS)); ResourceAddress resolvedAddress = makeFqAddress(operationAddress, resultAddress); new SingleRrdParser(rrdResult).parse(resolvedAddress, result); } } } else { ResourceAddress address = operationAddress(index); new SingleRrdParser(rrdResult).parse(address, stepResult); } index++; } return rrdResult; } CompositeRrdParser(Composite composite); RrdResult parse(CompositeResult compositeResult);  }
@Test public void parseFlat() { List<Operation> operations = Arrays.stream(FLAT_TEMPLATES) .map(template -> new Operation.Builder(AddressTemplate.of(template).resolve(StatementContext.NOOP), READ_RESOURCE_DESCRIPTION_OPERATION ).build()) .collect(toList()); Composite composite = new Composite(operations); ModelNode modelNode = ExternalModelNode .read(CompositeRrdParserTest.class.getResourceAsStream("composite_rrd_flat_description_only.dmr")); RrdResult rrdResult = new CompositeRrdParser(composite).parse(new CompositeResult(modelNode)); assertResourceDescriptions(rrdResult, 6, FLAT_TEMPLATES); }
@Test public void parseRecursive() { List<Operation> operations = Arrays.stream(FLAT_TEMPLATES) .map(template -> new Operation.Builder(AddressTemplate.of(template).resolve(StatementContext.NOOP), READ_RESOURCE_DESCRIPTION_OPERATION ).param(RECURSIVE, true).build()) .collect(toList()); Composite composite = new Composite(operations); ModelNode modelNode = ExternalModelNode .read(CompositeRrdParserTest.class.getResourceAsStream("composite_rrd_recursive_description_only.dmr")); RrdResult rrdResult = new CompositeRrdParser(composite).parse(new CompositeResult(modelNode)); assertResourceDescriptions(rrdResult, 36, RECURSIVE_TEMPLATES); }