keith-turner closed pull request #999: Create 'fluo remove' command #991
URL: https://github.com/apache/fluo/pull/999
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/api/src/main/java/org/apache/fluo/api/client/FluoAdmin.java
b/modules/api/src/main/java/org/apache/fluo/api/client/FluoAdmin.java
index fb25759d..ecda2d77 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/client/FluoAdmin.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/FluoAdmin.java
@@ -119,6 +119,15 @@ public TableExistsException() {
void initialize(InitializationOptions opts)
throws AlreadyInitializedException, TableExistsException;
+ /**
+ * Removes Fluo application, Accumulo table and shared configuration in
Zookeeper. Shared configuration
+ * consists of all properties except those with
+ * {@value org.apache.fluo.api.config.FluoConfiguration#CONNECTION_PREFIX}
prefix.
+ *
+ * @since 1.2.0
+ */
+ void remove();
+
/**
* Updates shared configuration in Zookeeper. Shared configuration consists
of all properties
* except those with {@value
org.apache.fluo.api.config.FluoConfiguration#CONNECTION_PREFIX}
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
new file mode 100644
index 00000000..0c337d23
--- /dev/null
+++ b/modules/command/src/main/java/org/apache/fluo/command/FluoRemove.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
+ */
+
+package org.apache.fluo.command;
+
+import org.apache.fluo.api.config.FluoConfiguration;
+import org.apache.fluo.core.client.FluoAdminImpl;
+
+public class FluoRemove {
+
+ public static void main(String[] args) {
+
+ CommonOpts opts = CommonOpts.parse("fluo remove", args);
+
+ FluoConfiguration config = CommandUtil.resolveFluoConfig();
+ config.setApplicationName(opts.getApplicationName());
+ opts.overrideFluoConfig(config);
+ 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);
+ }
+ System.out.println("Remove is complete.");
+
+ }
+ }
+}
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 e7117057..5d29cdbe 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
@@ -201,6 +201,44 @@ public void initialize(InitializationOptions opts)
}
}
+ @Override
+ public void remove() {
+ if (!config.hasRequiredAdminProps()) {
+ throw new IllegalArgumentException("Admin configuration is missing
required properties");
+ }
+ Preconditions.checkArgument(
+ !ZookeeperUtil.parseRoot(config.getInstanceZookeepers()).equals("/"),
+ "The Zookeeper connection string (set by 'fluo.connection.zookeepers')
"
+ + " must have a chroot suffix.");
+
+ Connector conn = AccumuloUtil.getConnector(config);
+
+ boolean tableExists =
conn.tableOperations().exists(config.getAccumuloTable());
+ // With preconditions met, it's now OK to delete table & zookeeper root
(if they exist)
+ if (tableExists) {
+ logger.info("The Accumulo table '{}' will be dropped",
config.getAccumuloTable());
+ try {
+ conn.tableOperations().delete(config.getAccumuloTable());
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ try {
+ if (rootCurator.checkExists().forPath(appRootDir) != null) {
+ logger.info("Clearing Fluo '{}' application in Zookeeper at {}",
+ config.getApplicationName(), config.getAppZookeepers());
+ rootCurator.delete().deletingChildrenIfNeeded().forPath(appRootDir);
+ }
+ } catch (KeeperException.NoNodeException nne) {
+ // it's ok if node doesn't exist
+ } catch (Exception e) {
+ logger.error("An error occurred deleting Zookeeper root of [" +
config.getAppZookeepers()
+ + "], error=[" + e.getMessage() + "]");
+ throw new RuntimeException(e);
+ }
+ }
+
private void initializeApplicationInZooKeeper(Connector conn) throws
Exception {
final String accumuloInstanceName = conn.getInstance().getInstanceName();
diff --git a/modules/distribution/src/main/scripts/fluo
b/modules/distribution/src/main/scripts/fluo
index 4116669f..03f6d137 100755
--- a/modules/distribution/src/main/scripts/fluo
+++ b/modules/distribution/src/main/scripts/fluo
@@ -66,6 +66,7 @@ function print_usage {
echo -e "Usage: fluo <command> (<argument> ...)\n"
echo -e "Possible commands:\n"
echo " init -a <app> -p <appProps> Initializes Fluo application for <app>
using <appProps>. Run with -h to see additional args."
+ echo " remove -a <app> Removes Fluo application for <app>"
echo " classpath Prints the classpath setup in
fluo-env.sh"
echo " config -a <app> Prints application configuration
stored in Zookeeper for <app>"
echo " get-jars -a <app> -d <dir> Copies <app> jars from DFS to local
<dir>"
@@ -184,6 +185,13 @@ init)
java org.apache.fluo.cluster.command.FluoCommand "$basedir"
"$HADOOP_PREFIX" "$@"
fi
;;
+remove)
+ if [[ $2 = *"-h"* ]]; then
+ $JAVA org.apache.fluo.command.FluoRemove -h
+ exit 0
+ fi
+ $JAVA org.apache.fluo.command.FluoRemove "${@:2}"
+ ;;
oracle)
if [[ $2 = *"-h"* ]]; then
$JAVA org.apache.fluo.command.FluoOracle -h
@@ -208,7 +216,7 @@ scan)
java org.apache.fluo.cluster.command.FluoCommand "$basedir"
"$HADOOP_PREFIX" "$@"
fi
;;
-ps)
+ps)
jps -m | grep Fluo
;;
list)
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services