Skip to content

Commit

Permalink
[WFCORE-7091] Adapt the test framework to use an stability level when…
Browse files Browse the repository at this point in the history
… it is preparing the legacy controllers

Jira issue: https://issues.redhat.com/browse/WFCORE-7091
  • Loading branch information
yersan committed Dec 15, 2024
1 parent 3804777 commit 1650871
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.jboss.as.host.controller.HostRunningModeControl;
import org.jboss.as.host.controller.RestartMode;
import org.jboss.as.model.test.ModelTestOperationValidatorFilter;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLMapper;

Expand All @@ -54,6 +55,28 @@ public static KernelServices create(List<ModelNode> bootOperations, ModelTestOpe
return AbstractKernelServicesImpl.create(ProcessType.HOST_CONTROLLER, runningModeControl, validateOpsFilter, bootOperations, testParser, legacyModelVersion, type, modelInitializer, extensionRegistry, null);
}

public static KernelServices create(List<ModelNode> bootOperations, ModelTestOperationValidatorFilter validateOpsFilter, ModelVersion legacyModelVersion,
List<LegacyModelInitializerEntry> modelInitializerEntries, String stabilityStr) throws Exception {

Stability stability = Stability.fromString(stabilityStr);
TestModelType type = TestModelType.DOMAIN;
XMLMapper xmlMapper = XMLMapper.Factory.create();
TestParser testParser = TestParser.create(stability, null, xmlMapper, type);
ModelInitializer modelInitializer = null;
if (modelInitializerEntries != null && !modelInitializerEntries.isEmpty()) {
modelInitializer = new LegacyModelInitializer(modelInitializerEntries);
}

RunningModeControl runningModeControl = new HostRunningModeControl(RunningMode.ADMIN_ONLY, RestartMode.HC_ONLY);

ExtensionRegistry extensionRegistry = ExtensionRegistry.builder(ProcessType.HOST_CONTROLLER)
.withRunningMode(runningModeControl.getRunningMode())
.withStability(stability)
.build();

return AbstractKernelServicesImpl.create(ProcessType.HOST_CONTROLLER, runningModeControl, validateOpsFilter, bootOperations, testParser, legacyModelVersion, type, modelInitializer, extensionRegistry, null);
}

private static class LegacyModelInitializer implements ModelInitializer {

private final List<LegacyModelInitializerEntry> entries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,89 @@
import org.jboss.as.core.model.bridge.impl.LegacyControllerKernelServicesProxy;
import org.jboss.as.core.model.test.LegacyModelInitializerEntry;
import org.jboss.as.model.test.ModelTestOperationValidatorFilter;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;

/**
*
* @author <a href="[email protected]">Kabir Khan</a>
*/
public class ScopedKernelServicesBootstrap {
Stability stability;
ClassLoader legacyChildFirstClassLoader;
ClassLoaderObjectConverter objectConverter;

public ScopedKernelServicesBootstrap(ClassLoader legacyChildFirstClassLoader) {
public ScopedKernelServicesBootstrap(ClassLoader legacyChildFirstClassLoader, Stability stability) {
this.legacyChildFirstClassLoader = legacyChildFirstClassLoader;
this.objectConverter = new ClassLoaderObjectConverterImpl(this.getClass().getClassLoader(), legacyChildFirstClassLoader);
this.stability = stability;
}


public LegacyControllerKernelServicesProxy createKernelServices(List<ModelNode> bootOperations, ModelTestOperationValidatorFilter validateOpsFilter, ModelVersion legacyModelVersion, List<LegacyModelInitializerEntry> modelInitializerEntries) throws Exception {

Object childClassLoaderKernelServices = createChildClassLoaderKernelServices(bootOperations, validateOpsFilter, legacyModelVersion, modelInitializerEntries);
return new LegacyControllerKernelServicesProxy(legacyChildFirstClassLoader, childClassLoaderKernelServices, objectConverter);
}

private Object createChildClassLoaderKernelServices(List<ModelNode> bootOperations, ModelTestOperationValidatorFilter validateOpsFilter, ModelVersion legacyModelVersion, List<LegacyModelInitializerEntry> modelInitializerEntries){
private Object createChildClassLoaderKernelServices(List<ModelNode> bootOperations, ModelTestOperationValidatorFilter validateOpsFilter, ModelVersion legacyModelVersion, List<LegacyModelInitializerEntry> modelInitializerEntries) {
try {
Class<?> clazz = legacyChildFirstClassLoader.loadClass(ChildFirstClassLoaderKernelServicesFactory.class.getName());
List<Object> convertedBootOps = getConvertedBootOps(bootOperations);
List<Object> convertedModelInitializerEntries = convertModelInitializer(modelInitializerEntries);

Method m = clazz.getMethod("create",
List.class,
legacyChildFirstClassLoader.loadClass(ModelTestOperationValidatorFilter.class.getName()),
legacyChildFirstClassLoader.loadClass(ModelVersion.class.getName()),
List.class);

List<Object> convertedBootOps = new ArrayList<Object>();
for (int i = 0 ; i < bootOperations.size() ; i++) {
ModelNode node = bootOperations.get(i);
if (node != null) {
convertedBootOps.add(objectConverter.convertModelNodeToChildCl(node));
}
}
Object convertedValidationFilter = objectConverter.convertValidateOperationsFilterToChildCl(validateOpsFilter);
Object convertedLegacyModelVersion = objectConverter.convertModelVersionToChildCl(legacyModelVersion);

List<Object> convertedModelInitializerEntries = null;
if (modelInitializerEntries != null) {
convertedModelInitializerEntries = new ArrayList<Object>();
for (LegacyModelInitializerEntry entry : modelInitializerEntries) {
convertedModelInitializerEntries.add(objectConverter.convertLegacyModelInitializerEntryToChildCl(entry));
}
}
if (!Stability.DEFAULT.equals(stability)) {
Method m = clazz.getMethod("create",
List.class,
legacyChildFirstClassLoader.loadClass(ModelTestOperationValidatorFilter.class.getName()),
legacyChildFirstClassLoader.loadClass(ModelVersion.class.getName()),
List.class,
String.class);

return m.invoke(null, convertedBootOps, objectConverter.convertValidateOperationsFilterToChildCl(validateOpsFilter), objectConverter.convertModelVersionToChildCl(legacyModelVersion), convertedModelInitializerEntries);
return m.invoke(null,
convertedBootOps,
convertedValidationFilter,
convertedLegacyModelVersion,
convertedModelInitializerEntries,
stability.toString());
} else {
Method m = clazz.getMethod("create",
List.class,
legacyChildFirstClassLoader.loadClass(ModelTestOperationValidatorFilter.class.getName()),
legacyChildFirstClassLoader.loadClass(ModelVersion.class.getName()),
List.class);

return m.invoke(null,
convertedBootOps,
convertedValidationFilter,
convertedLegacyModelVersion,
convertedModelInitializerEntries);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private List<Object> convertModelInitializer(List<LegacyModelInitializerEntry> modelInitializerEntries) {
List<Object> converted = null;
if (modelInitializerEntries != null) {
converted = new ArrayList<>();
for (LegacyModelInitializerEntry entry : modelInitializerEntries) {
converted.add(objectConverter.convertLegacyModelInitializerEntryToChildCl(entry));
}
}
return converted;
}

private List<Object> getConvertedBootOps(List<ModelNode> bootOperations) {
List<Object> converted = new ArrayList<>();
for (ModelNode node : bootOperations) {
if (node != null) {
converted.add(objectConverter.convertModelNodeToChildCl(node));
}
}
return converted;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,10 @@ private class KernelServicesBuilderImpl implements KernelServicesBuilder, ModelT
this.stability = stability;
this.processType = type == TestModelType.HOST || type == TestModelType.DOMAIN ? ProcessType.HOST_CONTROLLER : ProcessType.STANDALONE_SERVER;
runningModeControl = type == TestModelType.HOST ? new HostRunningModeControl(RunningMode.ADMIN_ONLY, RestartMode.HC_ONLY) : new RunningModeControl(RunningMode.ADMIN_ONLY);
extensionRegistry = ExtensionRegistry.builder(this.processType).withRunningModeControl(this.runningModeControl).withStability(stability).build();
extensionRegistry = ExtensionRegistry.builder(this.processType)
.withRunningModeControl(this.runningModeControl)
.withStability(stability)
.build();
testParser = TestParser.create(stability, extensionRegistry, xmlMapper, type);
}

Expand Down Expand Up @@ -680,6 +683,7 @@ private class LegacyKernelServicesInitializerImpl implements LegacyKernelService
private final ModelVersion modelVersion;
private final List<LegacyModelInitializerEntry> modelInitializerEntries = new ArrayList<LegacyModelInitializerEntry>();
private final ModelTestControllerVersion testControllerVersion;
private final Stability stability;
private boolean dontUseBootOperations = false;
private boolean skipReverseCheck;
private ModelFixer reverseCheckMainModelFixer;
Expand All @@ -690,6 +694,7 @@ private class LegacyKernelServicesInitializerImpl implements LegacyKernelService
this.classLoaderBuilder = new ChildFirstClassLoaderBuilder(version.isEap());
this.modelVersion = modelVersion;
this.testControllerVersion = version;
this.stability = version.getStability();
}

private LegacyControllerKernelServicesProxy install(AbstractKernelServicesImpl mainServices, ModelInitializer modelInitializer, ModelWriteSanitizer modelWriteSanitizer, List<String> contentRepositoryContents, List<ModelNode> bootOperations) throws Exception {
Expand All @@ -698,7 +703,7 @@ private LegacyControllerKernelServicesProxy install(AbstractKernelServicesImpl m
}

if (!skipReverseCheck) {
bootCurrentVersionWithLegacyBootOperations(bootOperations, modelInitializer, modelWriteSanitizer, contentRepositoryContents, mainServices);
bootCurrentVersionWithLegacyBootOperations(bootOperations, modelInitializer, modelWriteSanitizer, contentRepositoryContents, mainServices, stability);
}

final ClassLoader legacyCl;
Expand Down Expand Up @@ -733,7 +738,7 @@ private LegacyControllerKernelServicesProxy install(AbstractKernelServicesImpl m
}


ScopedKernelServicesBootstrap scopedBootstrap = new ScopedKernelServicesBootstrap(legacyCl);
ScopedKernelServicesBootstrap scopedBootstrap = new ScopedKernelServicesBootstrap(legacyCl, stability);
LegacyControllerKernelServicesProxy legacyServices = scopedBootstrap.createKernelServices(bootOperations, getOperationValidationFilter(), modelVersion, modelInitializerEntries);

return legacyServices;
Expand Down Expand Up @@ -793,8 +798,9 @@ public LegacyKernelServicesInitializer configureReverseControllerCheck(ModelFixe
return this;
}

private KernelServices bootCurrentVersionWithLegacyBootOperations(List<ModelNode> bootOperations, ModelInitializer modelInitializer, ModelWriteSanitizer modelWriteSanitizer, List<String> contentRepositoryHashes, KernelServices mainServices) throws Exception {
KernelServicesBuilder reverseServicesBuilder = createKernelServicesBuilder(TestModelType.DOMAIN, Stability.DEFAULT)
private KernelServices bootCurrentVersionWithLegacyBootOperations(List<ModelNode> bootOperations, ModelInitializer modelInitializer, ModelWriteSanitizer modelWriteSanitizer, List<String> contentRepositoryHashes, KernelServices mainServices, Stability stability) throws Exception {
testControllerVersion.getCoreVersion();
KernelServicesBuilder reverseServicesBuilder = createKernelServicesBuilder(TestModelType.DOMAIN, stability)
.setBootOperations(bootOperations)
.setModelInitializer(modelInitializer, modelWriteSanitizer);
for (String hash : contentRepositoryHashes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.descriptions.NonResolvingResourceDescriptionResolver;
import org.jboss.as.controller.extension.ExtensionRegistry;
import org.jboss.as.controller.operations.common.ProcessEnvironment;
import org.jboss.as.controller.persistence.ExtensibleConfigurationPersister;
import org.jboss.as.controller.persistence.NullConfigurationPersister;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
Expand Down Expand Up @@ -80,6 +81,7 @@
import org.jboss.as.server.controller.resources.VersionModelInitializer;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.version.ProductConfig;
import org.jboss.as.version.Stability;
import org.jboss.as.version.Version;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.StartContext;
Expand All @@ -102,6 +104,7 @@ class TestModelControllerService extends ModelTestModelControllerService {
private final ControlledProcessState processState;
private final ExtensionRegistry extensionRegistry;
private final CapabilityRegistry capabilityRegistry;
private final Stability stability;
private volatile Initializer initializer;

TestModelControllerService(ProcessType processType, RunningModeControl runningModeControl, StringConfigurationPersister persister, ModelTestOperationValidatorFilter validateOpsFilter,
Expand All @@ -110,6 +113,7 @@ class TestModelControllerService extends ModelTestModelControllerService {
super(processType, extensionRegistry.getStability(), runningModeControl, null, persister, validateOpsFilter, rootResourceDefinition, processState,
expressionResolver, capabilityRegistry);
this.type = type;
this.stability = extensionRegistry.getStability();
this.runningModeControl = runningModeControl;
this.pathManagerService = type == TestModelType.STANDALONE ? new ServerPathManagerService(capabilityRegistry) : new HostPathManagerService(capabilityRegistry);
this.modelInitializer = modelInitializer;
Expand Down Expand Up @@ -191,13 +195,15 @@ private ServerEnvironment createStandaloneServerEnvironment() {
throw new RuntimeException(e);
}
props.put(ServerEnvironment.JBOSS_SERVER_DEFAULT_CONFIG, "standalone.xml");
ProductConfig pc = new ProductConfig("Test", Version.AS_VERSION, "main");
return new ServerEnvironment(null, props, new HashMap<String, String>(), "standalone.xml", null, LaunchType.STANDALONE, runningModeControl.getRunningMode(), pc, false);
props.put(ProcessEnvironment.STABILITY, this.stability.toString());

ProductConfig productConfig = new ProductConfig("Standalone-under-test", Version.AS_VERSION, "main", this.stability);
return new ServerEnvironment(null, props, new HashMap<>(), "standalone.xml", null, LaunchType.STANDALONE, runningModeControl.getRunningMode(), productConfig, false);
}

private HostControllerEnvironment createHostControllerEnvironment() {
try {
Map<String, String> props = new HashMap<String, String>();
Map<String, String> props = new HashMap<>();
File home = new File("target/jbossas");
delete(home);
home.mkdir();
Expand Down Expand Up @@ -230,7 +236,11 @@ private HostControllerEnvironment createHostControllerEnvironment() {
RunningMode initialRunningMode = runningModeControl.getRunningMode();
boolean backupDomainFiles = false;
boolean useCachedDc = false;
ProductConfig productConfig = ProductConfig.fromFilesystemSlot(null, "", props);

props.put(ProcessEnvironment.STABILITY, this.stability.toString());

ProductConfig productConfig = new ProductConfig("HostController-under-test", Version.AS_VERSION, "main", this.stability);

return new HostControllerEnvironment(props, isRestart, modulePath, processControllerAddress, processControllerPort,
hostControllerAddress, hostControllerPort, defaultJVM, domainConfig, initialDomainConfig, hostConfig, initialHostConfig,
initialRunningMode, backupDomainFiles, useCachedDc, productConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static List<TransformersTestParameter> setupVersions(){
//we only test EAP 7.4 and newer
data.add(new TransformersTestParameter(ModelVersion.create(16, 0, 0), ModelTestControllerVersion.EAP_7_4_0));
data.add(new TransformersTestParameter(ModelVersion.create(22, 0, 0), ModelTestControllerVersion.EAP_8_0_0));
// Requires an update of the wildfly legacy test version
// data.add(new TransformersTestParameter(ModelVersion.create(24, 0, 0), ModelTestControllerVersion.WILDFLY_31_0_0));
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ public void testTransformerEAP800() throws Exception {
}

private KernelServices buildKernelServices(String xml, ModelTestControllerVersion controllerVersion, ModelVersion version, String... mavenResourceURLs) throws Exception {
KernelServicesBuilder builder = this.createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT).setSubsystemXml(xml);
AdditionalInitialization additionalInitialization = AdditionalInitialization.fromModelTestControllerVersion(controllerVersion);

builder.createLegacyKernelServicesBuilder(AdditionalInitialization.MANAGEMENT, controllerVersion, version)
KernelServicesBuilder builder = this.createKernelServicesBuilder(additionalInitialization).setSubsystemXml(xml);

builder.createLegacyKernelServicesBuilder(additionalInitialization, controllerVersion, version)
.addMavenResourceURL(mavenResourceURLs)
.skipReverseControllerCheck()
.addParentFirstClassPattern("org.jboss.as.controller.logging.ControllerLogger*")
Expand Down Expand Up @@ -151,8 +153,8 @@ private void testRejectingTransformers(ModelTestControllerVersion controllerVers
ModelVersion elytronVersion = controllerVersion.getSubsystemModelVersion(getMainSubsystemName());

//Boot up empty controllers with the resources needed for the ops coming from the xml to work
KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.withCapabilities(
RuntimeCapability.buildDynamicCapabilityName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, "ExampleDS")
KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.withCapabilities(controllerVersion.getStability(),
RuntimeCapability.buildDynamicCapabilityName(Capabilities.DATA_SOURCE_CAPABILITY_NAME, "ExampleDS")
));
builder.createLegacyKernelServicesBuilder(AdditionalInitialization.MANAGEMENT, controllerVersion, elytronVersion)
.addMavenResourceURL(controllerVersion.getCoreMavenGroupId() + ":wildfly-elytron-integration:" + controllerVersion.getCoreVersion())
Expand Down
Loading

0 comments on commit 1650871

Please sign in to comment.