mirror of
https://github.com/apache/sqoop.git
synced 2025-05-11 14:30:59 +08:00
SQOOP-643: Implement simple listings for connector and job objects rek
(Jarcec Cecho via Cheolsoo Park)
This commit is contained in:
parent
5be8eb6808
commit
03408d573e
@ -300,6 +300,20 @@ public class Constants {
|
|||||||
"update.job";
|
"update.job";
|
||||||
public static final String RES_UPDATE_JOB_SUCCESSFUL =
|
public static final String RES_UPDATE_JOB_SUCCESSFUL =
|
||||||
"update.job_successful";
|
"update.job_successful";
|
||||||
|
|
||||||
|
public static final String RES_TABLE_HEADER_ID =
|
||||||
|
"table.header.id";
|
||||||
|
public static final String RES_TABLE_HEADER_NAME =
|
||||||
|
"table.header.name";
|
||||||
|
public static final String RES_TABLE_HEADER_VERSION =
|
||||||
|
"table.header.version";
|
||||||
|
public static final String RES_TABLE_HEADER_CLASS =
|
||||||
|
"table.header.class";
|
||||||
|
public static final String RES_TABLE_HEADER_TYPE =
|
||||||
|
"table.header.type";
|
||||||
|
public static final String RES_TABLE_HEADER_CONNECTOR =
|
||||||
|
"table.header.connector";
|
||||||
|
|
||||||
private Constants() {
|
private Constants() {
|
||||||
// Instantiation is prohibited
|
// Instantiation is prohibited
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.OptionBuilder;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.sqoop.client.core.Constants;
|
import org.apache.sqoop.client.core.Constants;
|
||||||
|
import org.apache.sqoop.client.utils.TableDisplayer;
|
||||||
import org.apache.sqoop.json.ConnectionBean;
|
import org.apache.sqoop.json.ConnectionBean;
|
||||||
import org.apache.sqoop.model.MConnection;
|
import org.apache.sqoop.model.MConnection;
|
||||||
import org.codehaus.groovy.tools.shell.IO;
|
import org.codehaus.groovy.tools.shell.IO;
|
||||||
@ -27,6 +28,7 @@
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.apache.sqoop.client.utils.FormDisplayer.*;
|
import static org.apache.sqoop.client.utils.FormDisplayer.*;
|
||||||
@ -63,23 +65,40 @@ public void printHelp(PrintWriter out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object execute(List<String> args) {
|
public Object execute(List<String> args) {
|
||||||
if (args.size() == 1) {
|
|
||||||
printHelp(io.out);
|
|
||||||
io.out.println();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandLine line = parseOptions(this, 1, args);
|
CommandLine line = parseOptions(this, 1, args);
|
||||||
if (line.hasOption(Constants.OPT_ALL)) {
|
if (line.hasOption(Constants.OPT_ALL)) {
|
||||||
showConnection(null);
|
showConnection(null);
|
||||||
|
|
||||||
} else if (line.hasOption(Constants.OPT_XID)) {
|
} else if (line.hasOption(Constants.OPT_XID)) {
|
||||||
showConnection(line.getOptionValue(Constants.OPT_XID));
|
showConnection(line.getOptionValue(Constants.OPT_XID));
|
||||||
|
} else {
|
||||||
|
showSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSummary() {
|
||||||
|
ConnectionBean connectionBean = readConnection(null);
|
||||||
|
List<MConnection> connections = connectionBean.getConnections();
|
||||||
|
|
||||||
|
List<String> header = new LinkedList<String>();
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_ID));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_NAME));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_CONNECTOR));
|
||||||
|
|
||||||
|
List<String> ids = new LinkedList<String>();
|
||||||
|
List<String> names = new LinkedList<String>();
|
||||||
|
List<String> connectors = new LinkedList<String>();
|
||||||
|
|
||||||
|
for(MConnection connection : connections) {
|
||||||
|
ids.add(String.valueOf(connection.getPersistenceId()));
|
||||||
|
names.add(connection.getName());
|
||||||
|
connectors.add(String.valueOf(connection.getConnectorId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TableDisplayer.display(io, header, ids, names, connectors);
|
||||||
|
}
|
||||||
|
|
||||||
private void showConnection(String xid) {
|
private void showConnection(String xid) {
|
||||||
ConnectionBean connectionBean = readConnection(xid);
|
ConnectionBean connectionBean = readConnection(xid);
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@ -27,6 +28,7 @@
|
|||||||
import org.apache.commons.cli.OptionBuilder;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
import org.apache.sqoop.client.core.Constants;
|
import org.apache.sqoop.client.core.Constants;
|
||||||
|
import org.apache.sqoop.client.utils.TableDisplayer;
|
||||||
import org.apache.sqoop.json.ConnectorBean;
|
import org.apache.sqoop.json.ConnectorBean;
|
||||||
import org.apache.sqoop.model.MConnector;
|
import org.apache.sqoop.model.MConnector;
|
||||||
import org.codehaus.groovy.tools.shell.IO;
|
import org.codehaus.groovy.tools.shell.IO;
|
||||||
@ -63,23 +65,43 @@ public void printHelp(PrintWriter out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object execute(List<String> args) {
|
public Object execute(List<String> args) {
|
||||||
if (args.size() == 1) {
|
|
||||||
printHelp(io.out);
|
|
||||||
io.out.println();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandLine line = parseOptions(this, 1, args);
|
CommandLine line = parseOptions(this, 1, args);
|
||||||
if (line.hasOption(Constants.OPT_ALL)) {
|
if (line.hasOption(Constants.OPT_ALL)) {
|
||||||
showConnector(null);
|
showConnector(null);
|
||||||
|
|
||||||
} else if (line.hasOption(Constants.OPT_CID)) {
|
} else if (line.hasOption(Constants.OPT_CID)) {
|
||||||
showConnector(line.getOptionValue(Constants.OPT_CID));
|
showConnector(line.getOptionValue(Constants.OPT_CID));
|
||||||
|
} else {
|
||||||
|
showSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSummary() {
|
||||||
|
ConnectorBean connectorBean = readConnector(null);
|
||||||
|
List<MConnector> connectors = connectorBean.getConnectors();
|
||||||
|
|
||||||
|
List<String> header = new LinkedList<String>();
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_ID));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_NAME));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_VERSION));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_CLASS));
|
||||||
|
|
||||||
|
List<String> ids = new LinkedList<String>();
|
||||||
|
List<String> uniqueNames = new LinkedList<String>();
|
||||||
|
List<String> versions = new LinkedList<String>();
|
||||||
|
List<String> classes = new LinkedList<String>();
|
||||||
|
|
||||||
|
for(MConnector connector : connectors) {
|
||||||
|
ids.add(String.valueOf(connector.getPersistenceId()));
|
||||||
|
uniqueNames.add(connector.getUniqueName());
|
||||||
|
versions.add(connector.getVersion());
|
||||||
|
classes.add(connector.getClassName());
|
||||||
|
}
|
||||||
|
|
||||||
|
TableDisplayer.display(io, header, ids, uniqueNames, versions, classes);
|
||||||
|
}
|
||||||
|
|
||||||
private void showConnector(String cid) {
|
private void showConnector(String cid) {
|
||||||
ConnectorBean connectorBean = readConnector(cid);
|
ConnectorBean connectorBean = readConnector(cid);
|
||||||
List<MConnector> connectors = connectorBean.getConnectors();
|
List<MConnector> connectors = connectorBean.getConnectors();
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.OptionBuilder;
|
import org.apache.commons.cli.OptionBuilder;
|
||||||
import org.apache.sqoop.client.core.Constants;
|
import org.apache.sqoop.client.core.Constants;
|
||||||
|
import org.apache.sqoop.client.utils.TableDisplayer;
|
||||||
import org.apache.sqoop.json.JobBean;
|
import org.apache.sqoop.json.JobBean;
|
||||||
import org.apache.sqoop.model.MJob;
|
import org.apache.sqoop.model.MJob;
|
||||||
import org.codehaus.groovy.tools.shell.IO;
|
import org.codehaus.groovy.tools.shell.IO;
|
||||||
@ -27,6 +28,7 @@
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.apache.sqoop.client.utils.FormDisplayer.*;
|
import static org.apache.sqoop.client.utils.FormDisplayer.*;
|
||||||
@ -61,23 +63,43 @@ public void printHelp(PrintWriter out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Object execute(List<String> args) {
|
public Object execute(List<String> args) {
|
||||||
if (args.size() == 1) {
|
|
||||||
printHelp(io.out);
|
|
||||||
io.out.println();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
CommandLine line = parseOptions(this, 1, args);
|
CommandLine line = parseOptions(this, 1, args);
|
||||||
if (line.hasOption(Constants.OPT_ALL)) {
|
if (line.hasOption(Constants.OPT_ALL)) {
|
||||||
showJob(null);
|
showJob(null);
|
||||||
|
|
||||||
} else if (line.hasOption(Constants.OPT_JID)) {
|
} else if (line.hasOption(Constants.OPT_JID)) {
|
||||||
showJob(line.getOptionValue(Constants.OPT_JID));
|
showJob(line.getOptionValue(Constants.OPT_JID));
|
||||||
|
} else {
|
||||||
|
showSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSummary() {
|
||||||
|
JobBean jobBean = readJob(null);
|
||||||
|
List<MJob> jobs = jobBean.getJobs();
|
||||||
|
|
||||||
|
List<String> header = new LinkedList<String>();
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_ID));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_NAME));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_TYPE));
|
||||||
|
header.add(getResource().getString(Constants.RES_TABLE_HEADER_CONNECTOR));
|
||||||
|
|
||||||
|
List<String> ids = new LinkedList<String>();
|
||||||
|
List<String> names = new LinkedList<String>();
|
||||||
|
List<String> types = new LinkedList<String>();
|
||||||
|
List<String> connectors = new LinkedList<String>();
|
||||||
|
|
||||||
|
for(MJob job : jobs) {
|
||||||
|
ids.add(String.valueOf(job.getPersistenceId()));
|
||||||
|
names.add(job.getName());
|
||||||
|
types.add(job.getType().toString());
|
||||||
|
connectors.add(String.valueOf(job.getConnectorId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TableDisplayer.display(io, header, ids, names, types, connectors);
|
||||||
|
}
|
||||||
|
|
||||||
private void showJob(String jid) {
|
private void showJob(String jid) {
|
||||||
JobBean jobBean = readJob(jid);
|
JobBean jobBean = readJob(jid);
|
||||||
|
|
||||||
|
@ -0,0 +1,141 @@
|
|||||||
|
/**
|
||||||
|
* 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.codehaus.groovy.tools.shell.IO;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display table based data
|
||||||
|
*/
|
||||||
|
public class TableDisplayer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display given columns in nice table structure to given IO object.
|
||||||
|
*
|
||||||
|
* @param io Shell's IO object
|
||||||
|
* @param headers List of headers
|
||||||
|
* @param columns Array of columns
|
||||||
|
*/
|
||||||
|
public static void display(IO io, List<String> headers, List<String> ...columns) {
|
||||||
|
|
||||||
|
assert io != null;
|
||||||
|
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(io, widths);
|
||||||
|
|
||||||
|
// Print out header (text is centralised)
|
||||||
|
io.out.print("| ");
|
||||||
|
for(int i = 0 ; i < columnCount; i++) {
|
||||||
|
io.out.print(StringUtils.center(headers.get(i), widths.get(i), ' '));
|
||||||
|
io.out.print((i == columnCount -1) ? " |" : " | ");
|
||||||
|
}
|
||||||
|
io.out.println();
|
||||||
|
|
||||||
|
// End up header by border
|
||||||
|
drawLine(io, widths);
|
||||||
|
|
||||||
|
// Number of rows in the table
|
||||||
|
int rows = getMaximalRows(columns);
|
||||||
|
|
||||||
|
// Print out each row
|
||||||
|
for(int row = 0 ; row < rows; row++) {
|
||||||
|
io.out.print("| ");
|
||||||
|
for(int i = 0 ; i < columnCount; i++) {
|
||||||
|
io.out.print(StringUtils.rightPad(columns[i].get(row), widths.get(i), ' '));
|
||||||
|
io.out.print((i == columnCount -1) ? " |" : " | ");
|
||||||
|
}
|
||||||
|
io.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
// End table by final border
|
||||||
|
drawLine(io, widths);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw border line
|
||||||
|
*
|
||||||
|
* @param io Shell's associated IO object
|
||||||
|
* @param widths List of widths of each column
|
||||||
|
*/
|
||||||
|
private static void drawLine(IO io, List<Integer> widths) {
|
||||||
|
int last = widths.size() - 1;
|
||||||
|
io.out.print("+-");
|
||||||
|
for(int i = 0; i < widths.size(); i++) {
|
||||||
|
io.out.print(StringUtils.repeat("-", widths.get(i)));
|
||||||
|
io.out.print((i == last) ? "-+" : "-+-");
|
||||||
|
}
|
||||||
|
io.out.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) {
|
||||||
|
int max = header.length();
|
||||||
|
|
||||||
|
for(String value : column) {
|
||||||
|
if(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
|
||||||
|
}
|
||||||
|
}
|
@ -161,3 +161,11 @@ sqoop.prompt_shell_loadrc = Loading resource file {0}
|
|||||||
sqoop.prompt_shell_loadedrc = Resource file loaded.
|
sqoop.prompt_shell_loadedrc = Resource file loaded.
|
||||||
|
|
||||||
submission.usage = Usage: submission {0}
|
submission.usage = Usage: submission {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
|
||||||
|
Loading…
Reference in New Issue
Block a user