Skip to content

Commit 151c565

Browse files
authored
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.
1 parent dbdd1a5 commit 151c565

File tree

8 files changed

+120
-21
lines changed

8 files changed

+120
-21
lines changed

modules/cluster/src/main/java/org/apache/fluo/cluster/runner/ClusterAppRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void init(FluoConfiguration config, String propsPath, String[] args) {
127127

128128
try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
129129

130-
if (admin.oracleExists()) {
130+
if (admin.applicationRunning()) {
131131
System.err.println("Error - The Fluo '" + config.getApplicationName() + "' application"
132132
+ " is already running and must be stopped before running 'fluo init'. "
133133
+ " Aborted initialization.");

modules/command/src/main/java/org/apache/fluo/command/CommandUtil.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515

1616
package org.apache.fluo.command;
1717

18+
import org.apache.curator.framework.CuratorFramework;
19+
import org.apache.fluo.api.client.FluoAdmin;
1820
import org.apache.fluo.api.config.FluoConfiguration;
1921
import org.apache.fluo.core.client.FluoAdminImpl;
22+
import org.apache.fluo.core.util.CuratorUtil;
2023

2124
public class CommandUtil {
2225

@@ -30,10 +33,12 @@ public static void verifyAppInitialized(FluoConfiguration config) {
3033

3134
public static void verifyAppRunning(FluoConfiguration config) {
3235
verifyAppInitialized(config);
33-
if (!FluoAdminImpl.oracleExists(config)) {
34-
System.out.println("A Fluo '" + config.getApplicationName() + "' application is initialized "
35-
+ "but is not running!");
36-
System.exit(-1);
36+
try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
37+
if (admin.applicationRunning()) {
38+
System.out.println("A Fluo '" + config.getApplicationName()
39+
+ "' application is initialized " + "but is not running!");
40+
System.exit(-1);
41+
}
3742
}
3843
}
3944
}

modules/command/src/main/java/org/apache/fluo/command/FluoInit.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static void main(String[] args) {
143143

144144
try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
145145

146-
if (admin.oracleExists()) {
146+
if (admin.applicationRunning()) {
147147
System.err.println("Error - The Fluo '" + config.getApplicationName() + "' application"
148148
+ " is already running and must be stopped before running 'fluo init'. "
149149
+ " Aborted initialization.");

modules/command/src/main/java/org/apache/fluo/command/FluoList.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,20 @@ public static void main(String[] args) throws Exception {
6060

6161
System.out.println("Fluo instance (" + config.getInstanceZookeepers() + ") contains "
6262
+ children.size() + " application(s)\n");
63-
System.out.println("Application Status");
64-
System.out.println("----------- ------");
63+
System.out.println("Application Status # Workers");
64+
System.out.println("----------- ------ ---------");
65+
6566
for (String path : children) {
6667
FluoConfiguration appConfig = new FluoConfiguration(config);
6768
appConfig.setApplicationName(path);
68-
String state = "STOPPED";
69-
if (FluoAdminImpl.oracleExists(appConfig)) {
70-
state = "RUNNING";
69+
try (FluoAdminImpl admin = new FluoAdminImpl(appConfig)) {
70+
String state = "STOPPED";
71+
if (admin.applicationRunning()) {
72+
state = "RUNNING";
73+
}
74+
int numWorkers = admin.numWorkers();
75+
System.out.format("%-15s %-11s %4d\n", path, state, numWorkers);
7176
}
72-
System.out.format("%-15s %-11s\n", path, state);
7377
}
7478
}
7579
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3+
* agreements. See the NOTICE file distributed with this work for additional information regarding
4+
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5+
* "License"); you may not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
16+
package org.apache.fluo.command;
17+
18+
import java.io.File;
19+
import java.util.Collections;
20+
import java.util.List;
21+
import java.util.Objects;
22+
23+
import com.google.common.base.Preconditions;
24+
import org.apache.curator.framework.CuratorFramework;
25+
import org.apache.fluo.api.config.FluoConfiguration;
26+
import org.apache.fluo.core.client.FluoAdminImpl;
27+
import org.apache.fluo.core.util.CuratorUtil;
28+
29+
public class FluoStatus {
30+
31+
public static void main(String[] args) throws Exception {
32+
if (args.length != 2) {
33+
System.err.println("Usage: FluoStatus <connectionPropsPath> <applicationName>");
34+
System.exit(-1);
35+
}
36+
String connectionPropsPath = args[0];
37+
String applicationName = args[1];
38+
Objects.requireNonNull(connectionPropsPath);
39+
File connectionPropsFile = new File(connectionPropsPath);
40+
Preconditions.checkArgument(connectionPropsFile.exists(), connectionPropsPath
41+
+ " does not exist");
42+
43+
FluoConfiguration config = new FluoConfiguration(connectionPropsFile);
44+
config.setApplicationName(applicationName);
45+
46+
try (FluoAdminImpl admin = new FluoAdminImpl(config)) {
47+
if (!admin.zookeeperInitialized()) {
48+
System.out.println("NOT_FOUND");
49+
}
50+
if (admin.applicationRunning()) {
51+
System.out.println("RUNNING");
52+
} else {
53+
System.out.println("STOPPED");
54+
}
55+
}
56+
}
57+
}

modules/core/src/main/java/org/apache/fluo/core/client/FluoAdminImpl.java

+28-6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.apache.fluo.core.util.AccumuloUtil;
5555
import org.apache.fluo.core.util.ByteUtil;
5656
import org.apache.fluo.core.util.CuratorUtil;
57+
import org.apache.fluo.core.worker.finder.hash.PartitionManager;
5758
import org.apache.hadoop.conf.Configuration;
5859
import org.apache.hadoop.fs.FileSystem;
5960
import org.apache.hadoop.fs.Path;
@@ -400,9 +401,8 @@ private String getJarsFromClasspath() {
400401
return jars.toString();
401402
}
402403

403-
public static boolean oracleExists(FluoConfiguration config) {
404-
try (CuratorFramework curator = CuratorUtil.newAppCurator(config)) {
405-
curator.start();
404+
public static boolean oracleExists(CuratorFramework curator) {
405+
try {
406406
return curator.checkExists().forPath(ZookeeperPath.ORACLE_SERVER) != null
407407
&& !curator.getChildren().forPath(ZookeeperPath.ORACLE_SERVER).isEmpty();
408408
} catch (Exception e) {
@@ -411,13 +411,35 @@ public static boolean oracleExists(FluoConfiguration config) {
411411
}
412412

413413
public boolean oracleExists() {
414-
CuratorFramework curator = getAppCurator();
414+
return oracleExists(getAppCurator());
415+
}
416+
417+
public static int numWorkers(CuratorFramework curator) {
418+
int numWorkers = 0;
415419
try {
416-
return curator.checkExists().forPath(ZookeeperPath.ORACLE_SERVER) != null
417-
&& !curator.getChildren().forPath(ZookeeperPath.ORACLE_SERVER).isEmpty();
420+
if (curator.checkExists().forPath(ZookeeperPath.FINDERS) != null) {
421+
for (String path : curator.getChildren().forPath(ZookeeperPath.FINDERS)) {
422+
if (path.startsWith(PartitionManager.ZK_FINDER_PREFIX)) {
423+
numWorkers++;
424+
}
425+
}
426+
}
418427
} catch (Exception e) {
419428
throw new RuntimeException(e);
420429
}
430+
return numWorkers;
431+
}
432+
433+
public int numWorkers() {
434+
return numWorkers(getAppCurator());
435+
}
436+
437+
public static boolean applicationRunning(CuratorFramework curator) {
438+
return oracleExists(curator) || (numWorkers(curator) > 0);
439+
}
440+
441+
public boolean applicationRunning() {
442+
return applicationRunning(getAppCurator());
421443
}
422444

423445
public boolean zookeeperInitialized() {

modules/core/src/main/java/org/apache/fluo/core/worker/finder/hash/PartitionManager.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public class PartitionManager {
7171

7272
private static final Logger log = LoggerFactory.getLogger(PartitionManager.class);
7373

74+
public static final String ZK_FINDER_PREFIX = "f-";
75+
7476
private final PathChildrenCache childrenCache;
7577
private final PersistentEphemeralNode myESNode;
7678
private final int groupSize;
@@ -282,7 +284,7 @@ public void run() {
282284

283285
myESNode =
284286
new PersistentEphemeralNode(curator, Mode.EPHEMERAL_SEQUENTIAL, ZookeeperPath.FINDERS
285-
+ "/f-", ("" + groupSize).getBytes(UTF_8));
287+
+ "/" + ZK_FINDER_PREFIX, ("" + groupSize).getBytes(UTF_8));
286288
myESNode.start();
287289
myESNode.waitForInitialCreate(1, TimeUnit.MINUTES);
288290

modules/distribution/src/main/scripts/fluo

+11-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function print_usage {
6868
echo " get-jars <app> <dir> Copies <app> jars from DFS to local <dir>"
6969
echo " list Lists all Fluo applications in Fluo instance"
7070
echo " scan <app> Prints snapshot of data in Fluo <app>"
71+
echo " status <app> Prints status of Fluo application for <app>"
7172
echo " stop <app> Stops Fluo application processes on this machine for <app>"
7273
echo " oracle <app> Starts Fluo Oracle process for <app>"
7374
echo " worker <app> Starts Fluo Worker process for <app>"
@@ -80,7 +81,6 @@ function print_usage {
8081
echo " start <app> (Deprecated) Starts Fluo application on cluster"
8182
echo " init <app> (Deprecated) Initializes Fluo application using configuration in apps/<app>/conf/fluo.properties"
8283
echo " kill <app> (Deprecated) Kills Fluo application on cluster"
83-
echo " status <app> (Deprecated) Prints status of Fluo application"
8484
echo " info <app> (Deprecated) Prints information about containers of Fluo application"
8585
echo " "
8686
exit 1
@@ -252,6 +252,15 @@ exec)
252252
java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"
253253
fi
254254
;;
255+
status)
256+
if [ -f "$FLUO_CONN_PROPS" ]; then
257+
verify_app "$2"
258+
java org.apache.fluo.command.FluoStatus "$FLUO_CONN_PROPS" "$2"
259+
else
260+
check_hadoop
261+
java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"
262+
fi
263+
;;
255264
version)
256265
echo "$FLUO_VERSION"
257266
;;
@@ -291,7 +300,7 @@ start)
291300
export CLASSPATH="$APP_LIB_DIR/*:$CLASSPATH"
292301
java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"
293302
;;
294-
kill|status|info)
303+
kill|info)
295304
deprecated_verify "$2"
296305
check_hadoop
297306
java org.apache.fluo.cluster.command.FluoCommand "$basedir" "$HADOOP_PREFIX" "$@"

0 commit comments

Comments
 (0)