changeset 250:452e9d9a7109

More descriptive error when mongod is missing Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-April/000967.html
author Omair Majid <omajid@redhat.com>
date Fri, 20 Apr 2012 10:23:22 -0400
parents dae26ae4f542
children 1bf239bebc6d
files common/src/main/java/com/redhat/thermostat/common/utils/LoggedExternalProcess.java common/src/main/java/com/redhat/thermostat/tools/unix/UnixProcessUtilities.java tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java tools/src/main/java/com/redhat/thermostat/tools/db/MongoProcessRunner.java
diffstat 4 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/common/src/main/java/com/redhat/thermostat/common/utils/LoggedExternalProcess.java	Fri Apr 20 10:18:46 2012 -0400
+++ b/common/src/main/java/com/redhat/thermostat/common/utils/LoggedExternalProcess.java	Fri Apr 20 10:23:22 2012 -0400
@@ -43,6 +43,8 @@
 import java.util.List;
 import java.util.logging.Logger;
 
+import com.redhat.thermostat.tools.ApplicationException;
+
 public class LoggedExternalProcess extends Thread {
 
     private static final Logger logger = LoggingUtils.getLogger(LoggedExternalProcess.class);
@@ -58,15 +60,20 @@
         setDaemon(true);
     }
 
-    public int runAndReturnResult() throws IOException, InterruptedException {
+    public int runAndReturnResult() throws IOException, InterruptedException, ApplicationException{
         Process p = runAndReturnProcess();
         return p.waitFor();
     }
 
-    public Process runAndReturnProcess() throws IOException {
+    public Process runAndReturnProcess() throws IOException, ApplicationException {
         ProcessBuilder b = new ProcessBuilder(commands);
         b.redirectErrorStream(true);
-        Process p = b.start();
+        Process p = null;
+        try {
+            p = b.start();
+        } catch (IOException ioe) {
+            throw new ApplicationException("unable to execute " + commands[0], ioe);
+        }
         reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
         this.start();
         return p;
--- a/common/src/main/java/com/redhat/thermostat/tools/unix/UnixProcessUtilities.java	Fri Apr 20 10:18:46 2012 -0400
+++ b/common/src/main/java/com/redhat/thermostat/tools/unix/UnixProcessUtilities.java	Fri Apr 20 10:23:22 2012 -0400
@@ -47,6 +47,7 @@
 
 import com.redhat.thermostat.common.utils.LoggedExternalProcess;
 import com.redhat.thermostat.common.utils.LoggingUtils;
+import com.redhat.thermostat.tools.ApplicationException;
 
 public class UnixProcessUtilities {
 
@@ -82,7 +83,7 @@
                 result = output[output.length - 1];
             }
             
-        } catch (IOException e) {
+        } catch (IOException | ApplicationException e) {
             logger.log(Level.WARNING, "can't run ps!", e);
         }
         
@@ -95,7 +96,7 @@
         return new BufferedReader(isr);
     }
     
-    public Process createAndRunProcess(List<String> args) throws IOException {
+    public Process createAndRunProcess(List<String> args) throws IOException, ApplicationException {
         LoggedExternalProcess process = new LoggedExternalProcess(args);
         return process.runAndReturnProcess();
     }
--- a/tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java	Fri Apr 20 10:18:46 2012 -0400
+++ b/tools/src/main/java/com/redhat/thermostat/tools/ThermostatService.java	Fri Apr 20 10:23:22 2012 -0400
@@ -135,6 +135,10 @@
                     notifier.fireAction(ApplicationState.FAIL);
                 }
                 break;
+            case FAIL:
+                System.err.println("error starting db");
+                notifier.fireAction(ApplicationState.FAIL);
+                break;
             }
         } else if (actionEvent.getSource().equals(agent)) {
             // agent is running
--- a/tools/src/main/java/com/redhat/thermostat/tools/db/MongoProcessRunner.java	Fri Apr 20 10:18:46 2012 -0400
+++ b/tools/src/main/java/com/redhat/thermostat/tools/db/MongoProcessRunner.java	Fri Apr 20 10:23:22 2012 -0400
@@ -167,7 +167,15 @@
         }
         
         LoggedExternalProcess process = new LoggedExternalProcess(commands);
-        int status = process.runAndReturnResult();
+        int status = -1;
+        try {
+            status = process.runAndReturnResult();
+        } catch (ApplicationException ae) {
+            String message = "can not execute mongo process. is it installed?";
+            display(message);
+            throw ae;
+        }
+
         if (status == 0) {
             pid = getPid();
             if (pid == null) status = -1;