diff --git a/src/java/com/cloudera/sqoop/metastore/JobData.java b/src/java/com/cloudera/sqoop/metastore/JobData.java
index 12187a5a..94194d77 100644
--- a/src/java/com/cloudera/sqoop/metastore/JobData.java
+++ b/src/java/com/cloudera/sqoop/metastore/JobData.java
@@ -1,6 +1,4 @@
/**
- * Copyright 2011 The Apache Software Foundation
- *
* 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
@@ -24,47 +22,17 @@
import com.cloudera.sqoop.tool.SqoopTool;
/**
- * Container for all job data that should be stored to a
- * permanent resource.
+ * @deprecated Moving to use org.apache.sqoop namespace.
*/
-public class JobData {
- private SqoopOptions opts;
- private SqoopTool tool;
+public class JobData
+ extends org.apache.sqoop.metastore.JobData {
public JobData() {
+ super();
}
public JobData(SqoopOptions options, SqoopTool sqoopTool) {
- this.opts = options;
- this.tool = sqoopTool;
- }
-
- /**
- * Gets the SqoopOptions.
- */
- public SqoopOptions getSqoopOptions() {
- return this.opts;
- }
-
- /**
- * Gets the SqoopTool.
- */
- public SqoopTool getSqoopTool() {
- return this.tool;
- }
-
- /**
- * Sets the SqoopOptions.
- */
- public void setSqoopOptions(SqoopOptions options) {
- this.opts = options;
- }
-
- /**
- * Sets the SqoopTool.
- */
- public void setSqoopTool(SqoopTool sqoopTool) {
- this.tool = sqoopTool;
+ super(options, sqoopTool);
}
}
diff --git a/src/java/com/cloudera/sqoop/metastore/JobStorage.java b/src/java/com/cloudera/sqoop/metastore/JobStorage.java
index 599ff14f..bbc6aeac 100644
--- a/src/java/com/cloudera/sqoop/metastore/JobStorage.java
+++ b/src/java/com/cloudera/sqoop/metastore/JobStorage.java
@@ -1,6 +1,4 @@
/**
- * Copyright 2011 The Apache Software Foundation
- *
* 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
@@ -20,76 +18,10 @@
package com.cloudera.sqoop.metastore;
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.hadoop.conf.Configured;
-
/**
- * API that defines how jobs are saved, restored, and manipulated.
- *
- *
- * JobStorage instances may be created and then not used; the
- * JobStorage factory may create additional JobStorage instances
- * that return false from accept() and then discard them. The close()
- * method will only be triggered for a JobStorage if the connect()
- * method is called. Connection should not be triggered by a call to
- * accept().
+ * @deprecated Moving to use org.apache.sqoop namespace.
*/
-public abstract class JobStorage extends Configured implements Closeable {
-
- /**
- * Returns true if the JobStorage system can use the metadata in
- * the descriptor to connect to an underlying storage resource.
- */
- public abstract boolean canAccept(Map descriptor);
-
-
- /**
- * Opens / connects to the underlying storage resource specified by the
- * descriptor.
- */
- public abstract void open(Map descriptor)
- throws IOException;
-
- /**
- * Given a job name, reconstitute a JobData that contains all
- * configuration information required for the job. Returns null if the
- * job name does not match an available job.
- */
- public abstract JobData read(String jobName)
- throws IOException;
-
- /**
- * Forget about a saved job.
- */
- public abstract void delete(String jobName) throws IOException;
-
- /**
- * Given a job name and the data describing a configured job, record the job
- * information to the storage medium.
- */
- public abstract void create(String jobName, JobData data)
- throws IOException;
-
- /**
- * Given a job name and configured job data, update the underlying resource
- * to match the current job configuration.
- */
- public abstract void update(String jobName, JobData data)
- throws IOException;
-
- /**
- * Close any resources opened by the JobStorage system.
- */
- public void close() throws IOException {
- }
-
- /**
- * Enumerate all jobs held in the connected resource.
- */
- public abstract List list() throws IOException;
+public abstract class JobStorage
+ extends org.apache.sqoop.metastore.JobStorage {
}
diff --git a/src/java/com/cloudera/sqoop/metastore/JobStorageFactory.java b/src/java/com/cloudera/sqoop/metastore/JobStorageFactory.java
index aea31a29..3809e6b5 100644
--- a/src/java/com/cloudera/sqoop/metastore/JobStorageFactory.java
+++ b/src/java/com/cloudera/sqoop/metastore/JobStorageFactory.java
@@ -1,6 +1,4 @@
/**
- * Copyright 2011 The Apache Software Foundation
- *
* 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
@@ -20,55 +18,20 @@
package com.cloudera.sqoop.metastore;
-import java.util.List;
-import java.util.Map;
-
import org.apache.hadoop.conf.Configuration;
/**
- * Factory that produces the correct JobStorage system to work with
- * a particular job descriptor.
+ * @deprecated Moving to use org.apache.sqoop namespace.
*/
-public class JobStorageFactory {
+public class JobStorageFactory
+ extends org.apache.sqoop.metastore.JobStorageFactory {
- private Configuration conf;
-
- /**
- * Configuration key describing the list of JobStorage implementations
- * to use to handle jobs.
- */
public static final String AVAILABLE_STORAGES_KEY =
- "sqoop.job.storage.implementations";
-
- /** The default list of available JobStorage implementations. */
- private static final String DEFAULT_AVAILABLE_STORAGES =
- "com.cloudera.sqoop.metastore.hsqldb.HsqldbJobStorage,"
- + "com.cloudera.sqoop.metastore.hsqldb.AutoHsqldbStorage";
+ org.apache.sqoop.metastore.JobStorageFactory.AVAILABLE_STORAGES_KEY;
public JobStorageFactory(Configuration config) {
- this.conf = config;
-
- // Ensure that we always have an available storages list.
- if (this.conf.get(AVAILABLE_STORAGES_KEY) == null) {
- this.conf.set(AVAILABLE_STORAGES_KEY, DEFAULT_AVAILABLE_STORAGES);
- }
+ super(config);
}
- /**
- * Given a storage descriptor, determine the correct JobStorage
- * implementation to use to connect to the storage resource and return an
- * instance of it -- or null if no JobStorage instance is appropriate.
- */
- public JobStorage getJobStorage(Map descriptor) {
- List storages = this.conf.getInstances(
- AVAILABLE_STORAGES_KEY, JobStorage.class);
- for (JobStorage stor : storages) {
- if (stor.canAccept(descriptor)) {
- return stor;
- }
- }
-
- return null;
- }
}
diff --git a/src/java/com/cloudera/sqoop/metastore/hsqldb/AutoHsqldbStorage.java b/src/java/com/cloudera/sqoop/metastore/hsqldb/AutoHsqldbStorage.java
index bfecc91b..259d9f63 100644
--- a/src/java/com/cloudera/sqoop/metastore/hsqldb/AutoHsqldbStorage.java
+++ b/src/java/com/cloudera/sqoop/metastore/hsqldb/AutoHsqldbStorage.java
@@ -1,6 +1,4 @@
/**
- * Copyright 2011 The Apache Software Foundation
- *
* 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
@@ -20,97 +18,24 @@
package com.cloudera.sqoop.metastore.hsqldb;
-import java.io.File;
-import java.io.IOException;
-
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.hadoop.conf.Configuration;
-
/**
- * JobStorage implementation that auto-configures an HSQLDB
- * local-file-based instance to hold jobs.
+ * @deprecated Moving to use org.apache.sqoop namespace.
*/
-public class AutoHsqldbStorage extends HsqldbJobStorage {
+public class AutoHsqldbStorage
+ extends org.apache.sqoop.metastore.hsqldb.AutoHsqldbStorage {
- public static final Log LOG = LogFactory.getLog(
- AutoHsqldbStorage.class.getName());
-
- /**
- * Configuration key specifying whether this storage agent is active.
- * Defaults to "on" to allow zero-conf local users.
- */
public static final String AUTO_STORAGE_IS_ACTIVE_KEY =
- "sqoop.metastore.client.enable.autoconnect";
-
- /**
- * Configuration key specifying the connect string used by this
- * storage agent.
- */
+ org.apache.sqoop.metastore.hsqldb.
+ AutoHsqldbStorage.AUTO_STORAGE_IS_ACTIVE_KEY;
public static final String AUTO_STORAGE_CONNECT_STRING_KEY =
- "sqoop.metastore.client.autoconnect.url";
-
- /**
- * Configuration key specifying the username to bind with.
- */
+ org.apache.sqoop.metastore.hsqldb.
+ AutoHsqldbStorage.AUTO_STORAGE_CONNECT_STRING_KEY;
public static final String AUTO_STORAGE_USER_KEY =
- "sqoop.metastore.client.autoconnect.username";
-
-
- /** HSQLDB default user is named 'SA'. */
- private static final String DEFAULT_AUTO_USER = "SA";
-
- /**
- * Configuration key specifying the password to bind with.
- */
+ org.apache.sqoop.metastore.hsqldb.AutoHsqldbStorage.AUTO_STORAGE_USER_KEY;
public static final String AUTO_STORAGE_PASS_KEY =
- "sqoop.metastore.client.autoconnect.password";
+ org.apache.sqoop.metastore.hsqldb.AutoHsqldbStorage.AUTO_STORAGE_PASS_KEY;
+ public static final String DEFAULT_AUTO_PASSWORD =
+ org.apache.sqoop.metastore.hsqldb.AutoHsqldbStorage.DEFAULT_AUTO_PASSWORD;
- /** HSQLDB default user has an empty password. */
- public static final String DEFAULT_AUTO_PASSWORD = "";
-
- @Override
- /** {@inheritDoc} */
- public boolean canAccept(Map descriptor) {
- Configuration conf = this.getConf();
- return conf.getBoolean(AUTO_STORAGE_IS_ACTIVE_KEY, true);
- }
-
- /**
- * Determine the user's home directory and return a connect
- * string to HSQLDB that uses ~/.sqoop/ as the storage location
- * for the metastore database.
- */
- private String getHomeDirFileConnectStr() {
- String homeDir = System.getProperty("user.home");
-
- File homeDirObj = new File(homeDir);
- File sqoopDataDirObj = new File(homeDirObj, ".sqoop");
- File databaseFileObj = new File(sqoopDataDirObj, "metastore.db");
-
- String dbFileStr = databaseFileObj.toString();
- return "jdbc:hsqldb:file:" + dbFileStr
- + ";hsqldb.write_delay=false;shutdown=true";
- }
-
- @Override
- /**
- * Set the connection information to use the auto-inferred connection
- * string.
- */
- public void open(Map descriptor) throws IOException {
- Configuration conf = getConf();
- setMetastoreConnectStr(conf.get(AUTO_STORAGE_CONNECT_STRING_KEY,
- getHomeDirFileConnectStr()));
- setMetastoreUser(conf.get(AUTO_STORAGE_USER_KEY, DEFAULT_AUTO_USER));
- setMetastorePassword(conf.get(AUTO_STORAGE_PASS_KEY,
- DEFAULT_AUTO_PASSWORD));
- setConnectedDescriptor(descriptor);
-
- init();
- }
}
diff --git a/src/java/com/cloudera/sqoop/metastore/hsqldb/HsqldbJobStorage.java b/src/java/com/cloudera/sqoop/metastore/hsqldb/HsqldbJobStorage.java
index b1728ed9..083e2a37 100644
--- a/src/java/com/cloudera/sqoop/metastore/hsqldb/HsqldbJobStorage.java
+++ b/src/java/com/cloudera/sqoop/metastore/hsqldb/HsqldbJobStorage.java
@@ -1,6 +1,4 @@
/**
- * Copyright 2011 The Apache Software Foundation
- *
* 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
@@ -17,793 +15,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package com.cloudera.sqoop.metastore.hsqldb;
-import java.io.IOException;
-
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.apache.hadoop.conf.Configuration;
-
-import com.cloudera.sqoop.SqoopOptions;
-import com.cloudera.sqoop.metastore.JobData;
-import com.cloudera.sqoop.metastore.JobStorage;
-import com.cloudera.sqoop.tool.SqoopTool;
-
/**
- * JobStorage implementation that uses an HSQLDB-backed database to
- * hold job information.
+ * @deprecated Moving to use org.apache.sqoop namespace.
*/
-public class HsqldbJobStorage extends JobStorage {
+public class HsqldbJobStorage
+ extends org.apache.sqoop.metastore.hsqldb.HsqldbJobStorage {
- public static final Log LOG = LogFactory.getLog(
- HsqldbJobStorage.class.getName());
-
- /** descriptor key identifying the connect string for the metastore. */
- public static final String META_CONNECT_KEY = "metastore.connect.string";
-
- /** descriptor key identifying the username to use when connecting
- * to the metastore.
- */
- public static final String META_USERNAME_KEY = "metastore.username";
-
- /** descriptor key identifying the password to use when connecting
- * to the metastore.
- */
- public static final String META_PASSWORD_KEY = "metastore.password";
-
-
- /** Default name for the root metadata table in HSQLDB. */
- private static final String DEFAULT_ROOT_TABLE_NAME = "SQOOP_ROOT";
-
- /** Configuration key used to override root table name. */
+ public static final String META_CONNECT_KEY =
+ org.apache.sqoop.metastore.hsqldb.HsqldbJobStorage.META_CONNECT_KEY;
+ public static final String META_USERNAME_KEY =
+ org.apache.sqoop.metastore.hsqldb.HsqldbJobStorage.META_USERNAME_KEY;
+ public static final String META_PASSWORD_KEY =
+ org.apache.sqoop.metastore.hsqldb.HsqldbJobStorage.META_PASSWORD_KEY;
public static final String ROOT_TABLE_NAME_KEY =
- "sqoop.hsqldb.root.table.name";
+ org.apache.sqoop.metastore.hsqldb.HsqldbJobStorage.ROOT_TABLE_NAME_KEY;
- /** root metadata table key used to define the current schema version. */
- private static final String STORAGE_VERSION_KEY =
- "sqoop.hsqldb.job.storage.version";
-
- /** The current version number for the schema edition. */
- private static final int CUR_STORAGE_VERSION = 0;
-
- /** root metadata table key used to define the job table name. */
- private static final String SESSION_TABLE_KEY =
- "sqoop.hsqldb.job.info.table";
-
- /** Default value for SESSION_TABLE_KEY. */
- private static final String DEFAULT_SESSION_TABLE_NAME =
- "SQOOP_SESSIONS";
-
- /** Per-job key with propClass 'schema' that defines the set of
- * properties valid to be defined for propClass 'SqoopOptions'. */
- private static final String PROPERTY_SET_KEY =
- "sqoop.property.set.id";
-
- /** Current value for PROPERTY_SET_KEY. */
- private static final String CUR_PROPERTY_SET_ID = "0";
-
- // The following are values for propClass in the v0 schema which
- // describe different aspects of the stored metadata.
-
- /** Property class for properties about the stored data itself. */
- private static final String PROPERTY_CLASS_SCHEMA = "schema";
-
- /** Property class for properties that are loaded into SqoopOptions. */
- private static final String PROPERTY_CLASS_SQOOP_OPTIONS = "SqoopOptions";
-
- /** Property class for properties that are loaded into a Configuration. */
- private static final String PROPERTY_CLASS_CONFIG = "config";
-
- /**
- * Per-job key with propClass 'schema' that specifies the SqoopTool
- * to load.
- */
- private static final String SQOOP_TOOL_KEY = "sqoop.tool";
-
-
- private Map connectedDescriptor;
- private String metastoreConnectStr;
- private String metastoreUser;
- private String metastorePassword;
- private Connection connection;
-
- protected Connection getConnection() {
- return this.connection;
- }
-
- // After connection to the database and initialization of the
- // schema, this holds the name of the job table.
- private String jobTableName;
-
- protected void setMetastoreConnectStr(String connectStr) {
- this.metastoreConnectStr = connectStr;
- }
-
- protected void setMetastoreUser(String user) {
- this.metastoreUser = user;
- }
-
- protected void setMetastorePassword(String pass) {
- this.metastorePassword = pass;
- }
-
- private static final String DB_DRIVER_CLASS = "org.hsqldb.jdbcDriver";
-
- /**
- * Set the descriptor used to open() this storage.
- */
- protected void setConnectedDescriptor(Map descriptor) {
- this.connectedDescriptor = descriptor;
- }
-
- @Override
- /**
- * Initialize the connection to the database.
- */
- public void open(Map descriptor) throws IOException {
- setMetastoreConnectStr(descriptor.get(META_CONNECT_KEY));
- setMetastoreUser(descriptor.get(META_USERNAME_KEY));
- setMetastorePassword(descriptor.get(META_PASSWORD_KEY));
- setConnectedDescriptor(descriptor);
-
- init();
- }
-
- protected void init() throws IOException {
- try {
- // Load/initialize the JDBC driver.
- Class.forName(DB_DRIVER_CLASS);
- } catch (ClassNotFoundException cnfe) {
- throw new IOException("Could not load HSQLDB JDBC driver", cnfe);
- }
-
- try {
- if (null == metastoreUser) {
- this.connection = DriverManager.getConnection(metastoreConnectStr);
- } else {
- this.connection = DriverManager.getConnection(metastoreConnectStr,
- metastoreUser, metastorePassword);
- }
-
- connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- connection.setAutoCommit(false);
-
- // Initialize the root schema.
- if (!rootTableExists()) {
- createRootTable();
- }
-
- // Check the schema version.
- String curStorageVerStr = getRootProperty(STORAGE_VERSION_KEY, null);
- int actualStorageVer = -1;
- try {
- actualStorageVer = Integer.valueOf(curStorageVerStr);
- } catch (NumberFormatException nfe) {
- LOG.warn("Could not interpret as a number: " + curStorageVerStr);
- }
- if (actualStorageVer != CUR_STORAGE_VERSION) {
- LOG.error("Can not interpret metadata schema");
- LOG.error("The metadata schema version is " + curStorageVerStr);
- LOG.error("The highest version supported is " + CUR_STORAGE_VERSION);
- LOG.error("To use this version of Sqoop, "
- + "you must downgrade your metadata schema.");
- throw new IOException("Invalid metadata version.");
- }
-
- // Initialize the versioned schema.
- initV0Schema();
- } catch (SQLException sqle) {
- if (null != connection) {
- try {
- connection.rollback();
- } catch (SQLException e2) {
- LOG.warn("Error rolling back transaction in error handler: " + e2);
- }
- }
-
- throw new IOException("Exception creating SQL connection", sqle);
- }
- }
-
- @Override
- public void close() throws IOException {
- if (null != this.connection) {
- try {
- LOG.debug("Flushing current transaction");
- this.connection.commit();
- } catch (SQLException sqlE) {
- throw new IOException("Exception committing connection", sqlE);
- }
-
- try {
- LOG.debug("Closing connection");
- this.connection.close();
- } catch (SQLException sqlE) {
- throw new IOException("Exception closing connection", sqlE);
- } finally {
- this.connection = null;
- }
- }
- }
-
- @Override
- /** {@inheritDoc} */
- public boolean canAccept(Map descriptor) {
- // We return true if the desciptor contains a connect string to find
- // the database.
- return descriptor.get(META_CONNECT_KEY) != null;
- }
-
- @Override
- /** {@inheritDoc} */
- public JobData read(String jobName) throws IOException {
- try {
- if (!jobExists(jobName)) {
- LOG.error("Cannot restore job: " + jobName);
- LOG.error("(No such job)");
- throw new IOException("Cannot restore missing job " + jobName);
- }
-
- LOG.debug("Restoring job: " + jobName);
- Properties schemaProps = getV0Properties(jobName,
- PROPERTY_CLASS_SCHEMA);
- Properties sqoopOptProps = getV0Properties(jobName,
- PROPERTY_CLASS_SQOOP_OPTIONS);
- Properties configProps = getV0Properties(jobName,
- PROPERTY_CLASS_CONFIG);
-
- // Check that we're not using a saved job from a previous
- // version whose functionality has been deprecated.
- String thisPropSetId = schemaProps.getProperty(PROPERTY_SET_KEY);
- LOG.debug("System property set: " + CUR_PROPERTY_SET_ID);
- LOG.debug("Stored property set: " + thisPropSetId);
- if (!CUR_PROPERTY_SET_ID.equals(thisPropSetId)) {
- LOG.warn("The property set present in this database was written by");
- LOG.warn("an incompatible version of Sqoop. This may result in an");
- LOG.warn("incomplete operation.");
- // TODO(aaron): Should this fail out-right?
- }
-
- String toolName = schemaProps.getProperty(SQOOP_TOOL_KEY);
- if (null == toolName) {
- // Don't know what tool to create.
- throw new IOException("Incomplete metadata; missing "
- + SQOOP_TOOL_KEY);
- }
-
- SqoopTool tool = SqoopTool.getTool(toolName);
- if (null == tool) {
- throw new IOException("Error in job metadata: invalid tool "
- + toolName);
- }
-
- Configuration conf = new Configuration();
- for (Map.Entry