Skip to content

Commit

Permalink
WFCORE-6995 Allow stability-specific resource transformations for mix…
Browse files Browse the repository at this point in the history
…ed domains
  • Loading branch information
pferraro committed Oct 11, 2024
1 parent d8fde7a commit 406466c
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -52,5 +54,4 @@ public interface SubsystemTransformerRegistration {
* @return the version
*/
ModelVersion getCurrentSubsystemVersion();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -105,6 +117,11 @@ public TransformersSubRegistration registerModelTransformers(ModelVersionRange v
public ModelVersion getCurrentSubsystemVersion() {
return currentVersion;
}

@Override
public Stability getStability() {
return this.stability;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,17 +36,23 @@ abstract class AbstractTransformationDescriptionBuilder implements Transformatio
protected final List<TransformationDescriptionBuilder> children = new ArrayList<TransformationDescriptionBuilder>();
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;
this.operationTransformer = operationTransformer;
this.dynamicDiscardPolicy = dynamicDiscardPolicy;
}

@Override
public Stability getStability() {
return this.stability;
}

public TransformationDescriptionBuilder setResourceTransformer(ResourceTransformer resourceTransformer) {
this.resourceTransformer = resourceTransformer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Set;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.version.Stability;

/**
* @author <a href="[email protected]">Kabir Khan</a>
Expand All @@ -29,74 +30,72 @@ abstract class AttributeTransformationDescriptionBuilderImpl<T extends BaseAttri
}

@Override
public ResourceTransformationDescriptionBuilder end() {
return builder;
public Stability getStability() {
return this.builder.getStability();
}

@Override
public T setDiscard(DiscardAttributeChecker discardChecker, AttributeDefinition...discardedAttributes) {
AttributeDefinition[] useDefs = discardedAttributes;
for (AttributeDefinition attribute : useDefs) {
String attrName = getAttributeName(attribute);
registry.setDiscardedAttribute(discardChecker, attrName);
}
return thisBuilder();
public ResourceTransformationDescriptionBuilder end() {
return builder;
}

@Override
public T setDiscard(DiscardAttributeChecker discardChecker, Collection<AttributeDefinition> 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<RejectAttributeChecker> rejectCheckers, AttributeDefinition...rejectedAttributes) {
for (RejectAttributeChecker rejectChecker : rejectCheckers) {
addRejectCheck(rejectChecker, rejectedAttributes);
this.addRejectCheck(rejectChecker, rejectedAttributes);
}
return thisBuilder();
}

@Override
public T addRejectChecks(List<RejectAttributeChecker> 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();
}

Expand All @@ -106,19 +105,21 @@ public T addRename(String attributeName, String newName) {
return thisBuilder();
}

@Override
public T addRenames(Map<String, String> renames) {
for (Map.Entry<String, String> rename : renames.entrySet()) {
registry.addRenamedAttribute(rename.getKey(), rename.getValue());
this.addRename(rename.getKey(), rename.getValue());
}
return thisBuilder();
}


@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();
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.FeatureRegistry;


/**
Expand All @@ -34,7 +35,7 @@
* @author Emanuel Muckenhuber
* @author Kabir Khan
*/
public interface BaseAttributeTransformationDescriptionBuilder<T extends BaseAttributeTransformationDescriptionBuilder<?>> {
public interface BaseAttributeTransformationDescriptionBuilder<T extends BaseAttributeTransformationDescriptionBuilder<?>> extends FeatureRegistry {

/**
* Adds a RejectAttributeChecker. More than one reject checker can be used for an attribute, and the RejectAttributeCheckers
Expand Down Expand Up @@ -106,7 +107,9 @@ public interface BaseAttributeTransformationDescriptionBuilder<T extends BaseAtt
* @param discardedAttributes the attributes to check
* @return this builder
*/
T setDiscard(DiscardAttributeChecker discardChecker, AttributeDefinition...discardedAttributes);
default T setDiscard(DiscardAttributeChecker discardChecker, AttributeDefinition... discardedAttributes) {
return this.setDiscard(discardChecker, List.of(discardedAttributes));
}

/**
* Sets the DiscardChecker to be used to check if an attribute should be discarded. Only one discard checker can be used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import org.jboss.as.controller.transform.SubsystemTransformerRegistration;

/**
* A builder used to create chained transformers. Created using
* {@link TransformationDescriptionBuilder.Factory#createChainedInstance(org.jboss.as.controller.PathElement, ModelVersion)} or
* {@link TransformationDescriptionBuilder.Factory#createChainedSubystemInstance(ModelVersion)}. The {@code ModelVersion} parameter
* to these operations is the 'current' model version.
* A builder used to create chained transformers.
* Created using {@link ResourceTransformationDescriptionBuilderFactory#createChainedTransformationDescriptionBuilder(ModelVersion)}.
* The {@link ModelVersion} parameter to these operations is the 'current' model version.
* Internally this uses a {@link org.jboss.as.controller.registry.OperationTransformerRegistry.PlaceholderResolver} so
* if this is used, all children must also use chained transformers. Typically you should create a chain for the subsystem
* and add child transformations using the chained builder.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.controller.transform.description;

import org.jboss.as.controller.FeatureRegistry;
import org.jboss.as.controller.ModelVersion;

/**
* A factory for creating a chained transformation description builder.
*/
public interface ChainedTransformationDescriptionBuilderFactory extends FeatureRegistry {

/**
* Creates a builder of chained transformation descriptions for this subsystem.
* @return a builder of chained transformation descriptions for this subsystem.
*/
default ChainedTransformationDescriptionBuilder createChainedTransformationDescriptionBuilder() {
return new ChainedTransformationDescriptionBuilderImpl(this.getCurrentSubsystemVersion(), this.getStability(), null);
}

ModelVersion getCurrentSubsystemVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,32 @@
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;

/**
*
* @author <a href="[email protected]">Kabir Khan</a>
*/
class ChainedTransformationDescriptionBuilderImpl implements ChainedTransformationDescriptionBuilder {
private final Stability stability;
private final ModelVersion currentVersion;
private final Map<ModelVersionPair, TransformationDescriptionBuilder> 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<ModelVersion, TransformationDescription> build(ModelVersion...versions) {
ModelVersion[] allVersions = new ModelVersion[versions.length + 1];
allVersions[0] = currentVersion;
Expand Down Expand Up @@ -66,7 +70,7 @@ private Map<ModelVersion, TransformationDescription> 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));
Expand Down
Loading

0 comments on commit 406466c

Please sign in to comment.