diff --git a/embedded/src/main/java/org/wildfly/core/embedded/AbstractEmbeddedManagedProcess.java b/embedded/src/main/java/org/wildfly/core/embedded/AbstractEmbeddedManagedProcess.java index 6373db9bf0e..0aab41c1e7d 100644 --- a/embedded/src/main/java/org/wildfly/core/embedded/AbstractEmbeddedManagedProcess.java +++ b/embedded/src/main/java/org/wildfly/core/embedded/AbstractEmbeddedManagedProcess.java @@ -65,8 +65,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; } diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironmentWrapper.java b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironmentWrapper.java index ab19c3ad53b..62d9f319fd2 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironmentWrapper.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/HostControllerEnvironmentWrapper.java @@ -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; @@ -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) { diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/embedded/HostEmbeddedProcessBootstrap.java b/host-controller/src/main/java/org/jboss/as/host/controller/embedded/HostEmbeddedProcessBootstrap.java index 2ca0bd3fbb3..6f07f62a7cd 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/embedded/HostEmbeddedProcessBootstrap.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/embedded/HostEmbeddedProcessBootstrap.java @@ -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; @@ -51,6 +53,10 @@ protected Future 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); @@ -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(); } } diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/logging/HostControllerLogger.java b/host-controller/src/main/java/org/jboss/as/host/controller/logging/HostControllerLogger.java index ee227f7b03f..a62ef88e8cd 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/logging/HostControllerLogger.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/logging/HostControllerLogger.java @@ -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 diff --git a/server/src/main/java/org/jboss/as/server/ServerEnvironmentWrapper.java b/server/src/main/java/org/jboss/as/server/ServerEnvironmentWrapper.java index 189143d1a41..1bf9bed7909 100644 --- a/server/src/main/java/org/jboss/as/server/ServerEnvironmentWrapper.java +++ b/server/src/main/java/org/jboss/as/server/ServerEnvironmentWrapper.java @@ -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 } @@ -25,7 +25,7 @@ private ServerEnvironmentWrapper(ServerEnvironment serverEnvironment, ServerEnvi } ServerEnvironmentWrapper(ServerEnvironment serverEnvironment) { - this(serverEnvironment, null); + this(serverEnvironment, ServerEnvironmentStatus.NORMAL); } ServerEnvironmentWrapper(ServerEnvironmentStatus serverEnvironmentStatus) { diff --git a/server/src/main/java/org/jboss/as/server/embedded/AbstractEmbeddedProcessBootstrap.java b/server/src/main/java/org/jboss/as/server/embedded/AbstractEmbeddedProcessBootstrap.java index 38ecb3bca58..686622d84b7 100644 --- a/server/src/main/java/org/jboss/as/server/embedded/AbstractEmbeddedProcessBootstrap.java +++ b/server/src/main/java/org/jboss/as/server/embedded/AbstractEmbeddedProcessBootstrap.java @@ -60,7 +60,7 @@ public void exit(int status) { Future 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; } @@ -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 bootstrapEmbeddedProcess(ElapsedTime elapsedTime, diff --git a/server/src/main/java/org/jboss/as/server/embedded/StandaloneEmbeddedProcessBootstrap.java b/server/src/main/java/org/jboss/as/server/embedded/StandaloneEmbeddedProcessBootstrap.java index 4e72a82ed9b..29b18fef10b 100644 --- a/server/src/main/java/org/jboss/as/server/embedded/StandaloneEmbeddedProcessBootstrap.java +++ b/server/src/main/java/org/jboss/as/server/embedded/StandaloneEmbeddedProcessBootstrap.java @@ -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.embedded.spi.EmbeddedProcessBootstrapConfiguration; @@ -31,13 +33,20 @@ protected Future 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); diff --git a/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java b/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java index d72d840976c..f275117cec0 100644 --- a/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java +++ b/server/src/main/java/org/jboss/as/server/logging/ServerLogger.java @@ -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