changeset 1738:7d9b2bbefff0

Use start/stop storage rather than calling out to mongod directly. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-May/013799.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 26 May 2015 16:05:46 +0200
parents b239f24bbecd
children 4eaf55dd4a40
files distribution/scripts/thermostat-setup integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java
diffstat 2 files changed, 42 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/distribution/scripts/thermostat-setup	Tue May 26 12:13:31 2015 +0200
+++ b/distribution/scripts/thermostat-setup	Tue May 26 16:05:46 2015 +0200
@@ -270,34 +270,24 @@
   echo -e "connections.\n"
   readUsername "$defaultName"
   readPassword
-  mkdir -p "$USER_THERMOSTAT_HOME"/data/db/
-  mkdir -p "$USER_THERMOSTAT_HOME"/logs/
-  mkdir -p "$USER_THERMOSTAT_HOME"/run/
-  mkdir -p "$USER_THERMOSTAT_HOME"/etc/
-  mkdir -p "$USER_THERMOSTAT_HOME"/cache/
-  mongod --nojournal \
-         --quiet \
-         --fork \
-         --noauth \
-         --nohttpinterface \
-         --bind_ip 127.0.0.1 \
-         --port 27518 \
-         --dbpath "$USER_THERMOSTAT_HOME"/data/db \
-         --logpath "$USER_THERMOSTAT_HOME"/logs/db.log \
-         --pidfilepath "$USER_THERMOSTAT_HOME"/run/db.pid
+  $THERMOSTAT_HOME/bin/thermostat storage --start --permitLocalhostException
   MONGOD_RETVAL="$?"
   if [ "$MONGOD_RETVAL" -ne 0 ] ; then
+    echo -e "\nMongodb user setup failed. Error starting storage." 1>&2
+    exitFail
+  fi
+  sleep 3
+  mongo 127.0.0.1:27518 << EOF
+use thermostat
+db.addUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
+quit()
+EOF
+  MONGO_SETUP_RETVAL="$?"
+  if [ "$MONGO_SETUP_RETVAL" -ne 0 ] ; then
     echo -e "\nMongodb user setup failed." 1>&2
     exitFail
   fi
-  sleep 5
-  mongo 127.0.0.1:27518 << EOF
-use thermostat
-db.addUser({ user: "$USERNAME", pwd: "$PASSWORD", roles: [ "readWrite" ] })
-use admin
-db.shutdownServer()
-quit()
-EOF
+  $THERMOSTAT_HOME/bin/thermostat storage --stop
   MONGO_SETUP_RETVAL="$?"
   if [ "$MONGO_SETUP_RETVAL" -ne 0 ] ; then
     echo -e "\nMongodb user setup failed." 1>&2
--- a/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java	Tue May 26 12:13:31 2015 +0200
+++ b/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/WebAppTest.java	Tue May 26 16:05:46 2015 +0200
@@ -305,21 +305,33 @@
     public static void tearDownOnce() throws Exception {
         try {
             deleteCpuData();
-        
-            server.stop();
-            server.join();
-
-            stopStorage();
-            removeSetupCompleteStampFiles();
         } catch (Exception e) {
-            System.out.println("AN ERROR OCCURRED!");
+            System.out.println("AN ERROR OCCURRED DELETING CPU DATA!");
             e.printStackTrace();
             throw e;
         } finally {
-            Files.copy(backupUsers, new File(THERMOSTAT_USERS_FILE).toPath(), StandardCopyOption.REPLACE_EXISTING);
-            Files.copy(backupRoles, new File(THERMOSTAT_ROLES_FILE).toPath(), StandardCopyOption.REPLACE_EXISTING);
-            Files.copy(backupWebAuth, new File(THERMOSTAT_WEB_AUTH_FILE).toPath(), StandardCopyOption.REPLACE_EXISTING);
-            System.out.println("RESTORED web.auth!");
+            try {
+                server.stop();
+                server.join();
+            } catch (Exception e) {
+                System.out.println("AN ERROR OCCURRED STOPPING JETTY!");
+                e.printStackTrace();
+                throw e;
+            } finally {
+                try {
+                    stopStorage();
+                } catch (Exception e) {
+                    System.out.println("AN ERROR OCCURRED STOPPING STORAGE!");
+                    e.printStackTrace();
+                    throw e;
+                } finally {
+                    removeSetupCompleteStampFiles();
+                    Files.copy(backupUsers, new File(THERMOSTAT_USERS_FILE).toPath(), StandardCopyOption.REPLACE_EXISTING);
+                    Files.copy(backupRoles, new File(THERMOSTAT_ROLES_FILE).toPath(), StandardCopyOption.REPLACE_EXISTING);
+                    Files.copy(backupWebAuth, new File(THERMOSTAT_WEB_AUTH_FILE).toPath(), StandardCopyOption.REPLACE_EXISTING);
+                    System.out.println("RESTORED backed-up files!");
+                }
+            }
         }
     }
     
@@ -356,31 +368,11 @@
                 System.out.println("THERMOSTAT_HOME: " + getThermostatHome());
                 System.out.println("USER_THERMOSTAT_HOME: " + getUserThermostatHome());
 
-                // create directories that we use later down to store stuff in
-                // things fail silently if the directories do not exist
-                new File(getUserThermostatHome() + "/data/db").mkdirs();
-                new File(getUserThermostatHome() + "/logs/").mkdirs();
-                new File(getUserThermostatHome() + "/run/").mkdirs();
-                new File(getUserThermostatHome() + "/etc/").mkdirs();
-                new File(getUserThermostatHome() + "/cache/").mkdirs();
-
-                ExpectJ mongod = new ExpectJ(TIMEOUT_IN_SECONDS);
-                final String MONGOD_COMMAND = "mongod "
-                        + "--quiet "
-                        + "--fork "
-                        + "--noauth "
-                        + "--nohttpinterface "
-                        + "--bind_ip " + HOST + " "
-                        + "--port " + PORT + " "
-                        + "--dbpath " + getUserThermostatHome() + "/data/db "
-                        + "--logpath " + getUserThermostatHome() + "/logs/db.log "
-                        + "--pidfilepath " + getUserThermostatHome() + "/run/db.pid";
-                System.out.println(MONGOD_COMMAND);
-                Spawn mongodSpawn = mongod.spawn(MONGOD_COMMAND);
-                mongodSpawn.expectClose(TIMEOUT_IN_SECONDS);
+                // start mongod
+                startStorage();
 
                 System.out.println("Started mongod");
-                TimeUnit.SECONDS.sleep(5);
+                TimeUnit.SECONDS.sleep(3);
 
                 ExpectJ mongo = new ExpectJ(TIMEOUT_IN_SECONDS);
                 Spawn mongoSpawn = mongo.spawn("mongo " + HOST + ":" + PORT);
@@ -403,15 +395,11 @@
                 mongoSpawn.send("db[\"fake\"].findOne()\n");
                 mongoSpawn.send("show collections\n");
                 mongoSpawn.send("show users\n");
-
-                mongoSpawn.send("use admin\n");
-                mongoSpawn.expect("switched to db admin");
-                mongoSpawn.send("db.shutdownServer()\n");
-                mongoSpawn.send("quit()\n");
-                mongoSpawn.expectClose();
-
+                
             } catch (TimeoutException | IOException e) {
                 throw e;
+            } finally {
+                stopStorage();
             }
         } else {
             System.out.println("Not a development build. Skipping mongodb setup.");