mirror of
https://github.com/apache/sqoop.git
synced 2025-05-13 23:41:56 +08:00
SQOOP-694 Introduce client "verbose" mode
(Jarek Jarcec Cecho)
This commit is contained in:
parent
211c67819e
commit
18b5d70d31
@ -30,9 +30,12 @@ private Environment() {
|
|||||||
private static String serverPort;
|
private static String serverPort;
|
||||||
private static String serverWebapp;
|
private static String serverWebapp;
|
||||||
|
|
||||||
|
private static boolean verbose;
|
||||||
|
|
||||||
private static final String HOST_DEFAULT = "vm-sqoop2";
|
private static final String HOST_DEFAULT = "vm-sqoop2";
|
||||||
private static final String PORT_DEFAULT = "8080";
|
private static final String PORT_DEFAULT = "8080";
|
||||||
private static final String WEBAPP_DEFAULT = "sqoop";
|
private static final String WEBAPP_DEFAULT = "sqoop";
|
||||||
|
private static final boolean VERBOSE_DEFAULT = false;
|
||||||
|
|
||||||
private static ResourceBundle resourceBundle;
|
private static ResourceBundle resourceBundle;
|
||||||
|
|
||||||
@ -40,6 +43,7 @@ private Environment() {
|
|||||||
serverHost = HOST_DEFAULT;
|
serverHost = HOST_DEFAULT;
|
||||||
serverPort = PORT_DEFAULT;
|
serverPort = PORT_DEFAULT;
|
||||||
serverWebapp = WEBAPP_DEFAULT;
|
serverWebapp = WEBAPP_DEFAULT;
|
||||||
|
verbose = VERBOSE_DEFAULT;
|
||||||
|
|
||||||
resourceBundle =
|
resourceBundle =
|
||||||
ResourceBundle.getBundle(Constants.RESOURCE_NAME, Locale.getDefault());
|
ResourceBundle.getBundle(Constants.RESOURCE_NAME, Locale.getDefault());
|
||||||
@ -76,4 +80,12 @@ public static String getServerUrl() {
|
|||||||
public static ResourceBundle getResourceBundle() {
|
public static ResourceBundle getResourceBundle() {
|
||||||
return resourceBundle;
|
return resourceBundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setVerbose(boolean newValue) {
|
||||||
|
verbose = newValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isVerboose() {
|
||||||
|
return verbose;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,11 @@
|
|||||||
public class SetCommand extends SqoopCommand
|
public class SetCommand extends SqoopCommand
|
||||||
{
|
{
|
||||||
private SetServerFunction serverFunction;
|
private SetServerFunction serverFunction;
|
||||||
|
private SetOptionFunction optionFunction;
|
||||||
|
|
||||||
protected SetCommand(Shell shell) {
|
protected SetCommand(Shell shell) {
|
||||||
super(shell, "set", "\\st",
|
super(shell, "set", "\\st",
|
||||||
new String[] {"server", "connector"},
|
new String[] {"server", "option"},
|
||||||
"Set", "info");
|
"Set", "info");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,8 +50,11 @@ public Object execute(List args) {
|
|||||||
}
|
}
|
||||||
return serverFunction.execute(args);
|
return serverFunction.execute(args);
|
||||||
|
|
||||||
} else if (func.equals("client")) {
|
} else if (func.equals("option")) {
|
||||||
return null;
|
if (optionFunction == null) {
|
||||||
|
optionFunction = new SetOptionFunction(io);
|
||||||
|
}
|
||||||
|
return optionFunction.execute(args);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String msg = "Usage: set " + getUsage();
|
String msg = "Usage: set " + getUsage();
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
/**
|
||||||
|
* 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.sqoop.client.shell;
|
||||||
|
|
||||||
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
|
import org.apache.sqoop.client.core.Environment;
|
||||||
|
import org.codehaus.groovy.tools.shell.IO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SetOptionFunction extends SqoopFunction {
|
||||||
|
|
||||||
|
public static final String NAME = "name";
|
||||||
|
public static final String VALUE = "value";
|
||||||
|
|
||||||
|
private IO io;
|
||||||
|
|
||||||
|
@SuppressWarnings("static-access")
|
||||||
|
protected SetOptionFunction(IO io) {
|
||||||
|
this.io = io;
|
||||||
|
|
||||||
|
this.addOption(OptionBuilder.hasArg()
|
||||||
|
.withDescription("Client option name")
|
||||||
|
.withLongOpt(NAME)
|
||||||
|
.create(NAME.charAt(0)));
|
||||||
|
this.addOption(OptionBuilder.hasArg()
|
||||||
|
.withDescription("New option value")
|
||||||
|
.withLongOpt(VALUE)
|
||||||
|
.create(VALUE.charAt(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object execute(List<String> args) {
|
||||||
|
CommandLine line = parseOptions(this, 1, args);
|
||||||
|
if (!line.hasOption(NAME)) {
|
||||||
|
io.out.println("Required argument --name is missing.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!line.hasOption(VALUE)) {
|
||||||
|
io.out.println("Required argument --value is missing.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
handleOptionSetting(line.getOptionValue(NAME), line.getOptionValue(VALUE));
|
||||||
|
|
||||||
|
io.out.println();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleOptionSetting(String name, String value) {
|
||||||
|
if(name.equals("verbose")) {
|
||||||
|
boolean newValue = false;
|
||||||
|
|
||||||
|
if(value.equals("1") || value.equals("true")) {
|
||||||
|
newValue = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Environment.setVerbose(newValue);
|
||||||
|
io.out.println("Verbose option was changed to " + newValue);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
io.out.println("Unknown option " + name + ". Ignoring...");
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import groovy.lang.MissingPropertyException;
|
import groovy.lang.MissingPropertyException;
|
||||||
import org.apache.sqoop.client.core.ClientError;
|
import org.apache.sqoop.client.core.ClientError;
|
||||||
|
import org.apache.sqoop.client.core.Environment;
|
||||||
import org.apache.sqoop.common.SqoopException;
|
import org.apache.sqoop.common.SqoopException;
|
||||||
import org.codehaus.groovy.tools.shell.IO;
|
import org.codehaus.groovy.tools.shell.IO;
|
||||||
|
|
||||||
@ -57,12 +58,12 @@ public static void errorHook(Throwable t) {
|
|||||||
if(t instanceof SqoopException
|
if(t instanceof SqoopException
|
||||||
&& ((SqoopException)t).getErrorCode() == ClientError.CLIENT_0006) {
|
&& ((SqoopException)t).getErrorCode() == ClientError.CLIENT_0006) {
|
||||||
io.out.print("@|red Server has returned exception: |@");
|
io.out.print("@|red Server has returned exception: |@");
|
||||||
printThrowable(io, t.getCause());
|
printThrowable(io, t.getCause(), Environment.isVerboose());
|
||||||
} else if(t.getClass() == MissingPropertyException.class) {
|
} else if(t.getClass() == MissingPropertyException.class) {
|
||||||
io.out.print("@|red Unknown command: |@");
|
io.out.print("@|red Unknown command: |@");
|
||||||
io.out.println(t.getMessage());
|
io.out.println(t.getMessage());
|
||||||
} else {
|
} else {
|
||||||
printThrowable(io, t);
|
printThrowable(io, t, Environment.isVerboose());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,13 +73,14 @@ public static void errorHook(Throwable t) {
|
|||||||
* @param io IO object to use for generating output
|
* @param io IO object to use for generating output
|
||||||
* @param t Throwable to display
|
* @param t Throwable to display
|
||||||
*/
|
*/
|
||||||
protected static void printThrowable(IO io, Throwable t) {
|
protected static void printThrowable(IO io, Throwable t, boolean verbose) {
|
||||||
io.out.print("@|red Exception: |@");
|
io.out.print("@|red Exception: |@");
|
||||||
io.out.print(t.getClass().getName());
|
io.out.print(t.getClass().getName());
|
||||||
io.out.print(" @|red Message: |@");
|
io.out.print(" @|red Message: |@");
|
||||||
io.out.print(t.getMessage());
|
io.out.print(t.getMessage());
|
||||||
io.out.println();
|
io.out.println();
|
||||||
|
|
||||||
|
if(verbose) {
|
||||||
io.out.println("Stack trace:");
|
io.out.println("Stack trace:");
|
||||||
for(StackTraceElement e : t.getStackTrace()) {
|
for(StackTraceElement e : t.getStackTrace()) {
|
||||||
io.out.print("\t @|bold at |@ ");
|
io.out.print("\t @|bold at |@ ");
|
||||||
@ -91,7 +93,8 @@ protected static void printThrowable(IO io, Throwable t) {
|
|||||||
Throwable cause = t.getCause();
|
Throwable cause = t.getCause();
|
||||||
if(cause != null) {
|
if(cause != null) {
|
||||||
io.out.print("Caused by: ");
|
io.out.print("Caused by: ");
|
||||||
printThrowable(io, cause);
|
printThrowable(io, cause, verbose);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user