From 40e92fa00c13e9679984b81c354907e2dad3e29b Mon Sep 17 00:00:00 2001 From: Yeray Borges Date: Wed, 20 Mar 2024 17:23:55 +0000 Subject: [PATCH] [WFCORE-6731] Expose supported stability levels via the management API Jira issue: https://issues.redhat.com/browse/WFCORE-6731 --- .../operations/common/ProcessEnvironment.java | 9 +++++++++ .../controller/HostControllerEnvironment.java | 8 ++++++++ .../HostEnvironmentResourceDefinition.java | 17 ++++++++++++++++- .../descriptions/LocalDescriptions.properties | 2 ++ .../org/jboss/as/server/ServerEnvironment.java | 10 +++++++++- .../ServerEnvironmentResourceDescription.java | 11 ++++++++++- .../descriptions/LocalDescriptions.properties | 1 + .../org/jboss/as/version/ProductConfig.java | 3 ++- 8 files changed, 57 insertions(+), 4 deletions(-) diff --git a/controller/src/main/java/org/jboss/as/controller/operations/common/ProcessEnvironment.java b/controller/src/main/java/org/jboss/as/controller/operations/common/ProcessEnvironment.java index f8b21baa3c0..683e3c8324b 100644 --- a/controller/src/main/java/org/jboss/as/controller/operations/common/ProcessEnvironment.java +++ b/controller/src/main/java/org/jboss/as/controller/operations/common/ProcessEnvironment.java @@ -15,6 +15,7 @@ import java.nio.file.StandardOpenOption; import java.util.Collections; import java.util.NoSuchElementException; +import java.util.Set; import java.util.UUID; import java.util.stream.Stream; @@ -30,6 +31,7 @@ import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.interfaces.InetAddressUtil; import org.jboss.as.controller.logging.ControllerLogger; +import org.jboss.as.version.Stability; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; @@ -54,6 +56,13 @@ public abstract class ProcessEnvironment implements FeatureRegistry { public static final String STABILITY = "jboss.stability"; + /** + * Returns an unmodifiable set of all the permissible stability levels. + * + * @return a set of stability levels + */ + public abstract Set getStabilities(); + /** * Gets an {@link OperationStepHandler} that can read the {@code name} attribute for a processes root resource * @return the handler diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironment.java b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironment.java index c7aa92a746d..52a69157fb5 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironment.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironment.java @@ -16,6 +16,7 @@ import java.util.EnumSet; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.UUID; import org.jboss.as.controller.OperationContext; @@ -234,6 +235,7 @@ public class HostControllerEnvironment extends ProcessEnvironment { private final RunningMode initialRunningMode; private final Stability stability; + private final Set stabilities; private final ProductConfig productConfig; private final String qualifiedHostName; private final String hostName; @@ -485,6 +487,7 @@ public HostControllerEnvironment(Map hostSystemProperties, boole this.processType = processType; this.stability = getEnumProperty(hostSystemProperties, STABILITY, this.productConfig.getDefaultStability()); + this.stabilities = productConfig.getStabilitySet(); if (!this.productConfig.getStabilitySet().contains(this.stability)) { throw HostControllerLogger.ROOT_LOGGER.unsupportedStability(this.stability, this.productConfig.getProductName()); } @@ -808,6 +811,11 @@ public Stability getStability() { return this.stability; } + @Override + public Set getStabilities() { + return this.stabilities; + } + @Override protected boolean isRuntimeSystemPropertyUpdateAllowed(String propertyName, String propertyValue, boolean bootTime) { // Currently any system-property in host.xml should not be applied to the HC runtime. This method diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/descriptions/HostEnvironmentResourceDefinition.java b/host-controller/src/main/java/org/jboss/as/host/controller/descriptions/HostEnvironmentResourceDefinition.java index 70283770d21..dc8b119f423 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/descriptions/HostEnvironmentResourceDefinition.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/descriptions/HostEnvironmentResourceDefinition.java @@ -18,6 +18,7 @@ import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; +import org.jboss.as.controller.SimpleListAttributeDefinition; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.access.management.AccessConstraintDefinition; import org.jboss.as.controller.access.management.SensitiveTargetAccessConstraintDefinition; @@ -25,6 +26,7 @@ import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.services.path.PathInfoHandler; import org.jboss.as.host.controller.HostControllerEnvironment; +import org.jboss.as.version.Stability; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; @@ -63,6 +65,11 @@ public class HostEnvironmentResourceDefinition extends SimpleResourceDefinition private static final AttributeDefinition INITIAL_RUNNING_MODE = createAttributeDefinition("initial-running-mode"); private static final AttributeDefinition QUALIFIED_HOST_NAME = createAttributeDefinition("qualified-host-name"); private static final AttributeDefinition HOST_NAME = createAttributeDefinition("host-name"); + private static final AttributeDefinition STABILITY = createAttributeDefinition("stability"); + private static final AttributeDefinition PERMISSIBLE_STABILITY_LEVELS = new SimpleListAttributeDefinition.Builder("permissible-stability-levels", STABILITY) + .setStorageRuntime() + .setRuntimeServiceNotRequired() + .build(); private static final AttributeDefinition[] HOST_ENV_ATTRIBUTES = { PROCESS_CONTROLLER_ADDRESS, @@ -86,7 +93,9 @@ public class HostEnvironmentResourceDefinition extends SimpleResourceDefinition USE_CACHED_DC, INITIAL_RUNNING_MODE, QUALIFIED_HOST_NAME, - HOST_NAME + HOST_NAME, + STABILITY, + PERMISSIBLE_STABILITY_LEVELS }; private final HostEnvironmentReadHandler osh; @@ -217,6 +226,12 @@ public void execute(final OperationContext context, final ModelNode operation) t set(result, environment.getQualifiedHostName()); } else if (equals(name, HOST_NAME)) { set(result, environment.getHostName()); + } else if (equals(name, STABILITY)) { + result.set(environment.getStability().toString()); + } else if (equals(name, PERMISSIBLE_STABILITY_LEVELS)) { + for (Stability s : environment.getStabilities()) { + result.add(s.toString()); + } } } diff --git a/host-controller/src/main/resources/org/jboss/as/host/controller/descriptions/LocalDescriptions.properties b/host-controller/src/main/resources/org/jboss/as/host/controller/descriptions/LocalDescriptions.properties index ea8c89b4fb1..ad45e3215c9 100644 --- a/host-controller/src/main/resources/org/jboss/as/host/controller/descriptions/LocalDescriptions.properties +++ b/host-controller/src/main/resources/org/jboss/as/host/controller/descriptions/LocalDescriptions.properties @@ -110,6 +110,8 @@ host.env.use-cached-dc=Whether this host controller should use cached domain con host.env.initial-running-mode=The initial running mode of the host, when the Host Controller process was launched. Either NORMAL or ADMIN_ONLY. An ADMIN_ONLY server will start any configured management interfaces and accept management requests, but will not start services used for handling end user requests. host.env.qualified-host-name=The fully qualified host name detected at startup. host.env.host-name=The local host name detected at server startup. +host.env.stability=The stability level of the host controller. +host.env.permissible-stability-levels=A list of all the stability levels supported by this host controller. host.reload=Reloads the Host Controller by shutting down all its services and starting again. The JVM itself is not restarted. Note however that this will lead to a full process restart for any server processes managed by this host controller. diff --git a/server/src/main/java/org/jboss/as/server/ServerEnvironment.java b/server/src/main/java/org/jboss/as/server/ServerEnvironment.java index 40019885b5e..515731805d7 100644 --- a/server/src/main/java/org/jboss/as/server/ServerEnvironment.java +++ b/server/src/main/java/org/jboss/as/server/ServerEnvironment.java @@ -304,6 +304,7 @@ public ProcessType getProcessType() { private final boolean startGracefully; private final GitRepository repository; private final Stability stability; + private final Set stabilities; public ServerEnvironment(final String hostControllerName, final Properties props, final Map env, final String serverConfig, final ConfigurationFile.InteractionPolicy configInteractionPolicy, final LaunchType launchType, @@ -367,6 +368,7 @@ public ServerEnvironment(final String hostControllerName, final Properties props domainConfigurationDir = null; repository = null; this.stability = productConfig.getDefaultStability(); + this.stabilities = productConfig.getStabilitySet(); WildFlySecurityManager.setPropertyPrivileged(ServerEnvironment.JBOSS_PERSIST_SERVER_CONFIG, "false"); } else { @@ -523,7 +525,8 @@ public ServerEnvironment(final String hostControllerName, final Properties props } this.stability = getEnumProperty(props, ProcessEnvironment.STABILITY, productConfig.getDefaultStability()); - if (!productConfig.getStabilitySet().contains(this.stability)) { + this.stabilities = productConfig.getStabilitySet(); + if (!stabilities.contains(this.stability)) { throw ServerLogger.ROOT_LOGGER.unsupportedStability(this.stability, productConfig.getProductName()); } } @@ -1017,6 +1020,11 @@ public Stability getStability() { return this.stability; } + @Override + public Set getStabilities() { + return this.stabilities; + } + /** * Gets whether this server is an independently managed server, not managed as part of a managed domain. * diff --git a/server/src/main/java/org/jboss/as/server/ServerEnvironmentResourceDescription.java b/server/src/main/java/org/jboss/as/server/ServerEnvironmentResourceDescription.java index 214853127f4..c05490447f8 100644 --- a/server/src/main/java/org/jboss/as/server/ServerEnvironmentResourceDescription.java +++ b/server/src/main/java/org/jboss/as/server/ServerEnvironmentResourceDescription.java @@ -16,6 +16,7 @@ import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; +import org.jboss.as.controller.SimpleListAttributeDefinition; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.persistence.ConfigurationFile; @@ -23,6 +24,7 @@ import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.services.path.PathInfoHandler; import org.jboss.as.server.controller.descriptions.ServerDescriptions; +import org.jboss.as.version.Stability; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; @@ -55,10 +57,13 @@ public class ServerEnvironmentResourceDescription extends SimpleResourceDefiniti public static final AttributeDefinition START_SUSPENDED = SimpleAttributeDefinitionBuilder.create("start-suspended", ModelType.BOOLEAN).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); public static final AttributeDefinition GRACEFUL_STARTUP = SimpleAttributeDefinitionBuilder.create("start-gracefully", ModelType.BOOLEAN).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); static final AttributeDefinition STABILITY = SimpleAttributeDefinitionBuilder.create("stability", ModelType.STRING).setFlags(AttributeAccess.Flag.STORAGE_RUNTIME).build(); + static final AttributeDefinition PERMISSIBLE_STABILITY_LEVELS = new SimpleListAttributeDefinition.Builder("permissible-stability-levels", STABILITY) + .setFlags(AttributeAccess.Flag.STORAGE_RUNTIME) + .build(); private static final AttributeDefinition[] SERVER_ENV_ATTRIBUTES = { BASE_DIR, CONFIG_DIR, CONFIG_FILE, CONTENT_DIR, DATA_DIR, DEPLOY_DIR, EXT_DIRS, HOME_DIR, HOST_NAME, INITIAL_RUNNING_MODE, LAUNCH_TYPE, LOG_DIR, NODE_NAME, - QUALIFIED_HOST_NAME, SERVER_NAME, TEMP_DIR, START_SUSPENDED, GRACEFUL_STARTUP, STABILITY }; + QUALIFIED_HOST_NAME, SERVER_NAME, TEMP_DIR, START_SUSPENDED, GRACEFUL_STARTUP, STABILITY, PERMISSIBLE_STABILITY_LEVELS }; private final ServerEnvironmentReadHandler osh; @@ -175,6 +180,10 @@ public void execute(final OperationContext context, final ModelNode operation) t result.set(environment.isStartGracefully()); } else if (equals(name, STABILITY)) { result.set(environment.getStability().toString()); + } else if (equals(name, PERMISSIBLE_STABILITY_LEVELS)) { + for (Stability s : environment.getStabilities()) { + result.add(s.toString()); + } } } diff --git a/server/src/main/resources/org/jboss/as/server/controller/descriptions/LocalDescriptions.properties b/server/src/main/resources/org/jboss/as/server/controller/descriptions/LocalDescriptions.properties index 3efac468bb6..456a811cd43 100644 --- a/server/src/main/resources/org/jboss/as/server/controller/descriptions/LocalDescriptions.properties +++ b/server/src/main/resources/org/jboss/as/server/controller/descriptions/LocalDescriptions.properties @@ -59,6 +59,7 @@ server.suspend-state=The suspend state of the server server.env.start-suspended=Start the server suspended. server.env.start-gracefully=Start the server gracefully. server.env.stability=The stability level of the server. +server.env.permissible-stability-levels=A list of all the stability levels supported by this server. # Lifecycle operations diff --git a/version/src/main/java/org/jboss/as/version/ProductConfig.java b/version/src/main/java/org/jboss/as/version/ProductConfig.java index ec491412644..1a14e1c01d7 100644 --- a/version/src/main/java/org/jboss/as/version/ProductConfig.java +++ b/version/src/main/java/org/jboss/as/version/ProductConfig.java @@ -15,6 +15,7 @@ import java.nio.file.Paths; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.Collections; import java.util.EnumSet; import java.util.Map; import java.util.Properties; @@ -94,7 +95,7 @@ private ProductConfig(ModuleLoader loader, ProductConfProps productConfProps, Ma version = productVersion; this.consoleSlot = consoleSlot; this.defaultStability = defaultStability; - this.stabilities = EnumSet.range(maxStability, minStability); + this.stabilities = Collections.unmodifiableSet(EnumSet.range(maxStability, minStability)); } private static String getProductConf(String home) {