Skip to content

Commit

Permalink
[WFCORE-4510] Configure the remoting subsystem endpoint by reading fr…
Browse files Browse the repository at this point in the history
…om the subsystem root resource
  • Loading branch information
bstansberry committed Jun 6, 2019
1 parent df1dfca commit aa868e7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,10 @@ public void testRuntime() throws Exception {
.setSubsystemXml(getSubsystemXml())
.build();

ServiceController<Endpoint> endPointServiceController = (ServiceController<Endpoint>) 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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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<String, ModelNode> entry : ENDPOINT_CONFIG_TEST_DATA.entrySet()) {
Expand All @@ -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);
Expand Down Expand Up @@ -284,6 +310,22 @@ private static void checkEndpointSettings(ModelNode node, Map<String, ModelNode>
}
}

private static void checkEndpointService(KernelServices services) {
@SuppressWarnings("unchecked")
ServiceController<Endpoint> endPointServiceController = (ServiceController<Endpoint>) 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);
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit aa868e7

Please sign in to comment.