HADOOP-7014. Adding missed files

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1092853 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Konstantin Boudnik 2011-04-16 01:43:30 +00:00
parent 58ca2272bc
commit 98a2b7051f
5 changed files with 116 additions and 33 deletions

View File

@ -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
*
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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();
}

View File

@ -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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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 {
}

View File

@ -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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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 {
}

View File

@ -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;
}
}

View File

@ -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);
}
}