Skip to content

Commit

Permalink
Merge c997c15 into b94be1e
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro authored Dec 16, 2024
2 parents b94be1e + c997c15 commit c7edee2
Show file tree
Hide file tree
Showing 26 changed files with 580 additions and 221 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.controller.transform;

import java.util.EnumSet;
import java.util.function.BiConsumer;

import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.SubsystemModel;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescription;

/**
* A transformer registration of a single subsystem.
*/
public class SubsystemModelTransformerRegistration<E extends Enum<E> & SubsystemModel> implements ExtensionTransformerRegistration {

private final String subsystemName;
private final E currentSubsystemModel;
private final BiConsumer<ResourceTransformationDescriptionBuilder, ModelVersion> transformation;

/**
* Creates a transformer registration for a subsystem.
* @param subsystemName the subsystem name
* @param currentSubsystemModel the current subsystem model
* @param transformation a consumer that builds a transformer description for a given target model version
*/
public SubsystemModelTransformerRegistration(String subsystemName, E currentSubsystemModel, BiConsumer<ResourceTransformationDescriptionBuilder, ModelVersion> transformation) {
this.subsystemName = subsystemName;
this.currentSubsystemModel = currentSubsystemModel;
this.transformation = transformation;
}

@Override
public String getSubsystemName() {
return this.subsystemName;
}

@Override
public void registerTransformers(SubsystemTransformerRegistration registration) {
// Build and register transformation descriptions for all but the current subsystem model version
for (E model : EnumSet.complementOf(EnumSet.of(this.currentSubsystemModel))) {
ModelVersion version = model.getVersion();
ResourceTransformationDescriptionBuilder builder = registration.createResourceTransformationDescriptionBuilder();
this.transformation.accept(builder, version);
TransformationDescription.Tools.register(builder.build(), registration, version);
}
}
}
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:tomaz.cerar@redhat.com">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
Loading

0 comments on commit c7edee2

Please sign in to comment.