[jboss-cvs] JBossAS SVN: r82586 - in projects/server-manager/trunk/src: test/java/org/jboss/jbossas/servermanager/test/common and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 2 01:35:04 EST 2009
Author: akostadinov
Date: 2009-01-02 01:35:03 -0500 (Fri, 02 Jan 2009)
New Revision: 82586
Added:
projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopShutdownJarTest.java
Modified:
projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerController.java
projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerManager.java
projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/common/AsLifecycleDelegate.java
projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopTest.java
Log:
JBASM-27 - make it possible to use the legacy shutdown.jar method
Modified: projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerController.java
===================================================================
--- projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerController.java 2009-01-02 05:10:14 UTC (rev 82585)
+++ projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerController.java 2009-01-02 06:35:03 UTC (rev 82586)
@@ -27,11 +27,13 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.io.Writer;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.Socket;
import java.net.URL;
import java.net.URLConnection;
+import java.util.StringTokenizer;
/**
* Starts, stops, and (eventually) reboots server instances.
@@ -41,6 +43,7 @@
*/
public abstract class ServerController
{
+ private static final String SHUTDOWN_CLASS = "org.jboss.Shutdown";
private static final String MAIN = "org.jboss.Main";
@@ -161,6 +164,85 @@
return execCmd;
}
+ /**
+ * Get the server shutdown command line.
+ *
+ * @param server the server
+ * @param manager the manager
+ * @return the shutdown command
+ * @throws IOException for any error
+ */
+ private static String getStopCommandLine(Server server, ServerManager manager) throws IOException
+ {
+ String strAuth="";
+ String username = server.getUsername();
+ String password = server.getPassword();
+ if ( username != null && password != null )
+ {
+ strAuth = " -u " + username + " -p " + password;
+ }
+
+ String execCmd = manager.getJavaExecutable() + " -cp " + manager.getStopClasspath() + " ";
+ execCmd = execCmd + SHUTDOWN_CLASS + " --server " + server.getServerUrl();
+ execCmd = execCmd + strAuth +" --shutdown";
+ return execCmd;
+ }
+
+ /**
+ * Shutdown server with shutdown.jar
+ *
+ * @param server the server
+ * @param manager the manager
+ * @return the command output
+ * @throws IOException for any error
+ * @throws InterruptedException if interrupted while waiting for shutdown.jar
+ */
+ private static boolean stopServerCli(Server server, ServerManager manager, Writer log) throws IOException, InterruptedException
+ {
+ String shutdownCmd = getStopCommandLine(server, manager);
+ System.out.println("Shutting down server: " + shutdownCmd);
+
+ StringTokenizer cmdArrayTokenizer = new StringTokenizer(shutdownCmd);
+ String[] cmdArray = new String[cmdArrayTokenizer.countTokens()];
+ for (int i=0; i<cmdArray.length; i++)
+ {
+ cmdArray[i]=cmdArrayTokenizer.nextToken();
+ }
+
+ ProcessBuilder builder = new ProcessBuilder(cmdArray);
+ builder.redirectErrorStream(true);
+ Process proc = builder.start();
+
+ try
+ {
+ proc.getOutputStream().close();
+ BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ PrintWriter output = new PrintWriter(log);
+
+ OutputPumper pumper = new OutputPumper(stdout, output);
+ pumper.start();
+
+ // Wait 20.5 seconds for shutdown.jar to complete
+ pumper.join(20000);
+ Thread.sleep(500);
+
+ if (proc.exitValue() != 0) {
+ return false;
+ }
+ }
+ catch (IllegalThreadStateException itse)
+ {
+ return false;
+ }
+ finally
+ {
+ proc.destroy();
+ closeAllStreams(proc);
+ }
+
+ return true;
+ }
+
/**
* Wait until the jboss instance is full initialized
* @param server
@@ -227,7 +309,7 @@
}
}
}
- catch (java.io.IOException e)
+ catch (IOException e)
{
return false;
}
@@ -267,6 +349,9 @@
*/
public static void stopServer(Server server, ServerManager manager) throws IOException
{
+ boolean useShutdownJar = Boolean.getBoolean("sm.legacy.shutdown");
+ StringWriter shutdownJarOutput = null;
+
boolean cleanShutdown = true;
Throwable shutdownException = null;
@@ -280,7 +365,15 @@
/** Catch everything as we want the server killed unconditionally **/
try
{
- server.doShutdown();
+ if (useShutdownJar)
+ {
+ shutdownJarOutput = new StringWriter(512);
+ cleanShutdown = stopServerCli(server, manager, shutdownJarOutput);
+ }
+ else
+ {
+ server.doShutdown();
+ }
}
catch (Throwable e)
{
@@ -296,15 +389,16 @@
if (!cleanShutdown)
{
- // try to dump server trace
+ // try to provide some debug info
try
{
- writeServerDump(server);
+ if (useShutdownJar)
+ System.err.println(shutdownJarOutput.toString());
+ else
+ writeServerDump(server);
}
catch (Throwable e)
{
- System.err.println("Cannot write to "
- + server.getDumpFile().getAbsolutePath());
e.printStackTrace();
}
@@ -370,10 +464,20 @@
File dumpFile = server.getDumpFile();
System.out.println("Writing server thread dump to "
+ dumpFile.getAbsolutePath());
- FileWriter dumpFW = new FileWriter(dumpFile);
- dumpFW.write(threadDump);
- dumpFW.flush();
- dumpFW.close();
+
+ try
+ {
+ FileWriter dumpFW = new FileWriter(dumpFile);
+ dumpFW.write(threadDump);
+ dumpFW.flush();
+ dumpFW.close();
+ }
+ catch (Exception e)
+ {
+ System.err.println("Cannot write to "
+ + dumpFile.getAbsolutePath());
+ e.printStackTrace();
+ }
}
/**
Modified: projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerManager.java
===================================================================
--- projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerManager.java 2009-01-02 05:10:14 UTC (rev 82585)
+++ projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerManager.java 2009-01-02 06:35:03 UTC (rev 82586)
@@ -225,6 +225,19 @@
return runjar.toString() + File.pathSeparator + javaJar.toString();
}
+ /**
+ * The classpath used to stop the server.
+ *
+ * @return the string to put on the classpath
+ */
+ protected String getStopClasspath()
+ {
+ File shutdownJar = new File(jbossHome + "/bin/shutdown.jar");
+ File clientJar = new File(jbossHome + "/client/jbossall-client.jar");
+ File logJar = new File(jbossHome + "/client/jboss-common.jar");
+ return shutdownJar.toString() + File.pathSeparator + clientJar.toString() + File.pathSeparator + logJar.toString();
+ }
+
/**
* Get the jboss home.
*
Modified: projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/common/AsLifecycleDelegate.java
===================================================================
--- projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/common/AsLifecycleDelegate.java 2009-01-02 05:10:14 UTC (rev 82585)
+++ projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/common/AsLifecycleDelegate.java 2009-01-02 06:35:03 UTC (rev 82586)
@@ -78,15 +78,24 @@
*/
public void startJbossAs(String serverName) throws Throwable
{
+ Server server = null;
+
// Get ServerManager
ServerManager manager = this.getServerManager();
- // Create the Server
- Server server = new Server();
- server.setName(serverName);
+ try
+ {
+ server = manager.getServer(serverName);
+ }
+ catch (IllegalArgumentException e)
+ {
+ // Create the Server
+ server = new Server();
+ server.setName(serverName);
- // Add a Server to the Manager with defaults
- applyServerDefaults(server, manager);
+ // Add a Server to the Manager with defaults
+ applyServerDefaults(server, manager);
+ }
// Start the Server
ServerController.startServer(server, manager);
Added: projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopShutdownJarTest.java
===================================================================
--- projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopShutdownJarTest.java (rev 0)
+++ projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopShutdownJarTest.java 2009-01-02 06:35:03 UTC (rev 82586)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jbossas.servermanager.test.startstop.unit;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * StartStopShutdownJarTest
+ *
+ * Simple tests to check that the server may be started and stopped,
+ * and further that the ServerController may query as to the state
+ * of AS; by this tests the legacy shutdown.jar server stop method is
+ * used
+ *
+ * @author <a href="mailto:akostadinov at jboss.org">Aleksandar Kostadinov</a>
+ * @version $Revision: $
+ */
+ at RunWith(Suite.class)
+ at Suite.SuiteClasses({
+ StartStopTest.class
+})public class StartStopShutdownJarTest
+{
+ public static final String SHUTDOWN_METHOD_PROPERTY = "sm.legacy.shutdown";
+
+ @BeforeClass
+ public static void beforeClass()
+ {
+ System.setProperty(SHUTDOWN_METHOD_PROPERTY, "true");
+ }
+
+ @AfterClass
+ public static void afterClass()
+ {
+ System.clearProperty(SHUTDOWN_METHOD_PROPERTY);
+ }
+}
Modified: projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopTest.java
===================================================================
--- projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopTest.java 2009-01-02 05:10:14 UTC (rev 82585)
+++ projects/server-manager/trunk/src/test/java/org/jboss/jbossas/servermanager/test/startstop/unit/StartStopTest.java 2009-01-02 06:35:03 UTC (rev 82586)
@@ -117,9 +117,7 @@
@BeforeClass
public static void beforeClass() throws Throwable
{
-
getDelegate().startJbossAs(SERVER_NAME);
-
}
/**
@@ -132,15 +130,7 @@
@AfterClass
public static void afterClass() throws Throwable
{
- // Obtain the server
- ServerManager manager = delegate.getServerManager();
- Server server = manager.getServer(SERVER_NAME);
-
- // If started/running
- if (ServerController.isServerStarted(server))
- {
getDelegate().stopJbossAs(SERVER_NAME);
- }
}
//----------------------------------------------------------------------------------||
More information about the jboss-cvs-commits
mailing list