keith-turner closed pull request #1052: Issue 1003 - Refactor remove and init 
apis to check if running
URL: https://github.com/apache/fluo/pull/1052
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/modules/command/src/main/java/org/apache/fluo/command/FluoInit.java 
b/modules/command/src/main/java/org/apache/fluo/command/FluoInit.java
index 7d83f344..c73d8bcd 100644
--- a/modules/command/src/main/java/org/apache/fluo/command/FluoInit.java
+++ b/modules/command/src/main/java/org/apache/fluo/command/FluoInit.java
@@ -134,13 +134,6 @@ public static void main(String[] args) {
 
     try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
 
-      if (admin.applicationRunning()) {
-        System.err.println("Error - The Fluo '" + config.getApplicationName() 
+ "' application"
-            + " is already running and must be stopped before running 'fluo 
init'. "
-            + " Aborted initialization.");
-        System.exit(-1);
-      }
-
       FluoAdmin.InitializationOptions initOpts = new 
FluoAdmin.InitializationOptions();
 
       if (opts.getUpdate()) {
@@ -185,14 +178,16 @@ public static void main(String[] args) {
 
       System.out.println("Initializing Fluo '" + config.getApplicationName()
           + "' application using " + opts.getAppPropsPath());
-      try {
-        admin.initialize(initOpts);
-      } catch (Exception e) {
-        System.out.println("Initialization failed due to the following 
exception:");
-        e.printStackTrace();
-        System.exit(-1);
-      }
+
+      admin.initialize(initOpts);
       System.out.println("Initialization is complete.");
+    } catch (FluoAdmin.AlreadyInitializedException e) {
+      System.err.println(e.getMessage());
+      System.exit(-1);
+    } catch (Exception e) {
+      System.out.println("Initialization failed due to the following 
exception:");
+      e.printStackTrace();
+      System.exit(-1);
     }
   }
 }
diff --git 
a/modules/command/src/main/java/org/apache/fluo/command/FluoRemove.java 
b/modules/command/src/main/java/org/apache/fluo/command/FluoRemove.java
index 0c337d23..5426e414 100644
--- a/modules/command/src/main/java/org/apache/fluo/command/FluoRemove.java
+++ b/modules/command/src/main/java/org/apache/fluo/command/FluoRemove.java
@@ -15,7 +15,9 @@
 
 package org.apache.fluo.command;
 
+import org.apache.fluo.api.client.FluoAdmin;
 import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.api.exceptions.FluoException;
 import org.apache.fluo.core.client.FluoAdminImpl;
 
 public class FluoRemove {
@@ -30,22 +32,16 @@ public static void main(String[] args) {
     config = FluoAdminImpl.mergeZookeeperConfig(config);
 
     try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
-      if (admin.applicationRunning()) {
-        System.err.println("Error - The Fluo '" + config.getApplicationName() 
+ "' application"
-            + " is already running and must be stopped before running 'fluo 
remove'. "
-            + " Aborted remove.");
-        System.exit(-1);
-      }
       System.out.println("Removing Fluo '" + config.getApplicationName());
-      try {
-        admin.remove();
-      } catch (Exception e) {
-        System.out.println("Remove failed due to the following exception:");
-        e.printStackTrace();
-        System.exit(-1);
-      }
+      admin.remove();
       System.out.println("Remove is complete.");
-
+    } catch (FluoException e) {
+      System.err.println(e.getMessage());
+      System.exit(-1);
+    } catch (Exception e) {
+      System.out.println("Remove failed due to the following exception:");
+      e.printStackTrace();
+      System.exit(-1);
     }
   }
 }
diff --git 
a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java 
b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
index 8bea85f5..40563665 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java
@@ -107,7 +107,11 @@ public void initialize(InitializationOptions opts)
     Preconditions.checkArgument(
         config.getObserverJarsUrl().isEmpty() || 
config.getObserverInitDir().isEmpty(),
         "Only one of 'fluo.observer.init.dir' and 'fluo.observer.jars.url' can 
be set");
-
+    if (applicationRunning()) {
+      throw new AlreadyInitializedException("Error - The Fluo '" + 
config.getApplicationName()
+          + "' application" + " is already running and must be stopped before 
initializing. "
+          + " Aborted initialization.");
+    }
     if (zookeeperInitialized() && !opts.getClearZookeeper()) {
       throw new AlreadyInitializedException(
           "Fluo application already initialized at " + 
config.getAppZookeepers());
@@ -204,6 +208,10 @@ public void initialize(InitializationOptions opts)
 
   @Override
   public void remove() {
+    if (applicationRunning()) {
+      throw new FluoException("Error - The Fluo '" + 
config.getApplicationName() + "' application"
+          + " is already running and must be stopped before removing. Aborted 
remove.");
+    }
     if (!config.hasRequiredAdminProps()) {
       throw new IllegalArgumentException("Admin configuration is missing 
required properties");
     }
@@ -325,6 +333,11 @@ public void updateSharedConfig() {
     if (!config.hasRequiredAdminProps()) {
       throw new IllegalArgumentException("Admin configuration is missing 
required properties");
     }
+    if (applicationRunning()) {
+      throw new FluoException("Error - The Fluo '" + 
config.getApplicationName() + "' application"
+          + " is already running and must be stopped before updating shared 
configuration. "
+          + " Aborted update.");
+    }
     Properties sharedProps = new Properties();
     Iterator<String> iter = config.getKeys();
     while (iter.hasNext()) {
diff --git 
a/modules/integration-tests/src/main/java/org/apache/fluo/integration/impl/AppConfigIT.java
 
b/modules/integration-tests/src/main/java/org/apache/fluo/integration/impl/AppConfigIT.java
index 332a3da5..27d68b37 100644
--- 
a/modules/integration-tests/src/main/java/org/apache/fluo/integration/impl/AppConfigIT.java
+++ 
b/modules/integration-tests/src/main/java/org/apache/fluo/integration/impl/AppConfigIT.java
@@ -63,6 +63,7 @@ public void testBasic() {
     appConfig.setProperty("myapp.sizeLimit", 40000);
     appConfig.setProperty("myapp.timeLimit", 30000);
     try (FluoAdmin admin = FluoFactory.newAdmin(config)) {
+      miniFluo.close();
       admin.updateSharedConfig();
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to