Skip to content

Commit

Permalink
[AS7-6413] Fix up JGroups subsystem remove operation, part 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
rachmatowicz authored and bstansberry committed Jan 29, 2013
1 parent a12851d commit bdb7fd4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,44 @@ public class JGroupsSubsystemRemove extends AbstractRemoveStepHandler {

public static final JGroupsSubsystemRemove INSTANCE = new JGroupsSubsystemRemove();

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {

removeRuntimeServices(context, operation, model);
}

protected void removeRuntimeServices(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
// remove the subsystem first
ModelNode removeSubsystem = Util.createOperation(REMOVE, PathAddress.pathAddress(JGroupsExtension.SUBSYSTEM_PATH));
context.addStep(removeSubsystem, new OriginalSubsystemRemoveHandler(), OperationContext.Stage.IMMEDIATE);

// remove any existing child stacks
// now remove any existing child stacks
if (model.hasDefined(ModelKeys.STACK)) {
List<Property> stacks = model.get(ModelKeys.STACK).asPropertyList() ;
for (Property stack: stacks) {
PathAddress address = PathAddress.pathAddress(JGroupsExtension.SUBSYSTEM_PATH).append(ModelKeys.STACK, stack.getName());
ModelNode removeStack = Util.createOperation(REMOVE, address);
// just need to remove the existing stack services
ProtocolStackAdd.INSTANCE.removeRuntimeServices(context, removeStack, stack.getValue());
// remove the stack
context.addStep(removeStack, ProtocolStackRemove.INSTANCE, OperationContext.Stage.IMMEDIATE);
}
}

// remove the ProtocolDefaultsService
ServiceName protocolDefaultsService = ProtocolDefaultsService.SERVICE_NAME;
context.removeService(protocolDefaultsService);
context.stepCompleted();
}

static class OriginalSubsystemRemoveHandler extends AbstractRemoveStepHandler {

// remove the DefaultChannelFactoryServiceAlias
ServiceName defaultChannelFactoryService = ChannelFactoryService.getServiceName(null);
context.removeService(defaultChannelFactoryService);
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {
removeRuntimeServices(context, operation, model);
}

protected void removeRuntimeServices(OperationContext context, ModelNode operation, ModelNode model)
throws OperationFailedException {

// remove the ProtocolDefaultsService
ServiceName protocolDefaultsService = ProtocolDefaultsService.SERVICE_NAME;
context.removeService(protocolDefaultsService);

// remove the DefaultChannelFactoryServiceAlias
ServiceName defaultChannelFactoryService = ChannelFactoryService.getServiceName(null);
context.removeService(defaultChannelFactoryService);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,34 @@ public void testProtocolStackRemoveRollback() throws Exception {
*/
@Test
public void testSubsystemRemoveAddSequence() throws Exception {

ServiceName maximal = ServiceName.of("jboss","jgroups", "stack", "maximal");
ServiceName defaults = ServiceName.of("jboss","jgroups", "defaults");
ServiceName defaultStack = ServiceName.of("jboss","jgroups", "stack");

// Parse and install the XML into the controller
String subsystemXml = getSubsystemXml() ;
KernelServices servicesA = createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build();

// remove the jgroups subsystem
Assert.assertTrue("jboss.jgroups.stack.maximal MSC service not present", isMSCServicePresent(servicesA, maximal));
Assert.assertTrue("jboss.jgroups.defaults MSC service not present", isMSCServicePresent(servicesA, defaults));
Assert.assertTrue("jboss.jgroups.stack MSC service not present", isMSCServicePresent(servicesA, defaultStack));

ModelNode result = servicesA.executeOperation(removeSubsystemOp);
Assert.assertEquals("failure description: " + result.get(FAILURE_DESCRIPTION).toString(), SUCCESS, result.get(OUTCOME).asString());

Assert.assertFalse("jboss.jgroups.stack.maximal MSC service present", isMSCServicePresent(servicesA, maximal));
Assert.assertFalse("jboss.jgroups.defaults MSC service present", isMSCServicePresent(servicesA, defaults));
Assert.assertFalse("jboss.jgroups.stack MSC service present", isMSCServicePresent(servicesA, defaultStack));

// add the jgroups subsystem again
result = servicesA.executeOperation(addSubsystemOp);
Assert.assertEquals("failure description: " + result.get(FAILURE_DESCRIPTION).toString(), SUCCESS, result.get(OUTCOME).asString());

Assert.assertTrue("jboss.jgroups.defaults MSC service not present", isMSCServicePresent(servicesA, defaults));
Assert.assertTrue("jboss.jgroups.stack MSC service not present", isMSCServicePresent(servicesA, defaultStack));

// remove the jgroups subsystem again
result = servicesA.executeOperation(removeSubsystemOp);
Assert.assertEquals("failure description: " + result.get(FAILURE_DESCRIPTION).toString(), SUCCESS, result.get(OUTCOME).asString());
Expand All @@ -183,4 +199,9 @@ private void listMSCServices(KernelServices services, String marker) {
System.out.println("name = " + name.toString());
}
}

private boolean isMSCServicePresent(KernelServices services, ServiceName serviceName) {
ServiceRegistry registry = services.getContainer() ;
return (registry.getService(serviceName) != null);
}
}

0 comments on commit bdb7fd4

Please sign in to comment.