Skip to content
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-7091] Create the ModelTestModelControllerService variants for the WF 31 controllers #6280

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems to duplicate a lot of the code from the previous method. Can they be unified more?


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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be unified, e.g. so we just pass in null for the stabilty? If so you can get rid of this whole if/else block

}
} 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 @@ -94,6 +94,7 @@
import org.jboss.dmr.Property;
import org.jboss.staxmapper.XMLMapper;
import org.junit.Assert;
import org.junit.Assume;
import org.wildfly.common.xml.XMLInputFactoryUtil;
import org.wildfly.legacy.test.spi.Version;

Expand Down Expand Up @@ -446,7 +447,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,16 +684,19 @@ 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;
private ModelFixer reverseCheckLegacyModelFixer;
private ModelTestOperationValidatorFilter.Builder operationValidationExcludeFilterBuilder;

LegacyKernelServicesInitializerImpl(ModelVersion modelVersion, ModelTestControllerVersion version) {
Assume.assumeFalse("This model controller version is ignored for this server.", version.isIgnored());
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 +705,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 +740,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 +800,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 @@ -30,6 +30,7 @@
import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.AssumptionViolatedException;
import org.junit.Test;
import org.junit.runner.RunWith;

Expand Down Expand Up @@ -66,6 +67,9 @@ public void domainDeployment() throws Exception {
KernelServices legacyServices = mainServices.getLegacyServices(modelVersion);
Assert.assertTrue("Legacy services didn't boot for version " + modelVersion, legacyServices.isSuccessfulBoot());
checkCoreModelTransformation(mainServices, modelVersion);
} catch (AssumptionViolatedException ex) {
// If the test is ignored, we want to propagate the exception
throw ex;
} catch (Exception ex) {
throw new RuntimeException("Error for version " + modelVersion + " " + ex.getMessage(), ex);
}
Expand All @@ -86,10 +90,13 @@ public void domainExplodedDeployment() throws Exception {

List<ModelNode> operations = builder.parseXmlResource("domain-exploded-deployments.xml");
//removing the ading of "management-client-content" => "rollout-plans
operations = operations.subList(0, operations.size() -2);
operations = operations.subList(0, operations.size() - 2);
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, modelVersion, operations, getConfig());
} catch (AssumptionViolatedException ex) {
// If the test is ignored, we want to propagate the exception
throw ex;
} catch (Exception ex) {
throw new RuntimeException("Error for version " + modelVersion + " " + ex.getMessage(), ex);
throw new Exception("Error for version " + modelVersion + " " + ex.getMessage(), ex);
}
}

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
Loading
Loading