mirror of
https://github.com/apache/sqoop.git
synced 2025-05-08 12:01:09 +08:00
SQOOP-1438: Sqoop2: Take advantage of isRequired flag in OptionParser in Sqoop shell
This commit is contained in:
parent
2e79f9094c
commit
2f94baeb96
@ -45,19 +45,11 @@ public CloneConnectionFunction() {
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
|
||||
.withLongOpt(Constants.OPT_XID)
|
||||
.hasArg()
|
||||
.isRequired()
|
||||
.create(Constants.OPT_XID_CHAR)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_XID)) {
|
||||
printlnResource(Constants.RES_ARGS_XID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
|
||||
|
@ -45,19 +45,11 @@ public CloneJobFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
|
||||
.withLongOpt(Constants.OPT_JID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create(Constants.OPT_JID_CHAR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_JID)) {
|
||||
printlnResource(Constants.RES_ARGS_JID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
|
||||
return cloneJob(getLong(line, Constants.OPT_JID), line.getArgList(), isInteractive);
|
||||
|
@ -44,19 +44,11 @@ public CreateConnectionFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_CONNECTOR_ID))
|
||||
.withLongOpt(Constants.OPT_CID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create(Constants.OPT_CID_CHAR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_CID)) {
|
||||
printlnResource(Constants.RES_ARGS_CID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
|
||||
|
@ -45,30 +45,19 @@ public CreateJobFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
|
||||
.withLongOpt(Constants.OPT_FROM)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create(Constants.OPT_FXID_CHAR)
|
||||
);
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
|
||||
.withLongOpt(Constants.OPT_TO)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create(Constants.OPT_TXID_CHAR)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_FROM)) {
|
||||
printlnResource(Constants.RES_ARGS_FROM_MISSING);
|
||||
return false;
|
||||
}
|
||||
if (!line.hasOption(Constants.OPT_TO)) {
|
||||
printlnResource(Constants.RES_ARGS_TO_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
|
||||
|
@ -34,19 +34,11 @@ public DeleteConnectionFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
|
||||
.withLongOpt(Constants.OPT_XID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create('x'));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_FROM)) {
|
||||
printlnResource(Constants.RES_ARGS_XID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) {
|
||||
client.deleteConnection(getLong(line, Constants.OPT_XID));
|
||||
|
@ -35,19 +35,11 @@ public DeleteJobFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
|
||||
.withLongOpt(Constants.OPT_JID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create('j'));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_JID)) {
|
||||
printlnResource(Constants.RES_ARGS_JID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) {
|
||||
client.deleteJob(getLong(line, Constants.OPT_JID));
|
||||
|
@ -34,19 +34,11 @@ public DisableConnectionFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
|
||||
.withLongOpt(Constants.OPT_XID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create('x'));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_XID)) {
|
||||
printlnResource(Constants.RES_ARGS_XID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) {
|
||||
client.enableConnection(getLong(line, Constants.OPT_XID), false);
|
||||
|
@ -34,19 +34,11 @@ public EnableConnectionFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
|
||||
.withLongOpt(Constants.OPT_XID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create('x'));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_XID)) {
|
||||
printlnResource(Constants.RES_ARGS_XID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) {
|
||||
client.enableConnection(getLong(line, Constants.OPT_XID), true);
|
||||
|
@ -35,19 +35,11 @@ public EnableJobFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
|
||||
.withLongOpt(Constants.OPT_JID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create('j'));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_JID)) {
|
||||
printlnResource(Constants.RES_ARGS_JID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) {
|
||||
client.enableJob(getLong(line, Constants.OPT_JID), true);
|
||||
|
@ -34,26 +34,15 @@ public SetOptionFunction() {
|
||||
this.addOption(OptionBuilder.hasArg()
|
||||
.withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_NAME))
|
||||
.withLongOpt(Constants.OPT_NAME)
|
||||
.isRequired()
|
||||
.create(Constants.OPT_NAME_CHAR));
|
||||
this.addOption(OptionBuilder.hasArg()
|
||||
.withDescription(resourceString(Constants.RES_SET_PROMPT_OPT_VALUE))
|
||||
.withLongOpt(Constants.OPT_VALUE)
|
||||
.isRequired()
|
||||
.create(Constants.OPT_VALUE_CHAR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_NAME)) {
|
||||
printlnResource(Constants.RES_ARGS_NAME_MISSING);
|
||||
return false;
|
||||
}
|
||||
if (!line.hasOption(Constants.OPT_VALUE)) {
|
||||
printlnResource(Constants.RES_ARGS_VALUE_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) {
|
||||
if (!line.hasOption(Constants.OPT_NAME)) {
|
||||
|
@ -44,19 +44,11 @@ public UpdateConnectionFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
|
||||
.withLongOpt(Constants.OPT_XID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create(Constants.OPT_XID_CHAR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_XID)) {
|
||||
printlnResource(Constants.RES_ARGS_XID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
|
||||
|
@ -45,19 +45,11 @@ public UpdateJobFunction() {
|
||||
this.addOption(OptionBuilder
|
||||
.withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
|
||||
.withLongOpt(Constants.OPT_JID)
|
||||
.isRequired()
|
||||
.hasArg()
|
||||
.create(Constants.OPT_JID_CHAR));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateArgs(CommandLine line) {
|
||||
if (!line.hasOption(Constants.OPT_JID)) {
|
||||
printlnResource(Constants.RES_ARGS_JID_MISSING);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object executeFunction(CommandLine line, boolean isInteractive) throws IOException {
|
||||
|
@ -40,17 +40,23 @@ public class ThrowableDisplayer {
|
||||
* @param t Throwable to be displayed
|
||||
*/
|
||||
public static void errorHook(Throwable t) {
|
||||
println("@|red Exception has occurred during processing command |@");
|
||||
|
||||
// If this is server exception from server
|
||||
if(t instanceof SqoopException
|
||||
&& ((SqoopException)t).getErrorCode() == ShellError.SHELL_0006) {
|
||||
print("@|red Server has returned exception: |@");
|
||||
// Based on the kind of exception we are dealing with, let's provide different user experince
|
||||
if(t instanceof SqoopException && ((SqoopException)t).getErrorCode() == ShellError.SHELL_0006) {
|
||||
println("@|red Server has returned exception: |@");
|
||||
printThrowable(t.getCause(), isVerbose());
|
||||
} else if(t instanceof SqoopException && ((SqoopException)t).getErrorCode() == ShellError.SHELL_0003) {
|
||||
print("@|red Invalid command invocation: |@");
|
||||
// In most cases the cause will be actual parsing error, so let's print that alone
|
||||
if (t.getCause() != null) {
|
||||
println(t.getCause().getMessage());
|
||||
} else {
|
||||
println(t.getMessage());
|
||||
}
|
||||
} else if(t.getClass() == MissingPropertyException.class) {
|
||||
print("@|red Unknown command: |@");
|
||||
println(t.getMessage());
|
||||
} else {
|
||||
println("@|red Exception has occurred during processing command |@");
|
||||
printThrowable(t, isVerbose());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user