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 17, 2024
1 parent d8fde7a commit 1ab1249
Show file tree
Hide file tree
Showing 24 changed files with 513 additions and 211 deletions.
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 @@ -50,7 +52,10 @@ public interface SubsystemTransformerRegistration {
* Get the version of the subsystem
*
* @return the version
* @deprecated Superseded by {@link #getCurrentVersion()}
*/
ModelVersion getCurrentSubsystemVersion();

@Deprecated(forRemoval = true, since = "27.0.0")
default ModelVersion getCurrentSubsystemVersion() {
return this.getCurrentVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jboss.as.controller.operations.global.QueryOperationHandler;
import org.jboss.as.controller.registry.OperationTransformerRegistry;
import org.jboss.as.controller.registry.OperationTransformerRegistry.PlaceholderResolver;
import org.jboss.as.version.Stability;


/**
Expand Down Expand Up @@ -62,8 +63,13 @@ private TransformationTargetImpl(final TransformationTargetImpl target, final Pl
this.placeholderResolver = placeholderResolver;
}

@Deprecated(forRemoval = true, since = "27.0.0")
public static TransformationTarget createLocal() {
TransformerRegistry registry = new TransformerRegistry();
return createLocal(Stability.DEFAULT);
}

public static TransformationTarget createLocal(Stability stability) {
TransformerRegistry registry = new TransformerRegistry(stability);
OperationTransformerRegistry r2 = registry.resolveHost(ModelVersion.create(0), new HashMap<PathAddress, ModelVersion>());
return new TransformationTargetImpl(null, registry, ModelVersion.create(0), new HashMap<PathAddress, ModelVersion>(),
r2, TransformationTargetType.SERVER, Transformers.OperationExcludedTransformationRegistry.DEFAULT, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
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.controller.transform.description.ResourceTransformationDescriptionBuilderFactory;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.jboss.modules.Module;
Expand All @@ -34,7 +36,7 @@
* @author <a href="mailto:[email protected]">Tomaz Cerar</a>
* @author Emanuel Muckenhuber
*/
public final class TransformerRegistry {
public final class TransformerRegistry implements ResourceTransformationDescriptionBuilderFactory {

public static final ModelNode DISCARD_OPERATION = new ModelNode();
static {
Expand All @@ -47,19 +49,26 @@ public final class TransformerRegistry {
private static final PathElement PROFILE = PathElement.pathElement(ModelDescriptionConstants.PROFILE);
private static final PathElement SERVER = PathElement.pathElement(ModelDescriptionConstants.RUNNING_SERVER);

private final Stability stability;
private final GlobalTransformerRegistry domain = new GlobalTransformerRegistry();
private final GlobalTransformerRegistry subsystem = new GlobalTransformerRegistry();

TransformerRegistry() {
TransformerRegistry(Stability stability) {
this.stability = stability;
// Initialize the empty paths
domain.createChildRegistry(PathAddress.pathAddress(PROFILE), ModelVersion.create(0), ResourceTransformer.DEFAULT, false);
domain.createChildRegistry(PathAddress.pathAddress(HOST), ModelVersion.create(0), ResourceTransformer.DEFAULT, false);
domain.createChildRegistry(PathAddress.pathAddress(HOST, SERVER), ModelVersion.create(0), ResourceTransformer.DEFAULT, false);
}

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

public void loadAndRegisterTransformers(String name, ModelVersion subsystemVersion, String extensionModuleName) {
try {
SubsystemTransformerRegistration transformerRegistration = new SubsystemTransformerRegistrationImpl(name, subsystemVersion);
SubsystemTransformerRegistration transformerRegistration = this.createSubsystemTransformerRegistration(name, subsystemVersion);
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,16 +81,15 @@ public void loadAndRegisterTransformers(String name, ModelVersion subsystemVersi
}
}

public SubsystemTransformerRegistration createSubsystemTransformerRegistration(String name, ModelVersion currentVersion){
public SubsystemTransformerRegistration createSubsystemTransformerRegistration(String name, ModelVersion currentVersion) {
return new SubsystemTransformerRegistrationImpl(name, currentVersion);
}

private class SubsystemTransformerRegistrationImpl implements SubsystemTransformerRegistration{
private class SubsystemTransformerRegistrationImpl implements SubsystemTransformerRegistration {
private final String name;
private final ModelVersion currentVersion;


public SubsystemTransformerRegistrationImpl(String name, ModelVersion currentVersion) {
SubsystemTransformerRegistrationImpl(String name, ModelVersion currentVersion) {
this.name = name;
this.currentVersion = currentVersion;
}
Expand All @@ -102,9 +110,14 @@ public TransformersSubRegistration registerModelTransformers(ModelVersionRange v
}

@Override
public ModelVersion getCurrentSubsystemVersion() {
public ModelVersion getCurrentVersion() {
return currentVersion;
}

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

/**
Expand Down Expand Up @@ -276,11 +289,16 @@ public static class Factory {
* Create a new Transformer registry.
*
* @return the created transformer registry
* @deprecated Superseded by {@link #create(Stability)}.
*/
@Deprecated(forRemoval = true)
public static TransformerRegistry create() {
return new TransformerRegistry();
return create(Stability.DEFAULT);
}

public static TransformerRegistry create(Stability stability) {
return new TransformerRegistry(stability);
}
}

public static class TransformersSubRegistrationImpl implements TransformersSubRegistration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;

/**
Expand Down Expand Up @@ -252,10 +253,20 @@ public static ResourceTransformationContext create(TransformationTarget target,
*
* @return the transformers instance. Will not be {@code null}
*/
@Deprecated(forRemoval = true, since = "27.0.0")
public static Transformers createLocal() {
return new TransformersImpl(TransformationTargetImpl.createLocal());
}

/**
* Create a local transformer, which will use the default transformation rules, however still respect the
* ignored resource transformation.
* @param stability the stability level of the target host
* @return the transformers instance. Will not be {@code null}
*/
public static Transformers createLocal(Stability stability) {
return new TransformersImpl(TransformationTargetImpl.createLocal(stability));
}
}

/** Provides information on whether a target process is ignoring particular resource addresses. */
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
Loading

0 comments on commit 1ab1249

Please sign in to comment.