From ef478fe73e72692b660de818d8c8faa9a155a10b Mon Sep 17 00:00:00 2001 From: cxorm Date: Thu, 19 Sep 2019 09:16:12 +0200 Subject: [PATCH] HDDS-730. ozone fs cli prints hadoop fs in usage Closes #1464 --- hadoop-ozone/common/src/main/bin/ozone | 2 +- .../apache/hadoop/fs/ozone/OzoneFsShell.java | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java diff --git a/hadoop-ozone/common/src/main/bin/ozone b/hadoop-ozone/common/src/main/bin/ozone index e257519dce6..cd8f202c2cf 100755 --- a/hadoop-ozone/common/src/main/bin/ozone +++ b/hadoop-ozone/common/src/main/bin/ozone @@ -178,7 +178,7 @@ function ozonecmd_case OZONE_RUN_ARTIFACT_NAME="hadoop-ozone-recon" ;; fs) - HADOOP_CLASSNAME=org.apache.hadoop.fs.FsShell + HADOOP_CLASSNAME=org.apache.hadoop.fs.ozone.OzoneFsShell OZONE_RUN_ARTIFACT_NAME="hadoop-ozone-tools" ;; scmcli) diff --git a/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java b/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java new file mode 100644 index 00000000000..873c843b228 --- /dev/null +++ b/hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java @@ -0,0 +1,100 @@ +/** + * 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.hadoop.fs.ozone; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.conf.Configured; +import org.apache.hadoop.fs.FsShell; +import org.apache.hadoop.fs.shell.Command; +import org.apache.hadoop.fs.shell.CommandFactory; +import org.apache.hadoop.fs.shell.FsCommand; +import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.tools.TableListing; +import org.apache.hadoop.tracing.TraceUtils; +import org.apache.hadoop.util.StringUtils; +import org.apache.hadoop.util.Tool; +import org.apache.hadoop.util.ToolRunner; +import org.apache.htrace.core.TraceScope; +import org.apache.htrace.core.Tracer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Provide command line access to a Ozone FileSystem. */ +@InterfaceAudience.Private +public class OzoneFsShell extends FsShell { + + private final String ozoneUsagePrefix = "Usage: ozone fs [generic options]"; + + /** + * Default ctor with no configuration. Be sure to invoke + * {@link #setConf(Configuration)} with a valid configuration prior + * to running commands. + */ + public OzoneFsShell() { this(null); } + + /** + * Construct a OzoneFsShell with the given configuration. Commands can be + * executed via {@link #run(String[])} + * @param conf the hadoop configuration + */ + public OzoneFsShell(Configuration conf) { super(conf); } + + protected void registerCommands(CommandFactory factory) { + // TODO: DFSAdmin subclasses FsShell so need to protect the command + // registration. This class should morph into a base class for + // commands, and then this method can be abstract + if (this.getClass().equals(OzoneFsShell.class)) { + factory.registerCommands(FsCommand.class); + } + } + + @Override + protected String getUsagePrefix() { + return ozoneUsagePrefix; + } + + /** + * main() has some simple utility methods + * @param argv the command and its arguments + * @throws Exception upon error + */ + public static void main(String argv[]) throws Exception { + OzoneFsShell shell = newShellInstance(); + Configuration conf = new Configuration(); + conf.setQuietMode(false); + shell.setConf(conf); + int res; + try { + res = ToolRunner.run(shell, argv); + } finally { + shell.close(); + } + System.exit(res); + } + + // TODO: this should be abstract in a base class + protected static OzoneFsShell newShellInstance() { + return new OzoneFsShell(); + } +}