From aa868e7776c75bfe2f2a91b50b9c70310da2a867 Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Thu, 6 Jun 2019 17:37:42 -0500 Subject: [PATCH] [WFCORE-4510] Configure the remoting subsystem endpoint by reading from the subsystem root resource --- .../as/remoting/RemotingSubsystemAdd.java | 7 +- .../remoting/RemotingSubsystemTestCase.java | 66 +++++++++++++++---- 2 files changed, 58 insertions(+), 15 deletions(-) diff --git a/remoting/subsystem/src/main/java/org/jboss/as/remoting/RemotingSubsystemAdd.java b/remoting/subsystem/src/main/java/org/jboss/as/remoting/RemotingSubsystemAdd.java index a6fec9a8da7..b87c08574b2 100644 --- a/remoting/subsystem/src/main/java/org/jboss/as/remoting/RemotingSubsystemAdd.java +++ b/remoting/subsystem/src/main/java/org/jboss/as/remoting/RemotingSubsystemAdd.java @@ -30,7 +30,6 @@ import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; -import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.ProcessType; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; @@ -63,9 +62,11 @@ protected void populateModel(OperationContext context, ModelNode operation, Reso } @Override - protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { + protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { - ModelNode endpointModel = context.readResource(PathAddress.pathAddress(RemotingEndpointResource.ENDPOINT_PATH)).getModel(); + // WFCORE-4510 -- the effective endpoint configuration is from the root subsystem resource, + // not from the placeholder configuration=endpoint child resource. + ModelNode endpointModel = resource.getModel(); String workerName = WORKER.resolveModelAttribute(context, endpointModel).asString(); final OptionMap map = EndpointConfigFactory.populate(context, endpointModel); diff --git a/remoting/tests/src/test/java/org/jboss/as/remoting/RemotingSubsystemTestCase.java b/remoting/tests/src/test/java/org/jboss/as/remoting/RemotingSubsystemTestCase.java index ab5a6c12d34..cc2cd3e5d97 100644 --- a/remoting/tests/src/test/java/org/jboss/as/remoting/RemotingSubsystemTestCase.java +++ b/remoting/tests/src/test/java/org/jboss/as/remoting/RemotingSubsystemTestCase.java @@ -120,12 +120,10 @@ public void testRuntime() throws Exception { .setSubsystemXml(getSubsystemXml()) .build(); - ServiceController endPointServiceController = (ServiceController) services.getContainer().getRequiredService(RemotingServices.SUBSYSTEM_ENDPOINT); - endPointServiceController.setMode(ServiceController.Mode.ACTIVE); - Endpoint endpointService = endPointServiceController.getValue(); - assertNotNull("Endpoint service was null", endpointService); - assertNotNull(endpointService.getName()); - + checkEndpointService(services); + // Endpoint demanded 'default-remoting' worker, not 'default' + checkWorkerService(services, "default", ServiceController.State.DOWN); + checkWorkerService(services, "default-remoting", ServiceController.State.UP); ServiceName connectorServiceName = RemotingServices.serverServiceName("remoting-connector"); ServiceController remotingConnectorController = services.getContainer().getRequiredService(connectorServiceName); @@ -170,14 +168,23 @@ public void testSchemaOfSubsystemTemplates() throws Exception { */ @Test public void testEndpointConfigurationViaDeprecatedChild() throws Exception { - KernelServices services = createKernelServicesBuilder(createAdditionalInitialization()) + KernelServices services = createKernelServicesBuilder(createRuntimeAdditionalInitialization()) .build(); + checkWorkerService(services, "default", ServiceController.State.DOWN); + checkWorkerService(services, "default-remoting", ServiceController.State.DOWN); + // First, just the root resource with the endpoint unconfigured ModelNode rootAdd = Util.createAddOperation(ROOT_ADDRESS); services.executeForResult(rootAdd); checkEndpointSettings(services, Collections.emptyMap(), true); + // Confirm the endpoint service is correct + checkEndpointService(services); + // Endpoint demanded 'default' worker, not 'default-remoting' + checkWorkerService(services, "default", ServiceController.State.UP); + checkWorkerService(services, "default-remoting", ServiceController.State.DOWN); + // Now, add the child resource with no config. ModelNode childAdd = Util.createAddOperation(ENDPOINT_CONFIG_ADDRESS); services.executeForResult(childAdd); @@ -191,8 +198,12 @@ public void testEndpointConfigurationViaDeprecatedChild() throws Exception { services.executeForResult(childAdd); checkEndpointSettings(services, ENDPOINT_CONFIG_TEST_DATA, true); - // Remove all so we can start over - services.executeForResult(Util.createRemoveOperation(ROOT_ADDRESS)); + // Create new KernelServices so we can start over with clean MSC + services = createKernelServicesBuilder(createRuntimeAdditionalInitialization()) + .build(); + + checkWorkerService(services, "default", ServiceController.State.DOWN); + checkWorkerService(services, "default-remoting", ServiceController.State.DOWN); // Do the adds via a composite ModelNode composite = Util.createEmptyOperation(COMPOSITE, PathAddress.EMPTY_ADDRESS); @@ -201,6 +212,12 @@ public void testEndpointConfigurationViaDeprecatedChild() throws Exception { services.executeForResult(composite); checkEndpointSettings(services, ENDPOINT_CONFIG_TEST_DATA, true); + // Confirm the endpoint service is correct + checkEndpointService(services); + // Endpoint demanded 'default-remoting' worker, not 'default' + checkWorkerService(services, "default", ServiceController.State.DOWN); + checkWorkerService(services, "default-remoting", ServiceController.State.UP); + // Do an undefine-attribute for all children for (String attr : ENDPOINT_CONFIG_TEST_DATA.keySet()) { ModelNode op = Util.createEmptyOperation(UNDEFINE_ATTRIBUTE_OPERATION, ENDPOINT_CONFIG_ADDRESS); @@ -227,9 +244,12 @@ public void testEndpointConfigurationViaDeprecatedChild() throws Exception { */ @Test public void testEndpointConfigurationViaSubsystemRoot() throws Exception { - KernelServices services = createKernelServicesBuilder(createAdditionalInitialization()) + KernelServices services = createKernelServicesBuilder(createRuntimeAdditionalInitialization()) .build(); + checkWorkerService(services, "default", ServiceController.State.DOWN); + checkWorkerService(services, "default-remoting", ServiceController.State.DOWN); + // Add the root resource with the endpoint configured ModelNode rootAdd = Util.createAddOperation(ROOT_ADDRESS); for (Map.Entry entry : ENDPOINT_CONFIG_TEST_DATA.entrySet()) { @@ -238,6 +258,12 @@ public void testEndpointConfigurationViaSubsystemRoot() throws Exception { services.executeForResult(rootAdd); checkEndpointSettings(services, ENDPOINT_CONFIG_TEST_DATA, true); + // Confirm the endpoint service is correct + checkEndpointService(services); + // Endpoint demanded 'default-remoting' worker, not 'default' + checkWorkerService(services, "default", ServiceController.State.DOWN); + checkWorkerService(services, "default-remoting", ServiceController.State.UP); + // Do an undefine-attribute for all children for (String attr : ENDPOINT_CONFIG_TEST_DATA.keySet()) { ModelNode op = Util.createEmptyOperation(UNDEFINE_ATTRIBUTE_OPERATION, ROOT_ADDRESS); @@ -284,6 +310,22 @@ private static void checkEndpointSettings(ModelNode node, Map } } + private static void checkEndpointService(KernelServices services) { + @SuppressWarnings("unchecked") + ServiceController endPointServiceController = (ServiceController) services.getContainer().getRequiredService(RemotingServices.SUBSYSTEM_ENDPOINT); + endPointServiceController.setMode(ServiceController.Mode.ACTIVE); + Endpoint endpointService = endPointServiceController.getValue(); + assertNotNull("Endpoint service was null", endpointService); + assertNotNull(endpointService.getName()); + } + + private static void checkWorkerService(KernelServices services, String workerName, ServiceController.State expectedState) { + ServiceName serviceName = IOServices.WORKER.append(workerName); + ServiceController endPointServiceController = services.getContainer().getRequiredService(serviceName); + assertNotNull("Endpoint service was null", endPointServiceController); + assertEquals(expectedState, endPointServiceController.getState()); + } + @Override protected String getSubsystemXml(String resource) throws IOException { return readResource(resource); @@ -327,10 +369,10 @@ protected void addExtraServices(ServiceTarget target) { //Needed for initialization of the RealmAuthenticationProviderService AbsolutePathService.addService(ServerEnvironment.CONTROLLER_TEMP_DIR, new File("target/temp" + System.currentTimeMillis()).getAbsolutePath(), target); target.addService(IOServices.WORKER.append("default"), new WorkerService(Xnio.getInstance().createWorkerBuilder().setWorkerIoThreads(2))) - .setInitialMode(ServiceController.Mode.ACTIVE) + .setInitialMode(ServiceController.Mode.ON_DEMAND) .install(); target.addService(IOServices.WORKER.append("default-remoting"), new WorkerService(Xnio.getInstance().createWorkerBuilder().setWorkerIoThreads(2))) - .setInitialMode(ServiceController.Mode.ACTIVE) + .setInitialMode(ServiceController.Mode.ON_DEMAND) .install(); }