sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject sqoop git commit: SQOOP-2117: Sqoop2: Shell command 'show link' should show connector name
Date Thu, 19 Feb 2015 10:16:21 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 3f1420f71 -> 263e36204


SQOOP-2117: Sqoop2: Shell command 'show link' should show connector name

(Szehon Ho via Abraham Elmahrek)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/263e3620
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/263e3620
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/263e3620

Branch: refs/heads/sqoop2
Commit: 263e362045ef0062d03d74ef64f34763fc50c420
Parents: 3f1420f
Author: Abraham Elmahrek <abe@apache.org>
Authored: Thu Feb 19 02:11:50 2015 -0800
Committer: Abraham Elmahrek <abe@apache.org>
Committed: Thu Feb 19 02:11:50 2015 -0800

----------------------------------------------------------------------
 .../apache/sqoop/shell/ShowLinkFunction.java    | 47 +++++++++++++++++---
 .../org/apache/sqoop/shell/core/Constants.java  |  6 ++-
 .../main/resources/shell-resource.properties    |  5 ++-
 3 files changed, 47 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/263e3620/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java b/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java
index e92f0b4..1a5f354 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/ShowLinkFunction.java
@@ -19,14 +19,18 @@ package org.apache.sqoop.shell;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.OptionBuilder;
+import org.apache.sqoop.model.MConnector;
 import org.apache.sqoop.model.MLink;
 import org.apache.sqoop.shell.core.Constants;
 import org.apache.sqoop.shell.utils.TableDisplayer;
 import org.apache.sqoop.validation.Status;
 
 import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 import static org.apache.sqoop.shell.ShellEnvironment.*;
 import static org.apache.sqoop.shell.utils.ConfigDisplayer.*;
@@ -67,22 +71,25 @@ public class ShowLinkFunction extends SqoopFunction {
     List<String> header = new LinkedList<String>();
     header.add(resourceString(Constants.RES_TABLE_HEADER_ID));
     header.add(resourceString(Constants.RES_TABLE_HEADER_NAME));
-    header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR));
+    header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR_ID));
+    header.add(resourceString(Constants.RES_TABLE_HEADER_CONNECTOR_NAME));
     header.add(resourceString(Constants.RES_TABLE_HEADER_ENABLED));
 
     List<String> ids = new LinkedList<String>();
     List<String> names = new LinkedList<String>();
-    List<String> connectors = new LinkedList<String>();
+    List<String> connectorIds = new LinkedList<String>();
     List<String> availabilities = new LinkedList<String>();
 
-    for(MLink link : links) {
+    for (MLink link : links) {
       ids.add(String.valueOf(link.getPersistenceId()));
       names.add(link.getName());
-      connectors.add(String.valueOf(link.getConnectorId()));
+      connectorIds.add(String.valueOf(link.getConnectorId()));
       availabilities.add(String.valueOf(link.getEnabled()));
     }
 
-    TableDisplayer.display(header, ids, names, connectors, availabilities);
+    List<String> connectorNames = getConnectorNames(connectorIds);
+
+    TableDisplayer.display(header, ids, names, connectorIds, connectorNames, availabilities);
   }
 
   private void showLinks() {
@@ -117,10 +124,36 @@ public class ShowLinkFunction extends SqoopFunction {
     );
 
     long connectorId = link.getConnectorId();
-    printlnResource(Constants.RES_SHOW_PROMPT_LINK_CID_INFO, connectorId);
+    MConnector connector = client.getConnector(connectorId);
+    String connectorName = "";
+    if (connector != null) {
+      connectorName = connector.getUniqueName();
+    }
+    printlnResource(Constants.RES_SHOW_PROMPT_LINK_CID_INFO, connectorName, connectorId);
 
     // Display link config
     displayConfig(link.getConnectorLinkConfig().getConfigs(),
-                 client.getConnectorConfigBundle(connectorId));
+    client.getConnectorConfigBundle(connectorId));
+  }
+
+  private List<String> getConnectorNames(List<String> connectorIds) {
+    Map<String, String> connectorIdToName = new HashMap<String, String>();
+    for (String connectorId : connectorIds) {
+      if (!connectorIdToName.containsKey(connectorId)) {
+        MConnector connector = client.getConnector(Long.valueOf(connectorId));
+        if (connector != null) {
+          connectorIdToName.put(connectorId, connector.getUniqueName());
+        }
+      }
+    }
+    List<String> connectorNames = new ArrayList<String>();
+    for (String connectorId : connectorIds) {
+      if (connectorIdToName.get(connectorId) != null) {
+        connectorNames.add(connectorIdToName.get(connectorId));
+      } else {
+        connectorNames.add("");
+      }
+    }
+    return connectorNames;
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/263e3620/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
index 46f2b7f..482ddd9 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/core/Constants.java
@@ -337,8 +337,10 @@ public class Constants {
       "table.header.class";
   public static final String RES_TABLE_HEADER_SUPPORTED_DIRECTIONS =
       "table.header.supported_directions";
-  public static final String RES_TABLE_HEADER_CONNECTOR =
-      "table.header.connector";
+  public static final String RES_TABLE_HEADER_CONNECTOR_NAME =
+      "table.header.connector.name";
+  public static final String RES_TABLE_HEADER_CONNECTOR_ID =
+      "table.header.connector.id";
   public static final String RES_TABLE_HEADER_FROM_CONNECTOR =
       "table.header.connector.from";
   public static final String RES_TABLE_HEADER_TO_CONNECTOR =

http://git-wip-us.apache.org/repos/asf/sqoop/blob/263e3620/shell/src/main/resources/shell-resource.properties
----------------------------------------------------------------------
diff --git a/shell/src/main/resources/shell-resource.properties b/shell/src/main/resources/shell-resource.properties
index 9c88235..a462184 100644
--- a/shell/src/main/resources/shell-resource.properties
+++ b/shell/src/main/resources/shell-resource.properties
@@ -131,7 +131,7 @@ show.prompt_display_link_lid = Display the link with lid
 show.link_usage = Usage: show link
 show.prompt_links_to_show = @|bold {0} link(s) to show: |@
 show.prompt_link_info = link with id {0} and name {1} (Enabled: {2}, Created by {3} at {4},
Updated by {5} at {6})
-show.prompt_link_cid_info = Using Connector id {0}
+show.prompt_link_cid_info = Using Connector @|bold {0}|@ with id @|bold {1}|@
 
 show.prompt_display_all_connectors = Display all connectors
 show.prompt_display_connector_cid = Display the connector with cid
@@ -192,7 +192,8 @@ table.header.name = Name
 table.header.version = Version
 table.header.class = Class
 table.header.supported_directions = Supported Directions
-table.header.connector = Connector
+table.header.connector.id = Connector Id
+table.header.connector.name = Connector Name
 table.header.connector.from = From Connector
 table.header.connector.to = To Connector
 table.header.jid = Job Id


Mime
View raw message