sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject git commit: SQOOP-1653: Link and connector handler minor fixes
Date Mon, 03 Nov 2014 02:38:26 GMT
Repository: sqoop
Updated Branches:
  refs/heads/branch-1.99.4 bd7bed1fe -> 0c5a215ab


SQOOP-1653: Link and connector handler minor fixes

(Veena Basavaraj via Jarek Jarcec Cecho)


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

Branch: refs/heads/branch-1.99.4
Commit: 0c5a215ab2f76e2b38f18f626a8186b6a45bc395
Parents: bd7bed1
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Sun Nov 2 18:37:41 2014 -0800
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Sun Nov 2 18:38:19 2014 -0800

----------------------------------------------------------------------
 .../org/apache/sqoop/json/ConnectorsBean.java   |  1 -
 .../java/org/apache/sqoop/json/LinkBean.java    | 15 ++++----
 .../java/org/apache/sqoop/json/LinksBean.java   |  6 +--
 .../main/java/org/apache/sqoop/model/MLink.java |  6 +--
 .../org/apache/sqoop/json/TestLinkBean.java     |  8 ++--
 .../org/apache/sqoop/repository/Repository.java | 10 ++---
 .../sqoop/handler/ConnectorRequestHandler.java  |  1 +
 .../sqoop/handler/LinkRequestHandler.java       | 39 +++++++++++---------
 .../org/apache/sqoop/server/RequestHandler.java |  3 ++
 .../org/apache/sqoop/server/v1/LinkServlet.java | 20 +++++-----
 .../apache/sqoop/shell/UpdateLinkFunction.java  |  4 +-
 11 files changed, 57 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java b/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java
index 4cd3698..b04594e 100644
--- a/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/ConnectorsBean.java
@@ -46,7 +46,6 @@ public class ConnectorsBean extends ConnectorBean {
   @SuppressWarnings("unchecked")
   @Override
   public JSONObject extract(boolean skipSensitive) {
-
     JSONArray connectorArray = extractConnectors(skipSensitive);
     JSONObject connectors = new JSONObject();
     connectors.put(CONNECTORS, connectorArray);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/common/src/main/java/org/apache/sqoop/json/LinkBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/LinkBean.java b/common/src/main/java/org/apache/sqoop/json/LinkBean.java
index bc59352..ae3a4ff 100644
--- a/common/src/main/java/org/apache/sqoop/json/LinkBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/LinkBean.java
@@ -89,15 +89,15 @@ public class LinkBean implements JsonBean {
   @SuppressWarnings("unchecked")
   @Override
   public JSONObject extract(boolean skipSensitive) {
-    JSONArray linkArray = new JSONArray();
-    extractLinks(skipSensitive, linkArray);
-    JSONObject all = new JSONObject();
-    all.put(LINK, linkArray);
-    return all;
+    JSONArray linkArray = extractLinks(skipSensitive);
+    JSONObject link = new JSONObject();
+    link.put(LINK, linkArray);
+    return link;
   }
-
   @SuppressWarnings("unchecked")
-  protected void extractLinks(boolean skipSensitive, JSONArray linkArray) {
+  protected JSONArray extractLinks(boolean skipSensitive) {
+    JSONArray linkArray = new JSONArray();
+
     for(MLink link : links) {
       JSONObject linkJsonObject = new JSONObject();
       linkJsonObject.put(ID, link.getPersistenceId());
@@ -112,6 +112,7 @@ public class LinkBean implements JsonBean {
         extractConfigList(link.getConnectorLinkConfig().getConfigs(), link.getConnectorLinkConfig().getType(),
skipSensitive));
       linkArray.add(linkJsonObject);
     }
+    return linkArray;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/common/src/main/java/org/apache/sqoop/json/LinksBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/LinksBean.java b/common/src/main/java/org/apache/sqoop/json/LinksBean.java
index 5858a18..58cacb9 100644
--- a/common/src/main/java/org/apache/sqoop/json/LinksBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/LinksBean.java
@@ -43,8 +43,7 @@ public class LinksBean extends LinkBean {
   @SuppressWarnings("unchecked")
   @Override
   public JSONObject extract(boolean skipSensitive) {
-    JSONArray linkArray = new JSONArray();
-    super.extractLinks(skipSensitive, linkArray);
+    JSONArray linkArray = extractLinks(skipSensitive);
     JSONObject links = new JSONObject();
     links.put(LINKS, linkArray);
     return links;
@@ -52,8 +51,7 @@ public class LinksBean extends LinkBean {
 
   @Override
   public void restore(JSONObject jsonObject) {
-
     JSONArray array = (JSONArray) jsonObject.get(LINKS);
     super.restoreLinks(array);
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/common/src/main/java/org/apache/sqoop/model/MLink.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MLink.java b/common/src/main/java/org/apache/sqoop/model/MLink.java
index 7a9f538..8e31861 100644
--- a/common/src/main/java/org/apache/sqoop/model/MLink.java
+++ b/common/src/main/java/org/apache/sqoop/model/MLink.java
@@ -73,10 +73,6 @@ public class MLink extends MAccountableEntity implements MClonable {
     return connectorId;
   }
 
-  public void setConnectorId(long connectorId) {
-    this.connectorId = connectorId;
-  }
-
   public MLinkConfig getConnectorLinkConfig() {
     return connectorLinkConfig;
   }
@@ -108,4 +104,4 @@ public class MLink extends MAccountableEntity implements MClonable {
         && (mLink.getPersistenceId() == this.getPersistenceId())
         && (mLink.connectorLinkConfig.equals(this.connectorLinkConfig));
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java b/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
index 811cbf0..7c3c921 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestLinkBean.java
@@ -59,9 +59,9 @@ public class TestLinkBean {
     JSONObject json = linkBean.extract(false);
 
     // Check for sensitivity
-    JSONArray all = (JSONArray)json.get(LinkBean.LINK);
-    JSONObject allItem = (JSONObject)all.get(0);
-    JSONArray connectors = (JSONArray)allItem.get(LinkBean.LINK_CONFIG);
+    JSONArray linkArray = (JSONArray)json.get(LinkBean.LINK);
+    JSONObject linkItem = (JSONObject)linkArray.get(0);
+    JSONArray connectors = (JSONArray)linkItem.get(LinkBean.LINK_CONFIG);
     JSONObject connector = (JSONObject)connectors.get(0);
     JSONArray inputs = (JSONArray)connector.get(ConfigInputConstants.CONFIG_INPUTS);
     for (Object input1 : inputs) {
@@ -137,4 +137,4 @@ public class TestLinkBean {
     password = (JSONObject)inputs.get(2);
     assertFalse(password.containsKey(ConfigInputConstants.CONFIG_INPUT_VALUE));
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/core/src/main/java/org/apache/sqoop/repository/Repository.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/repository/Repository.java b/core/src/main/java/org/apache/sqoop/repository/Repository.java
index 79742b9..be05383 100644
--- a/core/src/main/java/org/apache/sqoop/repository/Repository.java
+++ b/core/src/main/java/org/apache/sqoop/repository/Repository.java
@@ -403,8 +403,8 @@ public abstract class Repository {
    */
   public final void upgradeConnector(MConnector oldConnector, MConnector newConnector) {
     LOG.info("Upgrading connector: " + oldConnector.getUniqueName());
-    long connectorID = oldConnector.getPersistenceId();
-    newConnector.setPersistenceId(connectorID);
+    long connectorId = oldConnector.getPersistenceId();
+    newConnector.setPersistenceId(connectorId);
 
     RepositoryTransaction tx = null;
     try {
@@ -415,9 +415,9 @@ public abstract class Repository {
       // 1. Get an upgrader for the connector
       ConnectorConfigurableUpgrader upgrader = connector.getConfigurableUpgrader();
       // 2. Get all links associated with the connector.
-      List<MLink> existingLinksByConnector = findLinksForConnector(connectorID);
+      List<MLink> existingLinksByConnector = findLinksForConnector(connectorId);
       // 3. Get all jobs associated with the connector.
-      List<MJob> existingJobsByConnector = findJobsForConnector(connectorID);
+      List<MJob> existingJobsByConnector = findJobsForConnector(connectorId);
       // -- BEGIN TXN --
       tx = getTransaction();
       tx.begin();
@@ -602,4 +602,4 @@ public abstract class Repository {
       LOG.error("\t" + entry.getKey() + ": " + StringUtils.join(entry.getValue(), ","));
     }
   }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
index 5694ea5..7903713 100644
--- a/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/ConnectorRequestHandler.java
@@ -71,6 +71,7 @@ public class ConnectorRequestHandler implements RequestHandler {
 
     } else {
       // NOTE: we now support using unique name as well as the connector id
+      // NOTE: connectorId is a fallback for older sqoop clients if any, since we want to
primarily use unique conenctorNames
       boolean cIdNameIdentfierUsed = true;
       Long cId = ConnectorManager.getInstance().getConnectorId(cIdentifier);
       if (cId == null) {

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/server/src/main/java/org/apache/sqoop/handler/LinkRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/handler/LinkRequestHandler.java b/server/src/main/java/org/apache/sqoop/handler/LinkRequestHandler.java
index 35a9635..9a81832 100644
--- a/server/src/main/java/org/apache/sqoop/handler/LinkRequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/handler/LinkRequestHandler.java
@@ -34,6 +34,7 @@ import org.apache.sqoop.json.ValidationResultBean;
 import org.apache.sqoop.model.ConfigUtils;
 import org.apache.sqoop.model.MLink;
 import org.apache.sqoop.model.MLinkConfig;
+import org.apache.sqoop.model.MPersistableEntity;
 import org.apache.sqoop.repository.Repository;
 import org.apache.sqoop.repository.RepositoryManager;
 import org.apache.sqoop.server.RequestContext;
@@ -51,7 +52,6 @@ public class LinkRequestHandler implements RequestHandler {
   static final String DISABLE = "disable";
   static final String LINKS_PATH = "links";
   static final String LINK_PATH = "link";
-  static final String CONNECTOR_NAME_QUERY_PARAM = "cname";
 
   public LinkRequestHandler() {
     LOG.info("LinkRequestHandler initialized");
@@ -124,10 +124,10 @@ public class LinkRequestHandler implements RequestHandler {
           "Expected one link while parsing JSON request but got " + links.size());
     }
 
-    MLink link = links.get(0);
+    MLink postedLink = links.get(0);
     MLinkConfig linkConfig = ConnectorManager.getInstance()
-        .getConnectorConfigurable(link.getConnectorId()).getLinkConfig();
-    if (!linkConfig.equals(link.getConnectorLinkConfig())) {
+        .getConnectorConfigurable(postedLink.getConnectorId()).getLinkConfig();
+    if (!linkConfig.equals(postedLink.getConnectorLinkConfig())) {
       throw new SqoopException(ServerError.SERVER_0003, "Detected incorrect link config structure");
     }
     // if update get the link id from the request URI
@@ -135,15 +135,17 @@ public class LinkRequestHandler implements RequestHandler {
       String linkIdentifier = ctx.getLastURLElement();
       // support linkName or linkId for the api
       long linkId = getLinkIdFromIdentifier(linkIdentifier, repository);
-      MLink existingLink = repository.findLink(linkId);
-      link.setConnectorId(existingLink.getConnectorId());
+      if (postedLink.getPersistenceId() == MPersistableEntity.PERSISTANCE_ID_DEFAULT) {
+        MLink existingLink = repository.findLink(linkId);
+        postedLink.setPersistenceId(existingLink.getPersistenceId());
+      }
     }
     // Associated connector for this link
     SqoopConnector connector = ConnectorManager.getInstance().getSqoopConnector(
-        link.getConnectorId());
+        postedLink.getConnectorId());
 
     // Validate user supplied config data
-    ConfigValidationResult connectorLinkConfigValidation = ConfigUtils.validateConfigs(link
+    ConfigValidationResult connectorLinkConfigValidation = ConfigUtils.validateConfigs(postedLink
         .getConnectorLinkConfig().getConfigs(), connector.getLinkConfigurationClass());
     // Return back link validation result bean
     ValidationResultBean linkValidationBean = new ValidationResultBean(
@@ -154,17 +156,17 @@ public class LinkRequestHandler implements RequestHandler {
       if (create) {
         AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(),
             ctx.getRequest().getRemoteAddr(), "create", "link",
-            String.valueOf(link.getPersistenceId()));
-        link.setCreationUser(username);
-        link.setLastUpdateUser(username);
-        repository.createLink(link);
-        linkValidationBean.setId(link.getPersistenceId());
+            String.valueOf(postedLink.getPersistenceId()));
+        postedLink.setCreationUser(username);
+        postedLink.setLastUpdateUser(username);
+        repository.createLink(postedLink);
+        linkValidationBean.setId(postedLink.getPersistenceId());
       } else {
         AuditLoggerManager.getInstance().logAuditEvent(ctx.getUserName(),
             ctx.getRequest().getRemoteAddr(), "update", "link",
-            String.valueOf(link.getPersistenceId()));
-        link.setLastUpdateUser(username);
-        repository.updateLink(link);
+            String.valueOf(postedLink.getPersistenceId()));
+        postedLink.setLastUpdateUser(username);
+        repository.updateLink(postedLink);
       }
     }
 
@@ -214,6 +216,7 @@ public class LinkRequestHandler implements RequestHandler {
 
   private long getLinkIdFromIdentifier(String identifier, Repository repository) {
     // support linkName or linkId for the api
+    // NOTE: linkId is a fallback for older sqoop clients if any, since we want to primarily
use unique linkNames
     long linkId;
     if (repository.findLink(identifier) != null) {
       linkId = repository.findLink(identifier).getPersistenceId();
@@ -221,7 +224,7 @@ public class LinkRequestHandler implements RequestHandler {
       try {
         linkId = Long.valueOf(identifier);
       } catch (NumberFormatException ex) {
-        // this means name nor Id existed
+        // this means name nor Id existed and we want to throw a user friendly message than
a number format exception
         throw new SqoopException(ServerError.SERVER_0005, "Invalid link: " + identifier
             + " requested");
       }
@@ -260,4 +263,4 @@ public class LinkRequestHandler implements RequestHandler {
     repository.enableLink(linkId, enabled);
     return JsonBean.EMPTY_BEAN;
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/server/src/main/java/org/apache/sqoop/server/RequestHandler.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/server/RequestHandler.java b/server/src/main/java/org/apache/sqoop/server/RequestHandler.java
index 508edd2..bd62f31 100644
--- a/server/src/main/java/org/apache/sqoop/server/RequestHandler.java
+++ b/server/src/main/java/org/apache/sqoop/server/RequestHandler.java
@@ -22,5 +22,8 @@ import org.apache.sqoop.json.JsonBean;
 
 public interface RequestHandler {
 
+  static final String CONNECTOR_NAME_QUERY_PARAM = "cname";
+  static final String JOB_NAME_QUERY_PARAM = "jname";
+
   JsonBean handleEvent(RequestContext ctx);
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/server/src/main/java/org/apache/sqoop/server/v1/LinkServlet.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/sqoop/server/v1/LinkServlet.java b/server/src/main/java/org/apache/sqoop/server/v1/LinkServlet.java
index 127903a..0e2e176 100644
--- a/server/src/main/java/org/apache/sqoop/server/v1/LinkServlet.java
+++ b/server/src/main/java/org/apache/sqoop/server/v1/LinkServlet.java
@@ -27,30 +27,30 @@ import org.apache.sqoop.server.SqoopProtocolServlet;
  * Provides operations for link resource
  *
  * GET /v1/link/{lid}
- *  Return details about one particular link with id :lid
+ *  Return details about one particular link with id lid
  * GET /v1/link/{lname}
- *  Return details about one particular link with name :lname
+ *  Return details about one particular link with name lname
  *
  * POST /v1/link/ with {connector-id} and {link-config-id} in the post data
  *  Create link for connector with id connector-id
  * PUT /v1/link/ with {connector-id} and {link-config-id} in the post data
  *  Edit/Update link for connector with id connector-id
-
+ *
  * PUT /v1/link/{lid}
- *  Edit/Update details about one particular link with id :lid
+ *  Edit/Update details about one particular link with id lid
  * PUT /v1/link/{lname}
- *  Edit/Update details about one particular link with name :lname
+ *  Edit/Update details about one particular link with name lname
  *
  * DELETE /v1/link/{lid}
- *  Delete/Remove one particular link with id :lid
+ *  Delete/Remove one particular link with id lid
  * DELETE /v1/link/{lname}
- *  Delete/Remove one particular link with name :lname
+ *  Delete/Remove one particular link with name lname
  *
  * PUT /v1/link/{lname}/enable
- * Enable link with id :lname
+ * Enable link with name lname
  *
  * PUT /v1/link/{lname}/disable
- * Disable link with id :lname
+ * Disable link with name lname
  *
  */
 @SuppressWarnings("serial")
@@ -81,4 +81,4 @@ public class LinkServlet extends SqoopProtocolServlet {
   protected JsonBean handleDeleteRequest(RequestContext ctx) throws Exception {
     return linkRequestHandler.handleEvent(ctx);
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/sqoop/blob/0c5a215a/shell/src/main/java/org/apache/sqoop/shell/UpdateLinkFunction.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/UpdateLinkFunction.java b/shell/src/main/java/org/apache/sqoop/shell/UpdateLinkFunction.java
index 176833a..60f9500 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/UpdateLinkFunction.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/UpdateLinkFunction.java
@@ -60,7 +60,7 @@ public class UpdateLinkFunction extends SqoopFunction {
 
     ConsoleReader reader = new ConsoleReader();
 
-    // TODO: why do we need 2 http calls for update?
+    // TODO(SQOOP-1634): using link config id, this call can be avoided
     MLink link = client.getLink(linkId);
 
     ResourceBundle connectorLinkConfigBundle = client.getConnectorConfigBundle(link.getConnectorId());
@@ -104,4 +104,4 @@ public class UpdateLinkFunction extends SqoopFunction {
 
     return status;
   }
-}
+}
\ No newline at end of file


Mime
View raw message