diff --git a/plugin/src/main/java/org/wildfly/plugin/cli/CommandExecutor.java b/plugin/src/main/java/org/wildfly/plugin/cli/CommandExecutor.java index 8f3836fd..079956de 100644 --- a/plugin/src/main/java/org/wildfly/plugin/cli/CommandExecutor.java +++ b/plugin/src/main/java/org/wildfly/plugin/cli/CommandExecutor.java @@ -12,6 +12,9 @@ import java.util.Collection; import java.util.List; import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javax.inject.Named; import javax.inject.Singleton; @@ -23,7 +26,7 @@ import org.wildfly.core.launcher.CliCommandBuilder; import org.wildfly.plugin.common.MavenModelControllerClientConfiguration; import org.wildfly.plugin.common.StandardOutput; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; /** * A command executor for executing CLI commands. @@ -48,7 +51,7 @@ public void execute(final CommandConfiguration config, MavenRepoManager artifact throws MojoFailureException, MojoExecutionException { if (config.isOffline()) { // The jbossHome is required for offline CLI - if (!ServerHelper.isValidHomeDirectory(config.getJBossHome())) { + if (!ServerManager.isValidHomeDirectory(config.getJBossHome())) { throw new MojoFailureException("Invalid JBoss Home directory is not valid: " + config.getJBossHome()); } executeInNewProcess(config); @@ -65,7 +68,13 @@ public void execute(final CommandConfiguration config, MavenRepoManager artifact } if (config.isAutoReload()) { // Reload the server if required - ServerHelper.reloadIfRequired(config.getClient(), config.getTimeout()); + try { + ServerManager.builder().client(config.getClient()).build().get(config.getTimeout(), TimeUnit.SECONDS) + .reloadIfRequired(config.getTimeout(), + TimeUnit.SECONDS); + } catch (IOException | InterruptedException | ExecutionException | TimeoutException e) { + throw new MojoExecutionException("Failed to reload server", e); + } } } @@ -89,7 +98,7 @@ protected int executeInNewProcess(final CommandConfiguration config, final Path private void executeInProcess(final CommandConfiguration config, MavenRepoManager artifactResolver) throws Exception { // The jbossHome is not required, but if defined should be valid final Path jbossHome = config.getJBossHome(); - if (jbossHome != null && !ServerHelper.isValidHomeDirectory(jbossHome)) { + if (jbossHome != null && !ServerManager.isValidHomeDirectory(jbossHome)) { throw new MojoFailureException("Invalid JBoss Home directory is not valid: " + jbossHome); } final Properties currentSystemProperties = System.getProperties(); diff --git a/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java b/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java index 45f749dd..02c0b39d 100644 --- a/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/cli/ExecuteCommandsMojo.java @@ -13,6 +13,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javax.inject.Inject; @@ -35,7 +38,7 @@ import org.wildfly.plugin.common.PropertyNames; import org.wildfly.plugin.common.Utils; import org.wildfly.plugin.core.MavenRepositoriesEnricher; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; /** * Execute commands to the running WildFly Application Server. @@ -246,13 +249,14 @@ public void execute() throws MojoExecutionException, MojoFailureException { // Check the server state if we're not in offline mode if (!offline) { try (ModelControllerClient client = createClient()) { - final String serverState = ServerHelper.serverState(client); + final String serverState = ServerManager.builder().client(client).build().get(timeout, TimeUnit.SECONDS) + .serverState(); if (!ClientConstants.CONTROLLER_PROCESS_STATE_RUNNING.equals(serverState)) { getLog().warn(String.format( "The server may be in an unexpected state for further interaction. The current state is %s", serverState)); } - } catch (IOException e) { + } catch (IOException | InterruptedException | ExecutionException | TimeoutException e) { final Log log = getLog(); log.warn(String.format( "Failed to determine the server-state. The server may be in an unexpected state. Failure: %s", diff --git a/plugin/src/main/java/org/wildfly/plugin/cli/OfflineCommandExecutor.java b/plugin/src/main/java/org/wildfly/plugin/cli/OfflineCommandExecutor.java index ed4ac2ca..f955dffe 100644 --- a/plugin/src/main/java/org/wildfly/plugin/cli/OfflineCommandExecutor.java +++ b/plugin/src/main/java/org/wildfly/plugin/cli/OfflineCommandExecutor.java @@ -16,7 +16,7 @@ import org.jboss.galleon.universe.maven.repo.MavenRepoManager; import org.wildfly.core.launcher.CliCommandBuilder; import org.wildfly.plugin.common.StandardOutput; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; /** * A command executor for executing offline CLI commands. @@ -39,7 +39,7 @@ public class OfflineCommandExecutor extends AbstractCommandExecutor profiles = getProfiles(); - final boolean isDomain = ServerHelper.getContainerDescription(client).isDomain(); + final boolean isDomain = ContainerDescription.lookup(client).isDomain(); for (Resource resource : resources) { if (isDomain && profiles.isEmpty()) { throw new IllegalStateException("Cannot add resources when no profiles were defined."); diff --git a/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java b/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java index a598ea9c..24db5e39 100644 --- a/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/dev/DevMojo.java @@ -93,9 +93,10 @@ import org.wildfly.plugin.tools.DeploymentResult; import org.wildfly.plugin.tools.GalleonUtils; import org.wildfly.plugin.tools.PluginProgressTracker; -import org.wildfly.plugin.tools.ServerHelper; import org.wildfly.plugin.tools.UndeployDescription; import org.wildfly.plugin.tools.VersionComparator; +import org.wildfly.plugin.tools.server.ServerManager; +import org.wildfly.plugin.tools.server.StandaloneManager; /** * Starts a standalone instance of WildFly and deploys the application to the server. The deployment type must be a WAR. @@ -450,11 +451,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { } registerDir(watcher, resolveWebAppSourceDir(), new WebAppResourceHandler(webExtensions)); try (ModelControllerClient client = createClient()) { - if (!ServerHelper.isStandaloneRunning(client)) { + final StandaloneManager serverManager = ServerManager.builder().client(client).standalone(); + if (!serverManager.isRunning()) { throw new MojoExecutionException("No standalone server appears to be running."); } if (remote) { - final ContainerDescription description = ServerHelper.getContainerDescription(client); + final ContainerDescription description = ContainerDescription.lookup(client); getLog().info(String.format("Deploying to remote %s container.", description)); } // Execute commands before the deployment is done @@ -478,7 +480,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { context = actOnServerState(client, context); } - final DeploymentManager deploymentManager = DeploymentManager.Factory.create(client); + final DeploymentManager deploymentManager = serverManager.deploymentManager(); final Deployment deployment = getDeploymentContent(); try { final DeploymentResult result = deploymentManager.forceDeploy(deployment); @@ -486,12 +488,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { throw new MojoExecutionException("Failed to deploy content: " + result.getFailureMessage()); } if (remote) { - getLog().info(String.format("Deployed %s", deployment.toString())); + getLog().info(String.format("Deployed %s", deployment)); } watch(watcher, deploymentManager, deployment); } finally { deploymentManager.undeploy(UndeployDescription.of(deployment)); - ServerHelper.shutdownStandalone(client); + serverManager.shutdown(); } } } catch (IOException e) { @@ -594,7 +596,7 @@ boolean reprovisionAndStart() } debug("Changes in layers detected, must re-provision the server"); try (ModelControllerClient client = createClient()) { - ServerHelper.shutdownStandalone(client); + ServerManager.builder().client(client).standalone().shutdown(); debug("Deleting existing installation " + installDir); IoUtils.recursiveDelete(installDir); } diff --git a/plugin/src/main/java/org/wildfly/plugin/server/AbstractServerStartMojo.java b/plugin/src/main/java/org/wildfly/plugin/server/AbstractServerStartMojo.java index 96d54187..7239333c 100644 --- a/plugin/src/main/java/org/wildfly/plugin/server/AbstractServerStartMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/server/AbstractServerStartMojo.java @@ -22,7 +22,7 @@ import org.wildfly.plugin.common.PropertyNames; import org.wildfly.plugin.common.Utils; import org.wildfly.plugin.tools.GalleonUtils; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; /** * @author James R. Perkins @@ -95,7 +95,7 @@ public abstract class AbstractServerStartMojo extends AbstractStartMojo { protected Path getServerHome() throws MojoExecutionException, MojoFailureException { // Validate the environment final Path jbossHome = provisionIfRequired(targetDir.toPath().resolve(provisioningDir)); - if (!ServerHelper.isValidHomeDirectory(jbossHome)) { + if (!ServerManager.isValidHomeDirectory(jbossHome)) { throw new MojoExecutionException(String.format("JBOSS_HOME '%s' is not a valid directory.", jbossHome)); } return jbossHome; diff --git a/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java b/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java index 0e8bf14f..606e19e4 100644 --- a/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/server/AbstractStartMojo.java @@ -9,7 +9,7 @@ import java.nio.file.Path; import java.util.List; import java.util.Map; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.maven.execution.MavenSession; @@ -25,7 +25,6 @@ import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.helpers.ClientConstants; import org.jboss.as.controller.client.helpers.Operations; -import org.jboss.as.controller.client.helpers.domain.DomainClient; import org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager; import org.jboss.galleon.universe.maven.repo.MavenRepoManager; import org.wildfly.core.launcher.CommandBuilder; @@ -34,7 +33,7 @@ import org.wildfly.plugin.common.PropertyNames; import org.wildfly.plugin.common.StandardOutput; import org.wildfly.plugin.core.MavenRepositoriesEnricher; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; /** * @author James R. Perkins @@ -133,6 +132,7 @@ public abstract class AbstractStartMojo extends AbstractServerConnection { private final AtomicBoolean initialized = new AtomicBoolean(); + protected ServerManager serverManager; protected MavenRepoManager mavenRepoManager; protected void init() throws MojoExecutionException { @@ -161,7 +161,7 @@ protected ServerContext startServer(final ServerType serverType) throws MojoExec // Create the server and close the client after the start. The process will continue running even after // the maven process may have been finished try (ModelControllerClient client = createClient()) { - if (ServerHelper.isStandaloneRunning(client) || ServerHelper.isDomainRunning(client)) { + if (ServerManager.isRunning(client)) { throw new MojoExecutionException(String.format("%s server is already running?", serverType)); } final CommandBuilder commandBuilder = createCommandBuilder(server); @@ -174,13 +174,16 @@ protected ServerContext startServer(final ServerType serverType) throws MojoExec out.getRedirect().ifPresent(launcher::redirectOutput); final Process process = launcher.launch(); + if (serverType == ServerType.DOMAIN) { + serverManager = ServerManager.builder().process(process).client(client).domain(); + } else { + serverManager = ServerManager.builder().process(process).client(client).standalone(); + } // Note that if this thread is started and no shutdown goal is executed this stop the stdout and stderr // from being logged any longer. The user was warned in the documentation. out.startConsumer(process); - if (serverType == ServerType.DOMAIN) { - ServerHelper.waitForDomain(process, DomainClient.Factory.create(client), startupTimeout); - } else { - ServerHelper.waitForStandalone(process, client, startupTimeout); + if (!serverManager.waitFor(startupTimeout, TimeUnit.SECONDS)) { + throw new MojoExecutionException(String.format("Server failed to start in %s seconds.", startupTimeout)); } if (!process.isAlive()) { throw new MojoExecutionException("The process has been terminated before the start goal has completed."); @@ -245,17 +248,19 @@ public void setJavaOpts(final String value) { */ protected ServerContext actOnServerState(final ModelControllerClient client, final ServerContext context) throws IOException, MojoExecutionException, MojoFailureException { - final String serverState = ServerHelper.serverState(client); + final String serverState = serverManager.serverState(); if (ClientConstants.CONTROLLER_PROCESS_STATE_RESTART_REQUIRED.equals(serverState)) { // Shutdown the server - ServerHelper.shutdownStandalone(client, timeout); + serverManager.shutdown(timeout); // Restart the server process return startServer(ServerType.STANDALONE); } else if (ClientConstants.CONTROLLER_PROCESS_STATE_RELOAD_REQUIRED.equals(serverState)) { - ServerHelper.executeReload(client, Operations.createOperation("reload")); + serverManager.executeReload(Operations.createOperation("reload")); try { - ServerHelper.waitForStandalone(context.process(), client, timeout); - } catch (InterruptedException | TimeoutException e) { + if (!serverManager.waitFor(startupTimeout, TimeUnit.SECONDS)) { + throw new MojoExecutionException(String.format("Server failed to start in %s seconds.", startupTimeout)); + } + } catch (InterruptedException e) { throw new MojoExecutionException("Failed to wait for standalone server after a reload.", e); } } else if (!ClientConstants.CONTROLLER_PROCESS_STATE_RUNNING.equals(serverState)) { diff --git a/plugin/src/main/java/org/wildfly/plugin/server/ShutdownMojo.java b/plugin/src/main/java/org/wildfly/plugin/server/ShutdownMojo.java index 898df772..8ddf0740 100644 --- a/plugin/src/main/java/org/wildfly/plugin/server/ShutdownMojo.java +++ b/plugin/src/main/java/org/wildfly/plugin/server/ShutdownMojo.java @@ -13,11 +13,10 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.jboss.as.controller.client.ModelControllerClient; -import org.jboss.as.controller.client.helpers.domain.DomainClient; import org.wildfly.plugin.common.AbstractServerConnection; import org.wildfly.plugin.common.PropertyNames; import org.wildfly.plugin.common.ServerOperations; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; /** * Shuts down a running WildFly Application Server. @@ -51,28 +50,27 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } try (ModelControllerClient client = createClient()) { - if (ServerHelper.getContainerDescription(client).isDomain()) { + if (ServerManager.isRunning(client)) { + final ServerManager serverManager = ServerManager.builder().client(client).build().get(timeout, + TimeUnit.SECONDS); if (reload) { - client.execute(ServerOperations.createOperation("reload-servers")); - ServerHelper.waitForDomain(client, timeout); + if (serverManager.containerDescription().isDomain()) { + client.execute(ServerOperations.createOperation("reload-servers")); + } else { + client.execute(ServerOperations.createOperation(ServerOperations.RELOAD)); + } + serverManager.waitFor(timeout, TimeUnit.SECONDS); } else { - ServerHelper.shutdownDomain(DomainClient.Factory.create(client)); + serverManager.shutdown(); } - } else { - if (reload) { - client.execute(ServerOperations.createOperation(ServerOperations.RELOAD)); - ServerHelper.waitForStandalone(client, timeout); - } else { - ServerHelper.shutdownStandalone(client); + // Bad hack to get maven to complete it's message output + try { + TimeUnit.MILLISECONDS.sleep(500L); + } catch (InterruptedException ignore) { + ignore.printStackTrace(); + // no-op } } - // Bad hack to get maven to complete it's message output - try { - TimeUnit.MILLISECONDS.sleep(500L); - } catch (InterruptedException ignore) { - ignore.printStackTrace(); - // no-op - } } catch (IOException e) { throw new MojoExecutionException(String.format("Please make sure a server is running before executing goal " + "%s. Reason: %s", goal(), e.getMessage()), e); diff --git a/pom.xml b/pom.xml index 4b16a720..3abecb84 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,7 @@ 3.5.3.Final 1.0.8.Final 1.7.0.Final - 1.0.0.Beta4 + 1.1.0.Final 23.0.3.Final 30.0.0.Final diff --git a/tests/domain-tests/src/test/java/org/wildfly/plugin/deployment/DeployTest.java b/tests/domain-tests/src/test/java/org/wildfly/plugin/deployment/DeployTest.java index ce29e302..9ee41252 100644 --- a/tests/domain-tests/src/test/java/org/wildfly/plugin/deployment/DeployTest.java +++ b/tests/domain-tests/src/test/java/org/wildfly/plugin/deployment/DeployTest.java @@ -26,8 +26,8 @@ import org.wildfly.plugin.common.ServerOperations; import org.wildfly.plugin.tests.AbstractWildFlyServerMojoTest; import org.wildfly.plugin.tools.DeploymentManager; -import org.wildfly.plugin.tools.ServerHelper; import org.wildfly.plugin.tools.UndeployDescription; +import org.wildfly.plugin.tools.server.ServerManager; /** * deploy mojo testcase. @@ -79,7 +79,8 @@ public void testDeployWithStoppedServer() throws Exception { if (deploymentManager.hasDeployment(DEPLOYMENT_NAME, DEFAULT_SERVER_GROUP)) { deploymentManager.undeploy(UndeployDescription.of(DEPLOYMENT_NAME).addServerGroups(DEFAULT_SERVER_GROUPS)); } - final ModelNode address = ServerHelper.determineHostAddress(client).add("server-config").add("server-one"); + final ModelNode address = ServerManager.builder().client(client).domain().determineHostAddress().add("server-config") + .add("server-one"); try { // Shutdown server-one final ModelNode op = ServerOperations.createOperation("stop", address); diff --git a/tests/domain-tests/src/test/java/org/wildfly/plugin/server/DomainTestServer.java b/tests/domain-tests/src/test/java/org/wildfly/plugin/server/DomainTestServer.java index cc01cf80..93e58852 100644 --- a/tests/domain-tests/src/test/java/org/wildfly/plugin/server/DomainTestServer.java +++ b/tests/domain-tests/src/test/java/org/wildfly/plugin/server/DomainTestServer.java @@ -6,17 +6,20 @@ package org.wildfly.plugin.server; import java.io.IOException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.jboss.as.controller.client.ModelControllerClient; import org.jboss.as.controller.client.helpers.domain.DomainClient; +import org.junit.Assert; import org.wildfly.core.launcher.DomainCommandBuilder; import org.wildfly.core.launcher.Launcher; import org.wildfly.core.launcher.ProcessHelper; import org.wildfly.plugin.tests.TestEnvironment; import org.wildfly.plugin.tools.ConsoleConsumer; import org.wildfly.plugin.tools.DeploymentManager; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.DomainManager; +import org.wildfly.plugin.tools.server.ServerManager; /** * @author James R. Perkins @@ -29,6 +32,7 @@ public class DomainTestServer implements TestServer { private volatile Thread shutdownThread; private volatile Thread consoleConsumer; private volatile DomainClient client; + private volatile DomainManager serverManager; private volatile DeploymentManager deploymentManager; @Override @@ -51,7 +55,10 @@ public void start() { client = DomainClient.Factory .create(ModelControllerClient.Factory.create(TestEnvironment.HOSTNAME, TestEnvironment.PORT)); currentProcess = process; - ServerHelper.waitForDomain(process, client, TestEnvironment.TIMEOUT); + serverManager = ServerManager.builder().process(process).client(client).domain(); + if (!serverManager.waitFor(TestEnvironment.TIMEOUT, TimeUnit.SECONDS)) { + Assert.fail(String.format("Server did not start withing %d seconds.", TestEnvironment.TIMEOUT)); + } deploymentManager = DeploymentManager.Factory.create(client); } catch (Throwable t) { try { @@ -76,7 +83,7 @@ public void stop() { } catch (Exception ignore) { } if (STARTED.compareAndSet(true, false)) { - ServerHelper.shutdownDomain(client); + serverManager.shutdown(); } final Thread consoleConsumer = this.consoleConsumer; if (consoleConsumer != null) { diff --git a/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java b/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java index 6791ec09..35be7b08 100644 --- a/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java +++ b/tests/shared/src/main/java/org/wildfly/plugin/tests/AbstractProvisionConfiguredMojoTestCase.java @@ -57,8 +57,8 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; import org.wildfly.core.launcher.ProcessHelper; -import org.wildfly.plugin.tools.ServerHelper; import org.wildfly.plugin.tools.bootablejar.BootableJarSupport; +import org.wildfly.plugin.tools.server.ServerManager; /** * A class to construct a properly configured MOJO. @@ -362,8 +362,9 @@ protected boolean checkURL(String url) { private static void shutdown() throws IOException { try (ModelControllerClient client = ModelControllerClient.Factory.create(TestEnvironment.HOSTNAME, TestEnvironment.PORT)) { - if (ServerHelper.isStandaloneRunning(client)) { - ServerHelper.shutdownStandalone(client, (int) TestEnvironment.TIMEOUT); + final ServerManager serverManager = ServerManager.builder().client(client).standalone(); + if (serverManager.isRunning()) { + serverManager.shutdown(TestEnvironment.TIMEOUT); } } } @@ -380,8 +381,9 @@ protected void checkURL(Path dir, String fileName, String url, boolean start, St // Check the server state in all cases. All test cases are provisioning the manager layer. try (ModelControllerClient client = ModelControllerClient.Factory.create(TestEnvironment.HOSTNAME, TestEnvironment.PORT)) { + final ServerManager serverManager = ServerManager.builder().client(client).standalone(); // Wait for the server to start, this calls into the management interface. - ServerHelper.waitForStandalone(process, client, TestEnvironment.TIMEOUT); + serverManager.waitFor(TestEnvironment.TIMEOUT, TimeUnit.SECONDS); } if (url == null) { diff --git a/tests/shared/src/test/java/org/wildfly/plugin/server/ServerFunctionMojoTest.java b/tests/shared/src/test/java/org/wildfly/plugin/server/ServerFunctionMojoTest.java index 6156b978..c7c0fda4 100644 --- a/tests/shared/src/test/java/org/wildfly/plugin/server/ServerFunctionMojoTest.java +++ b/tests/shared/src/test/java/org/wildfly/plugin/server/ServerFunctionMojoTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.wildfly.plugin.tests.AbstractWildFlyMojoTest; import org.wildfly.plugin.tests.TestEnvironment; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; /** * @author James R. Perkins @@ -32,21 +32,17 @@ public class ServerFunctionMojoTest extends AbstractWildFlyMojoTest { public void shutdown() throws Exception { // Ensure the server is shutdown try (ModelControllerClient client = createClient()) { - boolean isDomain; - try { - isDomain = ServerHelper.getContainerDescription(client).isDomain(); - } catch (Exception ignore) { - isDomain = false; + ServerManager serverManager = ServerManager.builder() + .client(client) + .standalone(); + if (serverManager.isRunning()) { + serverManager.shutdown(); } - // Ensure we shutdown the server - if (isDomain) { - if (ServerHelper.isDomainRunning(client)) { - ServerHelper.shutdownDomain(client); - } - } else { - if (ServerHelper.isStandaloneRunning(client)) { - ServerHelper.shutdownStandalone(client); - } + serverManager = ServerManager.builder() + .client(client) + .domain(); + if (serverManager.isRunning()) { + serverManager.shutdown(); } } } @@ -56,10 +52,11 @@ public void testStartStandalone() throws Exception { final StartMojo mojo = getStartMojo(); mojo.execute(); try (ModelControllerClient client = createClient()) { + final ServerManager serverManager = ServerManager.builder().client(client).standalone(); // Verify the server is running - Assert.assertTrue("The start goal did not start the server.", ServerHelper.isStandaloneRunning(client)); + Assert.assertTrue("The start goal did not start the server.", serverManager.isRunning()); Assert.assertFalse("This should be a standalone server, but found a domain server.", - ServerHelper.getContainerDescription(client).isDomain()); + serverManager.containerDescription().isDomain()); } } @@ -69,16 +66,18 @@ public void testShutdownStandalone() throws Exception { final StartMojo startMojo = getStartMojo(); startMojo.execute(); try (ModelControllerClient client = createClient()) { + final ServerManager serverManager = ServerManager.builder().client(client).standalone(); // Verify the server is running - Assert.assertTrue("The start goal did not start the server.", ServerHelper.isStandaloneRunning(client)); + Assert.assertTrue("The start goal did not start the server.", serverManager.isRunning()); } // Look up the stop mojo and attempt to stop final ShutdownMojo stopMojo = lookupMojoAndVerify("shutdown", "shutdown-pom.xml"); stopMojo.execute(); try (ModelControllerClient client = createClient()) { + final ServerManager serverManager = ServerManager.builder().client(client).standalone(); // Verify the server is running - Assert.assertFalse("The start goal did not start the server.", ServerHelper.isStandaloneRunning(client)); + Assert.assertFalse("The start goal did not start the server.", serverManager.isRunning()); } } @@ -90,8 +89,9 @@ public void testStartAndAddUserStandalone() throws Exception { setValue(mojo, "addUser", createAddUsers("admin:admin.1234:admin", "user:user.1234:user,mgmt::true")); mojo.execute(); try (ModelControllerClient client = createClient()) { + final ServerManager serverManager = ServerManager.builder().client(client).standalone(); // Verify the server is running - Assert.assertTrue("The start goal did not start the server.", ServerHelper.isStandaloneRunning(client)); + Assert.assertTrue("The start goal did not start the server.", serverManager.isRunning()); } final Path standaloneConfigDir = TestEnvironment.WILDFLY_HOME.resolve("standalone").resolve("configuration"); @@ -124,10 +124,11 @@ public void testStartDomain() throws Exception { final StartMojo mojo = getStartMojo("start-domain-pom.xml"); mojo.execute(); try (DomainClient client = DomainClient.Factory.create(createClient())) { + final ServerManager serverManager = ServerManager.builder().client(client).domain(); // Verify the server is running - Assert.assertTrue("The start goal did not start the server.", ServerHelper.isDomainRunning(client)); + Assert.assertTrue("The start goal did not start the server.", serverManager.isRunning()); Assert.assertTrue("This should be a domain server server, but found a standalone server.", - ServerHelper.getContainerDescription(client).isDomain()); + serverManager.containerDescription().isDomain()); } } @@ -137,16 +138,18 @@ public void testShutdownDomain() throws Exception { final StartMojo startMojo = getStartMojo("start-domain-pom.xml"); startMojo.execute(); try (DomainClient client = DomainClient.Factory.create(createClient())) { + final ServerManager serverManager = ServerManager.builder().client(client).domain(); // Verify the server is running - Assert.assertTrue("The start goal did not start the server.", ServerHelper.isDomainRunning(client)); + Assert.assertTrue("The start goal did not start the server.", serverManager.isRunning()); } // Look up the stop mojo and attempt to stop final ShutdownMojo stopMojo = lookupMojoAndVerify("shutdown", "shutdown-pom.xml"); stopMojo.execute(); try (DomainClient client = DomainClient.Factory.create(createClient())) { + final ServerManager serverManager = ServerManager.builder().client(client).domain(); // Verify the server is running - Assert.assertFalse("The start goal did not start the server.", ServerHelper.isDomainRunning(client)); + Assert.assertFalse("The start goal did not start the server.", serverManager.isRunning()); } } diff --git a/tests/standalone-tests/src/test/java/org/wildfly/plugin/server/StandaloneTestServer.java b/tests/standalone-tests/src/test/java/org/wildfly/plugin/server/StandaloneTestServer.java index 648c0b1c..0537c4f1 100644 --- a/tests/standalone-tests/src/test/java/org/wildfly/plugin/server/StandaloneTestServer.java +++ b/tests/standalone-tests/src/test/java/org/wildfly/plugin/server/StandaloneTestServer.java @@ -6,16 +6,19 @@ package org.wildfly.plugin.server; import java.io.IOException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.jboss.as.controller.client.ModelControllerClient; +import org.junit.Assert; import org.wildfly.core.launcher.Launcher; import org.wildfly.core.launcher.ProcessHelper; import org.wildfly.core.launcher.StandaloneCommandBuilder; import org.wildfly.plugin.tests.TestEnvironment; import org.wildfly.plugin.tools.ConsoleConsumer; import org.wildfly.plugin.tools.DeploymentManager; -import org.wildfly.plugin.tools.ServerHelper; +import org.wildfly.plugin.tools.server.ServerManager; +import org.wildfly.plugin.tools.server.StandaloneManager; /** * @author James R. Perkins @@ -27,6 +30,7 @@ public class StandaloneTestServer implements TestServer { private volatile Thread consoleConsumer; private volatile ModelControllerClient client; private volatile DeploymentManager deploymentManager; + private volatile StandaloneManager serverManager; @Override public void start() { @@ -43,8 +47,11 @@ public void start() { shutdownThread = ProcessHelper.addShutdownHook(process); client = ModelControllerClient.Factory.create(TestEnvironment.HOSTNAME, TestEnvironment.PORT); currentProcess = process; - ServerHelper.waitForStandalone(process, client, TestEnvironment.TIMEOUT); - deploymentManager = DeploymentManager.Factory.create(client); + serverManager = ServerManager.builder().process(process).client(client).standalone(); + if (!serverManager.waitFor(TestEnvironment.TIMEOUT, TimeUnit.SECONDS)) { + Assert.fail(String.format("Server did not start withing %d seconds.", TestEnvironment.TIMEOUT)); + } + deploymentManager = serverManager.deploymentManager(); } catch (Throwable t) { try { throw new RuntimeException("Failed to start server", t); @@ -68,7 +75,7 @@ public void stop() { } catch (Exception ignore) { } if (STARTED.compareAndSet(true, false)) { - ServerHelper.shutdownStandalone(client); + serverManager.shutdown(); } final Thread consoleConsumer = this.consoleConsumer; if (consoleConsumer != null) {