Skip to content

Commit

Permalink
Create a new reload-enhanced operation
Browse files Browse the repository at this point in the history
It supports different rbac and stability level
  • Loading branch information
kabir committed Mar 11, 2024
1 parent da7006c commit 51d6e3a
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 51 deletions.
1 change: 1 addition & 0 deletions cli/src/main/java/org/jboss/as/cli/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public class Util {
public static final String RELEASE_CODENAME = "release-codename";
public static final String RELEASE_VERSION = "release-version";
public static final String RELOAD = "reload";
public static final String RELOAD_ENHANCED = "reload-enhanced";
public static final String REMOVE = "remove";
public static final String REPLY_PROPERTIES = "reply-properties";
public static final String REQUEST_PROPERTIES = "request-properties";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ public void handleClose() {
// if the connection loss was triggered by an instruction to restart/reload
// then we don't disconnect yet
if(parsedCmd.getFormat() != null) {
if(Util.RELOAD.equals(parsedCmd.getOperationName())) {
if(Util.RELOAD.equals(parsedCmd.getOperationName()) || Util.RELOAD_ENHANCED.equals(parsedCmd.getOperationName())) {
// do nothing
} else if(Util.SHUTDOWN.equals(parsedCmd.getOperationName())) {
if(CommandFormat.INSTANCE.equals(parsedCmd.getFormat())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ public class ModelDescriptionConstants {
public static final String RELEASE_CODENAME = "release-codename";
public static final String RELEASE_VERSION = "release-version";
public static final String RELOAD = "reload";
public static final String RELOAD_ENHANCED = "reload-enhanced";
public static final String RELOAD_REQUIRED = "reload-required";
public static final String REMOVE = "remove";
public static final String REMOTE = "remote";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELOAD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELOAD_ENHANCED;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SHUTDOWN;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
Expand Down Expand Up @@ -68,7 +69,7 @@
*/
public class ModelControllerClientOperationHandler implements ManagementRequestHandlerFactory {

private static final Set<String> PREPARED_RESPONSE_OPERATIONS = Set.of(RELOAD, SHUTDOWN);
private static final Set<String> PREPARED_RESPONSE_OPERATIONS = Set.of(RELOAD, RELOAD_ENHANCED, SHUTDOWN);
private final ModelController controller;

private final ManagementChannelAssociation channelAssociation;
Expand Down Expand Up @@ -193,7 +194,7 @@ public void operationPrepared(ModelController.OperationTransaction transaction,
@Override
public void operationPrepared(ModelController.OperationTransaction transaction, final ModelNode preparedResult, OperationContext context) {
transaction.commit();
if (context == null || !RELOAD.equals(operation.get(OP).asString())) { // TODO deal with shutdown as well,
if (context == null || !RELOAD.equals(operation.get(OP).asString()) || !RELOAD_ENHANCED.equals(operation.get(OP).asString())) { // TODO deal with shutdown as well,
// the handlers for which have some
// subtleties that need thought
sendResponse(preparedResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELOAD;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RELOAD_ENHANCED;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;

Expand All @@ -29,7 +30,7 @@ final class EarlyResponseTransactionControl implements ModelController.Operation

EarlyResponseTransactionControl(ResponseCallback callback, ModelNode operation) {
this.callback = callback;
this.reload = RELOAD.equals(operation.get(OP).asString());
this.reload = RELOAD.equals(operation.get(OP).asString()) || RELOAD_ENHANCED.equals(operation.get(OP).asString());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,9 @@ public void registerOperations(ManagementResourceRegistration resourceRegistrati
resourceRegistration.registerOperationHandler(ServerDomainProcessShutdownHandler.DOMAIN_DEFINITION, new ServerDomainProcessShutdownHandler());

} else {
final ServerProcessReloadHandler reloadHandler = new ServerProcessReloadHandler(Services.JBOSS_AS, runningModeControl, processState, serverEnvironment);
resourceRegistration.registerOperationHandler(ServerProcessReloadHandler.DEFINITION, reloadHandler, false);

ServerProcessReloadHandler.registerStandardReloadOperation(resourceRegistration, runningModeControl, processState, serverEnvironment);
ServerProcessReloadHandler.registerEnhancedReloadOperation(resourceRegistration, runningModeControl, processState, serverEnvironment);

resourceRegistration.registerOperationHandler(ServerSuspendHandler.DEFINITION, ServerSuspendHandler.INSTANCE);
resourceRegistration.registerOperationHandler(ServerResumeHandler.DEFINITION, ServerResumeHandler.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.operations.common.ProcessReloadHandler;
import org.jboss.as.controller.operations.validation.EnumValidator;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.Services;
import org.jboss.as.server.controller.descriptions.ServerDescriptions;
import org.jboss.as.server.logging.ServerLogger;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.msc.service.ServiceName;

import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

/**
*
Expand All @@ -54,33 +59,73 @@ public class ServerProcessReloadHandler extends ProcessReloadHandler<RunningMode
.setAlternatives(ModelDescriptionConstants.ADMIN_ONLY)
.setDefaultValue(new ModelNode(StartMode.NORMAL.toString())).build();

private static final AttributeDefinition[] STANDARD_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, USE_CURRENT_SERVER_CONFIG, SERVER_CONFIG, START_MODE};


private static final OperationDefinition STANDARD_DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, ServerDescriptions.getResourceDescriptionResolver("server"))
.setParameters(STANDARD_ATTRIBUTES)
.setRuntimeOnly()
.build();

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Parameters only allowed in the 'enhanced' operation

private static final String ENHANCED_OPERATION_NAME = "reload-enhanced";

protected static final AttributeDefinition STABILITY = new SimpleAttributeDefinitionBuilder(ModelDescriptionConstants.STABILITY, ModelType.STRING, true)
.setStability(Stability.COMMUNITY)
.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SERVER_RELOAD_STABILITY)
.setValidator(EnumValidator.create(Stability.class)).build();
private static final AttributeDefinition[] ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, USE_CURRENT_SERVER_CONFIG, SERVER_CONFIG, START_MODE, STABILITY};

public static final OperationDefinition DEFINITION = new SimpleOperationDefinitionBuilder(OPERATION_NAME, ServerDescriptions.getResourceDescriptionResolver("server"))
.setParameters(ATTRIBUTES)
private static final AttributeDefinition[] ENHANCED_ATTRIBUTES = new AttributeDefinition[] {ADMIN_ONLY, USE_CURRENT_SERVER_CONFIG, SERVER_CONFIG, START_MODE, STABILITY};
private static final OperationDefinition ENHANCED_DEFINITION = new SimpleOperationDefinitionBuilder(ENHANCED_OPERATION_NAME, ServerDescriptions.getResourceDescriptionResolver("server"))
.setStability(Stability.COMMUNITY)
.setAccessConstraints(SensitiveTargetAccessConstraintDefinition.SERVER_RELOAD_STABILITY)
.setParameters(ENHANCED_ATTRIBUTES)
.setRuntimeOnly()
.build();

private final Set<String> additionalAttributes;
private final ServerEnvironment environment;
public ServerProcessReloadHandler(ServiceName rootService, RunningModeControl runningModeControl,
ControlledProcessState processState, ServerEnvironment environment) {

public ServerProcessReloadHandler(ServiceName rootService, RunningModeControl runningModeControl, ControlledProcessState processState, ServerEnvironment environment) {
this(rootService, runningModeControl, processState, environment, null);
}

public ServerProcessReloadHandler(ServiceName rootService, RunningModeControl runningModeControl, ControlledProcessState processState, ServerEnvironment environment, Set<String> additionalAttributes) {
super(rootService, runningModeControl, processState);
this.additionalAttributes = additionalAttributes == null ? Collections.emptySet() : additionalAttributes;
this.environment = environment;
}

public static void registerStandardReloadOperation(ManagementResourceRegistration resourceRegistration, RunningModeControl runningModeControl, ControlledProcessState processState, ServerEnvironment serverEnvironment) {
ServerProcessReloadHandler reloadHandler = new ServerProcessReloadHandler(Services.JBOSS_AS, runningModeControl, processState, serverEnvironment);
resourceRegistration.registerOperationHandler(ServerProcessReloadHandler.STANDARD_DEFINITION, reloadHandler, false);
}

public static void registerEnhancedReloadOperation(ManagementResourceRegistration resourceRegistration, RunningModeControl runningModeControl, ControlledProcessState processState, ServerEnvironment serverEnvironment) {
ServerProcessReloadHandler reloadHandler = new ServerProcessReloadHandler(Services.JBOSS_AS, runningModeControl, processState, serverEnvironment, getAttributeNames(ENHANCED_ATTRIBUTES));
resourceRegistration.registerOperationHandler(ServerProcessReloadHandler.ENHANCED_DEFINITION, reloadHandler, false);
}

private static Set<String> getAttributeNames(AttributeDefinition[] attributes) {
Set<String> names = new HashSet<>();
for (AttributeDefinition attr : attributes) {
names.add(attr.getName());
}
return names;
}

@Override
protected ProcessReloadHandler.ReloadContext<RunningModeControl> initializeReloadContext(final OperationContext context, final ModelNode operation) throws OperationFailedException {

System.out.println("======> RELOADING " + context.getCurrentOperationName());


final boolean unmanaged = context.getProcessType() != ProcessType.DOMAIN_SERVER; // make sure that the params are ignored for managed servers
boolean adminOnly = unmanaged && ADMIN_ONLY.resolveModelAttribute(context, operation).asBoolean(false);
final boolean useCurrentConfig = unmanaged && USE_CURRENT_SERVER_CONFIG.resolveModelAttribute(context, operation).asBoolean(true);
final String startMode = START_MODE.resolveModelAttribute(context, operation).asString();

final Stability stability;
if (operation.hasDefined(ModelDescriptionConstants.STABILITY)) {
if (additionalAttributes.contains(ModelDescriptionConstants.STABILITY) && operation.hasDefined(ModelDescriptionConstants.STABILITY)) {
String val = STABILITY.resolveModelAttribute(context, operation).asString();
stability = Stability.fromString(val);
} else {
Expand All @@ -91,8 +136,6 @@ protected ProcessReloadHandler.ReloadContext<RunningModeControl> initializeReloa
throw ServerLogger.ROOT_LOGGER.cannotSpecifyBothAdminOnlyAndStartMode();
}



boolean suspend = false;
if(!adminOnly) {
switch (startMode.toLowerCase(Locale.ENGLISH)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ server.reload=Reloads the server by shutting down all its services and starting
server.reload.admin-only=Whether the server should start in running mode ADMIN_ONLY when it restarts. 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.
server.reload.use-current-server-config=Only has an effect if --read-only-server-config was specified when starting the server. In that case, if this parameter is set to false the reloaded server loads the original configuration version; if null or true the current runtime version of the model is used.
server.reload.server-config=Use to override the name of the server config to use for the reloaded server. When making changes to the model after the reload, the changes will still be persisted to the original server configuration file that was first used to boot up the server. This parameter is resolved the same way as the --server-config command-line option.
server.reload.stability=Set to change the stabilty level of the reloaded server.
server.reload.start-mode=Can be either normal, suspend or admin-only. If it is suspend the server will be started in suspended mode, if it is admin only the server will be started in admin-only mode.
server.reload.admin-only.deprecated=Use start-mode=admin-only instead.
server.reload.blocking=Whether the operation should block and wait until the server is reloaded.
server.reload.reply=The status of the server following execution of this operation.
server.reload.deprecated=This operation may be removed from the server-config resource in a future version; use the /host=*/server= resource for server lifecycle operations.
server.reload-enhanced=Reloads the server by shutting down all its services and starting again. The JVM itself is not restarted. This is similar to the 'reload' operation, but exposes some more advanced options.
server.reload-enhanced.admin-only=Whether the server should start in running mode ADMIN_ONLY when it restarts. 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.
server.reload-enhanced.use-current-server-config=Only has an effect if --read-only-server-config was specified when starting the server. In that case, if this parameter is set to false the reloaded server loads the original configuration version; if null or true the current runtime version of the model is used.
server.reload-enhanced.server-config=Use to override the name of the server config to use for the reloaded server. When making changes to the model after the reload, the changes will still be persisted to the original server configuration file that was first used to boot up the server. This parameter is resolved the same way as the --server-config command-line option.
server.reload-enhanced.stability=Set to change the stabilty level of the reloaded server.
server.reload-enhanced.start-mode=Can be either normal, suspend or admin-only. If it is suspend the server will be started in suspended mode, if it is admin only the server will be started in admin-only mode.
server.reload-enhanced.admin-only.deprecated=Use start-mode=admin-only instead.
server.reload-enhanced.blocking=Whether the operation should block and wait until the server is reloaded.
server.reload-enhanced.reply=The status of the server following execution of this operation.
server.reload-enhanced.deprecated=This operation may be removed from the server-config resource in a future version; use the /host=*/server= resource for server lifecycle operations.
server.start=Start a server.
server.start.blocking=Whether the operation should block and wait until the server is started.
server.start.start-mode=The mode the servers should started in, can be either suspend or normal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public static void executeReloadAndWaitForCompletion(ModelControllerClient clien
private static void executeReload(ModelControllerClient client, Parameters parameters) {
ModelNode operation = new ModelNode();
operation.get(OP_ADDR).setEmptyList();
operation.get(OP).set("reload");
operation.get("admin-only").set(parameters.adminOnly);
if (parameters.stability != null) {
operation.get(OP).set("reload-enhanced");
operation.get("stability").set(parameters.stability.toString());
} else {
operation.get(OP).set("reload");
}

executeReload(client, operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public abstract class StabilityServerSetupTasks implements ServerSetupTask {

public StabilityServerSetupTasks(Stability desiredStability) {
this.desiredStability = desiredStability;
// We can't reload to default since that will not have the stability paremeter in the reload operation
Assume.assumeFalse(desiredStability.equals(Stability.DEFAULT));
}

@Override
public void setup(ManagementClient managementClient) throws Exception {
reloadToDesiredStability(managementClient.getControllerClient(), desiredStability);
// We can't reload to default since that will not have the stability paremeter in the reload operation
Assume.assumeFalse(desiredStability.equals(Stability.DEFAULT));

reloadToDesiredStability(managementClient.getControllerClient(), desiredStability);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public class StabilityDefaultServerSetupTestCase extends AbstractStabilityServer
public StabilityDefaultServerSetupTestCase() {
super(Stability.DEFAULT);
}

}
Loading

0 comments on commit 51d6e3a

Please sign in to comment.