Skip to content

Commit

Permalink
[WFCORE-7123] Embedded ignores invalid options
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Dec 26, 2024
1 parent fddefa9 commit b8d3000
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public final void start() throws EmbeddedProcessStartException {
EmbeddedProcessBootstrap bootstrap = loadEmbeddedProcessBootstrap();
embeddedProcess = bootstrap.startup(bootstrapConfiguration);
if (embeddedProcess == null) {
// TODO before adding embedded-spi, why did we ignore Main.determineEnvironment not providing one?
// This just continues that behavior
// bootstrapConfiguration.getCmdArgs() must have wanted --help or --version or the like
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
*/
public final class HostControllerEnvironmentWrapper {

enum HostControllerEnvironmentStatus {
NORMAL, // expected abort
public enum HostControllerEnvironmentStatus {
NORMAL, // environment created or an expected abort
ERROR // problematic abort
}

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

private HostControllerEnvironmentWrapper(HostControllerEnvironment hostControllerEnvironment, HostControllerEnvironmentStatus hostControllerEnvironmentStatus, ProductConfig productConfig) {
this.hostControllerEnvironment = hostControllerEnvironment;
Expand All @@ -29,7 +29,7 @@ private HostControllerEnvironmentWrapper(HostControllerEnvironment hostControlle
}

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

HostControllerEnvironmentWrapper(HostControllerEnvironmentStatus hostControllerEnvironmentStatus, ProductConfig productConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import org.jboss.as.controller.ProcessType;
import org.jboss.as.host.controller.HostControllerEnvironment;
import org.jboss.as.host.controller.HostControllerEnvironmentWrapper;
import org.jboss.as.host.controller.Main;
import org.jboss.as.host.controller.logging.HostControllerLogger;
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.server.embedded.AbstractEmbeddedProcessBootstrap;
import org.jboss.msc.service.ServiceActivator;
Expand Down Expand Up @@ -51,6 +53,10 @@ protected Future<ServiceContainer> bootstrapEmbeddedProcess(ElapsedTime elapsedT
ServiceActivator... extraServices) throws Exception {
// Determine the HostControllerEnvironment
HostControllerEnvironment environment = createHostControllerEnvironment(configuration.getJBossHome(), configuration.getCmdArgs(), elapsedTime);
if (environment == null) {
// configuration.getCmdArgs() must have wanted --help or --version or the like
return null;
}

final byte[] authBytes = new byte[16];
new Random(new SecureRandom().nextLong()).nextBytes(authBytes);
Expand Down Expand Up @@ -93,7 +99,14 @@ private static HostControllerEnvironment createHostControllerEnvironment(File jb
if (value != null)
cmds.add("-D" + prop + "=" + value);
}
return Main.determineEnvironment(cmds.toArray(new String[0]), elapsedTime, ProcessType.EMBEDDED_HOST_CONTROLLER).getHostControllerEnvironment();
HostControllerEnvironmentWrapper wrapper = Main.determineEnvironment(cmds.toArray(new String[0]), elapsedTime, ProcessType.EMBEDDED_HOST_CONTROLLER);
if (wrapper.getHostControllerEnvironmentStatus() == HostControllerEnvironmentWrapper.HostControllerEnvironmentStatus.ERROR) {
// I considered passing the cmdArgs to this, but I don't want to possibly leak anything sensitive.
// Main.determineEnvironment writes problems it finds to stdout so info is available that way.
throw HostControllerLogger.ROOT_LOGGER.cannotCreateHostControllerEnvironment();

}
return wrapper.getHostControllerEnvironment();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,9 @@ void noDomainControllerConfigurationProvidedForAdminOnly(String policyAttribute,
@Message(id = 223, value = "%s stability level is only supported on Host Controllers with the same management major and minor version than the Domain Controller. Domain Controller version is %d.%d. Remote Host Controller version is %d.%d")
OperationFailedException mixedDomainUnsupportedStability(Stability domainStability, int dcMajor, int dcMinor, int hcMajor, int hcMinor);

@Message(id = 224, value = "Cannot create a HostControllerEnvironment for an embedded host controller")
IllegalStateException cannotCreateHostControllerEnvironment();

////////////////////////////////////////////////
//Messages without IDs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/
public final class ServerEnvironmentWrapper {

enum ServerEnvironmentStatus {
NORMAL, // expected abort
public enum ServerEnvironmentStatus {
NORMAL, // environment created or an expected abort
ERROR // problematic abort
}

Expand All @@ -25,7 +25,7 @@ private ServerEnvironmentWrapper(ServerEnvironment serverEnvironment, ServerEnvi
}

ServerEnvironmentWrapper(ServerEnvironment serverEnvironment) {
this(serverEnvironment, null);
this(serverEnvironment, ServerEnvironmentStatus.NORMAL);
}

ServerEnvironmentWrapper(ServerEnvironmentStatus serverEnvironmentStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void exit(int status) {

Future<ServiceContainer> future = bootstrapEmbeddedProcess(elapsedTime, configuration, notifierCapture, clientFactoryCapture);
if (future == null) {
// TODO why do we ignore this?
// configuration.getCmdArgs() must have wanted --help or --version or the like
return null;
}

Expand Down Expand Up @@ -114,7 +114,8 @@ public void close() {
* @param elapsedTime tracker for elapsed time since embedded process 'start'. Cannot be {@code null}.
* @param configuration configuration information for starting. Cannot be {@code null}.
* @param extraServices activators for other services to start
* @return future from which the MSC service container can be obtained
* @return future from which the MSC service container can be obtained. May return {@code null} in the unusual
* case of the configuration not looking for a running process (e.g. used a {@code --help} commmand argument.)
* @throws Exception if one occurs
*/
protected abstract Future<ServiceContainer> bootstrapEmbeddedProcess(ElapsedTime elapsedTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.jboss.as.server.ElapsedTime;
import org.jboss.as.server.Main;
import org.jboss.as.server.ServerEnvironment;
import org.jboss.as.server.ServerEnvironmentWrapper;
import org.jboss.as.server.logging.ServerLogger;
import org.jboss.msc.service.ServiceActivator;
import org.jboss.msc.service.ServiceContainer;
import org.wildfly.core.embedding.spi.EmbeddedProcessBootstrapConfiguration;
Expand All @@ -31,13 +33,20 @@ protected Future<ServiceContainer> bootstrapEmbeddedProcess(ElapsedTime elapsedT


// Determine the ServerEnvironment
ServerEnvironment serverEnvironment = Main.determineEnvironment(configuration.getCmdArgs(),
ServerEnvironmentWrapper wrapper = Main.determineEnvironment(configuration.getCmdArgs(),
configuration.getSystemProperties(), configuration.getSystemEnv(),
ServerEnvironment.LaunchType.EMBEDDED, elapsedTime).getServerEnvironment();
ServerEnvironment.LaunchType.EMBEDDED, elapsedTime);
ServerEnvironment serverEnvironment = wrapper.getServerEnvironment();
if (serverEnvironment == null) {
// Nothing to do
if (wrapper.getServerEnvironmentStatus() == ServerEnvironmentWrapper.ServerEnvironmentStatus.ERROR) {
// I considered passing the cmdArgs to this but I don't want to possibly leak anything sensitive.
// Main.determineEnvironment writes problems it finds to stdout so info is available that way.
throw ServerLogger.ROOT_LOGGER.cannotCreateServerEnvironment();
}
// else configuration.getCmdArgs() must have wanted --help or --version or the like
return null;
}

Bootstrap bootstrap = Bootstrap.Factory.newInstance();
try {
Bootstrap.Configuration bootstrapConfiguration = new Bootstrap.Configuration(serverEnvironment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,9 @@ default void suspendingServer(long timeout, TimeUnit unit) {
@LogMessage(level = Logger.Level.ERROR)
void embeddedProcessServicesUnavailable(int timeout, String unavailable);

@Message(id = 311, value = "Cannot create a ServerEnvironment for an embedded server")
IllegalStateException cannotCreateServerEnvironment();

////////////////////////////////////////////////
//Messages without IDs

Expand Down

0 comments on commit b8d3000

Please sign in to comment.