From a8e6f1ef8093187967dd8df94f27fe8811521171 Mon Sep 17 00:00:00 2001 From: ChristinaDsl Date: Mon, 15 Jul 2024 16:58:11 +0300 Subject: [PATCH] [WFCORE-6788] Display in cli when server is in read-only mode --- cli/src/main/java/org/jboss/as/cli/Util.java | 22 +++++++++++++++++++ .../as/cli/impl/CLIModelControllerClient.java | 4 ++-- .../jboss/as/cli/impl/CommandContextImpl.java | 4 ++++ .../ServerEnvironmentResourceDescription.java | 6 ++++- .../descriptions/LocalDescriptions.properties | 1 + 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cli/src/main/java/org/jboss/as/cli/Util.java b/cli/src/main/java/org/jboss/as/cli/Util.java index 024098a0b58..38ac63af698 100644 --- a/cli/src/main/java/org/jboss/as/cli/Util.java +++ b/cli/src/main/java/org/jboss/as/cli/Util.java @@ -1864,4 +1864,26 @@ public static String compactToString(ModelNode node) { return stringWriter.toString(); } + public static boolean isServerInReadOnlyMode(CommandContext ctx) { + final ModelControllerClient client = ctx.getModelControllerClient(); + final ModelNode operation = new ModelNode(); + ModelNode result; + ModelNode address = operation.get("address"); + + address.add("core-service", "server-environment"); + operation.get(Util.OPERATION).set(Util.READ_RESOURCE); + operation.get(Util.INCLUDE_RUNTIME).set(true); + + try { + result = client.execute(operation); + if (isSuccess(result)) { + ModelNode serverEnv = result.get("result"); + return serverEnv.get("read-only").asBoolean(); + } + } catch (Exception e) { + } + return false; + + } + } diff --git a/cli/src/main/java/org/jboss/as/cli/impl/CLIModelControllerClient.java b/cli/src/main/java/org/jboss/as/cli/impl/CLIModelControllerClient.java index 4fd45fbf121..4e80910cf21 100644 --- a/cli/src/main/java/org/jboss/as/cli/impl/CLIModelControllerClient.java +++ b/cli/src/main/java/org/jboss/as/cli/impl/CLIModelControllerClient.java @@ -98,8 +98,8 @@ public void shutdown() { private final AtomicInteger state = new AtomicInteger(CLOSED); CLIModelControllerClient(final ControllerAddress address, CallbackHandler handler, int connectionTimeout, - final ConnectionCloseHandler closeHandler, Map saslOptions, SecurityFactory sslContextFactory, - boolean fallbackSslContext, ProtocolTimeoutHandler timeoutHandler, String clientBindAddress) throws IOException { + final ConnectionCloseHandler closeHandler, Map saslOptions, SecurityFactory sslContextFactory, + boolean fallbackSslContext, ProtocolTimeoutHandler timeoutHandler, String clientBindAddress) throws IOException { this.handler = handler; this.closeHandler = closeHandler; diff --git a/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java b/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java index 37155a1fcb1..b0f52808fa5 100644 --- a/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java +++ b/cli/src/main/java/org/jboss/as/cli/impl/CommandContextImpl.java @@ -1598,6 +1598,10 @@ String getPrompt() { } else { buffer.append("standalone@"); } + if (Util.isServerInReadOnlyMode(this)){ + buffer.append("(read-only)"); + printLine("Server is in read-only mode", "warning"); + } if (controllerHost != null) { buffer.append(controllerHost).append(':').append(getControllerPort()).append(' '); } else { 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 c05490447f8..ad8281d03ca 100644 --- a/server/src/main/java/org/jboss/as/server/ServerEnvironmentResourceDescription.java +++ b/server/src/main/java/org/jboss/as/server/ServerEnvironmentResourceDescription.java @@ -60,10 +60,11 @@ public class ServerEnvironmentResourceDescription extends SimpleResourceDefiniti static final AttributeDefinition PERMISSIBLE_STABILITY_LEVELS = new SimpleListAttributeDefinition.Builder("permissible-stability-levels", STABILITY) .setFlags(AttributeAccess.Flag.STORAGE_RUNTIME) .build(); + public static final AttributeDefinition READ_ONLY = SimpleAttributeDefinitionBuilder.create("read-only", ModelType.BOOLEAN).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, PERMISSIBLE_STABILITY_LEVELS }; + QUALIFIED_HOST_NAME, SERVER_NAME, TEMP_DIR, START_SUSPENDED, GRACEFUL_STARTUP, READ_ONLY, STABILITY, PERMISSIBLE_STABILITY_LEVELS }; private final ServerEnvironmentReadHandler osh; @@ -176,6 +177,9 @@ public void execute(final OperationContext context, final ModelNode operation) t if (equals(name, START_SUSPENDED)) { result.set(environment.isStartSuspended()); } + if (equals(name, READ_ONLY)) { + result.set(environment.getServerConfigurationFile().getInteractionPolicy().isReadOnly()); + } if (equals(name, GRACEFUL_STARTUP)) { result.set(environment.isStartGracefully()); } else if (equals(name, STABILITY)) { 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 a5e83cebfe6..78736dab76a 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 @@ -57,6 +57,7 @@ server.env.server-name=The name of the server. server.env.temp-dir=The temporary directory. server.suspend-state=The suspend state of the server server.env.start-suspended=Start the server suspended. +server.env.read-only=Start the server in read-only mode. 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.