-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WFCORE-6995 Allow stability-specific resource transformations for mixed domains #6214
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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; | ||
|
@@ -33,7 +35,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 { | ||
|
@@ -46,19 +48,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(extensionModuleName, ExtensionTransformerRegistration.class)) { | ||
if (registration.getSubsystemName().equals(name)) { //to prevent registering transformers for different subsystems | ||
|
@@ -71,16 +80,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; | ||
} | ||
|
@@ -101,9 +109,14 @@ public TransformersSubRegistration registerModelTransformers(ModelVersionRange v | |
} | ||
|
||
@Override | ||
public ModelVersion getCurrentSubsystemVersion() { | ||
public ModelVersion getCurrentVersion() { | ||
return currentVersion; | ||
} | ||
|
||
@Override | ||
public Stability getStability() { | ||
return TransformerRegistry.this.getStability(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -275,11 +288,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); | ||
} | ||
Comment on lines
+293
to
296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens with the current usage of this method in our code? Shouldn't we at least force the creation of a transformer registry using a specific Stability level? Otherwise, we will continue using the wrong registry and we won't be able yet to add specific transformations to the subsystems. |
||
|
||
public static TransformerRegistry create(Stability stability) { | ||
return new TransformerRegistry(stability); | ||
} | ||
} | ||
|
||
public static class TransformersSubRegistrationImpl implements TransformersSubRegistration { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an example of how to use this class?
I'm not a SME in these transformers and it is too big to digest it easily, but I guess what I cannot see is how this new way to register the transformers will be able to match what we currently have. At this moment, transformers are registered as a chain, with a common builder that registers the transformation from one version to another, however here we are only registering a single version with a specific builder, so I get lost on this.