Skip to content

Commit

Permalink
WFCORE-6894 Extract interfaces from SuspendController appropriate for…
Browse files Browse the repository at this point in the history
… its consumers.
  • Loading branch information
pferraro committed Jul 25, 2024
1 parent 73b636b commit 3973ccb
Show file tree
Hide file tree
Showing 30 changed files with 527 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<module name="org.jboss.msc"/>
<module name="org.jboss.staxmapper"/>
<module name="org.jboss.vfs" services="import"/>
<module name="org.wildfly.common"/>
<module name="org.wildfly.extension.core-management-client"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.service"/>
Expand Down
4 changes: 2 additions & 2 deletions core-feature-pack/galleon-feature-pack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
<artifactId>wildfly-core-model-test-framework</artifactId>
<exclusions>
<exclusion>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-model-test</artifactId>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.management.Capabilities;
import org.jboss.as.server.suspend.OperationListener;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.server.suspend.ServerSuspendController;
import org.jboss.as.server.suspend.ServerSuspendListener;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.wildfly.common.function.Functions;
import org.wildfly.extension.core.management.client.Process;
import org.wildfly.extension.core.management.client.Process.RunningState;
import org.wildfly.extension.core.management.client.RuntimeConfigurationStateChangeEvent;
Expand All @@ -57,10 +58,10 @@ public class ProcessStateListenerService implements Service {
static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("core", "management", "process-state-listener");

private final Supplier<ProcessStateNotifier> processStateNotifierSupplier;
private final Supplier<SuspendController> suspendControllerSupplier;
private final Supplier<ServerSuspendController> suspendControllerSupplier;
private final Supplier<Executor> executorSupplier;
private final PropertyChangeListener propertyChangeListener;
private final OperationListener operationListener;
private final ServerSuspendListener suspendListener;
private final ProcessStateListener listener;
private final ProcessStateListenerInitParameters parameters;
private final String name;
Expand All @@ -72,7 +73,7 @@ public class ProcessStateListenerService implements Service {

private ProcessStateListenerService(ProcessType processType, RunningMode runningMode, String name, ProcessStateListener listener, Map<String, String> properties, int timeout,
final Supplier<ProcessStateNotifier> processStateNotifierSupplier,
final Supplier<SuspendController> suspendControllerSupplier,
final Supplier<ServerSuspendController> suspendControllerSupplier,
final Supplier<Executor> executorSupplier
) {
CoreManagementLogger.ROOT_LOGGER.debugf("Initalizing ProcessStateListenerService with a running mode of %s", runningMode);
Expand All @@ -96,20 +97,20 @@ private ProcessStateListenerService(ProcessType processType, RunningMode running
this.suspendControllerSupplier = suspendControllerSupplier;
this.executorSupplier = executorSupplier;
if (!processType.isHostController()) {
this.operationListener = new OperationListener() {
this.suspendListener = new ServerSuspendListener() {
@Override
public void suspendStarted() {
suspendTransition(runningState, Process.RunningState.SUSPENDING);
}

@Override
public void complete() {
public void suspendCompleted() {
suspendTransition(runningState, Process.RunningState.SUSPENDED);
}

@Override
public void cancelled() {
if(runningState == null || runningState == Process.RunningState.STARTING) {//gracefull startup
public void suspendCancelled() {
if (runningState == null || runningState == Process.RunningState.STARTING) {//gracefull startup
suspendTransition(Process.RunningState.STARTING, Process.RunningState.SUSPENDED);
}
switch (runningMode) {
Expand All @@ -123,11 +124,11 @@ public void cancelled() {
}

@Override
public void timeout() {
public void suspendTimeout() {
}
};
} else {
operationListener = null;
suspendListener = null;
}
}

Expand Down Expand Up @@ -241,8 +242,8 @@ static void install(CapabilityServiceTarget serviceTarget, ProcessType processTy
final CapabilityServiceBuilder<?> builder = serviceTarget.addCapability(PROCESS_STATE_LISTENER_CAPABILITY.fromBaseCapability(listenerName));
final Supplier<ProcessStateNotifier> psnSupplier = builder.requires(ProcessStateNotifier.SERVICE_DESCRIPTOR);
final Supplier<Executor> esSupplier = builder.requires(Capabilities.MANAGEMENT_EXECUTOR);
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));
final Supplier<ServerSuspendController> suspendController = !processType.isHostController() ? builder.requires(ServerSuspendController.SERVICE_DESCRIPTOR) : Functions.constantSupplier(null);
builder.setInstance(new ProcessStateListenerService(processType, runningMode, listenerName, listener, properties, timeout, psnSupplier, suspendController, esSupplier));
builder.install();
}

Expand All @@ -258,10 +259,9 @@ public void start(StartContext context) {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(currentTccl);
}
processStateNotifierSupplier.get().addPropertyChangeListener(propertyChangeListener);
final Supplier<SuspendController> suspendControllerSupplier = ProcessStateListenerService.this.suspendControllerSupplier;
SuspendController controller = suspendControllerSupplier != null ? suspendControllerSupplier.get() : null;
ServerSuspendController controller = ProcessStateListenerService.this.suspendControllerSupplier.get();
if (controller != null) {
controller.addListener(operationListener);
controller.addSuspendListener(suspendListener);
CoreManagementLogger.ROOT_LOGGER.debugf("Starting ProcessStateListenerService with a SuspendControllerState %s", controller.getState());
switch (controller.getState()) {
case PRE_SUSPEND:
Expand Down Expand Up @@ -321,9 +321,9 @@ public void stop(StopContext context) {
Runnable asyncStop = () -> {
synchronized (stopLock) {
processStateNotifierSupplier.get().removePropertyChangeListener(propertyChangeListener);
SuspendController controller = suspendControllerSupplier != null ? suspendControllerSupplier.get() : null;
ServerSuspendController controller = ProcessStateListenerService.this.suspendControllerSupplier.get();
if (controller != null) {
controller.removeListener(operationListener);
controller.removeSuspendListener(suspendListener);
}
runningState = null;
ClassLoader currentTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
Expand Down
18 changes: 11 additions & 7 deletions core-model-test/framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>provided</scope>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wildfly.legacy.test</groupId>
<artifactId>wildfly-legacy-spi</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.wildfly.legacy.test</groupId>
<artifactId>wildfly-legacy-spi</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAMESPACES;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SCHEMA_LOCATIONS;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -78,6 +80,7 @@
import org.jboss.as.server.ServerPathManagerService;
import org.jboss.as.server.controller.resources.ServerRootResourceDefinition;
import org.jboss.as.server.controller.resources.VersionModelInitializer;
import org.jboss.as.server.suspend.ServerSuspendController;
import org.jboss.as.version.ProductConfig;
import org.jboss.as.version.Version;
import org.jboss.dmr.ModelNode;
Expand All @@ -102,6 +105,7 @@ class TestModelControllerService extends ModelTestModelControllerService {
private final ExtensionRegistry extensionRegistry;
private final CapabilityRegistry capabilityRegistry;
private volatile Initializer initializer;
private final ServerSuspendController suspendController = mock(ServerSuspendController.class);

TestModelControllerService(ProcessType processType, RunningModeControl runningModeControl, StringConfigurationPersister persister, ModelTestOperationValidatorFilter validateOpsFilter,
TestModelType type, ModelInitializer modelInitializer, TestDelegatingResourceDefinition rootResourceDefinition, ControlledProcessState processState, ExtensionRegistry extensionRegistry,
Expand All @@ -124,6 +128,7 @@ class TestModelControllerService extends ModelTestModelControllerService {
} else if (type == TestModelType.DOMAIN) {
initializer = new DomainInitializer();
}
doReturn(ServerSuspendController.State.RUNNING).when(this.suspendController).getState();
}

static TestModelControllerService create(ProcessType processType, RunningModeControl runningModeControl, StringConfigurationPersister persister, ModelTestOperationValidatorFilter validateOpsFilter,
Expand Down Expand Up @@ -407,7 +412,7 @@ public void setRootResourceDefinitionDelegate() {
securityIdentitySupplier,
AuditLogger.NO_OP_LOGGER,
getMutableRootResourceRegistrationProvider(),
getBootErrorCollector(), capabilityRegistry));
getBootErrorCollector(), capabilityRegistry, suspendController));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
hostRegistration.registerReadOnlyAttribute(HostResourceDefinition.RUNTIME_CONFIGURATION_STATE, new ProcessStateAttributeHandler(processState));
hostRegistration.registerReadOnlyAttribute(HostResourceDefinition.HOST_STATE, new ProcessStateAttributeHandler(processState));
hostRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.RUNNING_MODE, new RunningModeReadHandler(runningModeControl));
hostRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.SUSPEND_STATE, SuspendStateReadHandler.INSTANCE);
hostRegistration.registerReadOnlyAttribute(ServerRootResourceDefinition.SUSPEND_STATE, new SuspendStateReadHandler(null));
}


Expand Down
5 changes: 5 additions & 0 deletions request-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.jboss.as.server.suspend.CountingRequestCountCallback;
import org.jboss.as.server.suspend.ServerActivity;
import org.jboss.as.server.suspend.ServerActivityCallback;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.server.suspend.ServerSuspendController;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
Expand Down Expand Up @@ -59,9 +59,9 @@ public class RequestController implements Service<RequestController>, ServerActi
private volatile ServerActivityCallback listener = null;

private final boolean trackIndividualControlPoints;
private final Supplier<SuspendController> suspendController;
private final Supplier<ServerSuspendController> suspendController;

public RequestController(boolean trackIndividualControlPoints, Supplier<SuspendController> suspendControllerSupplier) {
public RequestController(boolean trackIndividualControlPoints, Supplier<ServerSuspendController> suspendControllerSupplier) {
this.trackIndividualControlPoints = trackIndividualControlPoints;
this.suspendController = suspendControllerSupplier;
}
Expand Down Expand Up @@ -302,13 +302,13 @@ public boolean isPaused() {

@Override
public void start(StartContext startContext) throws StartException {
suspendController.get().registerActivity(this);
suspendController.get().addServerActivity(this);
timer = new Timer();
}

@Override
public void stop(StopContext stopContext) {
suspendController.get().unRegisterActivity(this);
suspendController.get().removeServerActivity(this);
timer.cancel();
timer = null;
while (!taskQueue.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.server.suspend.ServerSuspendController;
import org.jboss.dmr.ModelNode;

import java.util.function.Supplier;
Expand Down Expand Up @@ -49,7 +49,7 @@ protected void execute(DeploymentProcessorTarget processorTarget) {


CapabilityServiceBuilder<?> svcBuilder = context.getCapabilityServiceTarget().addCapability(REQUEST_CONTROLLER_CAPABILITY);
Supplier<SuspendController> supplier = svcBuilder.requiresCapability("org.wildfly.server.suspend-controller", SuspendController.class);
Supplier<ServerSuspendController> supplier = svcBuilder.requires(ServerSuspendController.SERVICE_DESCRIPTOR);
RequestController requestController = new RequestController(trackIndividual, supplier);
requestController.setMaxRequestCount(maxRequests);
svcBuilder.setInstance(requestController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

package org.wildfly.extension.requestcontroller;

import static org.jboss.as.server.Services.JBOSS_SUSPEND_CONTROLLER;
import static org.mockito.Mockito.mock;

import java.io.IOException;
import java.util.function.Consumer;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.controller.notification.NotificationFilter;
import org.jboss.as.controller.notification.NotificationHandler;
import org.jboss.as.controller.notification.NotificationHandlerRegistry;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.controller.ServiceNameFactory;
import org.jboss.as.server.suspend.ServerSuspendController;
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.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceTarget;
import org.junit.Assert;
Expand Down Expand Up @@ -60,21 +60,9 @@ protected AdditionalInitialization createAdditionalInitialization() {

@Override
protected void addExtraServices(ServiceTarget target) {
SuspendController suspendController = new SuspendController();
final NotificationHandlerRegistry nhr = new NotificationHandlerRegistry() {
@Override
public void registerNotificationHandler(PathAddress source, NotificationHandler handler, NotificationFilter filter) {

}

@Override
public void unregisterNotificationHandler(PathAddress source, NotificationHandler handler, NotificationFilter filter) {

}
};
suspendController.getNotificationHandlerRegistry().setValue(() -> nhr);
target.addService(JBOSS_SUSPEND_CONTROLLER, suspendController)
.install();
ServiceBuilder<?> builder = target.addService();
Consumer<ServerSuspendController> injector = builder.provides(ServiceNameFactory.resolveServiceName(ServerSuspendController.SERVICE_DESCRIPTOR));
builder.setInstance(Service.newInstance(injector, mock(ServerSuspendController.class))).install();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.jboss.as.server.mgmt.domain.RemoteFileRepositoryService;
import org.jboss.as.server.moduleservice.ExternalModuleService;
import org.jboss.as.server.moduleservice.ServiceModuleLoader;
import org.jboss.as.server.suspend.SuspendController;
import org.jboss.as.server.suspend.ServerSuspendController;
import org.jboss.as.version.ProductConfig;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceActivator;
Expand All @@ -55,15 +55,15 @@ final class ApplicationServerService implements Service<AsyncFuture<ServiceConta
private final Bootstrap.Configuration configuration;
private final RunningModeControl runningModeControl;
private final ControlledProcessState processState;
private final SuspendController suspendController;
private final ServerSuspendController suspendController;
private final boolean standalone;
private final boolean selfContained;
private final ElapsedTime elapsedTime;
private volatile FutureServiceContainer futureContainer;
private volatile boolean everStopped;

ApplicationServerService(final List<ServiceActivator> extraServices, final Bootstrap.Configuration configuration,
final ControlledProcessState processState, final SuspendController suspendController,
final ControlledProcessState processState, final ServerSuspendController suspendController,
final ElapsedTime elapsedTime) {
this.extraServices = extraServices;
this.configuration = configuration;
Expand Down
Loading

0 comments on commit 3973ccb

Please sign in to comment.