You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fluo.apache.org by mw...@apache.org on 2017/08/18 19:55:47 UTC

[fluo] branch master updated: Fixes #912 - Create 'fluo status' command (#913)

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

mwalch 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 151c565  Fixes #912 - Create 'fluo status' command (#913)
151c565 is described below

commit 151c5653e4d8001ee23d69e64af2602c95870f0e
Author: Mike Walch <mw...@apache.org>
AuthorDate: Fri Aug 18 15:55:45 2017 -0400

    Fixes #912 - Create 'fluo status' command (#913)
    
    * Improved 'fluo list' command to print number of workers
    * List & status commands now looked at number of works
      when determining if application is running.
---
 .../fluo/cluster/runner/ClusterAppRunner.java      |  2 +-
 .../java/org/apache/fluo/command/CommandUtil.java  | 13 +++++--
 .../java/org/apache/fluo/command/FluoInit.java     |  2 +-
 .../java/org/apache/fluo/command/FluoList.java     | 16 +++++---
 .../command/{FluoList.java => FluoStatus.java}     | 43 ++++++----------------
 .../org/apache/fluo/core/client/FluoAdminImpl.java | 34 ++++++++++++++---
 .../core/worker/finder/hash/PartitionManager.java  |  4 +-
 modules/distribution/src/main/scripts/fluo         | 13 ++++++-
 8 files changed, 75 insertions(+), 52 deletions(-)

diff --git a/modules/cluster/src/main/java/org/apache/fluo/cluster/runner/ClusterAppRunner.java b/modules/cluster/src/main/java/org/apache/fluo/cluster/runner/ClusterAppRunner.java
index 907ba67..e16ce0c 100644
--- a/modules/cluster/src/main/java/org/apache/fluo/cluster/runner/ClusterAppRunner.java
+++ b/modules/cluster/src/main/java/org/apache/fluo/cluster/runner/ClusterAppRunner.java
@@ -127,7 +127,7 @@ public abstract class ClusterAppRunner extends AppRunner {
 
     try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
 
-      if (admin.oracleExists()) {
+      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.");
diff --git a/modules/command/src/main/java/org/apache/fluo/command/CommandUtil.java b/modules/command/src/main/java/org/apache/fluo/command/CommandUtil.java
index eece560..2f2ba83 100644
--- a/modules/command/src/main/java/org/apache/fluo/command/CommandUtil.java
+++ b/modules/command/src/main/java/org/apache/fluo/command/CommandUtil.java
@@ -15,8 +15,11 @@
 
 package org.apache.fluo.command;
 
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.fluo.api.client.FluoAdmin;
 import org.apache.fluo.api.config.FluoConfiguration;
 import org.apache.fluo.core.client.FluoAdminImpl;
+import org.apache.fluo.core.util.CuratorUtil;
 
 public class CommandUtil {
 
@@ -30,10 +33,12 @@ public class CommandUtil {
 
   public static void verifyAppRunning(FluoConfiguration config) {
     verifyAppInitialized(config);
-    if (!FluoAdminImpl.oracleExists(config)) {
-      System.out.println("A Fluo '" + config.getApplicationName() + "' application is initialized "
-          + "but is not running!");
-      System.exit(-1);
+    try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
+      if (admin.applicationRunning()) {
+        System.out.println("A Fluo '" + config.getApplicationName()
+            + "' application is initialized " + "but is not running!");
+        System.exit(-1);
+      }
     }
   }
 }
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 d3efc4f..0532c5f 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
@@ -143,7 +143,7 @@ public class FluoInit {
 
     try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
 
-      if (admin.oracleExists()) {
+      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.");
diff --git a/modules/command/src/main/java/org/apache/fluo/command/FluoList.java b/modules/command/src/main/java/org/apache/fluo/command/FluoList.java
index b389d03..262821a 100644
--- a/modules/command/src/main/java/org/apache/fluo/command/FluoList.java
+++ b/modules/command/src/main/java/org/apache/fluo/command/FluoList.java
@@ -60,16 +60,20 @@ public class FluoList {
 
       System.out.println("Fluo instance (" + config.getInstanceZookeepers() + ") contains "
           + children.size() + " application(s)\n");
-      System.out.println("Application     Status");
-      System.out.println("-----------     ------");
+      System.out.println("Application     Status     # Workers");
+      System.out.println("-----------     ------     ---------");
+
       for (String path : children) {
         FluoConfiguration appConfig = new FluoConfiguration(config);
         appConfig.setApplicationName(path);
-        String state = "STOPPED";
-        if (FluoAdminImpl.oracleExists(appConfig)) {
-          state = "RUNNING";
+        try (FluoAdminImpl admin = new FluoAdminImpl(appConfig)) {
+          String state = "STOPPED";
+          if (admin.applicationRunning()) {
+            state = "RUNNING";
+          }
+          int numWorkers = admin.numWorkers();
+          System.out.format("%-15s %-11s %4d\n", path, state, numWorkers);
         }
-        System.out.format("%-15s %-11s\n", path, state);
       }
     }
   }
diff --git a/modules/command/src/main/java/org/apache/fluo/command/FluoList.java b/modules/command/src/main/java/org/apache/fluo/command/FluoStatus.java
similarity index 53%
copy from modules/command/src/main/java/org/apache/fluo/command/FluoList.java
copy to modules/command/src/main/java/org/apache/fluo/command/FluoStatus.java
index b389d03..da56009 100644
--- a/modules/command/src/main/java/org/apache/fluo/command/FluoList.java
+++ b/modules/command/src/main/java/org/apache/fluo/command/FluoStatus.java
@@ -26,50 +26,31 @@ import org.apache.fluo.api.config.FluoConfiguration;
 import org.apache.fluo.core.client.FluoAdminImpl;
 import org.apache.fluo.core.util.CuratorUtil;
 
-public class FluoList {
+public class FluoStatus {
 
   public static void main(String[] args) throws Exception {
-    if (args.length != 1) {
-      System.err.println("Usage: FluoList <connectionPropsPath>");
+    if (args.length != 2) {
+      System.err.println("Usage: FluoStatus <connectionPropsPath> <applicationName>");
       System.exit(-1);
     }
     String connectionPropsPath = args[0];
+    String applicationName = args[1];
     Objects.requireNonNull(connectionPropsPath);
     File connectionPropsFile = new File(connectionPropsPath);
     Preconditions.checkArgument(connectionPropsFile.exists(), connectionPropsPath
         + " does not exist");
 
     FluoConfiguration config = new FluoConfiguration(connectionPropsFile);
+    config.setApplicationName(applicationName);
 
-    try (CuratorFramework curator = CuratorUtil.newFluoCurator(config)) {
-      curator.start();
-
-      if (curator.checkExists().forPath("/") == null) {
-        System.out.println("Fluo instance (" + config.getInstanceZookeepers() + ") has not been "
-            + "created yet in Zookeeper.  It will be created when the first Fluo application is "
-            + "initialized for this instance.");
-        return;
-      }
-      List<String> children = curator.getChildren().forPath("/");
-      if (children.isEmpty()) {
-        System.out.println("Fluo instance (" + config.getInstanceZookeepers() + ") does not "
-            + "contain any Fluo applications.");
-        return;
+    try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
+      if (!admin.zookeeperInitialized()) {
+        System.out.println("NOT_FOUND");
       }
-      Collections.sort(children);
-
-      System.out.println("Fluo instance (" + config.getInstanceZookeepers() + ") contains "
-          + children.size() + " application(s)\n");
-      System.out.println("Application     Status");
-      System.out.println("-----------     ------");
-      for (String path : children) {
-        FluoConfiguration appConfig = new FluoConfiguration(config);
-        appConfig.setApplicationName(path);
-        String state = "STOPPED";
-        if (FluoAdminImpl.oracleExists(appConfig)) {
-          state = "RUNNING";
-        }
-        System.out.format("%-15s %-11s\n", path, state);
+      if (admin.applicationRunning()) {
+        System.out.println("RUNNING");
+      } else {
+        System.out.println("STOPPED");
       }
     }
   }
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 eb22830..717d9f3 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
@@ -54,6 +54,7 @@ import org.apache.fluo.core.observer.ObserverUtil;
 import org.apache.fluo.core.util.AccumuloUtil;
 import org.apache.fluo.core.util.ByteUtil;
 import org.apache.fluo.core.util.CuratorUtil;
+import org.apache.fluo.core.worker.finder.hash.PartitionManager;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -400,9 +401,8 @@ public class FluoAdminImpl implements FluoAdmin {
     return jars.toString();
   }
 
-  public static boolean oracleExists(FluoConfiguration config) {
-    try (CuratorFramework curator = CuratorUtil.newAppCurator(config)) {
-      curator.start();
+  public static boolean oracleExists(CuratorFramework curator) {
+    try {
       return curator.checkExists().forPath(ZookeeperPath.ORACLE_SERVER) != null
           && !curator.getChildren().forPath(ZookeeperPath.ORACLE_SERVER).isEmpty();
     } catch (Exception e) {
@@ -411,13 +411,35 @@ public class FluoAdminImpl implements FluoAdmin {
   }
 
   public boolean oracleExists() {
-    CuratorFramework curator = getAppCurator();
+    return oracleExists(getAppCurator());
+  }
+
+  public static int numWorkers(CuratorFramework curator) {
+    int numWorkers = 0;
     try {
-      return curator.checkExists().forPath(ZookeeperPath.ORACLE_SERVER) != null
-          && !curator.getChildren().forPath(ZookeeperPath.ORACLE_SERVER).isEmpty();
+      if (curator.checkExists().forPath(ZookeeperPath.FINDERS) != null) {
+        for (String path : curator.getChildren().forPath(ZookeeperPath.FINDERS)) {
+          if (path.startsWith(PartitionManager.ZK_FINDER_PREFIX)) {
+            numWorkers++;
+          }
+        }
+      }
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
+    return numWorkers;
+  }
+
+  public int numWorkers() {
+    return numWorkers(getAppCurator());
+  }
+
+  public static boolean applicationRunning(CuratorFramework curator) {
+    return oracleExists(curator) || (numWorkers(curator) > 0);
+  }
+
+  public boolean applicationRunning() {
+    return applicationRunning(getAppCurator());
   }
 
   public boolean zookeeperInitialized() {
diff --git a/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/PartitionManager.java b/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/PartitionManager.java
index f0e6305..90524c4 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/PartitionManager.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/PartitionManager.java
@@ -71,6 +71,8 @@ public class PartitionManager {
 
   private static final Logger log = LoggerFactory.getLogger(PartitionManager.class);
 
+  public static final String ZK_FINDER_PREFIX = "f-";
+
   private final PathChildrenCache childrenCache;
   private final PersistentEphemeralNode myESNode;
   private final int groupSize;
@@ -282,7 +284,7 @@ public class PartitionManager {
 
       myESNode =
           new PersistentEphemeralNode(curator, Mode.EPHEMERAL_SEQUENTIAL, ZookeeperPath.FINDERS
-              + "/f-", ("" + groupSize).getBytes(UTF_8));
+              + "/" + ZK_FINDER_PREFIX, ("" + groupSize).getBytes(UTF_8));
       myESNode.start();
       myESNode.waitForInitialCreate(1, TimeUnit.MINUTES);
 
diff --git a/modules/distribution/src/main/scripts/fluo b/modules/distribution/src/main/scripts/fluo
index 989f6f4..60b617f 100755
--- a/modules/distribution/src/main/scripts/fluo
+++ b/modules/distribution/src/main/scripts/fluo
@@ -68,6 +68,7 @@ function print_usage {
   echo "  get-jars <app> <dir>          Copies <app> jars from DFS to local <dir>"
   echo "  list                          Lists all Fluo applications in Fluo instance"
   echo "  scan <app>                    Prints snapshot of data in Fluo <app>"
+  echo "  status <app>                  Prints status of Fluo application for <app>"
   echo "  stop <app>                    Stops Fluo application processes on this machine for <app>"
   echo "  oracle <app>                  Starts Fluo Oracle process for <app>"
   echo "  worker <app>                  Starts Fluo Worker process for <app>"
@@ -80,7 +81,6 @@ function print_usage {
   echo "  start <app>   (Deprecated) Starts Fluo application on cluster"
   echo "  init <app>    (Deprecated) Initializes Fluo application using configuration in apps/<app>/conf/fluo.properties"
   echo "  kill <app>    (Deprecated) Kills Fluo application on cluster"
-  echo "  status <app>  (Deprecated) Prints status of Fluo application"
   echo "  info <app>    (Deprecated) Prints information about containers of Fluo application"
   echo " "
   exit 1
@@ -252,6 +252,15 @@ exec)
     java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"
   fi
   ;;
+status)
+  if [ -f "$FLUO_CONN_PROPS" ]; then
+    verify_app "$2"
+    java org.apache.fluo.command.FluoStatus "$FLUO_CONN_PROPS" "$2"
+  else
+    check_hadoop
+    java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"
+  fi
+  ;;
 version)
   echo "$FLUO_VERSION"
   ;;
@@ -291,7 +300,7 @@ start)
   export CLASSPATH="$APP_LIB_DIR/*:$CLASSPATH"
   java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"
   ;;
-kill|status|info)
+kill|info)
   deprecated_verify "$2"
   check_hadoop
   java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"

-- 
To stop receiving notification emails like this one, please contact
['"commits@fluo.apache.org" <co...@fluo.apache.org>'].