Skip to content

Commit

Permalink
Only expose --stability CLI argument if multiple stability levels are…
Browse files Browse the repository at this point in the history
… supported.
  • Loading branch information
pferraro committed Dec 9, 2023
1 parent 610e4cb commit b20d4c0
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static EmbedHostControllerHandler create(final AtomicReference<EmbeddedProcessLa
result.removeExistingDomainConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_DOMAIN_CONFIG);
result.emptyHostConfig = new ArgumentWithoutValue(result, EMPTY_HOST_CONFIG);
result.removeExistingHostConfig = new ArgumentWithoutValue(result, REMOVE_EXISTING_HOST_CONFIG);
// TODO: Use ProductConfig.getStabilitySet()
result.stability = new ArgumentWithValue(result, new SimpleTabCompleter(EnumSet.allOf(Stability.class)), "--stability");
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static EmbedServerHandler create(final AtomicReference<EmbeddedProcessLaunch> se
result.removeExisting = new ArgumentWithoutValue(result, "--remove-existing");
result.removeExisting.addRequiredPreceding(result.emptyConfig);
result.timeout = new ArgumentWithValue(result, "--timeout");
// TODO: Use ProductConfig.getStabilitySet()
result.stability = new ArgumentWithValue(result, new SimpleTabCompleter(EnumSet.allOf(Stability.class)), "--stability");

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public HostControllerEnvironment(Map<String, String> hostSystemProperties, boole
this.processType = processType;

this.stability = getEnumProperty(hostSystemProperties, STABILITY, this.productConfig.getDefaultStability());
if (!this.productConfig.getMinimumStability().enables(this.stability)) {
if (!this.productConfig.getStabilitySet().contains(this.stability)) {
throw HostControllerLogger.ROOT_LOGGER.unsupportedStability(this.stability, this.productConfig.getProductName());
}
if (!hostSystemProperties.containsKey(STABILITY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.jboss.as.host.controller;

import org.jboss.as.version.ProductConfig;

/**
* @author wangc
*
Expand All @@ -18,18 +20,20 @@ enum HostControllerEnvironmentStatus {

private HostControllerEnvironment hostControllerEnvironment;
private HostControllerEnvironmentStatus hostControllerEnvironmentStatus;
private ProductConfig productConfig;

private HostControllerEnvironmentWrapper(HostControllerEnvironment hostControllerEnvironment, HostControllerEnvironmentStatus hostControllerEnvironmentStatus) {
private HostControllerEnvironmentWrapper(HostControllerEnvironment hostControllerEnvironment, HostControllerEnvironmentStatus hostControllerEnvironmentStatus, ProductConfig productConfig) {
this.hostControllerEnvironment = hostControllerEnvironment;
this.hostControllerEnvironmentStatus = hostControllerEnvironmentStatus;
this.productConfig = productConfig;
}

HostControllerEnvironmentWrapper(HostControllerEnvironment hostControllerEnvironment) {
this(hostControllerEnvironment, null);
this(hostControllerEnvironment, null, hostControllerEnvironment.getProductConfig());
}

HostControllerEnvironmentWrapper(HostControllerEnvironmentStatus hostControllerEnvironmentStatus) {
this(null, hostControllerEnvironmentStatus);
HostControllerEnvironmentWrapper(HostControllerEnvironmentStatus hostControllerEnvironmentStatus, ProductConfig productConfig) {
this(null, hostControllerEnvironmentStatus, productConfig);
}

public HostControllerEnvironment getHostControllerEnvironment() {
Expand All @@ -39,4 +43,8 @@ public HostControllerEnvironment getHostControllerEnvironment() {
public HostControllerEnvironmentStatus getHostControllerEnvironmentStatus() {
return hostControllerEnvironmentStatus;
}

public ProductConfig getProductConfig() {
return this.productConfig;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
package org.jboss.as.process;

import java.io.PrintStream;
import java.util.EnumSet;

import org.jboss.as.process.logging.ProcessLogger;
import org.jboss.as.version.Stability;
import org.jboss.as.version.ProductConfig;

public class CommandLineArgumentUsageImpl extends CommandLineArgumentUsage {

public static void init(){
public static void init(ProductConfig productConfig){

addArguments(CommandLineConstants.ADMIN_ONLY);
instructions.add(ProcessLogger.ROOT_LOGGER.argAdminOnly());
Expand Down Expand Up @@ -81,12 +80,14 @@ public static void init(){
addArguments(CommandLineConstants.SECMGR);
instructions.add(ProcessLogger.ROOT_LOGGER.argSecMgr());

addArguments(CommandLineConstants.STABILITY + "=<value>");
instructions.add(ProcessLogger.ROOT_LOGGER.argStability(EnumSet.allOf(Stability.class), Stability.DEFAULT));
if (productConfig.getStabilitySet().size() > 1) {
addArguments(CommandLineConstants.STABILITY + "=<value>");
instructions.add(ProcessLogger.ROOT_LOGGER.argStability(productConfig.getStabilitySet(), productConfig.getDefaultStability()));
}
}

public static void printUsage(final PrintStream out) {
init();
public static void printUsage(ProductConfig productConfig, PrintStream out) {
init(productConfig);
out.print(usage("domain"));
}
}
38 changes: 20 additions & 18 deletions process-controller/src/main/java/org/jboss/as/process/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static String getVersionString() {
return Version.AS_VERSION;
}

private static void usage() {
CommandLineArgumentUsageImpl.printUsage(System.out);
private static void usage(ProductConfig productConfig) {
CommandLineArgumentUsageImpl.printUsage(productConfig, System.out);
}

private Main() {
Expand All @@ -68,8 +68,8 @@ public static ProcessController start(String[] args) throws IOException {
String modulePath = null;
String bootJar = null;
String bootModule = HOST_CONTROLLER_MODULE;
final PCSocketConfig pcSocketConfig = new PCSocketConfig();

ProductConfig productConfig = ProductConfig.fromFilesystemSlot(Module.getBootModuleLoader(), jbossHome, null);
final PCSocketConfig pcSocketConfig = new PCSocketConfig(productConfig);
String currentWorkingDir = WildFlySecurityManager.getPropertyPrivileged("user.dir", null);

final List<String> javaOptions = new ArrayList<String>();
Expand Down Expand Up @@ -100,7 +100,7 @@ public static ProcessController start(String[] args) throws IOException {
if ("--".equals(arg)) {
for (i++; i < args.length; i++) {
arg = args[i];
if (handleHelpOrVersion(arg, jbossHome)) {
if (handleHelpOrVersion(productConfig, arg, jbossHome)) {
return null;
} else if (pcSocketConfig.processPCSocketConfigArgument(arg, args, i)) {
if (pcSocketConfig.isParseFailed()) {
Expand All @@ -109,12 +109,12 @@ public static ProcessController start(String[] args) throws IOException {
i += pcSocketConfig.getArgIncrement();
} else if (arg.startsWith("-D" + CommandLineConstants.PREFER_IPV4_STACK + "=")) {
// AS7-5409 set the property for this process and pass it to HC via javaOptions
String val = parseValue(arg, "-D" + CommandLineConstants.PREFER_IPV4_STACK);
String val = parseValue(productConfig, arg, "-D" + CommandLineConstants.PREFER_IPV4_STACK);
WildFlySecurityManager.setPropertyPrivileged(CommandLineConstants.PREFER_IPV4_STACK, val);
addJavaOption(arg, javaOptions);
} else if (arg.startsWith("-D" + CommandLineConstants.PREFER_IPV6_ADDRESSES + "=")) {
// AS7-5409 set the property for this process and pass it to HC via javaOptions
String val = parseValue(arg, "-D" + CommandLineConstants.PREFER_IPV6_ADDRESSES);
String val = parseValue(productConfig, arg, "-D" + CommandLineConstants.PREFER_IPV6_ADDRESSES);
WildFlySecurityManager.setPropertyPrivileged(CommandLineConstants.PREFER_IPV6_ADDRESSES, val);
addJavaOption(arg, javaOptions);

Expand All @@ -123,7 +123,7 @@ public static ProcessController start(String[] args) throws IOException {
}
}
break OUT;
} else if (handleHelpOrVersion(arg, jbossHome)) {
} else if (handleHelpOrVersion(productConfig, arg, jbossHome)) {
// This would normally come in via the nested if ("--".equals(arg)) case above, but in case someone tweaks the
// script to set it directly, we've handled it
return null;
Expand All @@ -145,7 +145,7 @@ public static ProcessController start(String[] args) throws IOException {
}
}
break OUT;
} else if (handleHelpOrVersion(arg, jbossHome)) {
} else if (handleHelpOrVersion(productConfig, arg, jbossHome)) {
// This would normally come in via the if ("--".equals(arg)) cases above, but in case someone tweaks the
// script to set it directly, we've handled it)
return null;
Expand Down Expand Up @@ -249,12 +249,12 @@ private static boolean isJavaSecurityManagerConfigured(final String arg) {
&& !"-Djava.security.manager=disallow".equals(arg);
}

private static String parseValue(final String arg, final String key) {
private static String parseValue(ProductConfig productConfig, final String arg, final String key) {
String value = null;
int splitPos = key.length();
if (arg.length() <= splitPos + 1 || arg.charAt(splitPos) != '=') {
System.out.println(ProcessLogger.ROOT_LOGGER.noArgValue(key));
usage();
usage(productConfig);
} else {
value = arg.substring(splitPos + 1);
}
Expand Down Expand Up @@ -283,10 +283,10 @@ private static void addJavaOption(String option, List<String> javaOptions) {
javaOptions.add(option);
}

private static boolean handleHelpOrVersion(String arg, String jbossHome) {
private static boolean handleHelpOrVersion(ProductConfig productConfig, String arg, String jbossHome) {
if (CommandLineConstants.HELP.equals(arg) || CommandLineConstants.SHORT_HELP.equals(arg)
|| CommandLineConstants.OLD_HELP.equals(arg)) {
usage();
usage(productConfig);
return true;
} else if (CommandLineConstants.VERSION.equals(arg) || CommandLineConstants.SHORT_VERSION.equals(arg)
|| CommandLineConstants.OLD_VERSION.equals(arg) || CommandLineConstants.OLD_SHORT_VERSION.equals(arg)) {
Expand All @@ -297,12 +297,14 @@ private static boolean handleHelpOrVersion(String arg, String jbossHome) {
}

private static class PCSocketConfig {
private final ProductConfig productConfig;
private String bindAddress;
private int bindPort = 0;
private int argIncrement = 0;
private boolean parseFailed;

private PCSocketConfig() {
private PCSocketConfig(ProductConfig productConfig) {
this.productConfig = productConfig;
}

private String getBindAddress() {
Expand Down Expand Up @@ -336,14 +338,14 @@ private boolean processPCSocketConfigArgument(final String arg, final String[] a
bindAddress = args[index +1];
argIncrement = 1;
} else if (arg.startsWith(CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR)) {
String addr = parseValue(arg, CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR);
String addr = parseValue(this.productConfig, arg, CommandLineConstants.PROCESS_CONTROLLER_BIND_ADDR);
if (addr == null) {
parseFailed = true;
} else {
bindAddress = addr;
}
} else if (arg.startsWith(CommandLineConstants.OLD_PROCESS_CONTROLLER_BIND_ADDR)) {
String addr = parseValue(arg, CommandLineConstants.OLD_PROCESS_CONTROLLER_BIND_ADDR);
String addr = parseValue(this.productConfig, arg, CommandLineConstants.OLD_PROCESS_CONTROLLER_BIND_ADDR);
if (addr == null) {
parseFailed = true;
} else {
Expand All @@ -353,14 +355,14 @@ private boolean processPCSocketConfigArgument(final String arg, final String[] a
bindPort = Integer.parseInt(args[index + 1]);
argIncrement = 1;
} else if (arg.startsWith(CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT)) {
String port = parseValue(arg, CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT);
String port = parseValue(this.productConfig, arg, CommandLineConstants.PROCESS_CONTROLLER_BIND_PORT);
if (port == null) {
parseFailed = true;
} else {
bindPort = Integer.parseInt(port);
}
} else if (arg.startsWith(CommandLineConstants.OLD_PROCESS_CONTROLLER_BIND_PORT)) {
String port = parseValue(arg, CommandLineConstants.OLD_PROCESS_CONTROLLER_BIND_PORT);
String port = parseValue(this.productConfig, arg, CommandLineConstants.OLD_PROCESS_CONTROLLER_BIND_PORT);
if (port == null) {
parseFailed = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
package org.jboss.as.server;

import java.io.PrintStream;
import java.util.EnumSet;

import org.jboss.as.controller.persistence.ConfigurationExtensionFactory;

import org.jboss.as.process.CommandLineArgumentUsage;
import org.jboss.as.process.CommandLineConstants;
import org.jboss.as.server.logging.ServerLogger;
import org.jboss.as.version.Stability;
import org.jboss.as.version.ProductConfig;

public class CommandLineArgumentUsageImpl extends CommandLineArgumentUsage {

public static void init(){
public static void init(ProductConfig productConfig){

addArguments(CommandLineConstants.ADMIN_ONLY);
instructions.add(ServerLogger.ROOT_LOGGER.argAdminOnly());
Expand Down Expand Up @@ -81,12 +80,14 @@ public static void init(){
instructions.add(ConfigurationExtensionFactory.getCommandLineInstructions());
}

addArguments(CommandLineConstants.STABILITY + "=<value>");
instructions.add(ServerLogger.ROOT_LOGGER.argStability(EnumSet.allOf(Stability.class), Stability.DEFAULT));
if (productConfig.getStabilitySet().size() > 1) {
addArguments(CommandLineConstants.STABILITY + "=<value>");
instructions.add(ServerLogger.ROOT_LOGGER.argStability(productConfig.getStabilitySet(), productConfig.getDefaultStability()));
}
}

public static void printUsage(final PrintStream out) {
init();
public static void printUsage(ProductConfig productConfig, PrintStream out) {
init(productConfig);
out.print(usage("standalone"));
}

Expand Down
Loading

0 comments on commit b20d4c0

Please sign in to comment.