Skip to content

Commit

Permalink
Merge pull request #6025 from pferraro/WFCORE-6841
Browse files Browse the repository at this point in the history
WFCORE-6841 Create ServiceDescriptors for capabilities defined in AbstractControllerService
  • Loading branch information
yersan authored Jun 3, 2024
2 parents 51fd85f + 8ebccc0 commit aec2bb2
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,10 @@ private static int getBootStackSize() {
}

/** Capability in-vm users of the controller use to create clients */
protected static final RuntimeCapability<Void> CLIENT_FACTORY_CAPABILITY =
RuntimeCapability.Builder.of("org.wildfly.management.model-controller-client-factory", ModelControllerClientFactory.class)
.build();
protected static final RuntimeCapability<Void> CLIENT_FACTORY_CAPABILITY = RuntimeCapability.Builder.of(ModelControllerClientFactory.SERVICE_DESCRIPTOR).build();

/** Capability in-vm users of the controller use to register notification handlers */
protected static final RuntimeCapability<Void> NOTIFICATION_REGISTRY_CAPABILITY =
RuntimeCapability.Builder.of("org.wildfly.management.notification-handler-registry", NotificationHandlerRegistry.class)
.build();
protected static final RuntimeCapability<Void> NOTIFICATION_REGISTRY_CAPABILITY = RuntimeCapability.Builder.of(NotificationHandlerRegistry.SERVICE_DESCRIPTOR).build();

/**
* Capability users of the controller use to coordinate changes to paths.
Expand All @@ -156,9 +152,7 @@ private static int getBootStackSize() {
* This capability isn't necessarily directly related to this class but we declare it
* here as it's as good a place as any at this time.
*/
protected static final RuntimeCapability<Void> PROCESS_STATE_NOTIFIER_CAPABILITY =
RuntimeCapability.Builder.of("org.wildfly.management.process-state-notifier", ProcessStateNotifier.class)
.build();
protected static final RuntimeCapability<Void> PROCESS_STATE_NOTIFIER_CAPABILITY = RuntimeCapability.Builder.of(ProcessStateNotifier.SERVICE_DESCRIPTOR).build();

private static final OperationDefinition INIT_CONTROLLER_OP = new SimpleOperationDefinitionBuilder("boottime-controller-initializer-step", null)
.setPrivateEntry()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import java.util.concurrent.Executor;

import org.wildfly.service.descriptor.NullaryServiceDescriptor;

/**
* Factory for obtaining a {@link org.jboss.as.controller.client.ModelControllerClient}
* for use in the same VM as the target {@link ModelController}.
*
* @author Brian Stansberry
*/
public interface ModelControllerClientFactory {
NullaryServiceDescriptor<ModelControllerClientFactory> SERVICE_DESCRIPTOR = NullaryServiceDescriptor.of("org.wildfly.management.model-controller-client-factory", ModelControllerClientFactory.class);

/**
* Create an in-VM client whose operations are executed with authorization checks performed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import java.beans.PropertyChangeListener;

import org.wildfly.service.descriptor.NullaryServiceDescriptor;

/**
* Allows callers to check the current {@link ControlledProcessState.State} of the process
* and to register for notifications of state changes.
*
* @author Brian Stansberry (c) 2019 Red Hat Inc.
*/
public interface ProcessStateNotifier {
NullaryServiceDescriptor<ProcessStateNotifier> SERVICE_DESCRIPTOR = NullaryServiceDescriptor.of("org.wildfly.management.process-state-notifier", ProcessStateNotifier.class);

/**
* Gets the current state of the controlled process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jboss.as.controller.notification;

import org.jboss.as.controller.PathAddress;
import org.wildfly.service.descriptor.NullaryServiceDescriptor;

/**
* The NotificationHandlerRegistry is used to register and unregister notification handlers.
Expand All @@ -23,6 +24,7 @@
* @author <a href="http://jmesnil.net/">Jeff Mesnil</a> (c) 2014 Red Hat inc.
*/
public interface NotificationHandlerRegistry {
NullaryServiceDescriptor<NotificationHandlerRegistry> SERVICE_DESCRIPTOR = NullaryServiceDescriptor.of("org.wildfly.management.notification-handler-registry", NotificationHandlerRegistry.class);

/**
* Special path address to register a notification handler for <em>any</em> source.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ManagementModel;
import org.jboss.as.controller.ModelControllerClientFactory;
import org.jboss.as.controller.ModelOnlyWriteAttributeHandler;
import org.jboss.as.controller.ObjectListAttributeDefinition;
import org.jboss.as.controller.ObjectTypeAttributeDefinition;
Expand All @@ -54,6 +55,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.PASSIVE;
import org.jboss.as.controller.descriptions.NonResolvingResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.notification.NotificationHandlerRegistry;
import org.jboss.as.controller.operations.global.ReadFeatureDescriptionHandler;
import org.jboss.as.controller.registry.RuntimePackageDependency;
import org.jboss.as.controller.registry.AliasEntry;
Expand Down Expand Up @@ -83,8 +85,6 @@ public class ReadFeatureDescriptionTestCase extends AbstractControllerTestBase {
private static final String MAIN_RESOURCE_REQUIRED_PACKAGE_NAME = "required-main-resource-package";
private static final String ROOT_CAPABILITY_NAME = "root-capability";
private static final String DYNAMIC_CAPABILITY_NAME = "dynamic-capability";
private static final String CLIENT_FACTORY_CAPABILITY_NAME = "org.wildfly.management.model-controller-client-factory";
private static final String NOTIFICATION_REGISTRY_CAPABILITY_NAME = "org.wildfly.management.notification-handler-registry";

private static final OperationStepHandler WRITE_HANDLER = new ModelOnlyWriteAttributeHandler();

Expand Down Expand Up @@ -403,8 +403,8 @@ public void testServerRoot() throws OperationFailedException {
}
Assert.assertTrue(providedCaps.contains(ROOT_CAPABILITY_NAME));
Assert.assertTrue(providedCaps.contains(DYNAMIC_CAPABILITY_NAME));
Assert.assertTrue(providedCaps.contains(CLIENT_FACTORY_CAPABILITY_NAME));
Assert.assertTrue(providedCaps.contains(NOTIFICATION_REGISTRY_CAPABILITY_NAME));
Assert.assertTrue(providedCaps.contains(ModelControllerClientFactory.SERVICE_DESCRIPTOR.getName()));
Assert.assertTrue(providedCaps.contains(NotificationHandlerRegistry.SERVICE_DESCRIPTOR.getName()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
<module name="org.jboss.staxmapper"/>
<module name="org.wildfly.extension.core-management-client"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.service"/>
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PersistentResourceDefinition;
import org.jboss.as.controller.ProcessStateNotifier;
import org.jboss.as.controller.PropertiesAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.SimpleResourceDefinition;
Expand All @@ -43,7 +44,7 @@ public class ProcessStateListenerResourceDefinition extends PersistentResourceDe
private static final String PROCESS_STATE_LISTENER_CAPABILITY_NAME = "org.wildfly.extension.core-management.process-state";
static final RuntimeCapability<Void> PROCESS_STATE_LISTENER_CAPABILITY =
RuntimeCapability.Builder.of(PROCESS_STATE_LISTENER_CAPABILITY_NAME, true, Void.class)
.addRequirements("org.wildfly.management.executor", "org.wildfly.management.process-state-notifier")
.addRequirements("org.wildfly.management.executor", ProcessStateNotifier.SERVICE_DESCRIPTOR.getName())
.build();

public static final PropertiesAttributeDefinition PROPERTIES = new PropertiesAttributeDefinition.Builder("properties", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void suspendTransition(Process.RunningState oldState, Process.RunningSta

static void install(CapabilityServiceTarget serviceTarget, ProcessType processType, RunningMode runningMode, String listenerName, ProcessStateListener listener, Map<String, String> properties, int timeout) {
final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(PROCESS_STATE_LISTENER_CAPABILITY.fromBaseCapability(listenerName));
final Supplier<ProcessStateNotifier> psnSupplier = builder.requiresCapability("org.wildfly.management.process-state-notifier", ProcessStateNotifier.class);
final Supplier<ProcessStateNotifier> psnSupplier = builder.requires(ProcessStateNotifier.SERVICE_DESCRIPTOR);
final Supplier<ExecutorService> esSupplier = builder.requiresCapability("org.wildfly.management.executor", ExecutorService.class);
final Supplier<SuspendController> scSupplier = !processType.isHostController() ? builder.requiresCapability("org.wildfly.server.suspend-controller", SuspendController.class) : null;
builder.setInstance(new ProcessStateListenerService(processType, runningMode, listenerName, listener, properties, timeout, psnSupplier, scSupplier, esSupplier));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ public static void addService(final OperationContext context, final PathAddress
final CapabilityServiceBuilder<?> sb = context.getCapabilityServiceTarget().addCapability(capName);
final Consumer<DeploymentScanner> serviceConsumer = sb.provides(capName);
final Supplier<PathManager> pathManager = sb.requires(PathManager.SERVICE_DESCRIPTOR);
final Supplier<NotificationHandlerRegistry> notificationRegistry = sb.requiresCapability("org.wildfly.management.notification-handler-registry", NotificationHandlerRegistry.class);
final Supplier<ModelControllerClientFactory> clientFactory = sb.requiresCapability("org.wildfly.management.model-controller-client-factory", ModelControllerClientFactory.class);
final Supplier<ProcessStateNotifier> processStateNotifier = sb.requiresCapability("org.wildfly.management.process-state-notifier", ProcessStateNotifier.class);
final Supplier<NotificationHandlerRegistry> notificationRegistry = sb.requires(NotificationHandlerRegistry.SERVICE_DESCRIPTOR);
final Supplier<ModelControllerClientFactory> clientFactory = sb.requires(ModelControllerClientFactory.SERVICE_DESCRIPTOR);
final Supplier<ProcessStateNotifier> processStateNotifier = sb.requires(ProcessStateNotifier.SERVICE_DESCRIPTOR);
sb.requires(org.jboss.as.server.deployment.Services.JBOSS_DEPLOYMENT_CHAINS);
final DeploymentScannerService service = new DeploymentScannerService(
serviceConsumer, pathManager, notificationRegistry, clientFactory, processStateNotifier, scheduledExecutorService,
Expand Down
2 changes: 1 addition & 1 deletion jmx/src/main/java/org/jboss/as/jmx/MBeanServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static ServiceController<?> addService(final OperationContext context, fi
return context.getServiceTarget().addService(MBeanServerService.SERVICE_NAME, service)
.setInitialMode(ServiceController.Mode.ACTIVE)
.addDependency(modelControllerName, ModelController.class, service.modelControllerValue)
.addDependency(context.getCapabilityServiceName("org.wildfly.management.notification-handler-registry", null), NotificationHandlerRegistry.class, service.notificationRegistryValue)
.addDependency(context.getCapabilityServiceName(NotificationHandlerRegistry.SERVICE_DESCRIPTOR), NotificationHandlerRegistry.class, service.notificationRegistryValue)
.addDependency(ManagementModelIntegration.SERVICE_NAME, ManagementModelIntegration.ManagementModelProvider.class, service.managementModelProviderValue)
.addAliases(LEGACY_MBEAN_SERVER_NAME)
.install();
Expand Down
4 changes: 3 additions & 1 deletion server/src/main/java/org/jboss/as/server/ServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
import org.jboss.as.controller.ControlledProcessState;
import org.jboss.as.controller.DelegatingResourceDefinition;
import org.jboss.as.controller.ManagementModel;
import org.jboss.as.controller.ModelControllerClientFactory;
import org.jboss.as.controller.ModelControllerServiceInitialization;
import org.jboss.as.controller.OperationStepHandler;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.RunningModeControl;
import org.jboss.as.controller.ServiceNameFactory;
import org.jboss.as.controller.access.management.DelegatingConfigurableAuthorizer;
import org.jboss.as.controller.access.management.ManagementSecurityIdentitySupplier;
import org.jboss.as.controller.audit.ManagedAuditLogger;
Expand Down Expand Up @@ -136,7 +138,7 @@
public final class ServerService extends AbstractControllerService {

/** Service is not for general use, so the service name is not declared in the more visible {@code Services} */
public static final ServiceName JBOSS_SERVER_CLIENT_FACTORY = CLIENT_FACTORY_CAPABILITY.getCapabilityServiceName();
public static final ServiceName JBOSS_SERVER_CLIENT_FACTORY = ServiceNameFactory.resolveServiceName(ModelControllerClientFactory.SERVICE_DESCRIPTOR);
/** Service is not for general use, so the service name is not declared in the more visible {@code Services} */
public static final ServiceName JBOSS_SERVER_NOTIFICATION_REGISTRY = NOTIFICATION_REGISTRY_CAPABILITY.getCapabilityServiceName();
/** Service is not for general use, so the service name is not declared in the more visible {@code Services} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class RootResourceDefinition extends SimpleResourceDefinition {

static final RuntimeCapability<Void> CAPABILITY = RuntimeCapability.Builder.of("boot.error", Void.class)
.addRequirements("org.wildfly.management.model-controller-client-factory", "org.wildfly.management.executor")
.addRequirements(ModelControllerClientFactory.SERVICE_DESCRIPTOR.getName(), "org.wildfly.management.executor")
.build();

static final SimpleAttributeDefinition ATTRIBUTE = new SimpleAttributeDefinitionBuilder("attribute", ModelType.STRING, true).build();
Expand Down Expand Up @@ -103,7 +103,7 @@ protected void performRuntime(OperationContext context, ModelNode operation, Res
// Add a service that will invoke an op that produces a failure during start. The service
// will start during boot so that simulates a non-boot op failing during boot
CapabilityServiceBuilder<?> builder = context.getCapabilityServiceTarget().addCapability(CAPABILITY);
Supplier<ModelControllerClientFactory> mccf = builder.requiresCapability("org.wildfly.management.model-controller-client-factory", ModelControllerClientFactory.class);
Supplier<ModelControllerClientFactory> mccf = builder.requires(ModelControllerClientFactory.SERVICE_DESCRIPTOR);
Supplier<Executor> executor = builder.requiresCapability("org.wildfly.management.executor", Executor.class);
builder.setInstance(new BootErrorService(mccf, executor)).install();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<module name="org.jboss.as.server" />
<module name="org.jboss.msc"/>
<module name="org.jboss.logging"/>
<module name="org.wildfly.service"/>
</dependencies>
</module>

0 comments on commit aec2bb2

Please sign in to comment.