You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by hs...@apache.org on 2013/08/07 01:22:02 UTC
[4/6] SQOOP-921. Sqoop2: Create standalone shell package
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java b/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
deleted file mode 100644
index 425a53f..0000000
--- a/client/src/main/java/org/apache/sqoop/client/shell/UpdateJobFunction.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/**
- * 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 jline.ConsoleReader;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.client.utils.FormDisplayer;
-import org.apache.sqoop.common.SqoopException;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.validation.Status;
-
-import java.io.IOException;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.utils.FormFiller.*;
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- *
- */
-public class UpdateJobFunction extends SqoopFunction {
- @SuppressWarnings("static-access")
- public UpdateJobFunction() {
- this.addOption(OptionBuilder
- .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
- .withLongOpt(Constants.OPT_JID)
- .hasArg()
- .create(Constants.OPT_JID_CHAR));
- }
-
- public Object executeFunction(CommandLine line) {
- if (!line.hasOption(Constants.OPT_JID)) {
- printlnResource(Constants.RES_ARGS_JID_MISSING);
- return null;
- }
-
- try {
- updateJob(getLong(line, Constants.OPT_JID));
- } catch (IOException ex) {
- throw new SqoopException(ClientError.CLIENT_0005, ex);
- }
-
- return null;
- }
-
- private void updateJob(Long jobId) throws IOException {
- printlnResource(Constants.RES_UPDATE_UPDATING_JOB, jobId);
-
- ConsoleReader reader = new ConsoleReader();
-
- MJob job = client.getJob(jobId);
-
- ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
- ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
-
- Status status = Status.FINE;
-
- printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
-
- do {
- // Print error introduction if needed
- if( !status.canProceed() ) {
- errorIntroduction();
- }
-
- // Fill in data from user
- if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
- return;
- }
-
- // Try to create
- status = client.updateJob(job);
- } while(!status.canProceed());
- FormDisplayer.displayFormWarning(job);
- printlnResource(Constants.RES_UPDATE_JOB_SUCCESSFUL, status.name());
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
deleted file mode 100644
index b044e22..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/**
- * 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.utils;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.model.MAccountableEntity;
-import org.apache.sqoop.model.MBooleanInput;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MEnumInput;
-import org.apache.sqoop.model.MForm;
-import org.apache.sqoop.model.MFramework;
-import org.apache.sqoop.model.MInput;
-import org.apache.sqoop.model.MInputType;
-import org.apache.sqoop.model.MIntegerInput;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MJobForms;
-import org.apache.sqoop.model.MMapInput;
-import org.apache.sqoop.model.MStringInput;
-import org.apache.sqoop.validation.Status;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Convenience static methods for displaying form related information
- */
-public final class FormDisplayer {
-
- public static void displayFormMetadataDetails(MFramework framework,
- ResourceBundle bundle) {
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SUPPORTED_JOBTYPE));
- println(framework.getAllJobsForms().keySet().toString());
-
- displayFormsMetadata(
- framework.getConnectionForms().getForms(),
- resourceString(Constants.RES_FORMDISPLAYER_CONNECTION),
- bundle);
-
- for (MJobForms jobForms : framework.getAllJobsForms().values()) {
- print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_FORM_JOBTYPE));
- print(jobForms.getType().name());
- println(":");
-
- displayFormsMetadata(jobForms.getForms(), resourceString(Constants.RES_FORMDISPLAYER_JOB), bundle);
- }
- }
-
- public static void displayFormsMetadata(List<MForm> forms,
- String type,
- ResourceBundle bundle) {
- Iterator<MForm> fiter = forms.iterator();
- int findx = 1;
- while (fiter.hasNext()) {
- print(" ");
- print(type);
- print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_FORM));
- print(findx++);
- println(":");
-
- MForm form = fiter.next();
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_NAME));
- println(form.getName());
-
- // Label
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_LABEL));
- println(bundle.getString(form.getLabelKey()));
-
- // Help text
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_HELP));
- println(bundle.getString(form.getHelpKey()));
-
- List<MInput<?>> inputs = form.getInputs();
- Iterator<MInput<?>> iiter = inputs.iterator();
- int iindx = 1;
- while (iiter.hasNext()) {
- print(" %s ", resourceString(Constants.RES_FORMDISPLAYER_INPUT));
- print(iindx++);
- println(":");
-
- MInput<?> input = iiter.next();
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_NAME));
- println(input.getName());
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_LABEL));
- println(bundle.getString(input.getLabelKey()));
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_HELP));
- println(bundle.getString(input.getHelpKey()));
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_TYPE));
- println(input.getType());
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SENSITIVE));
- println(input.isSensitive());
- if (input.getType() == MInputType.STRING) {
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_SIZE));
- println(((MStringInput)input).getMaxLength());
- } else if(input.getType() == MInputType.ENUM) {
- print(" %s: ", resourceString(Constants.RES_FORMDISPLAYER_POSSIBLE_VALUES));
- println(StringUtils.join(((MEnumInput)input).getValues(), ","));
- }
- }
- }
- }
-
- public static void displayForms(List<MForm> forms, ResourceBundle bundle) {
- for(MForm form : forms) {
- displayForm(form, bundle);
- }
- }
-
- /**
- * Method prints the warning message of ACCEPTABLE status
- * @param entity - connection or job instance
- */
- public static void displayFormWarning(MAccountableEntity entity) {
- List<MForm> formList = new ArrayList<MForm>();
- boolean showMessage = true;
- if (entity instanceof MConnection) {
- MConnection connection = (MConnection) entity;
- formList.addAll(connection.getConnectorPart().getForms());
- formList.addAll(connection.getFrameworkPart().getForms());
- } else if(entity instanceof MJob) {
- MJob job = (MJob) entity;
- formList.addAll(job.getConnectorPart().getForms());
- formList.addAll(job.getFrameworkPart().getForms());
- }
- for(MForm form : formList) {
- if(form.getValidationStatus() == Status.ACCEPTABLE) {
- if(showMessage) {
- print("\n@|yellow %s|@\n", resourceString(Constants.RES_FORMDISPLAYER_FORM_WARNING));
- showMessage = false;
- }
- FormFiller.warningMessage(form.getValidationMessage());
- }
- }
- }
-
- private static void displayForm(MForm form, ResourceBundle bundle) {
- print(" ");
- println(bundle.getString(form.getLabelKey()));
-
- for (MInput<?> input : form.getInputs()) {
- print(" ");
- print(bundle.getString(input.getLabelKey()));
- print(": ");
- if(!input.isEmpty()) {
- if (input.isSensitive()) {
- print("(%s)", resourceString(Constants.RES_FORMDISPLAYER_INPUT_SENSITIVE));
- } else {
- // Based on the input type, let's perform specific load
- switch (input.getType()) {
- case STRING:
- displayInputString((MStringInput) input);
- break;
- case INTEGER:
- displayInputInteger((MIntegerInput) input);
- break;
- case BOOLEAN:
- displayInputBoolean((MBooleanInput) input);
- break;
- case MAP:
- displayInputMap((MMapInput) input);
- break;
- case ENUM:
- displayInputEnum((MEnumInput) input);
- break;
- default:
- print("\n%s " + input.getType(), resourceString(Constants.RES_FORMDISPLAYER_UNSUPPORTED_DATATYPE));
- return;
- }
- }
- }
- println("");
- }
- }
-
- /**
- * Display content of String input.
- *
- * @param input String input
- */
- private static void displayInputString(MStringInput input) {
- print(input.getValue());
- }
-
- /**
- * Display content of Integer input.
- *
- * @param input Integer input
- */
- private static void displayInputInteger(MIntegerInput input) {
- print(input.getValue());
- }
-
- /**
- * Display content of Boolean input.
- *
- * @param input Boolean input
- */
- private static void displayInputBoolean(MBooleanInput input) {
- print(input.getValue());
- }
-
- /**
- * Display content of Map input
- *
- * @param input Map input
- */
- private static void displayInputMap(MMapInput input) {
- for(Map.Entry<String, String> entry : input.getValue().entrySet()) {
- println();
- print(" ");
- print(entry.getKey());
- print(" = ");
- print(entry.getValue());
- }
- }
-
- /**
- * Display content of Enum input
- *
- * @param input Enum input
- */
- private static void displayInputEnum(MEnumInput input) {
- print(input.getValue());
- }
-
- private FormDisplayer() {
- // Do not instantiate
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java b/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
deleted file mode 100644
index 2fbf129..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/FormFiller.java
+++ /dev/null
@@ -1,566 +0,0 @@
-/**
- * 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.utils;
-
-import jline.ConsoleReader;
-import org.apache.sqoop.model.MBooleanInput;
-import org.apache.sqoop.model.MConnection;
-import org.apache.sqoop.model.MEnumInput;
-import org.apache.sqoop.model.MForm;
-import org.apache.sqoop.model.MInput;
-import org.apache.sqoop.model.MIntegerInput;
-import org.apache.sqoop.model.MMapInput;
-import org.apache.sqoop.model.MJob;
-import org.apache.sqoop.model.MStringInput;
-import org.apache.sqoop.model.MValidatedElement;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.ResourceBundle;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Convenient methods for retrieving user input.
- */
-public final class FormFiller {
-
- /**
- * Internal input that will be reused for loading names for connection and
- * job objects.
- */
- private static MStringInput nameInput = new MStringInput("object-name", false, (short)25);
-
- /**
- * Fill job object based on user input.
- *
- * @param reader Associated console reader object
- * @param job Job that user is suppose to fill in
- * @param connectorBundle Connector resource bundle
- * @param frameworkBundle Framework resource bundle
- * @return True if we filled all inputs, false if user has stopped processing
- * @throws IOException
- */
- public static boolean fillJob(ConsoleReader reader,
- MJob job,
- ResourceBundle connectorBundle,
- ResourceBundle frameworkBundle)
- throws IOException {
-
- job.setName(getName(reader, job.getName()));
-
- // Fill in data from user
- return fillForms(reader,
- job.getConnectorPart().getForms(),
- connectorBundle,
- job.getFrameworkPart().getForms(),
- frameworkBundle);
- }
-
- /**
- * Fill connection object based on user input.
- *
- * @param reader Associated console reader object
- * @param connection Connection that user is suppose to fill in
- * @param connectorBundle Connector resource bundle
- * @param frameworkBundle Framework resouce bundle
- * @return True if we filled all inputs, false if user has stopped processing
- * @throws IOException
- */
- public static boolean fillConnection(ConsoleReader reader,
- MConnection connection,
- ResourceBundle connectorBundle,
- ResourceBundle frameworkBundle)
- throws IOException {
-
- connection.setName(getName(reader, connection.getName()));
-
- // Fill in data from user
- return fillForms(reader,
- connection.getConnectorPart().getForms(),
- connectorBundle,
- connection.getFrameworkPart().getForms(),
- frameworkBundle);
- }
-
- public static boolean fillForms(ConsoleReader reader,
- List<MForm> connectorForms,
- ResourceBundle connectorBundle,
- List<MForm> frameworkForms,
- ResourceBundle frameworkBundle
- ) throws IOException {
-
-
- // Query connector forms
- if(!fillForms(connectorForms, reader, connectorBundle)) {
- return false;
- }
-
- // Query framework forms
- if(!fillForms(frameworkForms, reader, frameworkBundle)) {
- return false;
- }
-
- return true;
- }
-
- public static boolean fillForms(List<MForm> forms,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- for (MForm form : forms) {
- if(!fillForm(form, reader, bundle)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean fillForm(MForm form,
- ConsoleReader reader,
- ResourceBundle bundle) throws IOException {
- println("");
- println(bundle.getString(form.getLabelKey()));
-
- // Print out form validation
- printValidationMessage(form);
- println("");
-
- for (MInput input : form.getInputs()) {
- if(!fillInput(input, reader, bundle)) {
- return false;
- }
- }
-
- return true;
- }
-
- public static boolean fillInput(MInput input,
- ConsoleReader reader,
- ResourceBundle bundle) throws IOException {
- // Print out validation
- printValidationMessage(input);
-
- // Based on the input type, let's perform specific load
- switch (input.getType()) {
- case STRING:
- return fillInputString((MStringInput) input, reader, bundle);
- case INTEGER:
- return fillInputInteger((MIntegerInput) input, reader, bundle);
- case BOOLEAN:
- return fillInputBoolean((MBooleanInput) input, reader, bundle);
- case MAP:
- return fillInputMap((MMapInput) input, reader, bundle);
- case ENUM:
- return fillInputEnum((MEnumInput) input, reader, bundle);
- default:
- println("Unsupported data type " + input.getType());
- return true;
- }
- }
-
- /**
- * Load user input for enum type.
- *
- * Print out numbered list of all available options and let user choose one
- * item from that.
- *
- * @param input Input that we should read or edit
- * @param reader Associated console reader
- * @param bundle Resource bundle
- * @return True if user with to continue with loading addtional inputs
- * @throws IOException
- */
- private static boolean fillInputEnum(MEnumInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- // Prompt in enum case
- println(bundle.getString(input.getLabelKey()) + ": ");
-
- // Indexes
- int i = -1;
- int lastChoice = -1;
-
- // Print out all values as a numbered list
- for(String value : input.getValues()) {
- i++;
-
- println(" " + i + " : " + value);
-
- // Only show last choice if not sensitive
- if(!input.isEmpty() && value.equals(input.getValue()) && !input.isSensitive()) {
- lastChoice = i;
- }
- }
-
- // Prompt
- reader.printString("Choose: ");
-
- // Fill previously filled index when available
- if(lastChoice != -1) {
- reader.putString(Integer.toString(lastChoice));
- }
-
- reader.flushConsole();
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- return false;
- } else if (userTyped.isEmpty()) {
- input.setEmpty();
- } else {
- Integer index;
- try {
- index = Integer.valueOf(userTyped);
-
- if(index < 0 || index >= input.getValues().length) {
- errorMessage("Invalid index");
- return fillInputEnum(input, reader, bundle);
- }
-
- input.setValue(input.getValues()[index]);
- } catch (NumberFormatException ex) {
- errorMessage("Input is not valid integer number");
- return fillInputEnum(input, reader, bundle);
- }
- }
-
- return true;
- }
-
- /**
- * Load user input for map type.
- *
- * This implementation will load one map entry at the time. Current flows is
- * as follows: if user did not enter anything (empty input) finish loading
- * and return from function. If user specified input with equal sign (=),
- * lets add new key value pair. Otherwise consider entire input as a key name
- * and try to remove it from the map.
- *
- * Please note that following code do not supports equal sign in property
- * name. It's however perfectly fine to have equal sign in value.
- *
- * @param input Input that we should read or edit
- * @param reader Associated console reader
- * @param bundle Resource bundle
- * @return True if user wish to continue with loading additional inputs
- * @throws IOException
- */
- private static boolean fillInputMap(MMapInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- // Special prompt in Map case
- println(bundle.getString(input.getLabelKey()) + ": ");
-
- // Internal loading map
- Map<String, String> values = input.getValue();
- if(values == null) {
- values = new HashMap<String, String>();
- }
-
- String userTyped;
-
- while(true) {
- // Print all current items in each iteration
- // However do not printout if this input contains sensitive information.
- println("There are currently " + values.size() + " values in the map:");
- if (!input.isSensitive()) {
- for(Map.Entry<String, String> entry : values.entrySet()) {
- println(entry.getKey() + " = " + entry.getValue());
- }
- }
-
- // Special prompt for Map entry
- reader.printString("entry# ");
- reader.flushConsole();
-
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if(userTyped == null) {
- // Finish loading and return back to Sqoop shell
- return false;
- } else if(userTyped.isEmpty()) {
- // User has finished loading data to Map input, either set input empty
- // if there are no entries or propagate entries to the input
- if(values.size() == 0) {
- input.setEmpty();
- } else {
- input.setValue(values);
- }
- return true;
- } else {
- // User has specified regular input, let's check if it contains equals
- // sign. Save new entry (or update existing one) if it does. Otherwise
- // try to remove entry that user specified.
- if(userTyped.contains("=")) {
- String []keyValue = userTyped.split("=", 2);
- values.put(handleUserInput(keyValue[0]), handleUserInput(keyValue[1]));
- } else {
- String key = handleUserInput(userTyped);
- if(values.containsKey(key)) {
- values.remove(key);
- } else {
- errorMessage("Don't know what to do with " + userTyped);
- }
- }
- }
-
- }
- }
-
- /**
- * Handle special cases in user input.
- *
- * Preserve null and empty values, remove whitespace characters before and
- * after loaded string and de-quote the string if it's quoted (to preserve
- * spaces for example).
- *
- * @param input String loaded from user
- * @return Unquoted transformed string
- */
- private static String handleUserInput(String input) {
- // Preserve null and empty values
- if(input == null) {
- return null;
- }
- if(input.isEmpty()) {
- return input;
- }
-
- // Removes empty characters at the begging and end of loaded string
- input = input.trim();
-
- int lastIndex = input.length() - 1;
- char first = input.charAt(0);
- char last = input.charAt(lastIndex);
-
- // Remove quoting if present
- if(first == '\'' && last == '\'') {
- input = input.substring(1, lastIndex);
- } else if(first == '"' && last == '"') {
- input = input.substring(1, lastIndex);
- }
-
- // Return final string
- return input;
- }
-
- private static boolean fillInputInteger(MIntegerInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- generatePrompt(reader, bundle, input);
-
- // Fill already filled data when available
- // However do not printout if this input contains sensitive information.
- if(!input.isEmpty() && !input.isSensitive()) {
- reader.putString(input.getValue().toString());
- }
-
- // Get the data
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- return false;
- } else if (userTyped.isEmpty()) {
- input.setEmpty();
- } else {
- Integer value;
- try {
- value = Integer.valueOf(userTyped);
- input.setValue(value);
- } catch (NumberFormatException ex) {
- errorMessage("Input is not valid integer number");
- return fillInputInteger(input, reader, bundle);
- }
-
- input.setValue(Integer.valueOf(userTyped));
- }
-
- return true;
- }
-
- /**
- * Load string input from the user.
- *
- * @param input Input that we should load in
- * @param reader Associated console reader
- * @param bundle Resource bundle for this input
- * @return
- * @throws IOException
- */
- public static boolean fillInputString(MStringInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- generatePrompt(reader, bundle, input);
-
- // Fill already filled data when available
- // However do not printout if this input contains sensitive information.
- if(!input.isEmpty() && !input.isSensitive()) {
- reader.putString(input.getValue());
- }
-
- // Get the data
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- // Propagate end of loading process
- return false;
- } else if (userTyped.isEmpty()) {
- // Empty input in case that nothing was given
- input.setEmpty();
- } else {
- // Set value that user has entered
- input.setValue(userTyped);
-
- // Check that it did not exceeds maximal allowance for given input
- if(userTyped.length() > input.getMaxLength()) {
- errorMessage("Size of input exceeds allowance for this input"
- + " field. Maximal allowed size is " + input.getMaxLength());
- return fillInputString(input, reader, bundle);
- }
- }
-
- return true;
- }
-
- /**
- * Load boolean input from the user.
- *
- * @param input Input that we should load in
- * @param reader Associated console reader
- * @param bundle Resource bundle for this input
- * @return
- * @throws IOException
- */
- public static boolean fillInputBoolean(MBooleanInput input,
- ConsoleReader reader,
- ResourceBundle bundle)
- throws IOException {
- generatePrompt(reader, bundle, input);
-
- // Fill already filled data when available
- // However do not printout if this input contains sensitive information.
- if(!input.isEmpty() && !input.isSensitive()) {
- reader.putString(input.getValue().toString());
- }
-
- // Get the data
- String userTyped;
- if(input.isSensitive()) {
- userTyped = reader.readLine('*');
- } else {
- userTyped = reader.readLine();
- }
-
- if (userTyped == null) {
- // Propagate end of loading process
- return false;
- } else if (userTyped.isEmpty()) {
- // Empty input in case that nothing was given
- input.setEmpty();
- } else {
- // Set value that user has entered
- input.setValue(Boolean.valueOf(userTyped));
- }
-
- return true;
- }
-
- public static void generatePrompt(ConsoleReader reader,
- ResourceBundle bundle,
- MInput input)
- throws IOException {
- reader.printString(bundle.getString(input.getLabelKey()) + ": ");
- reader.flushConsole();
- }
-
- public static String getName(ConsoleReader reader,
- String name) throws IOException {
- if(name == null) {
- nameInput.setEmpty();
- } else {
- nameInput.setValue(name);
- }
-
- fillInputString(nameInput, reader, getResourceBundle());
-
- return nameInput.getValue();
- }
-
- /**
- * Print validation message in cases that it's not in state "FINE"
- *
- * @param element Validated element
- */
- public static void printValidationMessage(MValidatedElement element) {
- switch (element.getValidationStatus()) {
- case UNACCEPTABLE:
- errorMessage(element.getValidationMessage());
- break;
- case ACCEPTABLE:
- warningMessage(element.getValidationMessage());
- break;
- default:
- // Simply ignore all other states for the moment
- break;
- }
- }
-
- public static void errorMessage(String message) {
- println("Error message: @|red " + message + " |@");
- }
-
- public static void warningMessage(String message) {
- println("Warning message: @|yellow " + message + " |@");
- }
-
- public static void errorIntroduction() {
- println();
- println("@|red There are issues with entered data, please revise your input:|@");
- }
-
- private FormFiller() {
- // Do not instantiate
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
deleted file mode 100644
index cbc956d..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/SubmissionDisplayer.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/**
- * 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.utils;
-
-import org.apache.sqoop.client.core.Constants;
-import org.apache.sqoop.model.MSubmission;
-import org.apache.sqoop.submission.SubmissionStatus;
-import org.apache.sqoop.submission.counter.Counter;
-import org.apache.sqoop.submission.counter.CounterGroup;
-import org.apache.sqoop.submission.counter.Counters;
-
-import java.text.SimpleDateFormat;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Class used for displaying or printing the submission details
- */
-public final class SubmissionDisplayer {
-
- private final static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
-
- /**
- * On job submission, displays the initial job info
- * @param submission
- */
- public static void displayHeader(MSubmission submission) {
- println("@|bold "+ resourceString(Constants.RES_SUBMISSION_SUBMISSION_DETAIL) +"|@");
-
- print(resourceString(Constants.RES_SUBMISSION_JOB_ID)+": ");
- println(submission.getJobId());
-
- print(resourceString(Constants.RES_SUBMISSION_SERVER_URL)+": ");
- println(getServerUrl());
-
- print(resourceString(Constants.RES_SUBMISSION_CREATION_DATE)+": ");
- println(dateFormat.format(submission.getCreationDate()));
-
- String externalId = submission.getExternalId();
- if(externalId != null) {
- print(resourceString(Constants.RES_SUBMISSION_EXTERNAL_ID)+": ");
- println(externalId);
-
- String externalLink = submission.getExternalLink();
- if(externalLink != null) {
- println("\t" + externalLink);
- }
- }
-
- if(isVerbose() && submission.getConnectorSchema() != null) {
- print(resourceString(Constants.RES_CONNECTOR_SCHEMA)+": ");
- println(submission.getConnectorSchema());
- }
-
- if(isVerbose() && submission.getHioSchema() != null) {
- print(resourceString(Constants.RES_HIO_SCHEMA)+": ");
- println(submission.getHioSchema());
- }
- }
-
- /**
- * Displays the progress of the executing job
- * @param submission
- */
- public static void displayProgress(MSubmission submission) {
- StringBuilder sb = new StringBuilder();
- if(submission.getStatus().isRunning()) {
- sb.append(dateFormat.format(submission.getLastUpdateDate())+": @|green "+submission.getStatus()+ " |@");
- double progress = submission.getProgress();
- sb.append(" - ");
- if(progress == -1) {
- sb.append(resourceString(Constants.RES_SUBMISSION_PROGRESS_NOT_AVAIL));
- } else {
- sb.append(String.format("%.2f %%", progress * 100));
- }
- } else {
- sb.append(dateFormat.format(submission.getLastUpdateDate())+": "+submission.getStatus());
- }
-
- println(sb.toString());
- }
-
- /**
- * On successfull or error, method is invoked
- * @param submission
- */
- public static void displayFooter(MSubmission submission) {
- if (submission.getStatus().toString().equals(SubmissionStatus.SUCCEEDED.toString())) {
- println(dateFormat.format(submission.getLastUpdateDate())+": @|green "+submission.getStatus()+ " |@");
- Counters counters = submission.getCounters();
- if (counters != null) {
- println(resourceString(Constants.RES_SUBMISSION_COUNTERS) + ":");
- for (CounterGroup group : counters) {
- print("\t");
- println(group.getName());
- for (Counter counter : group) {
- print("\t\t");
- print(counter.getName());
- print(": ");
- println(counter.getValue());
- }
- }
- println(resourceString(Constants.RES_SUBMISSION_EXECUTED_SUCCESS));
- }
- } else {
- if (submission.getStatus().isFailure()) {
- println(dateFormat.format(submission.getLastUpdateDate())+": @|red "+submission.getStatus()+ " |@");
- } else {
- println(dateFormat.format(submission.getLastUpdateDate())+": "+submission.getStatus());
- }
- // Exception handling
- if (submission.getExceptionInfo() != null) {
- print("@|red Exception: |@");
- println(submission.getExceptionInfo());
-
- if (isVerbose() && submission.getExceptionStackTrace() != null) {
- print("@|bold Stack trace: |@");
- println(submission.getExceptionStackTrace());
- }
- }
- }
- }
-
- public static void displaySubmission(MSubmission submission) {
- if(submission.getStatus().isFailure() || submission.getStatus().equals(SubmissionStatus.SUCCEEDED)) {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayFooter(submission);
- } else {
- SubmissionDisplayer.displayHeader(submission);
- SubmissionDisplayer.displayProgress(submission);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java
deleted file mode 100644
index 487fa50..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/TableDisplayer.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * 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.utils;
-
-import org.apache.commons.lang.StringUtils;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Display table based data
- */
-public class TableDisplayer {
-
- /**
- * Display given columns in nice table structure to given IO object.
- *
- * @param headers List of headers
- * @param columns Array of columns
- */
- public static void display(List<String> headers, List<String> ...columns) {
- assert headers != null;
- assert columns != null;
- assert headers.size() == columns.length;
-
- // Count of columns
- int columnCount = headers.size();
-
- // List of all maximal widths of each column
- List<Integer> widths = new LinkedList<Integer>();
- for(int i = 0; i < columnCount; i++) {
- widths.add(getMaximalWidth(headers.get(i), columns[i]));
- }
-
- // First line is border
- drawLine(widths);
-
- // Print out header (text is centralised)
- print("| ");
- for(int i = 0 ; i < columnCount; i++) {
- print(StringUtils.center(headers.get(i), widths.get(i), ' '));
- print((i == columnCount -1) ? " |" : " | ");
- }
- println();
-
- // End up header by border
- drawLine(widths);
-
- // Number of rows in the table
- int rows = getMaximalRows(columns);
-
- // Print out each row
- for(int row = 0 ; row < rows; row++) {
- print("| ");
- for(int i = 0 ; i < columnCount; i++) {
- print(StringUtils.rightPad(columns[i].get(row), widths.get(i), ' '));
- print((i == columnCount -1) ? " |" : " | ");
- }
- println();
- }
-
- // End table by final border
- drawLine(widths);
- }
-
- /**
- * Draw border line
- *
- * @param widths List of widths of each column
- */
- private static void drawLine(List<Integer> widths) {
- int last = widths.size() - 1;
- print("+-");
- for(int i = 0; i < widths.size(); i++) {
- print(StringUtils.repeat("-", widths.get(i)));
- print((i == last) ? "-+" : "-+-");
- }
- println();
- }
-
- /**
- * Get maximal width for given column with it's associated header.
- *
- * @param header Associated header
- * @param column All column values
- * @return Maximal
- */
- private static int getMaximalWidth(String header, List<String> column) {
- assert header != null;
- assert column != null;
-
- int max = header.length();
-
- for(String value : column) {
- if(value != null && value.length() > max) {
- max = value.length();
- }
- }
-
- return max;
- }
-
- /**
- * Get maximal number of rows available in the column list
- *
- * @param columns Array with all column values
- * @return
- */
- private static int getMaximalRows(List<String>... columns) {
- int max = 0;
-
- for(List<String> column : columns) {
- if(column.size() > max) {
- max = column.size();
- }
- }
-
- return max;
- }
-
- private TableDisplayer() {
- // Instantiation is prohibited
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java b/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java
deleted file mode 100644
index 8a34f34..0000000
--- a/client/src/main/java/org/apache/sqoop/client/utils/ThrowableDisplayer.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * 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.utils;
-
-import groovy.lang.MissingPropertyException;
-import org.apache.sqoop.client.core.ClientError;
-import org.apache.sqoop.common.SqoopException;
-
-import static org.apache.sqoop.client.shell.ShellEnvironment.*;
-
-/**
- * Pretty printing of Throwable objects
- */
-public class ThrowableDisplayer {
-
- /**
- * Error hook installed to Groovy shell.
- *
- * Will display exception that appeared during executing command. In most
- * cases we will simply delegate the call to printing throwable method,
- * however in case that we've received ClientError.CLIENT_0006 (server
- * exception), we will unwrap server issue and view only that as local
- * context shouldn't make any difference.
- *
- * @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() == ClientError.CLIENT_0006) {
- print("@|red Server has returned exception: |@");
- printThrowable(t.getCause(), isVerbose());
- } else if(t.getClass() == MissingPropertyException.class) {
- print("@|red Unknown command: |@");
- println(t.getMessage());
- } else {
- printThrowable(t, isVerbose());
- }
- }
-
- /**
- * Pretty print Throwable instance including stack trace and causes.
- *
- * @param t Throwable to display
- */
- protected static void printThrowable(Throwable t, boolean verbose) {
- print("@|red Exception: |@");
- print(t.getClass().getName());
- print(" @|red Message: |@");
- print(t.getMessage());
- println();
-
- if(verbose) {
- println("Stack trace:");
- for(StackTraceElement e : t.getStackTrace()) {
- print("\t @|bold at |@ ");
- print(e.getClassName());
- print(" (@|bold " + e.getFileName() + ":" + e.getLineNumber() + ") |@ ");
- println();
- }
-
- Throwable cause = t.getCause();
- if(cause != null) {
- print("Caused by: ");
- printThrowable(cause, verbose);
- }
- }
- }
-
- private ThrowableDisplayer() {
- // Instantiation is prohibited
- }
-}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/client/src/main/resources/client-resource.properties
----------------------------------------------------------------------
diff --git a/client/src/main/resources/client-resource.properties b/client/src/main/resources/client-resource.properties
deleted file mode 100644
index 1a8f963..0000000
--- a/client/src/main/resources/client-resource.properties
+++ /dev/null
@@ -1,232 +0,0 @@
-# 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.
-
-# Client Resources in default language (english)
-
-############################
-# Security Form
-#
-object-name.label = Name
-object-name.help = Non unique name of the entity to help you remember \
- it's purpose
-
-
-#############################
-# Messages
-#
-# Argument related
-#
-args.function.unknown = The specified function "{0}" is not recognized.
-args.xid_missing = Required argument --xid is missing.
-args.jid_missing = Required argument --jid is missing.
-args.cid_missing = Required argument --cid is missing.
-args.type_missing = Required argument --type is missing.
-args.name_missing = Required argument --name is missing.
-args.value_missing = Required argument --value is missing.
-
-
-## Generic description of various ids, types etc
-prompt.conn_id = Connection ID
-prompt.connector_id = Connector ID
-prompt.job_id = Job ID
-prompt.job_type = Job type
-
-## Prompt messages for updating, filling metadata info
-
-prompt.update_conn_metadata = Please update connection metadata:
-prompt.update_job_metadata = Please update job metadata:
-prompt.fill_conn_metadata = Please fill following values to create new \
-connection object
-prompt.fill_job_metadata = Please fill following values to create new \
-job object
-
-#
-# Update command
-update.conn = Updating connection with id {0}
-update.job = Updating job with id {0}
-update.usage = Usage: update {0}
-update.conn_successful = Connection was successfully updated with status {0}
-update.job_successful = Job was successfully updated with status {0}
-
-#
-# Clone command
-clone.usage = Usage: clone {0}
-clone.conn.successful = Connection was successfully created with validation \
- status {0} and persistent id {1}
-clone.job.successful = Job was successfully created with validation \
- status {0} and persistent id {1}
-clone.cloning_conn = Cloning connection with id {0}
-clone.cloning_job = Cloning job with id {0}
-
-#
-# Create command
-create.usage = Usage: create {0}
-create.conn_successful = New connection was successfully created with \
- validation status {0} and persistent id {1}
-create.job_successful = New job was successfully created with validation \
- status {0} and persistent id {1}
-## Creating messages
-create.creating_conn = Creating connection for connector with id {0}
-create.creating_job = Creating job for connection with id {0}
-
-#
-# Delete command
-delete.usage = Usage: delete {0}
-
-#
-# Enable command
-enable.usage = Usage: enable {0}
-enable.conn_successful = Connection {0} was successfully enabled
-enable.job_successful = Job {0} was successfully enabled
-
-#
-# Disable command
-disable.usage = Usage: disable {0}
-disable.conn_successful = Connection {0} was successfully disabled
-disable.job_successful = Job {0} was successfully disabled
-
-#
-# Help command
-help.usage = [<command>]
-help.description = Display this help message
-help.cmd_usage = Usage: @|bold {0} |@ {1}
-help.message = Display the list of commands or the help text for \
- @|bold command|@.
-help.info = For information about @|green Sqoop|@, visit: \
- @|cyan http://sqoop.apache.org/|@
-help.avail_commands = Available commands:
-help.cmd_description = @|bold {0} ({1}|@) {2}
-help.specific_cmd_info = For help on a specific command type: \
- help @|bold command|@
-
-unrecognized.cmd = Unrecognized command {0}
-
-#
-# Set command
-set.usage = Usage: set {0}
-set.prompt_opt_name = Client option name
-set.prompt_opt_value = New option value
-set.verbose_changed = Verbose option was changed to {0}
-set.poll_timeout_changed = Poll timeout option has been changed to {0}
-set.unknown_opt_ignored = Unknown option {0}. Ignoring...
-set.host_description = Host name to invoke server resources
-set.port_description = Port number to invoke server resources
-set.webapp_description = Web app to invoke server resources
-set.url_description = Url to invoke server resources
-set.server_usage = Usage: set server
-set.server_successful = Server is set successfully
-set.server_ignored = --host, --port or --webapp option is ignored, because --url option is given.
-
-
-show.usage = Usage: show {0}
-
-show.prompt_display_all_conns = Display all connections
-show.prompt_display_conn_xid = Display the connection with xid
-show.conn_usage = Usage: show connection
-show.prompt_conns_to_show = @|bold {0} connection(s) to show: |@
-show.prompt_conn_info = Connection with id {0} and name {1} (Enabled: {2}, Created {3}, Updated {4})
-show.prompt_conn_cid_info = Using Connector id {0}
-
-show.prompt_display_all_connectors = Display all connectors
-show.prompt_display_connector_cid = Display the connector with cid
-show.connector_usage = Usage: show connector
-show.prompt_connectors_to_show = @|bold {0} connector(s) to show: |@
-show.prompt_connector_info = Connector with id {0}:\n Name: {1} \n \
-Class: {2}\n Version: {3}
-
-show.framework_usage = Usage: show framework
-show.prompt_framework_opts = @|bold Framework specific options: |@\nPersistent id: {0}
-
-show.prompt_display_all_jobs = Display all jobs
-show.prompt_display_job_jid = Display jobwith given jid
-show.job_usage = Usage: show job
-show.prompt_jobs_to_show = @|bold {0} job(s) to show: |@
-show.prompt_job_info = Job with id {0} and name {1} (Enabled: {2}, Created {3}, Updated {4})
-show.prompt_job_xid_cid_info = Using Connection id {0} and Connector id {1}
-
-show.prompt_display_all_submissions = Display all submissions
-show.prompt_display_all_submissions_jid = Display all submissions given jid
-
-show.prompt_display_all_servers = Display all server information
-show.prompt_display_server_host = Display server host name
-show.prompt_display_server_port = Display server port number
-show.prompt_display_server_webapp = Display server web app name
-show.server_usage = Usage: show server
-show.prompt_server_host = @|bold Server host:|@ {0}
-show.prompt_server_port = @|bold Server port:|@ {0}
-show.prompt_server_webapp = @|bold Server webapp:|@ {0}
-
-show.prompt_display_all_versions = Display all versions
-show.prompt_display_version_server = Display server version
-show.prompt_display_version_client = Display client version
-show.prompt_display_version_protocol = Display protocol version
-show.version_usage = Usage: show version
-show.prompt_version_client_server = @|bold {0} version:|@\n Sqoop {1} \
-revision {2} \n Compiled by {3} on {4}
-show.prompt_version_protocol = @|bold Protocol version:|@\n {0}
-
-sqoop.shell_banner = @|green Sqoop Shell:|@ Type '@|bold help|@' or '@|bold \\h|@' for help.
-sqoop.prompt_shell_loadrc = Loading resource file {0}
-sqoop.prompt_shell_loadedrc = Resource file loaded.
-
-start.usage = Usage: start {0}
-start.prompt_synchronous = Wait for submission to finish
-
-stop.usage = Usage: stop {0}
-
-status.usage = Usage: status {0}
-
-# Various Table headers
-table.header.id = Id
-table.header.name = Name
-table.header.version = Version
-table.header.class = Class
-table.header.type = Type
-table.header.connector = Connector
-table.header.jid = Job Id
-table.header.eid = External Id
-table.header.status = Status
-table.header.date = Last Update Date
-table.header.enabled = Enabled
-
-#Form displayer resources
-formdisplayer.supported_job_types = Supported job types
-formdisplayer.connection = Connection
-formdisplayer.job = Job
-formdisplayer.forms_jobtype = Forms for job type
-formdisplayer.form = form
-formdisplayer.name = Name
-formdisplayer.label = Label
-formdisplayer.help = Help
-formdisplayer.input = Input
-formdisplayer.type = Type
-formdisplayer.sensitive = Sensitive
-formdisplayer.size = Size
-formdisplayer.possible_values = Possible values
-formdisplayer.unsupported_datatype = Unsupported data type
-formdisplayer.input_sensitive = This input is sensitive
-
-formdisplayer.warning_message = There were warnings while create or update, but saved successfully.
-
-submission.submission_detail = Submission details
-submission.job_id = Job ID
-submission.creation_date = Creation date
-submission.external_id = External ID
-submission.progress_not_available = Progress is not available
-submission.counters = Counters
-submission.executed_success = Job executed successfully
-submission.server_url = Server URL
-submission.connector_schema = Connector schema
-submission.hio_schema = Input/Output schema
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/dist/pom.xml
----------------------------------------------------------------------
diff --git a/dist/pom.xml b/dist/pom.xml
index dd67f85..9186a38 100644
--- a/dist/pom.xml
+++ b/dist/pom.xml
@@ -40,7 +40,7 @@ limitations under the License.
</dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
- <artifactId>sqoop-client</artifactId>
+ <artifactId>sqoop-shell</artifactId>
</dependency>
</dependencies>
@@ -167,16 +167,16 @@ limitations under the License.
<copy file="../server/target/sqoop.war"
toDir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/server/webapps"/>
- <!-- Build client directory -->
- <copy todir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/client/lib">
- <fileset dir="../client/target/lib">
+ <!-- Build shell client directory -->
+ <copy todir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/shell/lib">
+ <fileset dir="../shell/target/lib">
<include name="*.jar" />
<exclude name="junit-*.jar" />
<exclude name="mockito-*.jar" />
</fileset>
</copy>
- <copy file="../client/target/sqoop-client-${project.version}.jar"
- toDir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/client/lib"/>
+ <copy file="../shell/target/sqoop-shell-${project.version}.jar"
+ toDir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/shell/lib"/>
<!-- Build "bin" directory -->
<copy todir="target/sqoop-${project.version}-bin-hadoop${hadoop.profile}/bin">
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/dist/src/main/bin/sqoop.sh
----------------------------------------------------------------------
diff --git a/dist/src/main/bin/sqoop.sh b/dist/src/main/bin/sqoop.sh
index 88adb04..e3ed5ef 100755
--- a/dist/src/main/bin/sqoop.sh
+++ b/dist/src/main/bin/sqoop.sh
@@ -51,7 +51,7 @@ cd ${BASEDIR}
echo "Sqoop home directory: ${BASEDIR}"
CATALINA_BIN=${CATALINA_BIN:-server/bin}
-CLIENT_LIB=${CLIENT_LIB:-client/lib}
+CLIENT_LIB=${CLIENT_LIB:-shell/lib}
setup_catalina_opts() {
# The Java System properties 'sqoop.http.port' and 'sqoop.admin.port' are
@@ -107,7 +107,7 @@ case $COMMAND in
if [ -n "${JAVA_HOME}" ] ; then
EXEC_JAVA="${JAVA_HOME}/bin/java"
fi
- ${EXEC_JAVA} -classpath ${CLASSPATH} org.apache.sqoop.client.shell.SqoopShell $2
+ ${EXEC_JAVA} -classpath ${CLASSPATH} org.apache.sqoop.shell.SqoopShell $2
;;
*)
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5ea0633..513b6d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -247,6 +247,11 @@ limitations under the License.
<artifactId>sqoop-client</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-shell</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.sqoop</groupId>
<artifactId>sqoop-common</artifactId>
@@ -413,6 +418,7 @@ limitations under the License.
<module>repository</module>
<module>server</module>
<module>client</module>
+ <module>shell</module>
<module>docs</module>
<module>connector</module>
<module>execution</module>
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/pom.xml
----------------------------------------------------------------------
diff --git a/shell/pom.xml b/shell/pom.xml
new file mode 100644
index 0000000..947eab0
--- /dev/null
+++ b/shell/pom.xml
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>sqoop</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-shell</artifactId>
+ <name>Sqoop Shell</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <dependency>
+ <groupId>jline</groupId>
+ <artifactId>jline</artifactId>
+ <version>0.9.94</version>
+ </dependency>
+ <dependency>
+ <groupId>org.fusesource.jansi</groupId>
+ <artifactId>jansi</artifactId>
+ <version>1.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.8.5</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>dist</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java b/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java
new file mode 100644
index 0000000..980a908
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CloneCommand.java
@@ -0,0 +1,69 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ * Client side cloning of connection and job objects.
+ */
+public class CloneCommand extends SqoopCommand {
+
+ private CloneConnectionFunction connectionFunction;
+ private CloneJobFunction jobFunction;
+
+ public CloneCommand(Shell shell) {
+ super(shell, Constants.CMD_CLONE, Constants.CMD_CLONE_SC,
+ new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
+ Constants.PRE_CLONE, Constants.SUF_INFO);
+ }
+
+ public Object executeCommand(List args) {
+ if(!isInteractive()) {
+ throw new SqoopException(ShellError.SHELL_0007, "clone");
+ }
+
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_CLONE_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String)args.get(0);
+ if (func.equals(Constants.FN_CONNECTION)) {
+ if (connectionFunction == null) {
+ connectionFunction = new CloneConnectionFunction();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new CloneJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java
new file mode 100644
index 0000000..856abaa
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CloneConnectionFunction.java
@@ -0,0 +1,96 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.model.MPersistableEntity;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class CloneConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CloneConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create(Constants.OPT_XID_CHAR)
+ );
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+
+ try {
+ cloneConnection(getLong(line, Constants.OPT_XID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void cloneConnection(Long connectionId) throws IOException {
+ printlnResource(Constants.RES_CLONE_CLONING_CONN, connectionId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ MConnection connection = client.getConnection(connectionId);
+ // Remove persistent id as we're making a clone
+ connection.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
+
+ Status status = Status.FINE;
+ printlnResource(Constants.RES_PROMPT_UPDATE_CONN_METADATA);
+
+ ResourceBundle connectorBundle = client.getResourceBundle(connection.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ status = client.createConnection(connection);
+
+ } while(!status.canProceed());
+
+ printlnResource(Constants.RES_CLONE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java
new file mode 100644
index 0000000..3e23025
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CloneJobFunction.java
@@ -0,0 +1,99 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.model.MPersistableEntity;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class CloneJobFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CloneJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_ID))
+ .withLongOpt(Constants.OPT_JID)
+ .hasArg()
+ .create(Constants.OPT_JID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_JID)) {
+ printlnResource(Constants.RES_ARGS_JID_MISSING);
+ return null;
+ }
+
+ try {
+ cloneJob(getLong(line, Constants.OPT_JID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void cloneJob(Long jobId) throws IOException {
+ printlnResource(Constants.RES_CLONE_CLONING_JOB, jobId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ MJob job = client.getJob(jobId);
+ job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
+
+ ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+
+ Status status = Status.FINE;
+
+ // Remove persistent id as we're making a clone
+ job.setPersistenceId(MPersistableEntity.PERSISTANCE_ID_DEFAULT);
+
+ printlnResource(Constants.RES_PROMPT_UPDATE_JOB_METADATA);
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.createJob(job);
+ } while(!status.canProceed());
+
+ printlnResource(Constants.RES_CLONE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
new file mode 100644
index 0000000..e62ce08
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateCommand.java
@@ -0,0 +1,69 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class CreateCommand extends SqoopCommand {
+
+ private CreateConnectionFunction connectionFunction;
+ private CreateJobFunction jobFunction;
+
+ public CreateCommand(Shell shell) {
+ super(shell, Constants.CMD_CREATE, Constants.CMD_CREATE_SC,
+ new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
+ Constants.PRE_CREATE, Constants.SUF_INFO);
+ }
+
+ public Object executeCommand(List args) {
+ if(!isInteractive()) {
+ throw new SqoopException(ShellError.SHELL_0007, "create");
+ }
+
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_CREATE_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String)args.get(0);
+ if (func.equals(Constants.FN_CONNECTION)) {
+ if (connectionFunction == null) {
+ connectionFunction = new CreateConnectionFunction();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new CreateJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java
new file mode 100644
index 0000000..5fbf0a3
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateConnectionFunction.java
@@ -0,0 +1,93 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MConnection;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.FormDisplayer;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ *
+ */
+public class CreateConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CreateConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_CONNECTOR_ID))
+ .withLongOpt(Constants.OPT_CID)
+ .hasArg()
+ .create(Constants.OPT_CID_CHAR));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_CID)) {
+ printlnResource(Constants.RES_ARGS_CID_MISSING);
+ return null;
+ }
+
+ try {
+ createConnection(getLong(line, Constants.OPT_CID));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void createConnection(long connectorId) throws IOException {
+ printlnResource(Constants.RES_CREATE_CREATING_CONN, connectorId);
+
+ ConsoleReader reader = new ConsoleReader();
+
+ MConnection connection = client.newConnection(connectorId);
+
+ ResourceBundle connectorBundle = client.getResourceBundle(connectorId);
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+
+ Status status = Status.FINE;
+ printlnResource(Constants.RES_PROMPT_FILL_CONN_METADATA);
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillConnection(reader, connection, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.createConnection(connection);
+ } while(!status.canProceed());
+ FormDisplayer.displayFormWarning(connection);
+ printlnResource(Constants.RES_CREATE_CONN_SUCCESSFUL, status.name(), connection.getPersistenceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java b/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java
new file mode 100644
index 0000000..6e4f04b
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/CreateJobFunction.java
@@ -0,0 +1,106 @@
+/**
+ * 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.shell;
+
+import jline.ConsoleReader;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.model.MJob;
+import org.apache.sqoop.shell.core.ShellError;
+import org.apache.sqoop.shell.core.Constants;
+import org.apache.sqoop.shell.utils.FormDisplayer;
+import org.apache.sqoop.validation.Status;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+import static org.apache.sqoop.shell.utils.FormFiller.*;
+
+/**
+ * Handles creation of new job objects.
+ */
+public class CreateJobFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public CreateJobFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create(Constants.OPT_XID_CHAR)
+ );
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_JOB_TYPE))
+ .withLongOpt(Constants.OPT_TYPE)
+ .hasArg()
+ .create(Constants.OPT_TYPE_CHAR)
+ );
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+ if (!line.hasOption(Constants.OPT_TYPE)) {
+ printlnResource(Constants.RES_ARGS_TYPE_MISSING);
+ return null;
+ }
+
+ try {
+ createJob(getLong(line, Constants.OPT_XID),
+ line.getOptionValue(Constants.OPT_TYPE));
+ } catch (IOException ex) {
+ throw new SqoopException(ShellError.SHELL_0005, ex);
+ }
+
+ return null;
+ }
+
+ private void createJob(Long connectionId, String type) throws IOException {
+ printlnResource(Constants.RES_CREATE_CREATING_JOB, connectionId);
+
+ ConsoleReader reader = new ConsoleReader();
+ MJob job = client.newJob(connectionId, MJob.Type.valueOf(type.toUpperCase()));
+
+ ResourceBundle connectorBundle = client.getResourceBundle(job.getConnectorId());
+ ResourceBundle frameworkBundle = client.getFrameworkResourceBundle();
+
+ Status status = Status.FINE;
+
+ printlnResource(Constants.RES_PROMPT_FILL_JOB_METADATA);
+
+ do {
+ // Print error introduction if needed
+ if( !status.canProceed() ) {
+ errorIntroduction();
+ }
+
+ // Fill in data from user
+ if(!fillJob(reader, job, connectorBundle, frameworkBundle)) {
+ return;
+ }
+
+ // Try to create
+ status = client.createJob(job);
+ } while(!status.canProceed());
+ FormDisplayer.displayFormWarning(job);
+ printlnResource(Constants.RES_CREATE_JOB_SUCCESSFUL, status.name(), job.getPersistenceId());
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
new file mode 100644
index 0000000..abfcf2e
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DeleteCommand.java
@@ -0,0 +1,64 @@
+/**
+ * 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.shell;
+
+import org.apache.sqoop.shell.core.Constants;
+import org.codehaus.groovy.tools.shell.Shell;
+import java.util.List;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class DeleteCommand extends SqoopCommand {
+
+ private DeleteConnectionFunction connectionFunction;
+ private DeleteJobFunction jobFunction;
+
+ public DeleteCommand(Shell shell) {
+ super(shell, Constants.CMD_DELETE, Constants.CMD_DELETE_SC,
+ new String[] {Constants.FN_CONNECTION, Constants.FN_JOB},
+ Constants.PRE_DELETE, Constants.SUF_INFO);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public Object executeCommand(List args) {
+ if (args.size() == 0) {
+ printlnResource(Constants.RES_DELETE_USAGE, getUsage());
+ return null;
+ }
+
+ String func = (String)args.get(0);
+ if (func.equals(Constants.FN_CONNECTION)) {
+ if (connectionFunction == null) {
+ connectionFunction = new DeleteConnectionFunction();
+ }
+ return connectionFunction.execute(args);
+ } else if (func.equals(Constants.FN_JOB)) {
+ if (jobFunction == null) {
+ jobFunction = new DeleteJobFunction();
+ }
+ return jobFunction.execute(args);
+ } else {
+ printlnResource(Constants.RES_FUNCTION_UNKNOWN, func);
+ return null;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/sqoop/blob/21c1207b/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.java b/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.java
new file mode 100644
index 0000000..c123732
--- /dev/null
+++ b/shell/src/main/java/org/apache/sqoop/shell/DeleteConnectionFunction.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.sqoop.shell;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.shell.core.Constants;
+
+import static org.apache.sqoop.shell.ShellEnvironment.*;
+
+/**
+ *
+ */
+public class DeleteConnectionFunction extends SqoopFunction {
+ @SuppressWarnings("static-access")
+ public DeleteConnectionFunction() {
+ this.addOption(OptionBuilder
+ .withDescription(resourceString(Constants.RES_PROMPT_CONN_ID))
+ .withLongOpt(Constants.OPT_XID)
+ .hasArg()
+ .create('x'));
+ }
+
+ public Object executeFunction(CommandLine line) {
+ if (!line.hasOption(Constants.OPT_XID)) {
+ printlnResource(Constants.RES_ARGS_XID_MISSING);
+ return null;
+ }
+
+ client.deleteConnection(getLong(line, Constants.OPT_XID));
+
+ return null;
+ }
+
+}