From 98a2b7051f01d87f19948e1a251c3ee0e4b2523c Mon Sep 17 00:00:00 2001 From: Konstantin Boudnik Date: Sat, 16 Apr 2011 01:43:30 +0000 Subject: [PATCH] HADOOP-7014. Adding missed files git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1092853 13f79535-47bb-0310-9956-ffa450edef68 --- .../util/{CmdFactory.java => CLICommand.java} | 31 ++++-------- .../apache/hadoop/cli/util/CLICommandFS.java | 21 ++++++++ .../hadoop/cli/util/CLICommandTypes.java | 24 +++++++++ .../apache/hadoop/cli/util/CLITestCmd.java | 50 +++++++++++++++++++ .../{CLICommands.java => FSCmdExecutor.java} | 23 ++++----- 5 files changed, 116 insertions(+), 33 deletions(-) rename src/test/core/org/apache/hadoop/cli/util/{CmdFactory.java => CLICommand.java} (55%) create mode 100644 src/test/core/org/apache/hadoop/cli/util/CLICommandFS.java create mode 100644 src/test/core/org/apache/hadoop/cli/util/CLICommandTypes.java create mode 100644 src/test/core/org/apache/hadoop/cli/util/CLITestCmd.java rename src/test/core/org/apache/hadoop/cli/util/{CLICommands.java => FSCmdExecutor.java} (66%) diff --git a/src/test/core/org/apache/hadoop/cli/util/CmdFactory.java b/src/test/core/org/apache/hadoop/cli/util/CLICommand.java similarity index 55% rename from src/test/core/org/apache/hadoop/cli/util/CmdFactory.java rename to src/test/core/org/apache/hadoop/cli/util/CLICommand.java index f70ff2a222f..202b2429cbc 100644 --- a/src/test/core/org/apache/hadoop/cli/util/CmdFactory.java +++ b/src/test/core/org/apache/hadoop/cli/util/CLICommand.java @@ -6,9 +6,9 @@ * 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 - * + *

+ * 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. @@ -17,21 +17,12 @@ */ package org.apache.hadoop.cli.util; -import org.apache.hadoop.fs.FsShell; - -public abstract class CmdFactory { - public static CommandExecutor getCommandExecutor(CLITestData.TestCmd cmd, - String tag) - throws IllegalArgumentException { - CommandExecutor executor = null; - switch (cmd.getType()) { - case FS: - executor = new CLICommands.FSCmdExecutor(tag, new FsShell()); - break; - default: - throw new IllegalArgumentException("Unknown type of Test command:" + - cmd.getType()); - } - return executor; - } +/** + * This interface is to generalize types of test command for upstream projects + */ +public interface CLICommand { + public CommandExecutor getExecutor(String tag) throws IllegalArgumentException; + public CLICommandTypes getType(); + public String getCmd(); + public String toString(); } diff --git a/src/test/core/org/apache/hadoop/cli/util/CLICommandFS.java b/src/test/core/org/apache/hadoop/cli/util/CLICommandFS.java new file mode 100644 index 00000000000..eb96a06709b --- /dev/null +++ b/src/test/core/org/apache/hadoop/cli/util/CLICommandFS.java @@ -0,0 +1,21 @@ +/** + * 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.cli.util; + +public class CLICommandFS implements CLICommandTypes { +} diff --git a/src/test/core/org/apache/hadoop/cli/util/CLICommandTypes.java b/src/test/core/org/apache/hadoop/cli/util/CLICommandTypes.java new file mode 100644 index 00000000000..44e0c307d3e --- /dev/null +++ b/src/test/core/org/apache/hadoop/cli/util/CLICommandTypes.java @@ -0,0 +1,24 @@ +/** + * 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.cli.util; + +/** + * This interface is to provide command type for test commands enums + */ +public interface CLICommandTypes { +} diff --git a/src/test/core/org/apache/hadoop/cli/util/CLITestCmd.java b/src/test/core/org/apache/hadoop/cli/util/CLITestCmd.java new file mode 100644 index 00000000000..55e99b51a68 --- /dev/null +++ b/src/test/core/org/apache/hadoop/cli/util/CLITestCmd.java @@ -0,0 +1,50 @@ +/** + * 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.cli.util; + +import org.apache.hadoop.fs.FsShell; + +/** + * Class to define Test Command along with its type + */ +public class CLITestCmd implements CLICommand { + private final CLICommandTypes type; + private final String cmd; + + public CLITestCmd(String str, CLICommandTypes type) { + cmd = str; + this.type = type; + } + + public CommandExecutor getExecutor(String tag) throws IllegalArgumentException { + if (getType() instanceof CLICommandFS) + return new FSCmdExecutor(tag, new FsShell()); + throw new + IllegalArgumentException("Unknown type of test command: " + getType()); + } + + public CLICommandTypes getType() { + return type; + } + public String getCmd() { + return cmd; + } + public String toString() { + return cmd; + } +} diff --git a/src/test/core/org/apache/hadoop/cli/util/CLICommands.java b/src/test/core/org/apache/hadoop/cli/util/FSCmdExecutor.java similarity index 66% rename from src/test/core/org/apache/hadoop/cli/util/CLICommands.java rename to src/test/core/org/apache/hadoop/cli/util/FSCmdExecutor.java index b4d284dbada..86e86b6e1f2 100644 --- a/src/test/core/org/apache/hadoop/cli/util/CLICommands.java +++ b/src/test/core/org/apache/hadoop/cli/util/FSCmdExecutor.java @@ -20,20 +20,17 @@ package org.apache.hadoop.cli.util; import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.util.ToolRunner; -public class CLICommands { +public class FSCmdExecutor extends CommandExecutor { + protected String namenode = null; + protected FsShell shell = null; - public static class FSCmdExecutor extends CommandExecutor { - protected String namenode = null; - protected FsShell shell = null; - - public FSCmdExecutor(String namenode, FsShell shell) { - this.namenode = namenode; - this.shell = shell; - } + public FSCmdExecutor(String namenode, FsShell shell) { + this.namenode = namenode; + this.shell = shell; + } - protected void execute(final String cmd) throws Exception{ - String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode); - ToolRunner.run(shell, args); - } + protected void execute(final String cmd) throws Exception{ + String[] args = getCommandAsArgs(cmd, "NAMENODE", this.namenode); + ToolRunner.run(shell, args); } }