This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/fluo.git


The following commit(s) were added to refs/heads/master by this push:
     new 52f2079  Refactor remove, init, and updateSharedConfig APIs to check 
if applicaiton is running (#1052)
52f2079 is described below

commit 52f20793a299386b33c9d1e6901b75fb15cd2031
Author: Joseph Koshakow <jkos...@users.noreply.github.com>
AuthorDate: Tue Oct 16 14:05:19 2018 -0400

    Refactor remove, init, and updateSharedConfig APIs to check if applicaiton 
is running (#1052)
    
    Add logic to the start of remove, init, and updateSharedConfig methods
    in FluoAdminImpl to check if applicaiton is already running.
    This will eliminate the need to perform this check in clients that
    call these methods.
    
    Closes #1003
---
 .../java/org/apache/fluo/command/FluoInit.java     | 23 ++++++++-------------
 .../java/org/apache/fluo/command/FluoRemove.java   | 24 +++++++++-------------
 .../org/apache/fluo/core/client/FluoAdminImpl.java | 15 +++++++++++++-
 .../apache/fluo/integration/impl/AppConfigIT.java  |  1 +
 4 files changed, 34 insertions(+), 29 deletions(-)

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 7d83f34..c73d8bc 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 class FluoInit {
 
     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 class FluoInit {
 
       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 0c337d2..5426e41 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 class FluoRemove {
     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 8bea85f..4056366 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 class FluoAdminImpl implements FluoAdmin {
     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 class FluoAdminImpl implements FluoAdmin {
 
   @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 class FluoAdminImpl implements FluoAdmin {
     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 332a3da..27d68b3 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 class AppConfigIT extends ITBaseMini {
     appConfig.setProperty("myapp.sizeLimit", 40000);
     appConfig.setProperty("myapp.timeLimit", 30000);
     try (FluoAdmin admin = FluoFactory.newAdmin(config)) {
+      miniFluo.close();
       admin.updateSharedConfig();
     }
 

Reply via email to