diff --git a/controller/src/main/java/org/jboss/as/controller/extension/ExtensionRegistry.java b/controller/src/main/java/org/jboss/as/controller/extension/ExtensionRegistry.java index 9c01eaa60d5..9d8288d4622 100644 --- a/controller/src/main/java/org/jboss/as/controller/extension/ExtensionRegistry.java +++ b/controller/src/main/java/org/jboss/as/controller/extension/ExtensionRegistry.java @@ -752,7 +752,7 @@ public SubsystemRegistration registerSubsystem(String name, ModelVersion version SubsystemRegistrationImpl result = new SubsystemRegistrationImpl(name, version, this.stability, profileRegistration, deploymentsRegistration, extensionRegistryType, extension.extensionModuleName, processType); if (registerTransformers){ - transformerRegistry.loadAndRegisterTransformers(name, version, extension.extensionModuleName); + transformerRegistry.loadAndRegisterTransformers(name, version, this.getStability(), extension.extensionModuleName); } return result; } diff --git a/controller/src/main/java/org/jboss/as/controller/transform/SubsystemTransformerRegistration.java b/controller/src/main/java/org/jboss/as/controller/transform/SubsystemTransformerRegistration.java index 3b399d172d0..f981814d739 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/SubsystemTransformerRegistration.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/SubsystemTransformerRegistration.java @@ -7,6 +7,8 @@ import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.ModelVersionRange; +import org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilderFactory; +import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilderFactory; /** * Subsystem transformers registration API @@ -15,7 +17,7 @@ * * @author Tomaz Cerar (c) 2016 Red Hat Inc. */ -public interface SubsystemTransformerRegistration { +public interface SubsystemTransformerRegistration extends ResourceTransformationDescriptionBuilderFactory, ChainedTransformationDescriptionBuilderFactory { /** * Register transformers for a specific model versions. @@ -52,5 +54,4 @@ public interface SubsystemTransformerRegistration { * @return the version */ ModelVersion getCurrentSubsystemVersion(); - } diff --git a/controller/src/main/java/org/jboss/as/controller/transform/TransformerRegistry.java b/controller/src/main/java/org/jboss/as/controller/transform/TransformerRegistry.java index f20bee6298a..106823da6cd 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/TransformerRegistry.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/TransformerRegistry.java @@ -22,6 +22,7 @@ import org.jboss.as.controller.logging.ControllerLogger; import org.jboss.as.controller.registry.GlobalTransformerRegistry; import org.jboss.as.controller.registry.OperationTransformerRegistry; +import org.jboss.as.version.Stability; import org.jboss.dmr.ModelNode; import org.jboss.dmr.Property; import org.jboss.modules.Module; @@ -57,9 +58,14 @@ public final class TransformerRegistry { domain.createChildRegistry(PathAddress.pathAddress(HOST, SERVER), ModelVersion.create(0), ResourceTransformer.DEFAULT, false); } + @Deprecated(forRemoval = true, since = "27.0.0") public void loadAndRegisterTransformers(String name, ModelVersion subsystemVersion, String extensionModuleName) { + this.loadAndRegisterTransformers(name, subsystemVersion, Stability.DEFAULT, extensionModuleName); + } + + public void loadAndRegisterTransformers(String name, ModelVersion subsystemVersion, Stability stability, String extensionModuleName) { try { - SubsystemTransformerRegistration transformerRegistration = new SubsystemTransformerRegistrationImpl(name, subsystemVersion); + SubsystemTransformerRegistration transformerRegistration = this.createSubsystemTransformerRegistration(name, subsystemVersion, stability); if (Module.getCallerModule() != null) { //only register when running in modular environment, testsuite does its own loading for (ExtensionTransformerRegistration registration : Module.loadServiceFromCallerModuleLoader(ModuleIdentifier.fromString(extensionModuleName), ExtensionTransformerRegistration.class)) { if (registration.getSubsystemName().equals(name)) { //to prevent registering transformers for different subsystems @@ -72,18 +78,24 @@ public void loadAndRegisterTransformers(String name, ModelVersion subsystemVersi } } - public SubsystemTransformerRegistration createSubsystemTransformerRegistration(String name, ModelVersion currentVersion){ - return new SubsystemTransformerRegistrationImpl(name, currentVersion); + @Deprecated(forRemoval = true, since = "27.0.0") + public SubsystemTransformerRegistration createSubsystemTransformerRegistration(String name, ModelVersion currentVersion) { + return this.createSubsystemTransformerRegistration(name, currentVersion, Stability.DEFAULT); + } + + public SubsystemTransformerRegistration createSubsystemTransformerRegistration(String name, ModelVersion currentVersion, Stability stability) { + return new SubsystemTransformerRegistrationImpl(name, currentVersion, stability); } - private class SubsystemTransformerRegistrationImpl implements SubsystemTransformerRegistration{ + private class SubsystemTransformerRegistrationImpl implements SubsystemTransformerRegistration { private final String name; private final ModelVersion currentVersion; + private final Stability stability; - - public SubsystemTransformerRegistrationImpl(String name, ModelVersion currentVersion) { + SubsystemTransformerRegistrationImpl(String name, ModelVersion currentVersion, Stability stability) { this.name = name; this.currentVersion = currentVersion; + this.stability = stability; } @Override @@ -105,6 +117,11 @@ public TransformersSubRegistration registerModelTransformers(ModelVersionRange v public ModelVersion getCurrentSubsystemVersion() { return currentVersion; } + + @Override + public Stability getStability() { + return this.stability; + } } /** diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/AbstractTransformationDescriptionBuilder.java b/controller/src/main/java/org/jboss/as/controller/transform/description/AbstractTransformationDescriptionBuilder.java index 4e29607402d..f84a9497a4a 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/AbstractTransformationDescriptionBuilder.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/AbstractTransformationDescriptionBuilder.java @@ -18,12 +18,14 @@ import org.jboss.as.controller.transform.OperationTransformer; import org.jboss.as.controller.transform.PathAddressTransformer; import org.jboss.as.controller.transform.ResourceTransformer; +import org.jboss.as.version.Stability; /** * @author Emanuel Muckenhuber */ abstract class AbstractTransformationDescriptionBuilder implements TransformationDescriptionBuilder { + private final Stability stability; protected final PathElement pathElement; protected PathAddressTransformer pathAddressTransformer; @@ -34,10 +36,11 @@ abstract class AbstractTransformationDescriptionBuilder implements Transformatio protected final List children = new ArrayList(); protected final DynamicDiscardPolicy dynamicDiscardPolicy; - protected AbstractTransformationDescriptionBuilder(PathElement pathElement, PathAddressTransformer pathAddressTransformer, + protected AbstractTransformationDescriptionBuilder(Stability stability, PathElement pathElement, PathAddressTransformer pathAddressTransformer, ResourceTransformer resourceTransformer, OperationTransformer operationTransformer, DynamicDiscardPolicy dynamicDiscardPolicy) { + this.stability = stability; this.pathElement = pathElement; this.pathAddressTransformer = pathAddressTransformer; this.resourceTransformer = resourceTransformer; @@ -45,6 +48,11 @@ protected AbstractTransformationDescriptionBuilder(PathElement pathElement, Path this.dynamicDiscardPolicy = dynamicDiscardPolicy; } + @Override + public Stability getStability() { + return this.stability; + } + public TransformationDescriptionBuilder setResourceTransformer(ResourceTransformer resourceTransformer) { this.resourceTransformer = resourceTransformer; return this; diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/AttributeTransformationDescriptionBuilderImpl.java b/controller/src/main/java/org/jboss/as/controller/transform/description/AttributeTransformationDescriptionBuilderImpl.java index 5fa8623b21d..4e9edab0545 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/AttributeTransformationDescriptionBuilderImpl.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/AttributeTransformationDescriptionBuilderImpl.java @@ -14,6 +14,7 @@ import java.util.Set; import org.jboss.as.controller.AttributeDefinition; +import org.jboss.as.version.Stability; /** * @author Kabir Khan @@ -29,59 +30,55 @@ abstract class AttributeTransformationDescriptionBuilderImpl discardedAttributes) { - for (AttributeDefinition attribute : discardedAttributes) { - String attrName = getAttributeName(attribute); - registry.setDiscardedAttribute(discardChecker, attrName); + for (AttributeDefinition discardedAttribute : discardedAttributes) { + if (this.enables(discardedAttribute)) { + this.registry.setDiscardedAttribute(discardChecker, discardedAttribute.getName()); + } } - return thisBuilder(); + return this.thisBuilder(); } @Override public T setDiscard(DiscardAttributeChecker discardChecker, String... discardedAttributes) { - String[] useDefs = discardedAttributes; - for (String attrName : useDefs) { - registry.setDiscardedAttribute(discardChecker, attrName); + for (String discardedAttribute : discardedAttributes) { + this.registry.setDiscardedAttribute(discardChecker, discardedAttribute); } return thisBuilder(); } @Override - public T addRejectCheck(final RejectAttributeChecker checker, final AttributeDefinition...rejectedAttributes){ - for (AttributeDefinition attribute : rejectedAttributes) { - String attrName = getAttributeName(attribute); - registry.addAttributeCheck(attrName, checker); + public T addRejectCheck(final RejectAttributeChecker checker, final AttributeDefinition... rejectedAttributes){ + for (AttributeDefinition rejectedAttribute : rejectedAttributes) { + if (this.enables(rejectedAttribute)) { + this.registry.addAttributeCheck(rejectedAttribute.getName(), checker); + } } - return thisBuilder(); + return this.thisBuilder(); } @Override public T addRejectCheck(RejectAttributeChecker rejectChecker, String... rejectedAttributes) { - for (String attribute : rejectedAttributes) { - registry.addAttributeCheck(attribute, rejectChecker); + for (String rejectedAttribute : rejectedAttributes) { + this.registry.addAttributeCheck(rejectedAttribute, rejectChecker); } - return thisBuilder(); + return this.thisBuilder(); } @Override public T addRejectChecks(List rejectCheckers, AttributeDefinition...rejectedAttributes) { for (RejectAttributeChecker rejectChecker : rejectCheckers) { - addRejectCheck(rejectChecker, rejectedAttributes); + this.addRejectCheck(rejectChecker, rejectedAttributes); } return thisBuilder(); } @@ -89,14 +86,16 @@ public T addRejectChecks(List rejectCheckers, AttributeD @Override public T addRejectChecks(List rejectCheckers, String... rejectedAttributes) { for (RejectAttributeChecker rejectChecker : rejectCheckers) { - addRejectCheck(rejectChecker, rejectedAttributes); + this.addRejectCheck(rejectChecker, rejectedAttributes); } return thisBuilder(); } @Override - public T addRename(AttributeDefinition attributeName, String newName) { - registry.addRenamedAttribute(getAttributeName(attributeName), newName); + public T addRename(AttributeDefinition attribute, String newName) { + if (this.enables(attribute)) { + this.addRename(attribute.getName(), newName); + } return thisBuilder(); } @@ -106,9 +105,10 @@ public T addRename(String attributeName, String newName) { return thisBuilder(); } + @Override public T addRenames(Map renames) { for (Map.Entry rename : renames.entrySet()) { - registry.addRenamedAttribute(rename.getKey(), rename.getValue()); + this.addRename(rename.getKey(), rename.getValue()); } return thisBuilder(); } @@ -116,9 +116,10 @@ public T addRenames(Map renames) { @Override public T setValueConverter(AttributeConverter attributeConverter, AttributeDefinition...convertedAttributes) { - for (AttributeDefinition attribute : convertedAttributes) { - String attrName = getAttributeName(attribute); - registry.addAttributeConverter(attrName, attributeConverter); + for (AttributeDefinition convertedAttribute : convertedAttributes) { + if (this.enables(convertedAttribute)) { + this.registry.addAttributeConverter(convertedAttribute.getName(), attributeConverter); + } } return thisBuilder(); } @@ -131,10 +132,6 @@ public T setValueConverter(AttributeConverter attributeConverter, String... conv return thisBuilder(); } - protected String getAttributeName(AttributeDefinition attr) { - return attr.getName(); - } - protected AttributeTransformationDescriptionBuilderRegistry getLocalRegistry() { return registry; } diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/BaseAttributeTransformationDescriptionBuilder.java b/controller/src/main/java/org/jboss/as/controller/transform/description/BaseAttributeTransformationDescriptionBuilder.java index c56f500d897..cb709f1cae9 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/BaseAttributeTransformationDescriptionBuilder.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/BaseAttributeTransformationDescriptionBuilder.java @@ -10,6 +10,7 @@ import java.util.Map; import org.jboss.as.controller.AttributeDefinition; +import org.jboss.as.controller.FeatureRegistry; /** @@ -34,7 +35,7 @@ * @author Emanuel Muckenhuber * @author Kabir Khan */ -public interface BaseAttributeTransformationDescriptionBuilder> { +public interface BaseAttributeTransformationDescriptionBuilder> extends FeatureRegistry { /** * Adds a RejectAttributeChecker. More than one reject checker can be used for an attribute, and the RejectAttributeCheckers @@ -106,7 +107,9 @@ public interface BaseAttributeTransformationDescriptionBuilderKabir Khan */ class ChainedTransformationDescriptionBuilderImpl implements ChainedTransformationDescriptionBuilder { + private final Stability stability; private final ModelVersion currentVersion; private final Map builders = new HashMap<>(); private final PathElement element; - ChainedTransformationDescriptionBuilderImpl(ModelVersion currentVersion, PathElement element) { + ChainedTransformationDescriptionBuilderImpl(ModelVersion currentVersion, Stability stability, PathElement element) { this.currentVersion = currentVersion; + this.stability = stability; this.element = element; } @Override public ResourceTransformationDescriptionBuilder createBuilder(ModelVersion fromVersion, ModelVersion toVersion) { - ResourceTransformationDescriptionBuilder builder = new ResourceTransformationDescriptionBuilderImpl(element); + ResourceTransformationDescriptionBuilder builder = new ResourceTransformationDescriptionBuilderImpl(this.stability, element); builders.put(new ModelVersionPair(fromVersion, toVersion), builder); return builder; } + @Override public Map build(ModelVersion...versions) { ModelVersion[] allVersions = new ModelVersion[versions.length + 1]; allVersions[0] = currentVersion; @@ -66,7 +70,7 @@ private Map doBuild(ModelVersion...vers TransformationDescriptionBuilder builder = builders.get(pair); if (builder == null) { //Insert an empty builder in the chain for version deltas which don't have one registered - builder = new ResourceTransformationDescriptionBuilderImpl(element); + builder = new ResourceTransformationDescriptionBuilderImpl(this.stability, element); } placeholderResolvers.put(pair, ChainedPlaceholderResolver.create(builder.build())); TransformationDescription desc = new ChainedTransformingDescription(element, new LinkedHashMap<>(placeholderResolvers)); diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/ConcreteAttributeTransformationDescriptionBuilder.java b/controller/src/main/java/org/jboss/as/controller/transform/description/ConcreteAttributeTransformationDescriptionBuilder.java index 00943550918..92e5828617b 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/ConcreteAttributeTransformationDescriptionBuilder.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/ConcreteAttributeTransformationDescriptionBuilder.java @@ -20,5 +20,4 @@ protected ConcreteAttributeTransformationDescriptionBuilder(ResourceTransformati protected AttributeTransformationDescriptionBuilder thisBuilder() { return this; } - } diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/DiscardTransformationDescriptionBuilder.java b/controller/src/main/java/org/jboss/as/controller/transform/description/DiscardTransformationDescriptionBuilder.java index 5f074526e83..d093b8a698e 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/DiscardTransformationDescriptionBuilder.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/DiscardTransformationDescriptionBuilder.java @@ -9,17 +9,17 @@ import org.jboss.as.controller.transform.OperationTransformer; import org.jboss.as.controller.transform.PathAddressTransformer; import org.jboss.as.controller.transform.ResourceTransformer; +import org.jboss.as.version.Stability; /** * Transformation builder discarding all operations to this resource. * * @author Emanuel Muckenhuber */ -public final class DiscardTransformationDescriptionBuilder extends AbstractTransformationDescriptionBuilder implements TransformationDescriptionBuilder { +public final class DiscardTransformationDescriptionBuilder extends AbstractTransformationDescriptionBuilder { - protected DiscardTransformationDescriptionBuilder(PathElement pathElement) { - super(pathElement, PathAddressTransformer.DEFAULT, ResourceTransformer.DISCARD, - OperationTransformer.DISCARD, null); + protected DiscardTransformationDescriptionBuilder(Stability stability, PathElement pathElement) { + super(stability, pathElement, PathAddressTransformer.DEFAULT, ResourceTransformer.DISCARD, OperationTransformer.DISCARD, null); } @Override @@ -27,5 +27,4 @@ public TransformationDescription build() { final AttributeTransformationDescriptionBuilderImpl.AttributeTransformationDescriptionBuilderRegistry empty = new AttributeTransformationDescriptionBuilderImpl.AttributeTransformationDescriptionBuilderRegistry(); return buildDefault(DiscardPolicy.SILENT, true, empty); } - } diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/RejectTransformationDescriptionBuilder.java b/controller/src/main/java/org/jboss/as/controller/transform/description/RejectTransformationDescriptionBuilder.java index 4dc5a1a707e..e34656802de 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/RejectTransformationDescriptionBuilder.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/RejectTransformationDescriptionBuilder.java @@ -8,16 +8,16 @@ import org.jboss.as.controller.transform.OperationTransformer; import org.jboss.as.controller.transform.PathAddressTransformer; import org.jboss.as.controller.transform.ResourceTransformer; +import org.jboss.as.version.Stability; /** * * @author Kabir Khan */ -public class RejectTransformationDescriptionBuilder extends AbstractTransformationDescriptionBuilder implements TransformationDescriptionBuilder { +public class RejectTransformationDescriptionBuilder extends AbstractTransformationDescriptionBuilder { - protected RejectTransformationDescriptionBuilder(PathElement pathElement) { - super(pathElement, PathAddressTransformer.DEFAULT, ResourceTransformer.DEFAULT, - OperationTransformer.DEFAULT, null); + protected RejectTransformationDescriptionBuilder(Stability stability, PathElement pathElement) { + super(stability, pathElement, PathAddressTransformer.DEFAULT, ResourceTransformer.DEFAULT, OperationTransformer.DEFAULT, null); } @Override @@ -25,5 +25,4 @@ public TransformationDescription build() { final AttributeTransformationDescriptionBuilderImpl.AttributeTransformationDescriptionBuilderRegistry empty = new AttributeTransformationDescriptionBuilderImpl.AttributeTransformationDescriptionBuilderRegistry(); return buildDefault(DiscardPolicy.REJECT_AND_WARN, true, empty); } - } diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilder.java b/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilder.java index ef51c582ed4..5a4920b9f0d 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilder.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilder.java @@ -7,6 +7,7 @@ import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ResourceDefinition; +import org.jboss.as.controller.ResourceRegistration; import org.jboss.as.controller.transform.OperationTransformer; import org.jboss.as.controller.transform.PathAddressTransformer; import org.jboss.as.controller.transform.ResourceTransformer; @@ -66,7 +67,21 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param pathElement the path element * @return the builder for the child resource */ - ResourceTransformationDescriptionBuilder addChildResource(PathElement pathElement); + default ResourceTransformationDescriptionBuilder addChildResource(PathElement pathElement) { + return this.addChildResource(pathElement, null); + } + + /** + * Add a child resource to this builder. This is going to register the child automatically at the + * {@linkplain org.jboss.as.controller.transform.TransformersSubRegistration} when registering the transformation + * description created by this builder. + * + * @param registration a resource registration + * @return the builder for the child resource + */ + default ResourceTransformationDescriptionBuilder addChildResource(ResourceRegistration registration) { + return this.addChildResource(registration, null); + } /** * Add a child resource to this builder. This is going to register the child automatically at the @@ -77,7 +92,20 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param dynamicDiscardPolicy a checker to decide whether the child should be added or not * @return the builder for the child resource */ - ResourceTransformationDescriptionBuilder addChildResource(PathElement pathElement, DynamicDiscardPolicy dynamicDiscardPolicy); + default ResourceTransformationDescriptionBuilder addChildResource(PathElement pathElement, DynamicDiscardPolicy dynamicDiscardPolicy) { + return this.addChildResource(ResourceRegistration.of(pathElement), dynamicDiscardPolicy); + } + + /** + * Add a child resource to this builder. This is going to register the child automatically at the + * {@linkplain org.jboss.as.controller.transform.TransformersSubRegistration} when registering the transformation + * description created by this builder. + * + * @param registration a resource registration + * @param dynamicDiscardPolicy a checker to decide whether the child should be added or not + * @return the builder for the child resource + */ + ResourceTransformationDescriptionBuilder addChildResource(ResourceRegistration registration, DynamicDiscardPolicy dynamicDiscardPolicy); /** * Add a child resource to this builder. This is going to register the child automatically at the @@ -86,8 +114,13 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * * @param definition the resource definition * @return the builder for the child resource + * @deprecated Use {@link ResourceTransformationDescriptionBuilder#addChildResource(ResourceRegistration)} instead. */ - ResourceTransformationDescriptionBuilder addChildResource(ResourceDefinition definition); + @Deprecated(forRemoval = true) + default ResourceTransformationDescriptionBuilder addChildResource(ResourceDefinition definition) { + ResourceRegistration registration = definition; + return this.addChildResource(registration); + } /** * Add a child resource to this builder. This is going to register the child automatically at the @@ -97,9 +130,13 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param definition the resource definition * @param dynamicDiscardPolicy a checker to decide whether the child should be added or not * @return the builder for the child resource + * @deprecated Use {@link ResourceTransformationDescriptionBuilder#addChildResource(ResourceRegistration, DynamicDiscardPolicy)} instead. */ - ResourceTransformationDescriptionBuilder addChildResource(ResourceDefinition definition, DynamicDiscardPolicy dynamicDiscardPolicy); - + @Deprecated(forRemoval = true) + default ResourceTransformationDescriptionBuilder addChildResource(ResourceDefinition definition, DynamicDiscardPolicy dynamicDiscardPolicy) { + ResourceRegistration registration = definition; + return this.addChildResource(registration, dynamicDiscardPolicy); + } /** * Recursively discards all child resources and its operations. @@ -107,7 +144,17 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param pathElement the path element * @return the builder for the child resource */ - DiscardTransformationDescriptionBuilder discardChildResource(PathElement pathElement); + default DiscardTransformationDescriptionBuilder discardChildResource(PathElement pathElement) { + return this.discardChildResource(ResourceRegistration.of(pathElement)); + } + + /** + * Recursively discards all child resources and its operations. + * + * @param registration a resource registration + * @return the builder for the child resource + */ + DiscardTransformationDescriptionBuilder discardChildResource(ResourceRegistration registration); /** * Recursively rejects all child resources and its operations @@ -115,7 +162,17 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param pathElement the path element * @return the builder for the child resource */ - RejectTransformationDescriptionBuilder rejectChildResource(PathElement pathElement); + default RejectTransformationDescriptionBuilder rejectChildResource(PathElement pathElement) { + return this.rejectChildResource(ResourceRegistration.of(pathElement)); + } + + /** + * Recursively rejects all child resources and its operations + * + * @param registration a resource registration + * @return the builder for the child resource + */ + RejectTransformationDescriptionBuilder rejectChildResource(ResourceRegistration registration); /** * Add a child resource, where all operations will get redirected to the legacy address. You can either pass in @@ -129,7 +186,25 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param legacy the legacy path element. * @return the builder for the child resource */ - ResourceTransformationDescriptionBuilder addChildRedirection(PathElement current, PathElement legacy); + default ResourceTransformationDescriptionBuilder addChildRedirection(PathElement current, PathElement legacy) { + return this.addChildRedirection(ResourceRegistration.of(current), legacy); + } + + /** + * Add a child resource, where all operations will get redirected to the legacy address. You can either pass in + *
    + *
  • Fixed elements - e.g. {@code current:addr1=test} + {@code legacy:addr2=toast}, in which case {@code addr1=test} gets redirected to {@code addr2=toast}}
  • + *
  • Wildcard elements - e.g. {@code current:addr1=*} + {@code legacy:addr2=*}, in which case {@code addr1=test} gets redirected to {@code addr2=test}, + * {@code addr1=ping} gets redirected to {@code addr2=ping}, etc.
  • + *
+ * + * @param registration a resource registration + * @param legacy the legacy path element. + * @return the builder for the child resource + */ + default ResourceTransformationDescriptionBuilder addChildRedirection(ResourceRegistration registration, PathElement legacy) { + return this.addChildRedirection(registration, legacy, null); + } /** * Add a child resource, where all operations will get redirected to the legacy address. You can either pass in @@ -144,7 +219,29 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param dynamicDiscardPolicy a checker to decide whether the child should be added or not * @return the builder for the child resource */ - ResourceTransformationDescriptionBuilder addChildRedirection(PathElement current, PathElement legacy, DynamicDiscardPolicy dynamicDiscardPolicy); + default ResourceTransformationDescriptionBuilder addChildRedirection(PathElement current, PathElement legacy, DynamicDiscardPolicy dynamicDiscardPolicy) { + return this.addChildRedirection(ResourceRegistration.of(current), legacy, dynamicDiscardPolicy); + } + + /** + * Add a child resource, where all operations will get redirected to the legacy address. You can either pass in + *
    + *
  • Fixed elements - e.g. {@code current:addr1=test} + {@code legacy:addr2=toast}, in which case {@code addr1=test} gets redirected to {@code addr2=toast}}
  • + *
  • Wildcard elements - e.g. {@code current:addr1=*} + {@code legacy:addr2=*}, in which case {@code addr1=test} gets redirected to {@code addr2=test}, + * {@code addr1=ping} gets redirected to {@code addr2=ping}, etc.
  • + *
+ * + * @param registration a resource registration + * @param legacy the legacy path element. + * @param dynamicDiscardPolicy a checker to decide whether the child should be added or not + * @return the builder for the child resource + */ + default ResourceTransformationDescriptionBuilder addChildRedirection(ResourceRegistration registration, PathElement legacy, DynamicDiscardPolicy dynamicDiscardPolicy) { + PathElement path = registration.getPathElement(); + assert path.isWildcard() == legacy.isWildcard() : "wildcard mismatch between current and legacy paths"; + PathAddressTransformer transformation = legacy.isWildcard() ? new PathAddressTransformer.ReplaceElementKey(legacy.getKey()) : new PathAddressTransformer.BasicPathAddressTransformer(legacy); + return this.addChildRedirection(registration, transformation, dynamicDiscardPolicy); + } /** * Add a child resource, where all operation will get redirected to a different address defined by @@ -154,7 +251,21 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param pathAddressTransformer the path transformation * @return the builder for the child resource */ - ResourceTransformationDescriptionBuilder addChildRedirection(PathElement pathElement, PathAddressTransformer pathAddressTransformer); + default ResourceTransformationDescriptionBuilder addChildRedirection(PathElement pathElement, PathAddressTransformer pathAddressTransformer) { + return this.addChildRedirection(pathElement, pathAddressTransformer, null); + } + + /** + * Add a child resource, where all operation will get redirected to a different address defined by + * the path transformation. + * + * @param registration a resource registration + * @param pathAddressTransformer the path transformation + * @return the builder for the child resource + */ + default ResourceTransformationDescriptionBuilder addChildRedirection(ResourceRegistration registration, PathAddressTransformer pathAddressTransformer) { + return this.addChildRedirection(registration, pathAddressTransformer, null); + } /** * Add a child resource, where all operation will get redirected to a different address defined by @@ -165,14 +276,29 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @param dynamicDiscardPolicy a checker to decide whether the child should be added or not * @return the builder for the child resource */ - ResourceTransformationDescriptionBuilder addChildRedirection(PathElement pathElement, PathAddressTransformer pathAddressTransformer, DynamicDiscardPolicy dynamicDiscardPolicy); + default ResourceTransformationDescriptionBuilder addChildRedirection(PathElement pathElement, PathAddressTransformer pathAddressTransformer, DynamicDiscardPolicy dynamicDiscardPolicy) { + return this.addChildRedirection(ResourceRegistration.of(pathElement), pathAddressTransformer, dynamicDiscardPolicy); + } + + /** + * Add a child resource, where all operation will get redirected to a different address defined by + * the path transformation. + * + * @param registration a resource registration + * @param pathAddressTransformer the path transformation + * @param dynamicDiscardPolicy a checker to decide whether the child should be added or not + * @return the builder for the child resource + */ + ResourceTransformationDescriptionBuilder addChildRedirection(ResourceRegistration registration, PathAddressTransformer pathAddressTransformer, DynamicDiscardPolicy dynamicDiscardPolicy); /** * Add an already created {@link TransformationDescriptionBuilder} as a child of this builder. * * @param builder the builder * @return the builder for this resource + * @deprecated Use other methods for creating child transformation descriptions */ + @Deprecated(forRemoval = true) ResourceTransformationDescriptionBuilder addChildBuilder(TransformationDescriptionBuilder builder); /** @@ -182,5 +308,4 @@ public interface ResourceTransformationDescriptionBuilder extends Transformation * @return the builder for this resource */ ResourceTransformationDescriptionBuilder discardOperations(String... operationNames); - } diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilderFactory.java b/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilderFactory.java new file mode 100644 index 00000000000..a5cc383674b --- /dev/null +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilderFactory.java @@ -0,0 +1,22 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.jboss.as.controller.transform.description; + +import org.jboss.as.controller.FeatureRegistry; + +/** + * A factory for creating builders of transformation descriptions. + */ +public interface ResourceTransformationDescriptionBuilderFactory extends FeatureRegistry { + + /** + * Creates a builder of transformation descriptions for this subsystem. + * @return a builder of transformation descriptions for this subsystem. + */ + default ResourceTransformationDescriptionBuilder createResourceTransformationDescriptionBuilder() { + return new ResourceTransformationDescriptionBuilderImpl(this.getStability(), null); + } +} diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilderImpl.java b/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilderImpl.java index 3e1bc12958f..7afc1adb33f 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilderImpl.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/ResourceTransformationDescriptionBuilderImpl.java @@ -10,10 +10,11 @@ import java.util.List; import org.jboss.as.controller.PathElement; -import org.jboss.as.controller.ResourceDefinition; +import org.jboss.as.controller.ResourceRegistration; import org.jboss.as.controller.transform.OperationTransformer; import org.jboss.as.controller.transform.PathAddressTransformer; import org.jboss.as.controller.transform.ResourceTransformer; +import org.jboss.as.version.Stability; /** * @author Emanuel Muckenhuber @@ -25,94 +26,60 @@ class ResourceTransformationDescriptionBuilderImpl extends AbstractTransformatio private DiscardPolicy discardPolicy = DiscardPolicy.NEVER; private final AttributeTransformationDescriptionBuilderImpl.AttributeTransformationDescriptionBuilderRegistry registry = new AttributeTransformationDescriptionBuilderImpl.AttributeTransformationDescriptionBuilderRegistry(); - protected ResourceTransformationDescriptionBuilderImpl(final PathElement pathElement) { - this(pathElement, PathAddressTransformer.DEFAULT); + protected ResourceTransformationDescriptionBuilderImpl(Stability stability, final PathElement pathElement) { + this(stability, pathElement, PathAddressTransformer.DEFAULT); } - protected ResourceTransformationDescriptionBuilderImpl(final PathElement pathElement, final PathAddressTransformer pathAddressTransformer) { - this(pathElement, pathAddressTransformer, null); + protected ResourceTransformationDescriptionBuilderImpl(Stability stability, final PathElement pathElement, final PathAddressTransformer pathAddressTransformer) { + this(stability, pathElement, pathAddressTransformer, null); } - protected ResourceTransformationDescriptionBuilderImpl(PathElement pathElement, DynamicDiscardPolicy dynamicDiscardPolicy) { - this(pathElement, PathAddressTransformer.DEFAULT, dynamicDiscardPolicy); + protected ResourceTransformationDescriptionBuilderImpl(Stability stability, PathElement pathElement, DynamicDiscardPolicy dynamicDiscardPolicy) { + this(stability, pathElement, PathAddressTransformer.DEFAULT, dynamicDiscardPolicy); } - protected ResourceTransformationDescriptionBuilderImpl(final PathElement pathElement, + protected ResourceTransformationDescriptionBuilderImpl(Stability stability, final PathElement pathElement, final PathAddressTransformer pathAddressTransformer, DynamicDiscardPolicy dynamicDiscardPolicy) { - super(pathElement, pathAddressTransformer, ResourceTransformer.DEFAULT, OperationTransformer.DEFAULT, + super(stability, pathElement, pathAddressTransformer, ResourceTransformer.DEFAULT, OperationTransformer.DEFAULT, dynamicDiscardPolicy); } @Override - public ResourceTransformationDescriptionBuilder addChildResource(final PathElement pathElement) { - return addChildResource(pathElement, null); - } - - @Override - public ResourceTransformationDescriptionBuilder addChildResource(PathElement pathElement, DynamicDiscardPolicy dynamicDiscardPolicy) { - final ResourceTransformationDescriptionBuilderImpl builder = new ResourceTransformationDescriptionBuilderImpl( - pathElement, dynamicDiscardPolicy); - children.add(builder); + public ResourceTransformationDescriptionBuilder addChildResource(ResourceRegistration registration, DynamicDiscardPolicy dynamicDiscardPolicy) { + final ResourceTransformationDescriptionBuilderImpl builder = new ResourceTransformationDescriptionBuilderImpl(this.getStability(), registration.getPathElement(), dynamicDiscardPolicy); + if (this.enables(registration)) { + this.children.add(builder); + } return builder; } @Override - public ResourceTransformationDescriptionBuilder addChildResource(final ResourceDefinition definition) { - return addChildResource(definition.getPathElement(), null); - } - - @Override - public ResourceTransformationDescriptionBuilder addChildResource(ResourceDefinition definition, DynamicDiscardPolicy dynamicDiscardPolicy) { - return addChildResource(definition.getPathElement(), dynamicDiscardPolicy); - } - - @Override - public DiscardTransformationDescriptionBuilder discardChildResource(final PathElement pathElement) { - final DiscardTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createDiscardInstance(pathElement); - children.add(builder); + public DiscardTransformationDescriptionBuilder discardChildResource(ResourceRegistration registration) { + final DiscardTransformationDescriptionBuilder builder = new DiscardTransformationDescriptionBuilder(this.getStability(), registration.getPathElement()); + if (this.enables(registration)) { + this.children.add(builder); + } return builder; } @Override - public RejectTransformationDescriptionBuilder rejectChildResource(PathElement pathElement) { - final RejectTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createRejectInstance(pathElement); - children.add(builder); + public RejectTransformationDescriptionBuilder rejectChildResource(ResourceRegistration registration) { + final RejectTransformationDescriptionBuilder builder = new RejectTransformationDescriptionBuilder(this.getStability(), registration.getPathElement()); + if (this.enables(registration)) { + this.children.add(builder); + } return builder; } - @Override - public ResourceTransformationDescriptionBuilder addChildRedirection(final PathElement current, final PathElement legacy) { - return addChildRedirection(current, legacy, null); - } - - @Override - public ResourceTransformationDescriptionBuilder addChildRedirection(PathElement current, PathElement legacy, DynamicDiscardPolicy dynamicDiscardPolicy) { - final PathAddressTransformer transformation; - if (legacy.isWildcard()) { - assert current.isWildcard() : "legacy is wildcard while current is not"; - transformation = new PathAddressTransformer.ReplaceElementKey(legacy.getKey()); - } else { - assert !current.isWildcard() : "legacy is fixed while current is not"; - transformation = new PathAddressTransformer.BasicPathAddressTransformer(legacy); + public ResourceTransformationDescriptionBuilder addChildRedirection(ResourceRegistration registration, PathAddressTransformer pathAddressTransformer, DynamicDiscardPolicy dynamicDiscardPolicy) { + final ResourceTransformationDescriptionBuilderImpl builder = new ResourceTransformationDescriptionBuilderImpl(this.getStability(), registration.getPathElement(), pathAddressTransformer, dynamicDiscardPolicy); + if (this.enables(registration)) { + this.children.add(builder); } - return addChildRedirection(current, transformation, dynamicDiscardPolicy); - - } - - @Override - public ResourceTransformationDescriptionBuilder addChildRedirection(final PathElement oldAddress, final PathAddressTransformer pathAddressTransformer) { - return addChildRedirection(oldAddress, pathAddressTransformer, null); - } - - @Override - public ResourceTransformationDescriptionBuilder addChildRedirection(PathElement oldAddress, PathAddressTransformer pathAddressTransformer, DynamicDiscardPolicy dynamicDiscardPolicy) { - final ResourceTransformationDescriptionBuilderImpl builder = new ResourceTransformationDescriptionBuilderImpl(oldAddress, pathAddressTransformer, dynamicDiscardPolicy); - children.add(builder); return builder; } - @Override public ResourceTransformationDescriptionBuilder addChildBuilder(TransformationDescriptionBuilder builder) { children.add(builder); diff --git a/controller/src/main/java/org/jboss/as/controller/transform/description/TransformationDescriptionBuilder.java b/controller/src/main/java/org/jboss/as/controller/transform/description/TransformationDescriptionBuilder.java index 8de298056df..f2a3fa507ae 100644 --- a/controller/src/main/java/org/jboss/as/controller/transform/description/TransformationDescriptionBuilder.java +++ b/controller/src/main/java/org/jboss/as/controller/transform/description/TransformationDescriptionBuilder.java @@ -5,15 +5,18 @@ package org.jboss.as.controller.transform.description; +import org.jboss.as.controller.FeatureRegistry; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PathElement; +import org.jboss.as.controller.transform.SubsystemTransformerRegistration; +import org.jboss.as.version.Stability; /** * A transformation description builder. * * @author Emanuel Muckenhuber */ -public interface TransformationDescriptionBuilder { +public interface TransformationDescriptionBuilder extends FeatureRegistry { /** * Build the transformation description. Modifications to the builder won't affect the built description after this @@ -23,15 +26,17 @@ public interface TransformationDescriptionBuilder { */ TransformationDescription build(); + @Deprecated(forRemoval = true) class Factory { /** * Create a resource builder instance. * * @return the transformation builder + * @deprecated Superseded by {@link ResourceTransformationDescriptionBuilderFactory#createResourceTransformationDescriptionBuilder()} */ public static ResourceTransformationDescriptionBuilder createSubsystemInstance() { - return new ResourceTransformationDescriptionBuilderImpl(null); + return new ResourceTransformationDescriptionBuilderImpl(Stability.DEFAULT, null); } /** @@ -39,9 +44,10 @@ public static ResourceTransformationDescriptionBuilder createSubsystemInstance() * * @param pathElement the path element of the child to be transformed * @return the transformation builder + * @deprecated To be removed without replacement. */ public static ResourceTransformationDescriptionBuilder createInstance(final PathElement pathElement) { - return new ResourceTransformationDescriptionBuilderImpl(pathElement); + return new ResourceTransformationDescriptionBuilderImpl(Stability.DEFAULT, pathElement); } /** @@ -49,9 +55,10 @@ public static ResourceTransformationDescriptionBuilder createInstance(final Path * * @param pathElement the path element of the child to be transformed * @return the transformation builder + * @deprecated To be removed without replacement. */ public static DiscardTransformationDescriptionBuilder createDiscardInstance(PathElement pathElement) { - return new DiscardTransformationDescriptionBuilder(pathElement); + return new DiscardTransformationDescriptionBuilder(Stability.DEFAULT, pathElement); } /** @@ -59,18 +66,20 @@ public static DiscardTransformationDescriptionBuilder createDiscardInstance(Path * * @param pathElement the path element of the child to be transformed * @return the transformation builder + * @deprecated To be removed without replacement. */ public static RejectTransformationDescriptionBuilder createRejectInstance(PathElement pathElement) { - return new RejectTransformationDescriptionBuilder(pathElement); + return new RejectTransformationDescriptionBuilder(Stability.DEFAULT, pathElement); } /** * Create a chained builder instance for a subsystem * * @param currentVersion the current version of the subsystem. + * @deprecated Superseded by {@link ChainedTransformationDescriptionBuilderFactory#createChainedTransformationDescriptionBuilder()} */ public static ChainedTransformationDescriptionBuilder createChainedSubystemInstance(ModelVersion currentVersion) { - return new ChainedTransformationDescriptionBuilderImpl(currentVersion, null); + return new ChainedTransformationDescriptionBuilderImpl(currentVersion, Stability.DEFAULT, null); } /** @@ -78,9 +87,10 @@ public static ChainedTransformationDescriptionBuilder createChainedSubystemInsta * * @param pathElement the child resource element which the chained transformers handle * @param currentVersion the current version of the model containing the resource being transformed. + * @deprecated To be removed without replacement. */ public static ChainedTransformationDescriptionBuilder createChainedInstance(PathElement pathElement, ModelVersion currentVersion) { - return new ChainedTransformationDescriptionBuilderImpl(currentVersion, pathElement); + return new ChainedTransformationDescriptionBuilderImpl(currentVersion, Stability.DEFAULT, pathElement); } } diff --git a/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java b/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java index f684dd98544..1ad17dba6ee 100644 --- a/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java +++ b/subsystem-test/framework/src/main/java/org/jboss/as/subsystem/test/SubsystemTestDelegate.java @@ -586,7 +586,7 @@ private void loadTransformers(final ExtensionRegistry extensionRegistry) { for (ExtensionTransformerRegistration registration : ServiceLoader.load(ExtensionTransformerRegistration.class)) { if (registration.getSubsystemName().equals(getMainSubsystemName())) { registration.registerTransformers(extensionRegistry.getTransformerRegistry() - .createSubsystemTransformerRegistration(getMainSubsystemName(), version)); + .createSubsystemTransformerRegistration(getMainSubsystemName(), version, this.additionalInit.getStability())); } }