incubator-olio-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r822802 - in /incubator/olio/workload/rails/trunk/src/org/apache/olio/services: NginxService.java RailsService.java Thin.java
Date Wed, 07 Oct 2009 16:55:47 GMT
Author: shanti
Date: Wed Oct  7 16:55:47 2009
New Revision: 822802

URL: http://svn.apache.org/viewvc?rev=822802&view=rev
Log:
More fixes for OLIO-35. Made configure method throw Exception if parameters are missing.

Modified:
    incubator/olio/workload/rails/trunk/src/org/apache/olio/services/NginxService.java
    incubator/olio/workload/rails/trunk/src/org/apache/olio/services/RailsService.java
    incubator/olio/workload/rails/trunk/src/org/apache/olio/services/Thin.java

Modified: incubator/olio/workload/rails/trunk/src/org/apache/olio/services/NginxService.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/rails/trunk/src/org/apache/olio/services/NginxService.java?rev=822802&r1=822801&r2=822802&view=diff
==============================================================================
--- incubator/olio/workload/rails/trunk/src/org/apache/olio/services/NginxService.java (original)
+++ incubator/olio/workload/rails/trunk/src/org/apache/olio/services/NginxService.java Wed
Oct  7 16:55:47 2009
@@ -53,11 +53,11 @@
     @Context public ServiceContext ctx;
     private Logger logger = Logger.getLogger(NginxService.class.getName());
     private String[] myServers = new String[1];
-    private String nginxCmd, confFile, errlogFile, acclogFile; 
+    private String nginxCmd, confFile, errlogFile = null, acclogFile = null;
 	private static String pidFile;
 	private boolean getAccLog = false;
     CommandHandle nginxHandles[];
-	private boolean skipService = false;
+	private boolean skipService = false, skipLogs = false;
 
     /**
      * Configures the service.
@@ -68,32 +68,42 @@
 	 * and set all parameters appropriately.
      */
     @Configure
-    public void configure() {
+    public void configure() throws ConfigurationException {
         myServers = ctx.getUniqueHosts();
 		if (myServers == null) {
 			skipService = true;
 			return;
         }
-
         nginxCmd = ctx.getProperty("cmdPath");
+        if (nginxCmd == null) {
+           throw new ConfigurationException("cmdPath property not set. Cannot start/stop
nginx");
+        }
+        String pidDir = ctx.getProperty("pidDir");
+        if (pidDir != null && pidDir.trim().length() > 0) {
+            if (!pidDir.endsWith(File.separator))
+                pidDir = pidDir + File.separator;
+            pidFile = pidDir + "nginx.pid";
+            logger.fine("pidFile is " + pidFile);
+        } else {
+            throw new ConfigurationException("pidDir not set. Cannot start/stop nginx.");
+        }
         confFile = ctx.getProperty("confPath");
-		nginxCmd = nginxCmd + " -c " + confFile;
+        if (confFile == null) {
+            logger.warning("confPath not set. Will use system default");
+        } else
+		    nginxCmd = nginxCmd + " -c " + confFile;
 		getAccLog = Boolean.parseBoolean(ctx.getProperty("getAccLog"));
 
         String logsDir = ctx.getProperty("logsDir");
-        if (!logsDir.endsWith(File.separator)) {
-            logsDir = logsDir + File.separator;
+        if (logsDir != null && logsDir.trim().length() > 0) {
+            if (!logsDir.endsWith(File.separator))
+                logsDir = logsDir + File.separator;
+            errlogFile = logsDir + "error.log";
+            acclogFile = logsDir + "access.log";
+        } else {
+            logger.warning("logsDir not set. Cannot grab logs");
+            skipLogs = true;
         }
-        errlogFile = logsDir + "error.log";
-        acclogFile = logsDir + "access.log";
-
-        String pidDir = ctx.getProperty("pidDir");
-        if (!pidDir.endsWith(File.separator)) {
-            pidDir = pidDir + File.separator;
-        }
-        pidFile = pidDir + "nginx.pid";
-        logger.fine("pidFile is " + pidFile);
-
         nginxHandles = new CommandHandle[myServers.length];
     }
 
@@ -118,7 +128,6 @@
                 } else {
                     logger.severe("Failed to find " + pidFile + " on " + server);
                 }
-
             } catch (Exception e) {
                 logger.log(Level.WARNING, "Failed to start nginx server.", e);
             }
@@ -260,7 +269,7 @@
      */
     @ClearLogs
     public void clearLogs() {
-		if (skipService) return;
+		if (skipService || skipLogs) return;
         for (int i = 0; i < myServers.length; i++) {
             if (RunContext.isFile(myServers[i], errlogFile)) {
                 if (!RunContext.deleteFile(myServers[i], errlogFile)) {
@@ -281,17 +290,16 @@
 
     /*
      * transfer log files
-     * This method copies over the error log to the run output directory
+     * This method copies over the config file and error log to the run output directory
      * It will optionally copy over the access log if the user has
      * requested it
      */
     @GetLogs
     public void getLogs() {
-		if (skipService) return;
+		if (skipService || skipLogs) return;
         for (int i = 0; i < myServers.length; i++) {
             String outFile = RunContext.getOutDir() + "nginx_err.log." +
                     RunContext.getHostName(myServers[i]);
-
             /*
              * copy the error_log to the master
              * TODO: Truncate the error log to contain only entries for
@@ -307,6 +315,15 @@
             if (!RunContext.getFile(myServers[i], acclogFile, accFile))
                 logger.warning("Could not copy " + acclogFile + " to " + accFile);
             }
+
+            // Copy the configuration file
+            if (confFile != null) {
+                outFile = RunContext.getOutDir() + "nginx_conf.log." +
+                        RunContext.getHostName(myServers[i]);
+                if (!RunContext.getFile(myServers[i], confFile, outFile)) {
+                    logger.warning("Could not copy " + confFile + " to " + outFile);
+                }
+            }
             logger.fine("getLogs completed for " + myServers[i]);
         }
 

Modified: incubator/olio/workload/rails/trunk/src/org/apache/olio/services/RailsService.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/rails/trunk/src/org/apache/olio/services/RailsService.java?rev=822802&r1=822801&r2=822802&view=diff
==============================================================================
--- incubator/olio/workload/rails/trunk/src/org/apache/olio/services/RailsService.java (original)
+++ incubator/olio/workload/rails/trunk/src/org/apache/olio/services/RailsService.java Wed
Oct  7 16:55:47 2009
@@ -48,7 +48,7 @@
 public class RailsService {
  /** Injected service context. */
     @Context public ServiceContext ctx;
-    private Logger logger = Logger.getLogger(ThinService.class.getName());
+    private Logger logger = Logger.getLogger(RailsService.class.getName());
 
     private String[] myServers;
 	private List<NameValuePair<Integer>> hostPorts;
@@ -58,9 +58,7 @@
 
 	private boolean skipService = false;
 
-    @Configure public void configure() {
-		String pidFile, errlogFile;
-
+    @Configure public void configure() throws ConfigurationException {
         myServers = ctx.getUniqueHosts();
         hostPorts = ctx.getUniqueHostPorts();
 		if (hostPorts == null || hostPorts.get(0) == null) {
@@ -68,9 +66,9 @@
 			return;
         }
 		serverType = ctx.getProperty("type");
-		if (serverType.equals("thin"))
-			thin = new Thin(ctx);
-		   
+		if (serverType.equals("thin")) {
+            thin = new Thin(ctx);
+        }
 		appDir = ctx.getProperty("appDir");
 		if (appDir == null) {
 			logger.warning("appDir property not set. Assuming /export/home/oliorails");
@@ -79,12 +77,10 @@
 
         // We need to locate rake
 		rakePath = ctx.getProperty("rakePath");
-		if (rakePath == null) {
+		if (rakePath == null || rakePath.trim().length() <= 0) {
 			logger.warning("rakePath not set. Assuming /var/ruby/1.8/gem_home/bin");
 			rakePath = "/var/ruby/1.8/gem_home/bin";
 		}
-		if (!rakePath.endsWith(File.separator))
-			rakePath = rakePath + File.separator;
 		appLogFile = appDir + File.separator + "log" + 
                 File.separator + "production.log";
         appConfFile = appDir + File.separator + "config" +

Modified: incubator/olio/workload/rails/trunk/src/org/apache/olio/services/Thin.java
URL: http://svn.apache.org/viewvc/incubator/olio/workload/rails/trunk/src/org/apache/olio/services/Thin.java?rev=822802&r1=822801&r2=822802&view=diff
==============================================================================
--- incubator/olio/workload/rails/trunk/src/org/apache/olio/services/Thin.java (original)
+++ incubator/olio/workload/rails/trunk/src/org/apache/olio/services/Thin.java Wed Oct  7
16:55:47 2009
@@ -53,7 +53,7 @@
  */
 public class Thin {
     private ServiceContext ctx;
-    private Logger logger = Logger.getLogger(ThinService.class.getName());
+    private Logger logger = Logger.getLogger(Thin.class.getName());
 
     private static final int PORT = 3000;
     private final String logName = "thin.log";
@@ -64,12 +64,11 @@
     private String[] myServers;
 	private List<NameValuePair<Integer>> hostPorts;
     private String thinCmd, appDir, logsDir, pidsDir;
-    private String appLogFile, appConfFile;
     private static int numInstances, startPort;
     CommandHandle thinHandles[];
+    private boolean skipLogs = false;
 
-
-    public Thin(ServiceContext ctx) {
+    public Thin(ServiceContext ctx) throws ConfigurationException {
 		this.ctx = ctx;
 		String pidFile, errlogFile;
 
@@ -79,25 +78,36 @@
 		if (startPort == 0)
 			startPort = PORT;
         thinCmd = ctx.getProperty("cmdPath");
-        if (!thinCmd.endsWith(" ")) {
-            thinCmd = thinCmd + " ";
+        if (thinCmd != null && thinCmd.trim().length() > 0) {
+            if (!thinCmd.endsWith(" "))
+                thinCmd = thinCmd + " ";
+        } else {
+            throw new ConfigurationException("cmdPath not set. Cannot start/stop thin");
+        }
+        pidsDir = ctx.getProperty("pidsDir");
+        if (pidsDir != null && pidsDir.trim().length() > 0) {
+            if (!pidsDir.endsWith(File.separator))
+                pidsDir = pidsDir + File.separator;
+        } else {
+            throw new ConfigurationException("pidsDir not set. Cannot start/stop thin");
         }
-        numInstances = Integer.parseInt(ctx.getProperty("numInstances"));
+
+        String ni = ctx.getProperty("numInstances");
+        if (ni != null)
+            numInstances = Integer.parseInt(ni);
 		if (numInstances == 0)
 			numInstances = 1;
 		appDir = ctx.getProperty("appDir");
-		if (appDir == null) {
+		if (appDir == null || appDir.trim().length() <= 0) {
 			logger.warning("appDir property not set. Assuming /export/home/oliorails");
 			appDir = "/export/home/oliorails";
         }
         logsDir = ctx.getProperty("logsDir");
-        if (!logsDir.endsWith(File.separator)) {
-            logsDir = logsDir + File.separator;
-        }
-
-        pidsDir = ctx.getProperty("pidsDir");
-        if (!pidsDir.endsWith(File.separator)) {
-            pidsDir = pidsDir + File.separator;
+        if (logsDir != null && logsDir.trim().length() > 0) {
+            if (!logsDir.endsWith(File.separator))
+                logsDir = logsDir + File.separator;
+        } else {
+            skipLogs = true;
         }
 
         pidFile = pidsDir + pidName;
@@ -244,6 +254,7 @@
      * Clears the Thin server logs 
      */
     public void clearLogs() {
+        if (skipLogs) return;
         for (String server : myServers) {
             // Clear thin logs
             for (int i = 0; i < logFileNames.length; i++) {



Mime
View raw message