[jboss-cvs] JBossAS SVN: r79006 - in projects/server-manager/trunk: src/main/java/org/jboss/jbossas/servermanager and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 1 19:54:48 EDT 2008


Author: ALRubinger
Date: 2008-10-01 19:54:48 -0400 (Wed, 01 Oct 2008)
New Revision: 79006

Modified:
   projects/server-manager/trunk/pom.xml
   projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/Server.java
   projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerManager.java
Log:
[JBASM-13] Add to server-manager a port of JMX invocations upon a Server from jboss-test

Modified: projects/server-manager/trunk/pom.xml
===================================================================
--- projects/server-manager/trunk/pom.xml	2008-10-01 23:20:45 UTC (rev 79005)
+++ projects/server-manager/trunk/pom.xml	2008-10-01 23:54:48 UTC (rev 79006)
@@ -24,20 +24,42 @@
     <url>http://anonsvn.jboss.org/repos/maven/jbossas/projects/server-manager/trunk</url>
   </scm>
 
+
   <!-- Properties -->
-  <properties />
+  <properties>
 
+    <!--  
+      
+      Versioning
+      
+    -->
+
+    <!-- External -->
+    <version.junit_junit>4.4</version.junit_junit>
+    <version.commons.logging_commons_logging>1.1.1</version.commons.logging_commons_logging>
+
+  </properties>
+
   <!-- Build Configuration -->
   <build />
 
   <!-- Dependencies -->
   <dependencies>
+  
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.4</version>
+      <version>${version.junit_junit}</version>
       <scope>test</scope>
     </dependency>
+
+    <!-- Apache Commons Logging -->
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <version>${version.commons.logging_commons_logging}</version>
+    </dependency>
+
   </dependencies>
 
 </project>

Modified: projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/Server.java
===================================================================
--- projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/Server.java	2008-10-01 23:20:45 UTC (rev 79005)
+++ projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/Server.java	2008-10-01 23:54:48 UTC (rev 79006)
@@ -26,13 +26,21 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
+
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * A Server.
  *
@@ -41,6 +49,8 @@
  */
 public class Server
 {
+   private static final Log log = LogFactory.getLog(Server.class);
+   
    /** the directory where server config instances live **/
    public static final String JBOSS_SERVER_CONFIG_DIR_NAME = "server";
 
@@ -94,6 +104,12 @@
 
    /** the Naming Context */
    private Context namingContext;
+   
+   /** The MBean Server Connection for JMX Invocation **/
+   private MBeanServerConnection mBeanServerConnection;
+   
+   /** ObjectName of the Main Deployer **/
+   public final static String DEPLOYER_NAME = "jboss.system:service=MainDeployer";
 
    /** Server URL Override */
    private String serverUrl = null;
@@ -554,22 +570,164 @@
    {
 	this.namingContext = namingContext;
    }
+   
+   /*
+    * Code below this marker has been ported from jboss-test to supply 
+    * the Server with invokable operations support
+    */
+   
+   /**
+    * Gets the Main Deployer Name attribute of the JBossTestCase object
+    *
+    * @return                                  The Main DeployerName value
+    * @exception MalformedObjectNameException  Description of Exception
+    */
+   ObjectName getDeployerName() throws MalformedObjectNameException
+   {
+      return new ObjectName(DEPLOYER_NAME);
+   }
+   
+   /**
+    * Deploy a package with the main deployer. The supplied name is
+    * interpreted as a url, or as a filename in jbosstest.deploy.lib or output/lib.
+    *
+    * @param name           filename/url of package to deploy.
+    * @exception Exception  Description of Exception
+    */
+   public void deploy(File file) throws Exception
+   {
+      if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+      {
+         log.debug("Skipping deployment of: " + name);
+         return;
+      }
 
+      URL deployURL = file.toURL();
+      log.debug("Deploying " + name + ", url=" + deployURL);
+      invoke(getDeployerName(),
+         "deploy",
+         new Object[]{deployURL},
+         new String[]{"java.net.URL"});
+   }
 
+   public void redeploy(File file) throws Exception
+   {
+      if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+      {
+         log.debug("Skipping redeployment of: " + name);
+         return;
+      }
+
+      URL deployURL = file.toURL();
+      log.debug("Deploying " + name + ", url=" + deployURL);
+      invoke(getDeployerName(),
+         "redeploy",
+         new Object[]{deployURL},
+         new String[]{"java.net.URL"});
+   }
+   
    /**
+    * Undeploy a package with the main deployer. The supplied name is
+    * interpreted as a url, or as a filename in jbosstest.deploy.lib or output/lib.
     *
-    * Get the URL to pass to --server 
+    * @param name           filename/url of package to undeploy.
+    * @exception Exception  Description of Exception
+    */
+   public void undeploy(File file) throws Exception
+   {
+      if (Boolean.getBoolean("jbosstest.nodeploy") == true)
+         return;
+      URL deployURL = file.toURL();
+      log.debug("Undeploying " + name + ", url=" + deployURL);
+      Object[] args = {deployURL};
+      String[] sig = {"java.net.URL"};
+      invoke(getDeployerName(), "undeploy", args, sig);
+   }
+   
+   /**
+    * Gets the Server attribute of the JBossTestCase object
     *
+    * @return   The Server value
+    * @throws Exception for any error
     */
-   public String getServerUrl()
+   protected MBeanServerConnection getMBeanServerConnection() throws Exception
    {
-	serverUrl = getSysProperty("jbosstest.server.url");
+      if (mBeanServerConnection == null)
+      {
+         String adaptorName = System.getProperty("jbosstest.server.name", "jmx/invoker/RMIAdaptor");
+         Context context = this.getNamingContext();
+         mBeanServerConnection = (MBeanServerConnection) context.lookup(adaptorName);
+      }
+      return mBeanServerConnection;
+   }
+   
+   /**
+    * invoke wraps an invoke call to the mbean server in a lot of exception
+    * unwrapping.
+    *
+    * @param name           ObjectName of the mbean to be called
+    * @param method         mbean method to be called
+    * @param args           Object[] of arguments for the mbean method.
+    * @param sig            String[] of types for the mbean methods parameters.
+    * @return               Object returned by mbean method invocation.
+    * @exception Exception  Description of Exception
+    */
+   public Object invoke(ObjectName name, String method, Object[] args, String[] sig) throws Exception
+   {
+      return invoke(this.getMBeanServerConnection(), name, method, args, sig);
+   }
 
-	if (null == serverUrl ) 
-		return getRmiUrl();
-
-	return serverUrl;
+   public Object invoke(MBeanServerConnection server, ObjectName name, String method, Object[] args, String[] sig)
+      throws Exception
+   {
+      try
+      {
+         log.debug("Invoking " + name.getCanonicalName() + " method=" + method);
+         if (args != null)
+            log.debug("args=" + Arrays.asList(args));
+         return server.invoke(name, method, args, sig);
+      }
+      catch (javax.management.MBeanException e)
+      {
+         log.error("MbeanException", e.getTargetException());
+         throw e.getTargetException();
+      }
+      catch (javax.management.ReflectionException e)
+      {
+         log.error("ReflectionException", e.getTargetException());
+         throw e.getTargetException();
+      }
+      catch (javax.management.RuntimeOperationsException e)
+      {
+         log.error("RuntimeOperationsException", e.getTargetException());
+         throw e.getTargetException();
+      }
+      catch (javax.management.RuntimeMBeanException e)
+      {
+         log.error("RuntimeMbeanException", e.getTargetException());
+         throw e.getTargetException();
+      }
+      catch (javax.management.RuntimeErrorException e)
+      {
+         log.error("RuntimeErrorException", e.getTargetError());
+         throw e.getTargetError();
+      }
    }
 
+   /**
+   *
+   * Get the URL to pass to --server 
+   *
+   */
+  public String getServerUrl()
+  {
+   serverUrl = getSysProperty("jbosstest.server.url");
 
+   if (null == serverUrl ) 
+       return getRmiUrl();
+
+   return serverUrl;
+  }
+   
+   
 }

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	2008-10-01 23:20:45 UTC (rev 79005)
+++ projects/server-manager/trunk/src/main/java/org/jboss/jbossas/servermanager/ServerManager.java	2008-10-01 23:54:48 UTC (rev 79006)
@@ -40,8 +40,10 @@
     * Wait for 45 secs
     */
    // set jbossas.startup.timeout property in env.ANT_OPTS
-   private static final int WAIT_TIME = Integer.parseInt(System.getProperty("jbossas.startup.timeout", "45"));
-   private static final int START_TIME = Integer.parseInt(System.getProperty("jbossas.startup.timeout", "120"));
+   public static final String SYSTEM_PROPERTY_JBOSSAS_STARTUP_TIMEOUT = "jbossas.startup.timeout";
+   public static final String SYSTEM_PROPERTY_JBOSSAS_SHUTDOWN_TIMEOUT = "jbossas.shutdown.timeout";
+   private static final int WAIT_TIME = Integer.parseInt(System.getProperty(SYSTEM_PROPERTY_JBOSSAS_STARTUP_TIMEOUT, "45"));
+   private static final int START_TIME = Integer.parseInt(System.getProperty(SYSTEM_PROPERTY_JBOSSAS_STARTUP_TIMEOUT, "120"));
    
    /** jboss root **/
    private String jbossHome;




More information about the jboss-cvs-commits mailing list