diff --git a/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptor.java b/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptor.java index 4ebcca08064..af26c104793 100644 --- a/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptor.java +++ b/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptor.java @@ -81,8 +81,19 @@ default Set> getResourceCapabilityReferen * Returns a transformer to be applied to all operations that operate on an existing resource. * This is typically used to adapt legacy operations to conform to the current version of the model. * @return an operation handler transformer. + * @deprecated Superseded by {@link #getOperationTransformation(String)}. */ + @Deprecated(forRemoval = true, since = "26.0.0") default UnaryOperator getResourceOperationTransformation() { + return this.getOperationTransformation(""); // Returns default operation transformer + } + + /** + * Returns a transformer to be applied the specified operation. + * This is typically used to adapt legacy operations to conform to the current version of the model. + * @return an operation handler transformer. + */ + default UnaryOperator getOperationTransformation(String operationName) { return UnaryOperator.identity(); } @@ -114,9 +125,11 @@ default Set> getCapabilities() { * Returns a transformer for the add operation handler. * This is typically used to adapt legacy operations to conform to the current version of the model. * @return an operation handler transformer. + * @deprecated Superseded by {@link #getOperationTransformation(String)} */ + @Deprecated(forRemoval = true, since = "26.0.0") default UnaryOperator getAddOperationTransformation() { - return UnaryOperator.identity(); + return this.getOperationTransformation(ModelDescriptionConstants.ADD); } /** @@ -150,8 +163,8 @@ class DefaultResourceDescriptor implements ResourceDescriptor { private final Set requiredSingletonChildren; private final Map attributeTranslations; private final Set> resourceCapabilityReferences; - private final UnaryOperator addOperationTransformer; - private final UnaryOperator operationTransformer; + private final Map> operationTransformers; + private final UnaryOperator defaultOperationTransformer; private final UnaryOperator resourceTransformer; private final Optional> deploymentChainContributor; private final OperationEntry.Flag addOperationRestartFlag; @@ -187,8 +200,8 @@ public BiPredicate getCapabilityFilter(RuntimeCapabi this.requiredChildren = builder.requiredChildren; this.requiredSingletonChildren = builder.requiredSingletonChildren; this.resourceCapabilityReferences = builder.resourceCapabilityReferences; - this.addOperationTransformer = builder.addOperationTransformer; - this.operationTransformer = builder.operationTransformer; + this.operationTransformers = builder.operationTransformers; + this.defaultOperationTransformer = builder.defaultOperationTransformer; this.resourceTransformer = builder.resourceTransformer; this.deploymentChainContributor = builder.deploymentChainContributor; this.addOperationRestartFlag = builder.addOperationRestartFlag; @@ -221,8 +234,8 @@ public Set> getResourceCapabilityReferenc } @Override - public UnaryOperator getResourceOperationTransformation() { - return this.operationTransformer; + public UnaryOperator getOperationTransformation(String operationName) { + return this.operationTransformers.getOrDefault(operationName, this.defaultOperationTransformer); } @Override @@ -250,11 +263,6 @@ public Set getRequiredSingletonChildren() { return this.requiredSingletonChildren; } - @Override - public UnaryOperator getAddOperationTransformation() { - return this.addOperationTransformer; - } - @Override public UnaryOperator getResourceTransformation() { return this.resourceTransformer; @@ -435,16 +443,36 @@ default C addResourceCapabilityReference(ResourceCapabilityReferenceRecorder * Applies the specified transformation to the {@value ModelDescriptionConstants#ADD} operation of this resource. * @param transformation an operation handler transformation * @return a reference to this configurator + * @deprecated Superseded by {@link #withOperationTransformation(String, UnaryOperator)}. */ - C withAddResourceOperationTransformation(UnaryOperator transformation); + @Deprecated(forRemoval = true, since = "26.0.0") + default C withAddResourceOperationTransformation(UnaryOperator transformation) { + return this.withOperationTransformation(ModelDescriptionConstants.ADD, transformation); + } /** - * Applies the specified transformation to the {@value ModelDescriptionConstants#REMOVE} and all global operations of this resource. + * Applies the specified transformation to all operations for this resource. * @param transformation an operation handler transformation * @return a reference to this configurator */ C withOperationTransformation(UnaryOperator transformation); + /** + * Applies the specified transformation to the specified operation for this resource. + * @param transformation an operation handler transformation + * @return a reference to this configurator + */ + default C withOperationTransformation(String operationName, UnaryOperator transformation) { + return this.withOperationTransformation(Set.of(operationName), transformation); + } + + /** + * Applies the specified transformation to the specified operations for this resource. + * @param transformation an operation handler transformation + * @return a reference to this configurator + */ + C withOperationTransformation(Set operationNames, UnaryOperator transformation); + /** * Applies the specified transformation to the {@link Resource} created by this resource's {@value ModelDescriptionConstants#ADD} operation. * @param transformation an operation handler transformation @@ -545,8 +573,8 @@ abstract static class AbstractConfigurator> implements private Set requiredSingletonChildren = Set.of(); private Map attributeTranslations = Map.of(); private Set> resourceCapabilityReferences = Set.of(); - private UnaryOperator addOperationTransformer = UnaryOperator.identity(); - private UnaryOperator operationTransformer = UnaryOperator.identity(); + private Map> operationTransformers = Map.of(); + private UnaryOperator defaultOperationTransformer = UnaryOperator.identity(); private UnaryOperator resourceTransformer = UnaryOperator.identity(); private Optional> deploymentChainContributor = Optional.empty(); @@ -645,14 +673,14 @@ public C addResourceCapabilityReferences(Collection transformation) { - this.addOperationTransformer = transformation; + public C withOperationTransformation(UnaryOperator transformation) { + this.defaultOperationTransformer = transformation; return this.self(); } @Override - public C withOperationTransformation(UnaryOperator transformation) { - this.operationTransformer = transformation; + public C withOperationTransformation(Set operationNames, UnaryOperator transformation) { + this.operationTransformers = concat(this.operationTransformers, operationNames.stream(), transformation); return this.self(); } diff --git a/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptorRegistrar.java b/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptorRegistrar.java index f28cc6f037c..9e269463aed 100644 --- a/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptorRegistrar.java +++ b/subsystem/src/main/java/org/wildfly/subsystem/resource/ResourceDescriptorRegistrar.java @@ -19,18 +19,7 @@ import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.global.ListOperations; import org.jboss.as.controller.operations.global.MapOperations; -import org.jboss.as.controller.operations.global.QueryOperationHandler; -import org.jboss.as.controller.operations.global.ReadAttributeGroupHandler; -import org.jboss.as.controller.operations.global.ReadAttributeGroupNamesHandler; -import org.jboss.as.controller.operations.global.ReadAttributeHandler; -import org.jboss.as.controller.operations.global.ReadChildrenNamesHandler; -import org.jboss.as.controller.operations.global.ReadChildrenResourcesHandler; -import org.jboss.as.controller.operations.global.ReadChildrenTypesHandler; -import org.jboss.as.controller.operations.global.ReadOperationNamesHandler; -import org.jboss.as.controller.operations.global.ReadResourceDescriptionHandler; -import org.jboss.as.controller.operations.global.ReadResourceHandler; import org.jboss.as.controller.operations.global.UndefineAttributeHandler; -import org.jboss.as.controller.operations.global.WriteAttributeHandler; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.OperationEntry; @@ -68,17 +57,6 @@ OperationEntry.Flag getRemoveOperationFlag() { } private static final Map GLOBAL_OPERATIONS = Map.ofEntries( - Map.entry(ReadAttributeHandler.RESOLVE_DEFINITION, ReadAttributeHandler.RESOLVE_INSTANCE), - Map.entry(ReadResourceHandler.RESOLVE_DEFINITION, ReadResourceHandler.RESOLVE_INSTANCE), - Map.entry(ReadAttributeGroupHandler.RESOLVE_DEFINITION, ReadAttributeGroupHandler.RESOLVE_INSTANCE), - Map.entry(ReadResourceDescriptionHandler.DEFINITION, ReadResourceDescriptionHandler.INSTANCE), - Map.entry(ReadAttributeGroupNamesHandler.DEFINITION, ReadAttributeGroupNamesHandler.INSTANCE), - Map.entry(ReadChildrenNamesHandler.DEFINITION, ReadChildrenNamesHandler.INSTANCE), - Map.entry(ReadChildrenTypesHandler.DEFINITION, ReadChildrenTypesHandler.INSTANCE), - Map.entry(ReadChildrenResourcesHandler.DEFINITION, ReadChildrenResourcesHandler.INSTANCE), - Map.entry(ReadOperationNamesHandler.DEFINITION, ReadOperationNamesHandler.INSTANCE), - Map.entry(QueryOperationHandler.DEFINITION, QueryOperationHandler.INSTANCE), - Map.entry(WriteAttributeHandler.DEFINITION, WriteAttributeHandler.INSTANCE), Map.entry(UndefineAttributeHandler.DEFINITION, UndefineAttributeHandler.INSTANCE), Map.entry(MapOperations.MAP_PUT_DEFINITION, MapOperations.MAP_PUT_HANDLER), Map.entry(MapOperations.MAP_GET_DEFINITION, MapOperations.MAP_GET_HANDLER), @@ -121,39 +99,42 @@ public void register(ManagementResourceRegistration registration) { } } - // Register add resource operation handler - boolean ordered = registration.isOrderedChildResource(); - Stream attributes = registration.getAttributes(PathAddress.EMPTY_ADDRESS).values().stream() - .filter(AttributeAccess.Storage.CONFIGURATION) // Ignore runtime attributes - .map(AttributeAccess::getAttributeDefinition) - .filter(Predicate.not(AttributeDefinition::isResourceOnly)) // Ignore resource-only attributes - ; - if (ordered) { - attributes = Stream.concat(Stream.of(DefaultResourceAddDescriptionProvider.INDEX), attributes); + if (!registration.isRuntimeOnly()) { + // Register add resource operation handler + boolean ordered = registration.isOrderedChildResource(); + Stream attributes = registration.getAttributes(PathAddress.EMPTY_ADDRESS).values().stream() + .filter(AttributeAccess.Storage.CONFIGURATION) // Ignore runtime attributes + .map(AttributeAccess::getAttributeDefinition) + .filter(Predicate.not(AttributeDefinition::isResourceOnly)) // Ignore resource-only attributes + ; + if (ordered) { + attributes = Stream.concat(Stream.of(DefaultResourceAddDescriptionProvider.INDEX), attributes); + } + OperationDefinition addDefinition = new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.ADD, this.descriptor.getResourceDescriptionResolver()) + .setParameters(attributes.toArray(AttributeDefinition[]::new)) + .setDescriptionProvider(new DefaultResourceAddDescriptionProvider(registration, this.descriptor.getResourceDescriptionResolver(), ordered)) + .setStability(registration.getStability()) + .withFlag(this.descriptor.getAddOperationRestartFlag()) + .build(); + registration.registerOperationHandler(addDefinition, this.descriptor.getOperationTransformation(ModelDescriptionConstants.ADD).apply(new AddResourceOperationStepHandler(this.descriptor))); + + // Register remove resource operation handler + OperationDefinition removeDefinition = new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.REMOVE, this.descriptor.getResourceDescriptionResolver()) + .setDescriptionProvider(new DefaultResourceRemoveDescriptionProvider(this.descriptor.getResourceDescriptionResolver())) + .setStability(registration.getStability()) + .withFlag(this.descriptor.getRemoveOperationRestartFlag()) + .build(); + registration.registerOperationHandler(removeDefinition, this.descriptor.getOperationTransformation(ModelDescriptionConstants.REMOVE).apply(new RemoveResourceOperationStepHandler(this.descriptor))); } - OperationDefinition addDefinition = new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.ADD, this.descriptor.getResourceDescriptionResolver()) - .setParameters(attributes.toArray(AttributeDefinition[]::new)) - .setDescriptionProvider(new DefaultResourceAddDescriptionProvider(registration, this.descriptor.getResourceDescriptionResolver(), ordered)) - .setStability(registration.getStability()) - .withFlag(this.descriptor.getAddOperationRestartFlag()) - .build(); - registration.registerOperationHandler(addDefinition, this.descriptor.getAddOperationTransformation().apply(new AddResourceOperationStepHandler(this.descriptor))); - - // Register remove resource operation handler - OperationDefinition removeDefinition = new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.REMOVE, this.descriptor.getResourceDescriptionResolver()) - .setDescriptionProvider(new DefaultResourceRemoveDescriptionProvider(this.descriptor.getResourceDescriptionResolver())) - .setStability(registration.getStability()) - .withFlag(this.descriptor.getRemoveOperationRestartFlag()) - .build(); - registration.registerOperationHandler(removeDefinition, this.descriptor.getResourceOperationTransformation().apply(new RemoveResourceOperationStepHandler(this.descriptor))); // Override global operations with transformed operations, if necessary for (Map.Entry entry : GLOBAL_OPERATIONS.entrySet()) { + OperationDefinition definition = entry.getKey(); OperationStepHandler handler = entry.getValue(); // Only override global operation handlers for non-identity transformations - OperationStepHandler transformedHandler = this.descriptor.getResourceOperationTransformation().apply(handler); + OperationStepHandler transformedHandler = this.descriptor.getOperationTransformation(definition.getName()).apply(handler); if (handler != transformedHandler) { - registration.registerOperationHandler(entry.getKey(), transformedHandler); + registration.registerOperationHandler(definition, transformedHandler); } } }