/** * @return contextual discard policy if any resource attributes are undefined and has no children; {@link DiscardPolicy#SILENT} otherwise. */ @Override public DiscardPolicy checkResource(TransformationContext context, PathAddress address) { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); ImmutableManagementResourceRegistration registration = context.getResourceRegistration(PathAddress.EMPTY_ADDRESS); ModelNode model = resource.getModel(); if (model.isDefined()) { for (String attribute : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { if (model.hasDefined(attribute)) { return this.policy; } } } for (PathElement path : registration.getChildAddresses(PathAddress.EMPTY_ADDRESS)) { if (path.isWildcard() ? resource.hasChildren(path.getKey()) : resource.hasChild(path)) { return this.policy; } } return DiscardPolicy.SILENT; } }
@Override public ImmutableManagementResourceRegistration getResourceRegistration(PathAddress address) { return delegate.getResourceRegistration(address); }
@Override public ImmutableManagementResourceRegistration getResourceRegistration(PathAddress address) { return delegate.getResourceRegistration(address); }
@Override public ImmutableManagementResourceRegistration getResourceRegistration(PathAddress address) { return delegate.getResourceRegistration(address); }
@Override public ImmutableManagementResourceRegistration getResourceRegistration(PathAddress address) { return delegate.getResourceRegistration(address); }
@Override public OperationTransformer.TransformedOperation transformOperation(final TransformationContext context, final ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); //If this is an alias, get the real address before transforming ImmutableManagementResourceRegistration reg = context.getResourceRegistration(address); final PathAddress useAddress; if (reg != null && reg.isAlias()) { useAddress = reg.getAliasEntry().convertToTargetAddress(address, AliasEntry.AliasContext.create(operation, context)); } else { useAddress = address; } final String operationName = operation.require(OP).asString(); TransformationContext opCtx = ResourceTransformationContextImpl.wrapForOperation(context, operation); final OperationTransformer transformer = target.resolveTransformer(opCtx, useAddress, operationName); if (transformer == null) { ControllerLogger.ROOT_LOGGER.tracef("operation %s does not need transformation", operation); return new OperationTransformer.TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT); } // Transform the path address final PathAddress transformed = transformAddress(useAddress, target); // Update the operation using the new path address operation.get(OP_ADDR).set(transformed.toModelNode()); // TODO should this happen by default? OperationTransformer.TransformedOperation res = transformer.transformOperation(opCtx, transformed, operation); context.getLogger().flushLogQueue(); return res; }
@Override public OperationTransformer.TransformedOperation transformOperation(final TransformationContext context, final ModelNode operation) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR)); //If this is an alias, get the real address before transforming ImmutableManagementResourceRegistration reg = context.getResourceRegistration(address); final PathAddress useAddress; if (reg != null && reg.isAlias()) { useAddress = reg.getAliasEntry().convertToTargetAddress(address, AliasEntry.AliasContext.create(operation, context)); } else { useAddress = address; } final String operationName = operation.require(OP).asString(); TransformationContext opCtx = ResourceTransformationContextImpl.wrapForOperation(context, operation); final OperationTransformer transformer = target.resolveTransformer(opCtx, useAddress, operationName); if (transformer == null) { ControllerLogger.ROOT_LOGGER.tracef("operation %s does not need transformation", operation); return new OperationTransformer.TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT); } // Transform the path address final PathAddress transformed = transformAddress(useAddress, target); // Update the operation using the new path address operation.get(OP_ADDR).set(transformed.toModelNode()); // TODO should this happen by default? OperationTransformer.TransformedOperation res = transformer.transformOperation(opCtx, transformed, operation); context.getLogger().flushLogQueue(); return res; }
/** * @return contextual discard policy if any resource attributes are undefined and has no children; {@link DiscardPolicy#SILENT} otherwise. */ @Override public DiscardPolicy checkResource(TransformationContext context, PathAddress address) { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); ImmutableManagementResourceRegistration registration = context.getResourceRegistration(PathAddress.EMPTY_ADDRESS); ModelNode model = resource.getModel(); if (model.isDefined()) { for (String attribute : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { if (model.hasDefined(attribute)) { return this.policy; } } } for (PathElement path : registration.getChildAddresses(PathAddress.EMPTY_ADDRESS)) { if (path.isWildcard() ? resource.hasChildren(path.getKey()) : resource.hasChild(path)) { return this.policy; } } return DiscardPolicy.SILENT; } }