Skip to content

Commit

Permalink
Merge pull request #6048 from pferraro/WFCORE-6866
Browse files Browse the repository at this point in the history
WFCORE-6866 Create ServiceDescriptor for management executor
  • Loading branch information
bstansberry authored Jul 9, 2024
2 parents 8d0d18f + a5a87e0 commit de94126
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.extension.MutableRootResourceRegistrationProvider;
import org.jboss.as.controller.logging.ControllerLogger;
import org.jboss.as.controller.management.Capabilities;
import org.jboss.as.controller.notification.NotificationHandlerRegistry;
import org.jboss.as.controller.notification.NotificationSupport;
import org.jboss.as.controller.operations.common.Util;
Expand Down Expand Up @@ -143,9 +144,9 @@ 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.
*/
public static final RuntimeCapability<Void> EXECUTOR_CAPABILITY =
RuntimeCapability.Builder.of("org.wildfly.management.executor", ExecutorService.class)
.build();
// TODO Exposing the ability to shutdown the executor is not ideal
// TODO Remove type narrowing once references to ExecutorService are removed from WildFly
public static final RuntimeCapability<Void> EXECUTOR_CAPABILITY = RuntimeCapability.Builder.of(Capabilities.MANAGEMENT_EXECUTOR.asType(ExecutorService.class)).build();

/**
* Capability users of the controller use to read process state and get notification of state changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

package org.jboss.as.controller.management;

import java.util.concurrent.Executor;

import org.wildfly.service.descriptor.NullaryServiceDescriptor;

/**
* Class to hold capabilities provided by and required by resources within this package.
*
* @author <a href="mailto:[email protected]">Darran Lofthouse</a>
*/
public final class Capabilities {
public static final NullaryServiceDescriptor<Executor> MANAGEMENT_EXECUTOR = NullaryServiceDescriptor.of("org.wildfly.management.executor", Executor.class);

public static final String HTTP_MANAGEMENT_CAPABILITY = "org.wildfly.management.http-interface";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.management.Capabilities;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
Expand All @@ -44,7 +45,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", ProcessStateNotifier.SERVICE_DESCRIPTOR.getName())
.addRequirements(Capabilities.MANAGEMENT_EXECUTOR, ProcessStateNotifier.SERVICE_DESCRIPTOR)
.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 @@ -11,9 +11,10 @@
import java.beans.PropertyChangeListener;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.Executor;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
Expand All @@ -25,6 +26,7 @@
import org.jboss.as.controller.ProcessStateNotifier;
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.msc.Service;
Expand Down Expand Up @@ -56,7 +58,7 @@ public class ProcessStateListenerService implements Service {

private final Supplier<ProcessStateNotifier> processStateNotifierSupplier;
private final Supplier<SuspendController> suspendControllerSupplier;
private final Supplier<ExecutorService> executorServiceSupplier;
private final Supplier<Executor> executorSupplier;
private final PropertyChangeListener propertyChangeListener;
private final OperationListener operationListener;
private final ProcessStateListener listener;
Expand All @@ -71,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<ExecutorService> executorServiceSupplier
final Supplier<Executor> executorSupplier
) {
CoreManagementLogger.ROOT_LOGGER.debugf("Initalizing ProcessStateListenerService with a running mode of %s", runningMode);
this.listener = listener;
Expand All @@ -92,7 +94,7 @@ private ProcessStateListenerService(ProcessType processType, RunningMode running
};
this.processStateNotifierSupplier = processStateNotifierSupplier;
this.suspendControllerSupplier = suspendControllerSupplier;
this.executorServiceSupplier = executorServiceSupplier;
this.executorSupplier = executorSupplier;
if (!processType.isHostController()) {
this.operationListener = new OperationListener() {
@Override
Expand Down Expand Up @@ -135,7 +137,7 @@ private void transition(Process.RuntimeConfigurationState oldState, Process.Runt
return;
}
final RuntimeConfigurationStateChangeEvent event = new RuntimeConfigurationStateChangeEvent(oldState, newState);
Future<?> controlledProcessStateTransition = executorServiceSupplier.get().submit(() -> {
RunnableFuture<Void> controlledProcessStateTransition = new FutureTask<>(() -> {
CoreManagementLogger.ROOT_LOGGER.debugf("Executing runtimeConfigurationStateChanged %s in thread %s", event, Thread.currentThread().getName());
ClassLoader currentTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
Expand All @@ -144,7 +146,8 @@ private void transition(Process.RuntimeConfigurationState oldState, Process.Runt
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(currentTccl);
}
});
}, null);
executorSupplier.get().execute(controlledProcessStateTransition);
try {
controlledProcessStateTransition.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
Expand Down Expand Up @@ -206,7 +209,7 @@ private void suspendTransition(Process.RunningState oldState, Process.RunningSta
}
this.runningState = newState;
final RunningStateChangeEvent event = new RunningStateChangeEvent(oldState, newState);
Future<?> suspendStateTransition = executorServiceSupplier.get().submit(() -> {
RunnableFuture<Void> suspendStateTransition = new FutureTask<>(() -> {
CoreManagementLogger.ROOT_LOGGER.debugf("Executing runningStateChanged %s in thread %s", event, Thread.currentThread().getName());
ClassLoader currentTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
Expand All @@ -215,7 +218,8 @@ private void suspendTransition(Process.RunningState oldState, Process.RunningSta
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(currentTccl);
}
});
}, null);
executorSupplier.get().execute(suspendStateTransition);
try {
suspendStateTransition.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
Expand All @@ -236,7 +240,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.requires(ProcessStateNotifier.SERVICE_DESCRIPTOR);
final Supplier<ExecutorService> esSupplier = builder.requiresCapability("org.wildfly.management.executor", ExecutorService.class);
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));
builder.install();
Expand Down Expand Up @@ -299,7 +303,7 @@ public void start(StartContext context) {
}
};
try {
executorServiceSupplier.get().execute(task);
executorSupplier.get().execute(task);
} catch (RejectedExecutionException e) {
task.run();
} finally {
Expand Down Expand Up @@ -334,10 +338,10 @@ public void stop(StopContext context) {
}
}
};
final ExecutorService executorService = executorServiceSupplier.get();
final Executor executor = executorSupplier.get();
try {
try {
executorService.execute(asyncStop);
executor.execute(asyncStop);
} catch (RejectedExecutionException e) {
asyncStop.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
import java.io.File;
import java.util.List;
import java.util.ServiceLoader;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;

import org.jboss.as.controller.AbstractControllerService;
import org.jboss.as.controller.CapabilityRegistry;
import org.jboss.as.controller.ModelController;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.RunningModeControl;
import org.jboss.as.controller.ServiceNameFactory;
import org.jboss.as.controller.extension.ExtensionRegistry;
import org.jboss.as.controller.management.Capabilities;
import org.jboss.as.controller.operations.validation.OperationValidator;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.transform.OperationTransformer.TransformedOperation;
Expand Down Expand Up @@ -103,9 +105,9 @@ public static AbstractKernelServicesImpl create(ProcessType processType, Running
.setMaximumPoolSize(256)
.setKeepAliveTime(20L, TimeUnit.SECONDS)
.build();
ServiceName sn = AbstractControllerService.EXECUTOR_CAPABILITY.getCapabilityServiceName();
ServiceName sn = ServiceNameFactory.resolveServiceName(Capabilities.MANAGEMENT_EXECUTOR);
ServiceBuilder sb = target.addService(sn);
Consumer<ExecutorService> c = sb.provides(sn);
Consumer<Executor> c = sb.provides(sn);
sb.setInstance(Service.newInstance(c, mgmtExecutor));
sb.install();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

package org.wildfly.core.instmgr;

import static org.jboss.as.controller.AbstractControllerService.EXECUTOR_CAPABILITY;
import static org.jboss.as.controller.AbstractControllerService.PATH_MANAGER_CAPABILITY;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST;

import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Supplier;

Expand All @@ -19,6 +17,8 @@
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.ProcessType;
import org.jboss.as.controller.ServiceNameFactory;
import org.jboss.as.controller.management.Capabilities;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.PlaceholderResource;
import org.jboss.as.controller.registry.Resource;
Expand Down Expand Up @@ -87,8 +87,8 @@ private InstMgrService createImService(ServiceTarget target, InstallationManager
ServiceName serviceName = InstMgrResourceDefinition.INSTALLATION_MANAGER_CAPABILITY.getCapabilityServiceName();
ServiceBuilder<?> serviceBuilder = target.addService(serviceName);
Consumer<InstMgrService> consumer = serviceBuilder.provides(serviceName);
Supplier<PathManager> pathManagerSupplier = serviceBuilder.requires(PATH_MANAGER_CAPABILITY.getCapabilityServiceName());
Supplier<ExecutorService> executorSupplier = serviceBuilder.requires(EXECUTOR_CAPABILITY.getCapabilityServiceName());
Supplier<PathManager> pathManagerSupplier = serviceBuilder.requires(ServiceNameFactory.resolveServiceName(PathManager.SERVICE_DESCRIPTOR));
Supplier<Executor> executorSupplier = serviceBuilder.requires(ServiceNameFactory.resolveServiceName(Capabilities.MANAGEMENT_EXECUTOR));

InstMgrService imService = new InstMgrService(imf, pathManagerSupplier, executorSupplier, consumer);
serviceBuilder.setInstance(imService).setInitialMode(ServiceController.Mode.PASSIVE).install();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -128,7 +128,7 @@ protected Path getUploadedMvnRepoRoot(Path source) throws Exception, ZipExceptio
protected List<Repository> getRepositoriesFromOperationStreams(OperationContext context, List<ModelNode> mavenRepoFileIndexes, Path workDir)
throws OperationFailedException, ExecutionException {
final List<CompletableFuture<Repository>> futureResults = new ArrayList<>();
final ExecutorService mgmtExecutor = imService.getMgmtExecutor();
final Executor mgmtExecutor = imService.getMgmtExecutor();
for (ModelNode indexMn : mavenRepoFileIndexes) {
int index = indexMn.asInt();
CompletableFuture<Path> futureZip = CompletableFuture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand All @@ -45,7 +45,7 @@ class InstMgrService implements Service {
private final InstallationManagerFactory imf;
private final Supplier<PathManager> pathManagerSupplier;
private final Consumer<InstMgrService> consumer;
private final Supplier<ExecutorService> executorSupplier;
private final Supplier<Executor> executorSupplier;
private PathManager pathManager;
private final AtomicBoolean started = new AtomicBoolean(false);
private Path homeDir;
Expand All @@ -55,9 +55,9 @@ class InstMgrService implements Service {
private Path controllerTempDir;
private final ConcurrentMap<String, Path> tempDirs = new ConcurrentHashMap<>();
private final InstMgrCandidateStatus candidateStatus;
private ExecutorService executor;
private Executor executor;

InstMgrService(InstallationManagerFactory imf, Supplier<PathManager> pathManagerSupplier, Supplier<ExecutorService> executorSupplier, Consumer<InstMgrService> consumer) {
InstMgrService(InstallationManagerFactory imf, Supplier<PathManager> pathManagerSupplier, Supplier<Executor> executorSupplier, Consumer<InstMgrService> consumer) {
this.imf = imf;
this.pathManagerSupplier = pathManagerSupplier;
this.candidateStatus = new InstMgrCandidateStatus();
Expand Down Expand Up @@ -205,7 +205,7 @@ Path getControllerTempDir() {
return controllerTempDir;
}

public ExecutorService getMgmtExecutor() {
public Executor getMgmtExecutor() {
return executor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.wildfly.extension.io.WorkerResourceDefinition.STACK_SIZE;

import java.lang.management.ManagementFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand All @@ -26,6 +26,7 @@
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.management.Capabilities;
import org.jboss.as.controller.registry.Resource;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
Expand Down Expand Up @@ -209,7 +210,7 @@ protected void performRuntime(OperationContext context, ModelNode operation, Mod

final CapabilityServiceBuilder<?> capBuilder = context.getCapabilityServiceTarget().addCapability(WorkerResourceDefinition.CAPABILITY);
final Consumer<XnioWorker> workerConsumer = capBuilder.provides(WorkerResourceDefinition.CAPABILITY);
final Supplier<ExecutorService> executorSupplier = capBuilder.requiresCapability("org.wildfly.management.executor", ExecutorService.class);
final Supplier<Executor> executorSupplier = capBuilder.requires(Capabilities.MANAGEMENT_EXECUTOR);
capBuilder.setInstance(new WorkerService(workerConsumer.andThen(maxThreadsRecorder), executorSupplier, builder));
capBuilder.setInitialMode(ServiceController.Mode.ON_DEMAND);
capBuilder.install();
Expand Down
Loading

0 comments on commit de94126

Please sign in to comment.