sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject git commit: SQOOP-739 Connectors should be versionable (Jarek Jarcec Cecho)
Date Sat, 08 Dec 2012 04:42:37 GMT
Updated Branches:
  refs/heads/sqoop2 b16ca584f -> 671d84934


SQOOP-739 Connectors should be versionable
(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/671d8493
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/671d8493
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/671d8493

Branch: refs/heads/sqoop2
Commit: 671d84934e147cb8317dbb5da90fde6f4f018074
Parents: b16ca58
Author: Bilung Lee <blee@apache.org>
Authored: Fri Dec 7 20:04:46 2012 -0800
Committer: Bilung Lee <blee@apache.org>
Committed: Fri Dec 7 20:04:46 2012 -0800

----------------------------------------------------------------------
 .../sqoop/client/shell/ShowConnectorFunction.java  |    6 ++--
 .../java/org/apache/sqoop/json/ConnectorBean.java  |    4 ++-
 .../apache/sqoop/json/util/FormSerialization.java  |    1 +
 .../java/org/apache/sqoop/model/MConnector.java    |   13 +++++++--
 .../test/java/org/apache/sqoop/json/TestUtil.java  |    2 +-
 .../sqoop/connector/jdbc/GenericJdbcConnector.java |   12 ++++++++
 .../apache/sqoop/connector/ConnectorHandler.java   |    4 ++-
 .../repository/derby/DerbyRepositoryHandler.java   |    4 ++-
 .../repository/derby/DerbySchemaConstants.java     |    2 +
 .../sqoop/repository/derby/DerbySchemaQuery.java   |   21 ++++++++++----
 .../sqoop/repository/derby/DerbyTestCase.java      |    6 ++--
 .../apache/sqoop/connector/spi/SqoopConnector.java |    7 +++++
 12 files changed, 63 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
index ac2683c..3116cd9 100644
--- a/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
+++ b/client/src/main/java/org/apache/sqoop/client/shell/ShowConnectorFunction.java
@@ -82,9 +82,7 @@ public class ShowConnectorFunction extends SqoopFunction
     Map<Long, ResourceBundle> bundles = connectorBean.getResourceBundles();
 
     io.out.println("@|bold " + connectors.size() + " connector(s) to show: |@");
-    for (int i = 0; i < connectors.size(); i++) {
-      MConnector connector = connectors.get(i);
-
+    for (MConnector connector : connectors) {
       io.out.print("Connector with id ");
       io.out.print(connector.getPersistenceId());
       io.out.println(":");
@@ -93,6 +91,8 @@ public class ShowConnectorFunction extends SqoopFunction
       io.out.println(connector.getUniqueName());
       io.out.print("  Class: ");
       io.out.println(connector.getClassName());
+      io.out.print("  Version: ");
+      io.out.println(connector.getVersion());
 
       displayFormMetadataDetails(io, connector, bundles.get(connector.getPersistenceId()));
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java b/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
index 82d865c..601040d 100644
--- a/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/ConnectorBean.java
@@ -72,6 +72,7 @@ public class ConnectorBean implements JsonBean {
       object.put(ID, connector.getPersistenceId());
       object.put(NAME, connector.getUniqueName());
       object.put(CLASS, connector.getClassName());
+      object.put(VERSION, connector.getVersion());
       object.put(CON_FORMS, extractForms(connector.getConnectionForms().getForms()));
 
       JSONObject jobForms = new JSONObject();
@@ -113,6 +114,7 @@ public class ConnectorBean implements JsonBean {
       long connectorId = (Long) object.get(ID);
       String uniqueName = (String) object.get(NAME);
       String className = (String) object.get(CLASS);
+      String version = (String) object.get(VERSION);
 
       List<MForm> connForms = restoreForms((JSONArray) object.get(CON_FORMS));
 
@@ -127,7 +129,7 @@ public class ConnectorBean implements JsonBean {
         jobs.add(new MJobForms(type, jobForms));
       }
 
-      MConnector connector = new MConnector(uniqueName, className, new MConnectionForms(connForms),
jobs);
+      MConnector connector = new MConnector(uniqueName, className, version, new MConnectionForms(connForms),
jobs);
       connector.setPersistenceId(connectorId);
 
       connectors.add(connector);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java b/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
index 732293a..e4919b2 100644
--- a/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
+++ b/common/src/main/java/org/apache/sqoop/json/util/FormSerialization.java
@@ -40,6 +40,7 @@ public final class FormSerialization {
   public static final String ALL = "all";
   public static final String ID = "id";
   public static final String NAME = "name";
+  public static final String VERSION = "version";
   public static final String CLASS = "class";
   public static final String CON_FORMS = "con-forms";
   public static final String JOB_FORMS = "job-forms";

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/common/src/main/java/org/apache/sqoop/model/MConnector.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/model/MConnector.java b/common/src/main/java/org/apache/sqoop/model/MConnector.java
index 5b3b884..9207c62 100644
--- a/common/src/main/java/org/apache/sqoop/model/MConnector.java
+++ b/common/src/main/java/org/apache/sqoop/model/MConnector.java
@@ -29,8 +29,9 @@ public final class MConnector extends MFramework {
 
   private final String uniqueName;
   private final String className;
+  private final String version;
 
-  public MConnector(String uniqueName, String className,
+  public MConnector(String uniqueName, String className, String version,
       MConnectionForms connectionForms, List<MJobForms> jobForms) {
     super(connectionForms, jobForms);
 
@@ -40,6 +41,7 @@ public final class MConnector extends MFramework {
 
     this.uniqueName = uniqueName;
     this.className = className;
+    this.version = version;
   }
 
   public String getUniqueName() {
@@ -50,6 +52,10 @@ public final class MConnector extends MFramework {
     return className;
   }
 
+  public String getVersion() {
+    return version;
+  }
+
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder("connector-");
@@ -74,8 +80,9 @@ public final class MConnector extends MFramework {
     }
 
     MConnector mc = (MConnector) other;
-    return (uniqueName.equals(mc.uniqueName)
-        && className.equals(mc.className))
+    return uniqueName.equals(mc.uniqueName)
+        && className.equals(mc.className)
+        && version.equals(mc.version)
         && super.equals(other);
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/common/src/test/java/org/apache/sqoop/json/TestUtil.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestUtil.java b/common/src/test/java/org/apache/sqoop/json/TestUtil.java
index 791e999..7dab5a4 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestUtil.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestUtil.java
@@ -39,7 +39,7 @@ import java.util.ResourceBundle;
  */
 public class TestUtil {
   public static MConnector getConnector(String name) {
-    return new MConnector(name, name + ".class",
+    return new MConnector(name, name + ".class", "1.0-test",
       getConnectionForms(), getAllJobForms());
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
----------------------------------------------------------------------
diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
index 26daaf7..ea92d0c 100644
--- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
+++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
@@ -20,6 +20,7 @@ package org.apache.sqoop.connector.jdbc;
 import java.util.Locale;
 import java.util.ResourceBundle;
 
+import org.apache.sqoop.common.VersionInfo;
 import org.apache.sqoop.connector.jdbc.configuration.ConnectionConfiguration;
 import org.apache.sqoop.connector.jdbc.configuration.ExportJobConfiguration;
 import org.apache.sqoop.connector.jdbc.configuration.ImportJobConfiguration;
@@ -43,6 +44,17 @@ public class GenericJdbcConnector implements SqoopConnector {
       GenericJdbcExportDestroyer.class);
 
 
+  /**
+   * {@inheritDoc}
+   *
+   * As this is build-in connector it will return same version as rest of the
+   * Sqoop infrastructure.
+   */
+  @Override
+  public String getVersion() {
+    return VersionInfo.getVersion();
+  }
+
   @Override
   public ResourceBundle getBundle(Locale locale) {
     return ResourceBundle.getBundle(

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java b/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
index 00315ea..b80de7f 100644
--- a/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
+++ b/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
@@ -104,8 +104,10 @@ public final class ConnectorHandler {
     MConnectionForms connectionForms = new MConnectionForms(
       FormUtils.toForms(connector.getConnectionConfigurationClass()));
 
+    String connectorVersion = connector.getVersion();
+
     mConnector = new MConnector(connectorUniqueName, connectorClassName,
-      connectionForms, jobForms);
+      connectorVersion, connectionForms, jobForms);
 
     if (LOG.isInfoEnabled()) {
       LOG.info("Connector [" + connectorClassName + "] initialized.");

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
index b9ba746..c62730c 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
@@ -97,6 +97,7 @@ public class DerbyRepositoryHandler implements JdbcRepositoryHandler {
           Statement.RETURN_GENERATED_KEYS);
       baseConnectorStmt.setString(1, mc.getUniqueName());
       baseConnectorStmt.setString(2, mc.getClassName());
+      baseConnectorStmt.setString(3, mc.getVersion());
 
       int baseConnectorCount = baseConnectorStmt.executeUpdate();
       if (baseConnectorCount != 1) {
@@ -276,6 +277,7 @@ public class DerbyRepositoryHandler implements JdbcRepositoryHandler {
       long connectorId = rsetBaseConnector.getLong(1);
       String connectorName = rsetBaseConnector.getString(2);
       String connectorClassName = rsetBaseConnector.getString(3);
+      String connectorVersion = rsetBaseConnector.getString(4);
 
       formFetchStmt = conn.prepareStatement(STMT_FETCH_FORM_CONNECTOR);
       formFetchStmt.setLong(1, connectorId);
@@ -287,7 +289,7 @@ public class DerbyRepositoryHandler implements JdbcRepositoryHandler {
 
       loadForms(connectionForms, jobForms, formFetchStmt, inputFetchStmt, 1);
 
-      mc = new MConnector(connectorName, connectorClassName,
+      mc = new MConnector(connectorName, connectorClassName, connectorVersion,
         new MConnectionForms(connectionForms),
         convertToJobList(jobForms));
       mc.setPersistenceId(connectorId);

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
index 1d1fc09..875b41a 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaConstants.java
@@ -36,6 +36,8 @@ public final class DerbySchemaConstants {
 
   public static final String COLUMN_SQC_CLASS = "SQC_CLASS";
 
+  public static final String COLUMN_SQC_VERSION = "SQC_VERSION";
+
   // SQ_FORM
 
   public static final String TABLE_SQ_FORM_NAME = "SQ_FORM";

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
index f836500..d0fd598 100644
--- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
+++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaQuery.java
@@ -32,6 +32,7 @@ import static org.apache.sqoop.repository.derby.DerbySchemaConstants.*;
  *    | SQC_ID: BIGINT PK AUTO-GEN |
  *    | SQC_NAME: VARCHAR(64)      |
  *    | SQC_CLASS: VARCHAR(255)    |
+ *    | SQC_VERSION: VARCHAR(25)   |
  *    +----------------------------+
  * </pre>
  * </p>
@@ -185,7 +186,8 @@ public final class DerbySchemaQuery {
       "CREATE TABLE " + TABLE_SQ_CONNECTOR + " ("
       + COLUMN_SQC_ID + " BIGINT GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY
1) PRIMARY KEY, "
       + COLUMN_SQC_NAME + " VARCHAR(64), "
-      + COLUMN_SQC_CLASS + " VARCHAR(255)"
+      + COLUMN_SQC_CLASS + " VARCHAR(255), "
+      + COLUMN_SQC_VERSION + " VARCHAR(25) "
       + ")";
 
   // DDL: Create table SQ_FORM
@@ -303,9 +305,13 @@ public final class DerbySchemaQuery {
 
   // DML: Fetch connector Given Name
   public static final String STMT_FETCH_BASE_CONNECTOR =
-      "SELECT " + COLUMN_SQC_ID + ", " + COLUMN_SQC_NAME + ", "
-      + COLUMN_SQC_CLASS + " FROM " + TABLE_SQ_CONNECTOR + " WHERE "
-      + COLUMN_SQC_NAME + " = ?";
+      "SELECT "
+      + COLUMN_SQC_ID + ", "
+      + COLUMN_SQC_NAME + ", "
+      + COLUMN_SQC_CLASS + ", "
+      + COLUMN_SQC_VERSION
+      + " FROM " + TABLE_SQ_CONNECTOR
+      + " WHERE " + COLUMN_SQC_NAME + " = ?";
 
 
   // DML: Fetch all forms for a given connector
@@ -357,8 +363,11 @@ public final class DerbySchemaQuery {
 
   // DML: Insert connector base
   public static final String STMT_INSERT_CONNECTOR_BASE =
-      "INSERT INTO " + TABLE_SQ_CONNECTOR + " (" + COLUMN_SQC_NAME
-      + ", " + COLUMN_SQC_CLASS + ") VALUES ( ?, ?)";
+      "INSERT INTO " + TABLE_SQ_CONNECTOR + " ("
+      + COLUMN_SQC_NAME + ", "
+      + COLUMN_SQC_CLASS + ", "
+      + COLUMN_SQC_VERSION
+      + ") VALUES (?, ?, ?)";
 
   // DML: Insert form base
   public static final String STMT_INSERT_FORM_BASE =

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
----------------------------------------------------------------------
diff --git a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
index 0efa19d..5ace598 100644
--- a/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
+++ b/repository/repository-derby/src/test/java/org/apache/sqoop/repository/derby/DerbyTestCase.java
@@ -142,8 +142,8 @@ abstract public class DerbyTestCase extends TestCase {
    */
   protected void loadConnectorAndFramework() throws Exception {
     // Connector entry
-    runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS)"
-      + "VALUES('A', 'org.apache.sqoop.test.A')");
+    runQuery("INSERT INTO SQOOP.SQ_CONNECTOR(SQC_NAME, SQC_CLASS, SQC_VERSION)"
+      + "VALUES('A', 'org.apache.sqoop.test.A', '1.0-test')");
 
     for(String connector : new String[] {"1", "NULL"}) {
       // Form entries
@@ -294,7 +294,7 @@ abstract public class DerbyTestCase extends TestCase {
   }
 
   protected MConnector getConnector() {
-    return new MConnector("A", "org.apache.sqoop.test.A",
+    return new MConnector("A", "org.apache.sqoop.test.A", "1.0-test",
       getConnectionForms(), getJobForms());
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/671d8493/spi/src/main/java/org/apache/sqoop/connector/spi/SqoopConnector.java
----------------------------------------------------------------------
diff --git a/spi/src/main/java/org/apache/sqoop/connector/spi/SqoopConnector.java b/spi/src/main/java/org/apache/sqoop/connector/spi/SqoopConnector.java
index 52d0852..dc08675 100644
--- a/spi/src/main/java/org/apache/sqoop/connector/spi/SqoopConnector.java
+++ b/spi/src/main/java/org/apache/sqoop/connector/spi/SqoopConnector.java
@@ -31,6 +31,13 @@ import org.apache.sqoop.validation.Validator;
 public interface SqoopConnector {
 
   /**
+   * Retrieve connector version.
+   *
+   * @return Version encoded as a string
+   */
+  String getVersion();
+
+  /**
    * @param locale
    * @return the resource bundle associated with the given locale.
    */


Mime
View raw message