Skip to content

Commit

Permalink
Merge pull request #5480 from parsharma/WFCORE-6321
Browse files Browse the repository at this point in the history
WFCORE-6321 Expose ServerEnvironment via a capability
  • Loading branch information
yersan authored Aug 4, 2023
2 parents 99a7223 + 277b1db commit 48584a4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.jboss.as.server;

import static org.jboss.as.server.ServerService.SERVER_ENVIRONMENT_CAPABILITY;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
Expand Down Expand Up @@ -54,7 +55,10 @@
*/
public class ServerEnvironmentService implements Service<ServerEnvironment> {


/** Standard ServiceName under which a ServerEnvironmentService would be registered */
/** @deprecated Use {@link #SERVER_ENVIRONMENT_CAPABILITY.getCapabilityServiceName() instead} */
@Deprecated
public static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("server", "environment");

/**
Expand All @@ -65,8 +69,9 @@ public class ServerEnvironmentService implements Service<ServerEnvironment> {
* @param target the batch builder. Cannot be {@code null}
*/
public static void addService(ServerEnvironment serverEnvironment, ServiceTarget target) {
target.addService(SERVICE_NAME, new ServerEnvironmentService(serverEnvironment))
.install();
target.addService(SERVER_ENVIRONMENT_CAPABILITY.getCapabilityServiceName(), new ServerEnvironmentService(serverEnvironment))
.addAliases(SERVICE_NAME)
.install();
}

private final ServerEnvironment serverEnvironment;
Expand Down
6 changes: 6 additions & 0 deletions server/src/main/java/org/jboss/as/server/ServerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public final class ServerService extends AbstractControllerService {

static final String SUSPEND_CONTROLLER_CAPABILITY_NAME = "org.wildfly.server.suspend-controller";
static final String EXTERNAL_MODULE_CAPABILITY_NAME = "org.wildfly.management.external-module";
public static final String SERVER_ENVIRONMENT_CAPABILITY_NAME = "org.wildfly.server.environment";

static final RuntimeCapability<Void> SUSPEND_CONTROLLER_CAPABILITY =
RuntimeCapability.Builder.of(SUSPEND_CONTROLLER_CAPABILITY_NAME, SuspendController.class)
Expand All @@ -186,6 +187,8 @@ public final class ServerService extends AbstractControllerService {
static final RuntimeCapability<Void> EXTERNAL_MODULE_CAPABILITY =
RuntimeCapability.Builder.of(EXTERNAL_MODULE_CAPABILITY_NAME, ExternalModule.class)
.build();
static final RuntimeCapability<Void> SERVER_ENVIRONMENT_CAPABILITY = RuntimeCapability.Builder.of(SERVER_ENVIRONMENT_CAPABILITY_NAME, ServerEnvironment.class).build();


/**
* Construct a new instance.
Expand Down Expand Up @@ -504,6 +507,8 @@ protected void initModel(ManagementModel managementModel, Resource modelControll
new RuntimeCapabilityRegistration(EXTERNAL_MODULE_CAPABILITY, CapabilityScope.GLOBAL,new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));
capabilityRegistry.registerCapability(
new RuntimeCapabilityRegistration(CONSOLE_AVAILABILITY_CAPABILITY, CapabilityScope.GLOBAL, new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));
capabilityRegistry.registerCapability(
new RuntimeCapabilityRegistration(SERVER_ENVIRONMENT_CAPABILITY, CapabilityScope.GLOBAL, new RegistrationPoint(PathAddress.EMPTY_ADDRESS, null)));

// Record the core capabilities with the root MRR so reads of it will show it as their provider
// This also gets them recorded as 'possible capabilities' in the capability registry
Expand All @@ -514,6 +519,7 @@ protected void initModel(ManagementModel managementModel, Resource modelControll
rootRegistration.registerCapability(PROCESS_STATE_NOTIFIER_CAPABILITY);
rootRegistration.registerCapability(EXTERNAL_MODULE_CAPABILITY);
rootRegistration.registerCapability(CONSOLE_AVAILABILITY_CAPABILITY);
rootRegistration.registerCapability(SERVER_ENVIRONMENT_CAPABILITY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static void doDeploy(final OperationContext context, final String deploym
contentService = ContentServitor.addService(serviceTarget, contentsServiceName, contents[0].hash);
} else {
isExplodedContent = true;
contentService = ManagedExplodedContentServitor.addService(serviceTarget, contentsServiceName, managementName, contents[0].hash);
contentService = ManagedExplodedContentServitor.addService(context, contentsServiceName, managementName, contents[0].hash);
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.jboss.as.server.deployment;

import static org.jboss.as.server.ServerService.SERVER_ENVIRONMENT_CAPABILITY_NAME;
import static org.jboss.as.server.Services.requireServerExecutor;

import java.io.IOException;
Expand All @@ -29,15 +30,14 @@
import java.util.function.Supplier;
import java.util.stream.Stream;

import org.jboss.as.controller.OperationContext;
import org.jboss.as.repository.ContentRepository;
import org.jboss.as.repository.ExplodedContentException;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerEnvironmentService;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
Expand All @@ -61,11 +61,11 @@ class ManagedExplodedContentServitor implements Service {
private final byte[] hash;
private volatile Path deploymentRoot;

static ServiceController<?> addService(final ServiceTarget serviceTarget, final ServiceName serviceName, final String managementName, final byte[] hash) {
final ServiceBuilder<?> sb = serviceTarget.addService(serviceName);
static ServiceController<?> addService(OperationContext context, final ServiceName serviceName, final String managementName, final byte[] hash) {
final ServiceBuilder<?> sb = context.getCapabilityServiceTarget().addService(serviceName);
final Consumer<VirtualFile> vfConsumer = sb.provides(serviceName);
final Supplier<ContentRepository> crSupplier = sb.requires(ContentRepository.SERVICE_NAME);
final Supplier<ServerEnvironment> seSupplier = sb.requires(ServerEnvironmentService.SERVICE_NAME);
final Supplier<ServerEnvironment> seSupplier = sb.requires(context.getCapabilityServiceName(SERVER_ENVIRONMENT_CAPABILITY_NAME, ServerEnvironment.class));
final Supplier<ExecutorService> esSupplier = requireServerExecutor(sb);
sb.setInstance(new ManagedExplodedContentServitor(managementName, hash, vfConsumer, crSupplier, seSupplier, esSupplier));
return sb.install();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.jboss.as.server.operations;

import static org.jboss.as.remoting.RemotingHttpUpgradeService.HTTP_UPGRADE_REGISTRY;
import static org.jboss.as.server.ServerService.SERVER_ENVIRONMENT_CAPABILITY_NAME;
import static org.jboss.as.server.mgmt.HttpManagementResourceDefinition.SECURE_SOCKET_BINDING;
import static org.jboss.as.server.mgmt.HttpManagementResourceDefinition.SOCKET_BINDING;
import static org.jboss.as.server.mgmt.HttpManagementResourceDefinition.SOCKET_BINDING_CAPABILITY_NAME;
Expand Down Expand Up @@ -58,7 +59,6 @@
import org.jboss.as.remoting.management.ManagementRemotingServices;
import org.jboss.as.server.ExternalManagementRequestExecutor;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerEnvironmentService;
import org.jboss.as.server.Services;
import org.jboss.as.server.logging.ServerLogger;
import org.jboss.as.server.mgmt.HttpManagementRequestsService;
Expand Down Expand Up @@ -157,9 +157,7 @@ protected List<ServiceName> installServices(OperationContext context, HttpInterf
final Supplier<XnioWorker> xwSupplier = builder.requires(ManagementWorkerService.SERVICE_NAME);
final Supplier<Executor> eSupplier = builder.requires(ExternalManagementRequestExecutor.SERVICE_NAME);
final Supplier<HttpAuthenticationFactory> hafSupplier = httpAuthenticationFactory != null ? builder.requiresCapability(HTTP_AUTHENTICATION_FACTORY_CAPABILITY, HttpAuthenticationFactory.class, httpAuthenticationFactory) : null;
// TODO WFCORE-6321 Expose ServerEnvironment via a capability
// Supplier<ServerEnvironment> environment = builder.requiresCapability("org.wildfly.server.environment", ServerEnvironment.class);
Supplier<ServerEnvironment> environment = builder.requires(ServerEnvironmentService.SERVICE_NAME);
Supplier<ServerEnvironment> environment = builder.requiresCapability(SERVER_ENVIRONMENT_CAPABILITY_NAME, ServerEnvironment.class);
Supplier<String> consoleSlot = new Supplier<>() {
@Override
public String get() {
Expand Down

0 comments on commit 48584a4

Please sign in to comment.