[jboss-cvs] JBossAS SVN: r111032 - projects/jboss-jca/branches/performance/faban/src/main/java/org/jboss/jca/perf/services/ironjacamar.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 25 09:36:33 EDT 2011


Author: whitingjr
Date: 2011-03-25 09:36:33 -0400 (Fri, 25 Mar 2011)
New Revision: 111032

Modified:
   projects/jboss-jca/branches/performance/faban/src/main/java/org/jboss/jca/perf/services/ironjacamar/IronJacamarService.java
Log:
Updated with working service start implementation. Corrected start script command formatting.

Modified: projects/jboss-jca/branches/performance/faban/src/main/java/org/jboss/jca/perf/services/ironjacamar/IronJacamarService.java
===================================================================
--- projects/jboss-jca/branches/performance/faban/src/main/java/org/jboss/jca/perf/services/ironjacamar/IronJacamarService.java	2011-03-25 13:28:37 UTC (rev 111031)
+++ projects/jboss-jca/branches/performance/faban/src/main/java/org/jboss/jca/perf/services/ironjacamar/IronJacamarService.java	2011-03-25 13:36:33 UTC (rev 111032)
@@ -21,7 +21,6 @@
   */
 package org.jboss.jca.perf.services.ironjacamar;
 
-import java.io.File;
 import java.io.IOException;
 import java.net.Socket;
 import java.util.Arrays;
@@ -29,6 +28,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.commons.lang.StringUtils;
 
 import com.sun.faban.common.Command;
 import com.sun.faban.driver.ConfigurationException;
@@ -56,26 +56,22 @@
    public ServiceContext sc ;
    private Logger logger = Logger.getLogger(IronJacamarService.class.getName());
    private List<String> jcaServers;
-   private String serverHome;
+   private String workingDirectory;
    private String serverStartScript;
-   private String jcaCommand;
+   private String jcaCommand, javaOpts;
    private String interfaceBindname;
    private String dbConnectUrl, dbDriverClass, dbUserName, dbPassword;
    private Long port;
    private static final String SERVER_HOME = "serverHome";
    private static final String RUN_SCRIPT = "runScript";
-   private static final String INTERFACE_BINDNAME = "intefaceBindname";
+   private static final String INTERFACE_BINDNAME = "interfaceBindname";
    private static final String DB_CONNECT_URL = "dbConnectUrl";
    private static final String DB_DRIVER_CLASS = "dbDriverClass";
    private static final String DB_USERNAME = "dbUsername";
    private static final String DB_PASSWORD = "dbPassword";
    private static final String LISTEN_PORT = "listenPort";
-   
-   private static final String SCRIPT_PATH = "$1%s$2%sbin$2%s$3%s";
-   private static final String COMMAND_WITH_INTERFACE_BINDING = "$1%s -b $2%s";
-   private static final String COMMAND_WITH_DB_CONNECT_URL_PROPERTY = "$1%s -Ddb-vendor.connectionURL=$2%s";
-   private static final String COMMAND_WITH_DB_DRIVER_FQCN_PROPERTY = "$1%s -Ddb-vendor.driverClass=$2%s";
-   private static final String COMMAND_WITH_DB_USERNAME_AND_PASSWORD = "$1%s -Ddb-vendor.driverClass=$2%s";
+   private static final String JAVA_OPTS = "JAVA_OPTS";
+   private static final String BIN = "bin";
       
    /**
     * This method first extracts the properties from the configuration xml.
@@ -96,65 +92,63 @@
       {
          throw new ConfigurationException("Server hosts is empty, enter a host name.");
       }
-      this.serverHome = sc.getProperty(SERVER_HOME);
-      if (null == serverHome || "".equals(serverHome.trim()))
+      
+      if (StringUtils.isBlank(sc.getProperty(SERVER_HOME)))
       {
          throw new ConfigurationException("Server home is undefined, enter a server path.");
       }
-      this.serverStartScript = sc.getProperty(RUN_SCRIPT);
-      if (null == serverStartScript )
+      else 
       {
-         throw new ConfigurationException("Start script file name is undefined, enter a file name.");
+         this.workingDirectory = String.format("%1$s/%2$s/",  sc.getProperty(SERVER_HOME), BIN);
       }
-      else if ("".equals(serverStartScript.trim()))
+      
+      if (StringUtils.isBlank( sc.getProperty(RUN_SCRIPT)) )
       {
          throw new ConfigurationException("Start script file name is undefined, enter a file name.");
       }
-      
-      this.dbConnectUrl  = sc.getProperty(DB_CONNECT_URL);
-      if (null == this.dbConnectUrl )
+      else
       {
-         throw new ConfigurationException("db connect url is undefined, enter a url.");
+         this.serverStartScript = sc.getProperty(RUN_SCRIPT);
       }
-      else if ("".equals(this.dbConnectUrl.trim()))
+      if (StringUtils.isBlank(sc.getProperty(DB_CONNECT_URL)) )
       {
          throw new ConfigurationException("db connect url is undefined, enter a url.");
       }
-      
-      this.dbDriverClass  = sc.getProperty(DB_DRIVER_CLASS);
-      if (null == this.dbDriverClass )
+      else 
       {
-         throw new ConfigurationException("db driver class is undefined, enter a url.");
+         this.dbConnectUrl  = sc.getProperty(DB_CONNECT_URL);
       }
-      else if ("".equals(this.dbDriverClass.trim()))
+      if (StringUtils.isBlank(sc.getProperty(DB_DRIVER_CLASS)))
       {
          throw new ConfigurationException("db driver class is undefined, enter a url.");
       }
-      
-      this.dbUserName = sc.getProperty(DB_USERNAME);
-      if (null == this.dbUserName )
+      else 
       {
-         throw new ConfigurationException("db username is undefined, enter a username.");
+         this.dbDriverClass  = sc.getProperty(DB_DRIVER_CLASS);
       }
-      else if ("".equals(this.dbUserName.trim()))
+      if (StringUtils.isBlank(sc.getProperty(DB_USERNAME)))
       {
          throw new ConfigurationException("db username is undefined, enter a username.");
       }
+      else 
+      {
+         this.dbUserName = sc.getProperty(DB_USERNAME);
+      }
       
-      this.dbPassword = sc.getProperty(DB_PASSWORD);
+      this.dbPassword = StringUtils.defaultString( sc.getProperty(DB_PASSWORD));
       // an empty value for the password is permitted
       
       this.interfaceBindname = sc.getProperty(INTERFACE_BINDNAME);
       // an empty value is permitted
       
-      String portValue= sc.getProperty(LISTEN_PORT);
-      if (null == portValue )
+      String portValue = null;
+      if (StringUtils.isBlank(sc.getProperty(LISTEN_PORT)))
       {
          throw new ConfigurationException("Listen port is undefined, enter a port number.");
       }
-      else if ("".equals(portValue.trim()))
+      else 
       {
-         throw new ConfigurationException("Listen port is undefined, enter a port number.");
+         portValue = sc.getProperty(LISTEN_PORT);
       }
       try
       {
@@ -166,14 +160,14 @@
       }
       
       //build command
-      String fullScriptPath = String.format(SCRIPT_PATH, this.serverHome, File.separator, this.serverStartScript);
-      if (null != this.interfaceBindname && !"".equals(this.interfaceBindname.trim()))
+      String fullScriptPath = String.format("%1$s/%2$s", this.workingDirectory,this.serverStartScript);
+      if (StringUtils.isNotBlank(this.interfaceBindname))
       {
          this.jcaCommand = withBindFlag(this.interfaceBindname, fullScriptPath);
       }
-      //add required properties
-      this.jcaCommand = withDBConnectUrl(this.dbConnectUrl, this.jcaCommand);
-      this.jcaCommand = withDBDriverFQCN(this.dbDriverClass, jcaCommand);
+      this.javaOpts = withDBConnectUrl(this.dbConnectUrl);
+      this.javaOpts = withDBDriverFQCN(this.dbDriverClass);
+      this.javaOpts = withUsernamePassword(this.dbUserName, this.dbPassword);
       if (logger.isLoggable(Level.FINE))
       {
          logger.fine("Configuring IronJacamar Complete.");
@@ -188,26 +182,27 @@
       {
          if (logger.isLoggable(Level.FINE))
          {
-            logger.fine(String.format( "Starting IronJacamar on [$1%s]" , host));
+            logger.fine(String.format( "Starting IronJacamar on [%1$s]" , host));
          }
          Command command = new Command(this.jcaCommand);
          if (logger.isLoggable(Level.FINE))
          {
             logger.fine("Starting IronJacamar.");
          }
-         command.setWorkingDirectory(this.serverHome);
+         command.setWorkingDirectory(this.workingDirectory);
          command.setSynchronous(false);
+         command.setEnvironment(new String[] {String.format("%1$s=%2$s", JAVA_OPTS, this.javaOpts) });
          try
          {
             RunContext.exec(host, command);
             // check it is running
             if (!checkServerListening(host, port))
             {
-               logger.severe(String.format( "IronJacamar server did not startup and respond to requests on [$1%s]" , host));
+               logger.severe(String.format( "IronJacamar server did not startup and respond to requests on [%1$s]" , host));
             }
             if (logger.isLoggable(Level.FINE))
             {
-               logger.fine(String.format("Completed IronJacamar start attempt on [$1%s].", host) );
+               logger.fine(String.format("Completed IronJacamar start attempt on [%1$s].", host) );
             }
          }
          catch (Exception e)
@@ -287,6 +282,39 @@
       {
          logger.fine("IronJacamar server is stopped.");
       }
+      for(String host : jcaServers)
+      {
+         if (logger.isLoggable(Level.FINE))
+         {
+            logger.fine(String.format( "Stopping IronJacamar on [%1$s]" , host));
+         }
+         Command command = new Command("java -jar fungal-cli.jar shutdown");
+         if (logger.isLoggable(Level.FINE))
+         {
+            logger.fine("Starting IronJacamar.");
+         }
+         command.setWorkingDirectory(this.workingDirectory);
+         command.setSynchronous(false);
+         //command.setEnvironment(new String[] {String.format("%1$s=%2$s", JAVA_OPTS, this.javaOpts) });
+         try
+         {
+            RunContext.exec(host, command);
+            // check it is running
+            /*if (!checkServerListening(host, port))
+            {
+               logger.severe(String.format( "IronJacamar server did not stop on [%1$s]" , host));
+            }
+            */
+            if (logger.isLoggable(Level.FINE))
+            {
+               logger.fine(String.format("Completed IronJacamar shutdown on [%1$s].", host) );
+            }
+         }
+         catch (Exception e)
+         {
+            logger.log(Level.WARNING, "Stop failure.", e);
+         }
+      }
    }
    
    @ClearLogs
@@ -318,7 +346,7 @@
       String returnValue = command;
       if (null != bindValue && !"".equals(bindValue.trim()))
       {
-         returnValue = String.format(COMMAND_WITH_INTERFACE_BINDING, command, bindValue);
+         returnValue = String.format("%1$s -b %2$s", command, bindValue);
       }
       return returnValue;
    }
@@ -329,9 +357,9 @@
     * @param command
     * @return
     */
-   private String withDBConnectUrl(String url, String command)
+   private String withDBConnectUrl(String url)
    {
-      return String.format(COMMAND_WITH_DB_CONNECT_URL_PROPERTY, command, url);
+      return String.format("-Ddb-vendor.connectionURL=%1$s", url);
    }
    
    /**
@@ -340,10 +368,19 @@
     * @param command
     * @return
     */
-   private String withDBDriverFQCN(String fqcn, String command)
+   private String withDBDriverFQCN(String fqcn)
    {
-      return String.format(COMMAND_WITH_DB_DRIVER_FQCN_PROPERTY, command, fqcn);
+      return String.format("%1$s -Ddb-vendor.driverClass=%2$s", javaOpts, fqcn);
    }
-   
-   
+   /**
+    * This method adds a username and password property.
+    * 
+    * @param fqcn
+    * @param command
+    * @return
+    */
+   private String withUsernamePassword(String username, String password)
+   {
+      return String.format("%1$s -Ddb-vendor.userName=%2$s -Ddb-vendor.password=%3$s ", javaOpts, username, password);
+   }
 }



More information about the jboss-cvs-commits mailing list