From a24d8acaf50b68b24d99d5cf03272574c5d2be0c Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Wed, 7 Oct 2015 20:13:39 +0200 Subject: [PATCH] Revert "Revert "WFLY-5489 Fix and and add missing transformations for EAP in modcluster subsystem"" This reverts commit df351c859609841f8837144d016e4f1cee7070ca. --- .../ModClusterConfigResourceDefinition.java | 4 +- .../mod_cluster/ModClusterModel.java | 1 + .../ModClusterSubsystemParsingTestCase.java | 120 ++++++++ .../ModClusterSubsystemTestCase.java | 255 ----------------- .../ModClusterTransformersTestCase.java | 263 ++++++++++++++++++ .../extension/mod_cluster/package-info.java | 39 +++ ...em_2_0-reject.xml => subsystem-reject.xml} | 9 +- .../mod_cluster/subsystem-transform.xml | 75 +++++ .../extension/mod_cluster/subsystem_1_0.xml | 24 +- .../extension/mod_cluster/subsystem_1_1.xml | 12 +- .../extension/mod_cluster/subsystem_1_2.xml | 5 +- .../extension/mod_cluster/subsystem_2_0.xml | 4 +- .../subsystem_2_0_simple-load-provider.xml | 26 +- 13 files changed, 533 insertions(+), 304 deletions(-) create mode 100644 mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemParsingTestCase.java delete mode 100644 mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemTestCase.java create mode 100644 mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterTransformersTestCase.java create mode 100644 mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/package-info.java rename mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/{subsystem_2_0-reject.xml => subsystem-reject.xml} (96%) create mode 100644 mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem-transform.xml diff --git a/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterConfigResourceDefinition.java b/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterConfigResourceDefinition.java index 6b9f58e91dd9..a3158d22893a 100644 --- a/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterConfigResourceDefinition.java +++ b/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterConfigResourceDefinition.java @@ -73,7 +73,7 @@ class ModClusterConfigResourceDefinition extends SimpleResourceDefinition { static final SimpleAttributeDefinition SESSION_DRAINING_STRATEGY = SimpleAttributeDefinitionBuilder.create(CommonAttributes.SESSION_DRAINING_STRATEGY, ModelType.STRING, true) .setAllowExpression(true) .setDefaultValue(new ModelNode(SessionDrainingStrategyEnum.DEFAULT.name())) - .setValidator(new EnumValidator(SessionDrainingStrategyEnum.class, true, true, + .setValidator(new EnumValidator<>(SessionDrainingStrategyEnum.class, true, true, SessionDrainingStrategyEnum.ALWAYS, SessionDrainingStrategyEnum.DEFAULT, SessionDrainingStrategyEnum.NEVER)) @@ -310,7 +310,7 @@ public static void buildTransformation(ModelVersion version, ResourceTransformat .end(); } - if (ModClusterModel.VERSION_2_0_0.requiresTransformation(version)) { + if (ModClusterModel.VERSION_1_5_0.requiresTransformation(version)) { builder.getAttributeBuilder() .addRejectCheck(SessionDrainingStrategyChecker.INSTANCE, SESSION_DRAINING_STRATEGY) .setDiscard(SessionDrainingStrategyChecker.INSTANCE, SESSION_DRAINING_STRATEGY) diff --git a/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterModel.java b/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterModel.java index 874eb28e2de5..014fe62f88dd 100644 --- a/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterModel.java +++ b/mod_cluster/extension/src/main/java/org/wildfly/extension/mod_cluster/ModClusterModel.java @@ -32,6 +32,7 @@ public enum ModClusterModel { VERSION_1_4_0(1, 4, 0), + VERSION_1_5_0(1, 5, 0), VERSION_2_0_0(2, 0, 0), VERSION_3_0_0(3, 0, 0), ; diff --git a/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemParsingTestCase.java b/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemParsingTestCase.java new file mode 100644 index 000000000000..940c25d27b18 --- /dev/null +++ b/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemParsingTestCase.java @@ -0,0 +1,120 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2015, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.wildfly.extension.mod_cluster; + +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SSL; +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; +import static org.wildfly.extension.mod_cluster.CommonAttributes.CONFIGURATION; +import static org.wildfly.extension.mod_cluster.CommonAttributes.MOD_CLUSTER_CONFIG; + +import java.io.IOException; + +import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; +import org.jboss.as.subsystem.test.AdditionalInitialization; +import org.jboss.as.subsystem.test.KernelServices; +import org.jboss.as.subsystem.test.KernelServicesBuilder; +import org.jboss.dmr.ModelNode; +import org.jboss.modcluster.config.MCMPHandlerConfiguration; +import org.jboss.msc.service.ServiceController; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Kabir Khan + * @author Jean-Frederic Clere + * @author Radoslav Husar + * @version Apr 2015 + */ +public class ModClusterSubsystemParsingTestCase extends AbstractSubsystemBaseTest { + + public ModClusterSubsystemParsingTestCase() { + super(ModClusterExtension.SUBSYSTEM_NAME, new ModClusterExtension()); + } + + // --------------------------------------------------- Standard Subsystem tests + + @Test + public void testXsd10() throws Exception { + standardSubsystemTest("subsystem_1_0.xml", false); + } + + @Test + public void testXsd11() throws Exception { + standardSubsystemTest("subsystem_1_1.xml", false); + } + + @Test + public void testXsd12() throws Exception { + standardSubsystemTest("subsystem_1_2.xml", false); + } + + @Test + public void testSubsystemWithSimpleLoadProvider() throws Exception { + super.standardSubsystemTest("subsystem_2_0_simple-load-provider.xml"); + } + + @Override + protected String getSubsystemXml() throws IOException { + return readResource("subsystem_2_0.xml"); + } + + @Override + protected String getSubsystemXsdPath() throws Exception { + return "schema/jboss-as-mod-cluster_2_0.xsd"; + } + + @Override + protected String[] getSubsystemTemplatePaths() throws IOException { + return new String[] { + "/subsystem-templates/mod_cluster.xml" + }; + } + + @Test + public void testSSL() throws Exception { + KernelServicesBuilder builder = createKernelServicesBuilder(new AdditionalInitialization()).setSubsystemXml(getSubsystemXml()); + KernelServices services = builder.build(); + ModelNode model = services.readWholeModel(); + ModelNode config = model.get(SUBSYSTEM, getMainSubsystemName()).get(MOD_CLUSTER_CONFIG, CONFIGURATION); + ModelNode ssl = config.get(SSL, CONFIGURATION); + Assert.assertEquals("/home/rhusar/client-keystore.jks", ssl.get("ca-certificate-file").resolve().asString()); + Assert.assertEquals("/home/rhusar/revocations", ssl.get("ca-revocation-url").resolve().asString()); + Assert.assertEquals("/home/rhusar/client-keystore.jks", ssl.get("certificate-key-file").resolve().asString()); + Assert.assertEquals("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA", ssl.get("cipher-suite").resolve().asString()); + Assert.assertEquals("mykeyalias", ssl.get("key-alias").resolve().asString()); + Assert.assertEquals("mypassword", ssl.get("password").resolve().asString()); + Assert.assertEquals("TLSv1", ssl.get("protocol").resolve().asString()); + ServiceController service = services.getContainer().getService(ContainerEventHandlerService.CONFIG_SERVICE_NAME); + MCMPHandlerConfiguration sslConfig = (MCMPHandlerConfiguration) service.getValue(); + Assert.assertTrue(sslConfig.isSsl()); + Assert.assertEquals("mykeyalias", sslConfig.getSslKeyAlias()); + Assert.assertEquals("mypassword", sslConfig.getSslTrustStorePassword()); + Assert.assertEquals("mypassword", sslConfig.getSslKeyStorePassword()); + Assert.assertEquals("/home/rhusar/client-keystore.jks", sslConfig.getSslKeyStore()); + Assert.assertEquals("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA", sslConfig.getSslCiphers()); + Assert.assertEquals("TLSv1", sslConfig.getSslProtocol()); + Assert.assertEquals("/home/rhusar/client-keystore.jks", sslConfig.getSslTrustStore()); + Assert.assertEquals("/home/rhusar/revocations", sslConfig.getSslCrlFile()); + } + +} diff --git a/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemTestCase.java b/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemTestCase.java deleted file mode 100644 index 85afdc2b7c98..000000000000 --- a/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterSubsystemTestCase.java +++ /dev/null @@ -1,255 +0,0 @@ -/** - * JBoss, Home of Professional Open Source. - * Copyright 2013, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - -package org.wildfly.extension.mod_cluster; - -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SSL; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; -import static org.wildfly.extension.mod_cluster.CommonAttributes.CONFIGURATION; -import static org.wildfly.extension.mod_cluster.CommonAttributes.MOD_CLUSTER_CONFIG; - -import java.io.IOException; - -import org.jboss.as.controller.ModelVersion; -import org.jboss.as.controller.PathAddress; -import org.jboss.as.controller.PathElement; -import org.jboss.as.model.test.FailedOperationTransformationConfig; -import org.jboss.as.model.test.FailedOperationTransformationConfig.AttributesPathAddressConfig; -import org.jboss.as.model.test.FailedOperationTransformationConfig.ChainedConfig; -import org.jboss.as.model.test.ModelTestControllerVersion; -import org.jboss.as.model.test.ModelTestUtils; -import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; -import org.jboss.as.subsystem.test.AdditionalInitialization; -import org.jboss.as.subsystem.test.ControllerInitializer; -import org.jboss.as.subsystem.test.KernelServices; -import org.jboss.as.subsystem.test.KernelServicesBuilder; -import org.jboss.dmr.ModelNode; -import org.jboss.modcluster.config.MCMPHandlerConfiguration; -import org.jboss.msc.service.ServiceController; -import org.junit.Assert; -import org.junit.Test; - -/** - * Quick versions overview: - *

- * AS version / model version / schema version - * 7.3.0 / 1.4.0 / 1_2 - * 8.0.0 / 2.0.0 / 1_2 (this should have been 2_0...) - * 9.0.0 / 3.0.0 / 2_0 - * - * @author Kabir Khan - * @author Jean-Frederic Clere - * @author Radoslav Husar - */ -public class ModClusterSubsystemTestCase extends AbstractSubsystemBaseTest { - - public ModClusterSubsystemTestCase() { - super(ModClusterExtension.SUBSYSTEM_NAME, new ModClusterExtension()); - } - - // --------------------------------------------------- Standard Subsystem tests - - @Test - public void testXsd10() throws Exception { - standardSubsystemTest("subsystem_1_0.xml", false); - } - - @Test - public void testXsd11() throws Exception { - standardSubsystemTest("subsystem_1_1.xml", false); - } - - @Test - public void testXsd12() throws Exception { - standardSubsystemTest("subsystem_1_2.xml", false); - } - - @Test - public void testSubsystemWithSimpleLoadProvider() throws Exception { - super.standardSubsystemTest("subsystem_2_0_simple-load-provider.xml"); - } - - @Override - protected String getSubsystemXml() throws IOException { - return readResource("subsystem_2_0.xml"); - } - - @Override - protected String getSubsystemXsdPath() throws Exception { - return "schema/jboss-as-mod-cluster_2_0.xsd"; - } - - @Override - protected String[] getSubsystemTemplatePaths() throws IOException { - return new String[] { - "/subsystem-templates/mod_cluster.xml" - }; - } - - @Test - public void testTransformers800() throws Exception { - testTransformers_2_0_0(ModelTestControllerVersion.WILDFLY_8_0_0_FINAL, "1.3.0.Final"); - } - - private void testTransformers_2_0_0(ModelTestControllerVersion controllerVersion, String modClusterJarVersion) throws Exception { - String subsystemXml = getSubsystemXml(); - ModelVersion modelVersion = ModelVersion.create(2, 0, 0); - KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization()) - .setSubsystemXml(subsystemXml); - builder.createLegacyKernelServicesBuilder(null, controllerVersion, modelVersion) - .addMavenResourceURL("org.wildfly:wildfly-mod_cluster-extension:" + controllerVersion.getMavenGavVersion()) - .addMavenResourceURL("org.jboss.mod_cluster:mod_cluster-core:" + modClusterJarVersion) - .setExtensionClassName("org.wildfly.extension.mod_cluster.ModClusterExtension"); - - KernelServices mainServices = builder.build(); - KernelServices legacyServices = mainServices.getLegacyServices(modelVersion); - - Assert.assertNotNull(legacyServices); - Assert.assertTrue(mainServices.isSuccessfulBoot()); - Assert.assertTrue(legacyServices.isSuccessfulBoot()); - - checkSubsystemModelTransformation(mainServices, modelVersion); - } - - /** - * Tests that: - * - status-interval is rejected if set to value other than 10. - * - * @throws Exception - */ - @Test - public void testRejections800() throws Exception { - testRejections_2_0_0(ModelTestControllerVersion.WILDFLY_8_0_0_FINAL, "1.3.0.Final"); - } - - private void testRejections_2_0_0(ModelTestControllerVersion controllerVersion, String modClusterJarVersion) throws Exception { - String subsystemXml = readResource("subsystem_2_0-reject.xml"); - - ModelVersion modelVersion = ModelVersion.create(2, 0, 0); - KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization()); - - builder.createLegacyKernelServicesBuilder(null, controllerVersion, modelVersion) - .addMavenResourceURL("org.wildfly:wildfly-mod_cluster-extension:" + controllerVersion.getMavenGavVersion()) - .addMavenResourceURL("org.jboss.mod_cluster:mod_cluster-core:" + modClusterJarVersion) - .setExtensionClassName("org.wildfly.extension.mod_cluster.ModClusterExtension"); - - KernelServices mainServices = builder.build(); - KernelServices legacyServices = mainServices.getLegacyServices(modelVersion); - Assert.assertNotNull(legacyServices); - Assert.assertTrue(mainServices.isSuccessfulBoot()); - Assert.assertTrue(legacyServices.isSuccessfulBoot()); - - PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, ModClusterExtension.SUBSYSTEM_NAME)) - .append(PathElement.pathElement(MOD_CLUSTER_CONFIG, CONFIGURATION)); - ModelTestUtils.checkFailedTransformedBootOperations(mainServices, modelVersion, parse(subsystemXml), - new FailedOperationTransformationConfig() - .addFailedAttribute(addr, - ChainedConfig.createBuilder(CommonAttributes.STATUS_INTERVAL) - .addConfig(new StatusIntervalConfig(CommonAttributes.STATUS_INTERVAL)) - .addConfig(new ProxiesConfig(CommonAttributes.PROXIES)) - .build()) - ); - } - - @Test - public void testSSL() throws Exception { - KernelServicesBuilder builder = createKernelServicesBuilder(new AdditionalInitialization()).setSubsystemXml(getSubsystemXml()); - KernelServices services = builder.build(); - ModelNode model = services.readWholeModel(); - ModelNode config = model.get(SUBSYSTEM, getMainSubsystemName()).get(MOD_CLUSTER_CONFIG, CONFIGURATION); - ModelNode ssl = config.get(SSL, CONFIGURATION); - Assert.assertEquals("/home/rhusar/client-keystore.jks", ssl.get("ca-certificate-file").resolve().asString()); - Assert.assertEquals("/home/rhusar/revocations", ssl.get("ca-revocation-url").resolve().asString()); - Assert.assertEquals("/home/rhusar/client-keystore.jks", ssl.get("certificate-key-file").resolve().asString()); - Assert.assertEquals("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA", ssl.get("cipher-suite").resolve().asString()); - Assert.assertEquals("mykeyalias", ssl.get("key-alias").resolve().asString()); - Assert.assertEquals("mypassword", ssl.get("password").resolve().asString()); - Assert.assertEquals("TLSv1", ssl.get("protocol").resolve().asString()); - ServiceController service = services.getContainer().getService(ContainerEventHandlerService.CONFIG_SERVICE_NAME); - MCMPHandlerConfiguration sslConfig = (MCMPHandlerConfiguration) service.getValue(); - Assert.assertTrue(sslConfig.isSsl()); - Assert.assertEquals("mykeyalias", sslConfig.getSslKeyAlias()); - Assert.assertEquals("mypassword", sslConfig.getSslTrustStorePassword()); - Assert.assertEquals("mypassword", sslConfig.getSslKeyStorePassword()); - Assert.assertEquals("/home/rhusar/client-keystore.jks", sslConfig.getSslKeyStore()); - Assert.assertEquals("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA", sslConfig.getSslCiphers()); - Assert.assertEquals("TLSv1", sslConfig.getSslProtocol()); - Assert.assertEquals("/home/rhusar/client-keystore.jks", sslConfig.getSslTrustStore()); - Assert.assertEquals("/home/rhusar/revocations", sslConfig.getSslCrlFile()); - } - - private static class ProxiesConfig extends AttributesPathAddressConfig { - public ProxiesConfig(String... attributes) { - super(attributes); - } - - @Override - protected boolean isAttributeWritable(String attributeName) { - return true; - } - - @Override - protected boolean checkValue(String attrName, ModelNode attribute, boolean isWriteAttribute) { - return !attribute.equals(new ModelNode()); - } - - @Override - protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute) { - return new ModelNode(); - } - } - - private static class StatusIntervalConfig extends AttributesPathAddressConfig { - public StatusIntervalConfig(String... attributes) { - super(attributes); - } - - @Override - protected boolean isAttributeWritable(String attributeName) { - return true; - } - - @Override - protected boolean checkValue(String attrName, ModelNode attribute, boolean isWriteAttribute) { - return !attribute.equals(new ModelNode(10)); - } - - @Override - protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute) { - return new ModelNode(10); - } - } - - @Override - protected AdditionalInitialization createAdditionalInitialization() { - return new AdditionalInitialization.ManagementAdditionalInitialization() { - @Override - protected void setupController(ControllerInitializer controllerInitializer) { - super.setupController(controllerInitializer); - - controllerInitializer.addSocketBinding("modcluster", 0); // "224.0.1.105", "23364" - controllerInitializer.addRemoteOutboundSocketBinding("proxy1", "localhost", 6666); - controllerInitializer.addRemoteOutboundSocketBinding("proxy2", "localhost", 6766); - } - }; - } -} diff --git a/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterTransformersTestCase.java b/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterTransformersTestCase.java new file mode 100644 index 000000000000..6b2e31c28270 --- /dev/null +++ b/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/ModClusterTransformersTestCase.java @@ -0,0 +1,263 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2015, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.wildfly.extension.mod_cluster; + +import org.jboss.as.controller.ModelVersion; +import org.jboss.as.controller.PathAddress; +import org.jboss.as.model.test.FailedOperationTransformationConfig; +import org.jboss.as.model.test.ModelTestControllerVersion; +import org.jboss.as.model.test.ModelTestUtils; +import org.jboss.as.subsystem.test.AbstractSubsystemTest; +import org.jboss.as.subsystem.test.AdditionalInitialization; +import org.jboss.as.subsystem.test.ControllerInitializer; +import org.jboss.as.subsystem.test.KernelServices; +import org.jboss.as.subsystem.test.KernelServicesBuilder; +import org.jboss.dmr.ModelNode; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Radoslav Husar + * @version Oct 2015 + */ +public class ModClusterTransformersTestCase extends AbstractSubsystemTest { + + public ModClusterTransformersTestCase() { + super(ModClusterExtension.SUBSYSTEM_NAME, new ModClusterExtension()); + } + + private static String formatSubsystemArtifact(ModelTestControllerVersion version) { + return formatArtifact("org.wildfly:wildfly-mod_cluster-extension:%s", version); + } + + private static String formatLegacySubsystemArtifact(ModelTestControllerVersion version) { + return formatArtifact("org.jboss.as:jboss-as-modcluster:%s", version); + } + + private static String formatArtifact(String pattern, ModelTestControllerVersion version) { + return String.format(pattern, version.getMavenGavVersion()); + } + + @Test + public void testTransformerEAP_6_2_0() throws Exception { + ModelTestControllerVersion version = ModelTestControllerVersion.EAP_6_2_0; + this.testTransformation(ModClusterModel.VERSION_1_4_0, version, + formatLegacySubsystemArtifact(version), + "org.jboss.mod_cluster:mod_cluster-core:1.2.6.Final-redhat-1" + ); + } + + @Test + public void testTransformerEAP_6_3_0() throws Exception { + ModelTestControllerVersion version = ModelTestControllerVersion.EAP_6_3_0; + this.testTransformation(ModClusterModel.VERSION_1_5_0, version, + formatLegacySubsystemArtifact(version), + "org.jboss.mod_cluster:mod_cluster-core:1.2.9.Final-redhat-1" + ); + } + + @Test + public void testTransformerEAP_6_4_0() throws Exception { + ModelTestControllerVersion version = ModelTestControllerVersion.EAP_6_4_0; + this.testTransformation(ModClusterModel.VERSION_1_5_0, version, + formatLegacySubsystemArtifact(version), + "org.jboss.mod_cluster:mod_cluster-core:1.2.11.Final-redhat-1" + ); + } + + private void testTransformation(ModClusterModel model, ModelTestControllerVersion controllerVersion, String... dependencies) throws Exception { + String subsystemXml = readResource("subsystem-transform.xml"); + ModelVersion modelVersion = model.getVersion(); + String extensionClassName = (model.getVersion().getMajor() == 1) ? "org.jboss.as.modcluster.ModClusterExtension" : "org.wildfly.extension.mod_cluster.ModClusterExtension"; + + KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization()) + .setSubsystemXml(subsystemXml); + builder.createLegacyKernelServicesBuilder(null, controllerVersion, modelVersion) + .addMavenResourceURL(dependencies) + .setExtensionClassName(extensionClassName); + + KernelServices mainServices = builder.build(); + KernelServices legacyServices = mainServices.getLegacyServices(modelVersion); + + Assert.assertNotNull(legacyServices); + Assert.assertTrue(mainServices.isSuccessfulBoot()); + Assert.assertTrue(legacyServices.isSuccessfulBoot()); + + checkSubsystemModelTransformation(mainServices, modelVersion, null, false); + } + + @Test + public void testRejectionsEAP_6_2_0() throws Exception { + ModelTestControllerVersion version = ModelTestControllerVersion.EAP_6_2_0; + this.testRejections(ModClusterModel.VERSION_1_4_0, version, + formatLegacySubsystemArtifact(version), + "org.jboss.mod_cluster:mod_cluster-core:1.2.6.Final-redhat-1" + ); + } + + @Test + public void testRejectionsEAP_6_3_0() throws Exception { + ModelTestControllerVersion version = ModelTestControllerVersion.EAP_6_3_0; + this.testRejections(ModClusterModel.VERSION_1_5_0, version, + formatLegacySubsystemArtifact(version), + "org.jboss.mod_cluster:mod_cluster-core:1.2.9.Final-redhat-1" + ); + } + + @Test + public void testRejectionsEAP_6_4_0() throws Exception { + ModelTestControllerVersion version = ModelTestControllerVersion.EAP_6_4_0; + this.testRejections(ModClusterModel.VERSION_1_5_0, version, + formatLegacySubsystemArtifact(version), + "org.jboss.mod_cluster:mod_cluster-core:1.2.11.Final-redhat-1" + ); + } + + private void testRejections(ModClusterModel model, ModelTestControllerVersion controllerVersion, String... dependencies) throws Exception { + String subsystemXml = readResource("subsystem-reject.xml"); + ModelVersion modelVersion = model.getVersion(); + String extensionClassName = (model.getVersion().getMajor() == 1) ? "org.jboss.as.modcluster.ModClusterExtension" : "org.wildfly.extension.mod_cluster.ModClusterExtension"; + + KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization()); + builder.createLegacyKernelServicesBuilder(null, controllerVersion, modelVersion) + .addMavenResourceURL(dependencies) + .setExtensionClassName(extensionClassName); + + KernelServices mainServices = builder.build(); + KernelServices legacyServices = mainServices.getLegacyServices(modelVersion); + + Assert.assertNotNull(legacyServices); + Assert.assertTrue(mainServices.isSuccessfulBoot()); + Assert.assertTrue(legacyServices.isSuccessfulBoot()); + + ModelTestUtils.checkFailedTransformedBootOperations(mainServices, modelVersion, parse(subsystemXml), createFailedOperationConfig(modelVersion)); + } + + /** + * Changed attributes: + * + * - proxies configuration + * - status-interval is rejected if set to value other than 10 + * - session-draining-strategy configuration + */ + private static FailedOperationTransformationConfig createFailedOperationConfig(ModelVersion version) { + FailedOperationTransformationConfig config = new FailedOperationTransformationConfig(); + + PathAddress subsystemAddress = PathAddress.pathAddress(ModClusterSubsystemResourceDefinition.PATH); + PathAddress configurationAddress = subsystemAddress.append(ModClusterConfigResourceDefinition.PATH); + + if (ModClusterModel.VERSION_3_0_0.requiresTransformation(version)) { + config.addFailedAttribute(configurationAddress, FailedOperationTransformationConfig.ChainedConfig.createBuilder(CommonAttributes.STATUS_INTERVAL, CommonAttributes.PROXIES) + .addConfig(new StatusIntervalConfig(CommonAttributes.STATUS_INTERVAL)) + .addConfig(new ProxiesConfig(CommonAttributes.PROXIES)) + .build()); + } + + if (ModClusterModel.VERSION_1_5_0.requiresTransformation(version)) { + config.addFailedAttribute(configurationAddress, FailedOperationTransformationConfig.ChainedConfig.createBuilder(CommonAttributes.STATUS_INTERVAL, CommonAttributes.PROXIES, CommonAttributes.SESSION_DRAINING_STRATEGY) + .addConfig(new StatusIntervalConfig(CommonAttributes.STATUS_INTERVAL)) + .addConfig(new ProxiesConfig(CommonAttributes.PROXIES)) + .addConfig(new SessionDrainingStrategyConfig(CommonAttributes.SESSION_DRAINING_STRATEGY)) + .build()); + } + + return config; + } + + private static class SessionDrainingStrategyConfig extends FailedOperationTransformationConfig.AttributesPathAddressConfig { + public SessionDrainingStrategyConfig(String... attributes) { + super(attributes); + } + + @Override + protected boolean isAttributeWritable(String attributeName) { + return true; + } + + @Override + protected boolean checkValue(String attrName, ModelNode attribute, boolean isWriteAttribute) { + return !(attribute.equals(new ModelNode()) || attribute.equals(new ModelNode("DEFAULT"))); + } + + @Override + protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute) { + return new ModelNode("DEFAULT"); + } + } + + private static class ProxiesConfig extends FailedOperationTransformationConfig.AttributesPathAddressConfig { + public ProxiesConfig(String... attributes) { + super(attributes); + } + + @Override + protected boolean isAttributeWritable(String attributeName) { + return true; + } + + @Override + protected boolean checkValue(String attrName, ModelNode attribute, boolean isWriteAttribute) { + return !attribute.equals(new ModelNode()); + } + + @Override + protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute) { + return new ModelNode(); + } + } + + private static class StatusIntervalConfig extends FailedOperationTransformationConfig.AttributesPathAddressConfig { + public StatusIntervalConfig(String... attributes) { + super(attributes); + } + + @Override + protected boolean isAttributeWritable(String attributeName) { + return true; + } + + @Override + protected boolean checkValue(String attrName, ModelNode attribute, boolean isWriteAttribute) { + return !attribute.equals(new ModelNode(10)); + } + + @Override + protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute) { + return new ModelNode(10); + } + } + + protected AdditionalInitialization createAdditionalInitialization() { + return new AdditionalInitialization.ManagementAdditionalInitialization() { + @Override + protected void setupController(ControllerInitializer controllerInitializer) { + super.setupController(controllerInitializer); + + controllerInitializer.addSocketBinding("modcluster", 0); // "224.0.1.105", "23364" + controllerInitializer.addRemoteOutboundSocketBinding("proxy1", "localhost", 6666); + controllerInitializer.addRemoteOutboundSocketBinding("proxy2", "localhost", 6766); + controllerInitializer.addRemoteOutboundSocketBinding("proxy3", "localhost", 6866); + } + }; + } +} diff --git a/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/package-info.java b/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/package-info.java new file mode 100644 index 000000000000..7bc59e8044c1 --- /dev/null +++ b/mod_cluster/extension/src/test/java/org/wildfly/extension/mod_cluster/package-info.java @@ -0,0 +1,39 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2015, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +/** + * Package containing tests for mod_cluster subsystem. + * + * Versions overview: + * + * Server version / model version / schema version + * EAP 6.2.0 / 1.4.0 / 1_2 + * EAP 6.3.0 / 1.5.0 / 1_2 + * EAP 6.4.0 / 1.5.0 / 1_2 + * AS 8.0.0 / 2.0.0 / 1_2 (this should have been 2_0!) + * AS 9.0.0 / 3.0.0 / 2_0 + * AS 10.0.0 / 3.0.0 / 2_0 + * + * @author Radoslav Husar + * @version Apr 2015 + */ +package org.wildfly.extension.mod_cluster; \ No newline at end of file diff --git a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0-reject.xml b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem-reject.xml similarity index 96% rename from mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0-reject.xml rename to mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem-reject.xml index 8a2873f9920c..8920a15d4055 100644 --- a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0-reject.xml +++ b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem-reject.xml @@ -21,6 +21,7 @@ --> + - + session-draining-strategy="${modcluster.session-draining-strategy:ALWAYS}" + status-interval="15" + > diff --git a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem-transform.xml b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem-transform.xml new file mode 100644 index 000000000000..9c698ea446bd --- /dev/null +++ b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem-transform.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_0.xml b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_0.xml index e31ffdcdfeb4..4f00ef9b34d0 100644 --- a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_0.xml +++ b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_0.xml @@ -21,9 +21,15 @@ --> - - + @@ -38,11 +44,11 @@ + ca-revocation-url="/home/rhusar/revocations" + certificate-key-file="/home/rhusar/client-keystore.jks" + cipher-suite="SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA" + key-alias="mykeyalias" + password="mypassword" + protocol="TLS"/> diff --git a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_1.xml b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_1.xml index 610485013f25..2644e4393f2b 100644 --- a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_1.xml +++ b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_1.xml @@ -21,12 +21,16 @@ --> - - + stop-context-timeout="10" + > diff --git a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_2.xml b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_2.xml index e02e4a618edb..0efabce1bfcf 100644 --- a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_2.xml +++ b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_1_2.xml @@ -45,8 +45,7 @@ ttl="${modcluster.ttl:1}" worker-timeout="${modcluster.worker-timeout:2}" session-draining-strategy="${modcluster.session-draining-strategy:ALWAYS}" - > - + > @@ -69,6 +68,6 @@ cipher-suite="${modcluster.cipher-suite:SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA}" key-alias="${modcluster.key-alias:mykeyalias}" password="${modcluster.password:mypassword}" - protocol="${modcluster.protocol:TLS}"/> + protocol="${modcluster.protocol:TLSv1}"/> diff --git a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0.xml b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0.xml index 4c7915f733d6..3105e5447f26 100644 --- a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0.xml +++ b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0.xml @@ -34,8 +34,8 @@ max-attempts="${modcluster.max-attempts:10}" node-timeout="${modcluster.node-timeout:123}" ping="${modcluster.ping:10}" - proxy-url="${modcluster.proxy-url:/}" proxies="proxy1 proxy2" + proxy-url="${modcluster.proxy-url:/}" smax="${modcluster.smax:2}" socket-timeout="${modcluster.socket-timeout:20}" sticky-session="${modcluster.sticky-session:true}" @@ -46,7 +46,7 @@ worker-timeout="${modcluster.worker-timeout:2}" session-draining-strategy="${modcluster.session-draining-strategy:ALWAYS}" status-interval="10" - > + > diff --git a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0_simple-load-provider.xml b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0_simple-load-provider.xml index 6486c2dec34e..1e1cd4cda087 100644 --- a/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0_simple-load-provider.xml +++ b/mod_cluster/extension/src/test/resources/org/wildfly/extension/mod_cluster/subsystem_2_0_simple-load-provider.xml @@ -21,31 +21,7 @@ --> - +