mirror of
https://github.com/apache/sqoop.git
synced 2025-05-17 09:20:43 +08:00
SQOOP-63. JobBase classes unnecessarily create ConnManagers.
ImportJobContext and ExportJobContext now contain references to the already-instantiated ConnManager. JobBase subclasses should no longer use a ConnFactory, but should use the existing ConnManager. From: Aaron Kimball <aaron@cloudera.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149953 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
692ee04f14
commit
6a9eef446b
@ -19,12 +19,10 @@
|
|||||||
package com.cloudera.sqoop.mapreduce;
|
package com.cloudera.sqoop.mapreduce;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
|
||||||
import org.apache.hadoop.mapreduce.InputFormat;
|
import org.apache.hadoop.mapreduce.InputFormat;
|
||||||
import org.apache.hadoop.mapreduce.Job;
|
import org.apache.hadoop.mapreduce.Job;
|
||||||
import org.apache.hadoop.mapreduce.Mapper;
|
import org.apache.hadoop.mapreduce.Mapper;
|
||||||
@ -32,7 +30,6 @@
|
|||||||
import com.cloudera.sqoop.mapreduce.db.DBConfiguration;
|
import com.cloudera.sqoop.mapreduce.db.DBConfiguration;
|
||||||
import com.cloudera.sqoop.mapreduce.db.DBOutputFormat;
|
import com.cloudera.sqoop.mapreduce.db.DBOutputFormat;
|
||||||
|
|
||||||
import com.cloudera.sqoop.ConnFactory;
|
|
||||||
import com.cloudera.sqoop.manager.ConnManager;
|
import com.cloudera.sqoop.manager.ConnManager;
|
||||||
import com.cloudera.sqoop.manager.ExportJobContext;
|
import com.cloudera.sqoop.manager.ExportJobContext;
|
||||||
|
|
||||||
@ -68,8 +65,7 @@ protected Class<? extends Mapper> getMapperClass() {
|
|||||||
protected void configureOutputFormat(Job job, String tableName,
|
protected void configureOutputFormat(Job job, String tableName,
|
||||||
String tableClassName) throws IOException {
|
String tableClassName) throws IOException {
|
||||||
|
|
||||||
Configuration conf = options.getConf();
|
ConnManager mgr = context.getConnManager();
|
||||||
ConnManager mgr = new ConnFactory(conf).getManager(options);
|
|
||||||
try {
|
try {
|
||||||
String username = options.getUsername();
|
String username = options.getUsername();
|
||||||
if (null == username || username.length() == 0) {
|
if (null == username || username.length() == 0) {
|
||||||
@ -93,12 +89,6 @@ protected void configureOutputFormat(Job job, String tableName,
|
|||||||
job.getConfiguration().set(SQOOP_EXPORT_TABLE_CLASS_KEY, tableClassName);
|
job.getConfiguration().set(SQOOP_EXPORT_TABLE_CLASS_KEY, tableClassName);
|
||||||
} catch (ClassNotFoundException cnfe) {
|
} catch (ClassNotFoundException cnfe) {
|
||||||
throw new IOException("Could not load OutputFormat", cnfe);
|
throw new IOException("Could not load OutputFormat", cnfe);
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
mgr.close();
|
|
||||||
} catch (SQLException sqlE) {
|
|
||||||
LOG.warn("Error closing connection: " + sqlE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,12 +19,10 @@
|
|||||||
package com.cloudera.sqoop.mapreduce;
|
package com.cloudera.sqoop.mapreduce;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
|
||||||
import org.apache.hadoop.mapreduce.InputFormat;
|
import org.apache.hadoop.mapreduce.InputFormat;
|
||||||
import org.apache.hadoop.mapreduce.Job;
|
import org.apache.hadoop.mapreduce.Job;
|
||||||
import org.apache.hadoop.mapreduce.Mapper;
|
import org.apache.hadoop.mapreduce.Mapper;
|
||||||
@ -32,7 +30,6 @@
|
|||||||
import com.cloudera.sqoop.mapreduce.db.DBConfiguration;
|
import com.cloudera.sqoop.mapreduce.db.DBConfiguration;
|
||||||
import com.cloudera.sqoop.mapreduce.db.DBOutputFormat;
|
import com.cloudera.sqoop.mapreduce.db.DBOutputFormat;
|
||||||
|
|
||||||
import com.cloudera.sqoop.ConnFactory;
|
|
||||||
import com.cloudera.sqoop.manager.ConnManager;
|
import com.cloudera.sqoop.manager.ConnManager;
|
||||||
import com.cloudera.sqoop.manager.ExportJobContext;
|
import com.cloudera.sqoop.manager.ExportJobContext;
|
||||||
import com.cloudera.sqoop.shims.ShimLoader;
|
import com.cloudera.sqoop.shims.ShimLoader;
|
||||||
@ -85,8 +82,7 @@ protected Class<? extends Mapper> getMapperClass() {
|
|||||||
protected void configureOutputFormat(Job job, String tableName,
|
protected void configureOutputFormat(Job job, String tableName,
|
||||||
String tableClassName) throws IOException {
|
String tableClassName) throws IOException {
|
||||||
|
|
||||||
Configuration conf = options.getConf();
|
ConnManager mgr = context.getConnManager();
|
||||||
ConnManager mgr = new ConnFactory(conf).getManager(options);
|
|
||||||
try {
|
try {
|
||||||
String username = options.getUsername();
|
String username = options.getUsername();
|
||||||
if (null == username || username.length() == 0) {
|
if (null == username || username.length() == 0) {
|
||||||
@ -131,12 +127,6 @@ protected void configureOutputFormat(Job job, String tableName,
|
|||||||
job.getConfiguration().set(SQOOP_EXPORT_UPDATE_COL_KEY, updateKeyCol);
|
job.getConfiguration().set(SQOOP_EXPORT_UPDATE_COL_KEY, updateKeyCol);
|
||||||
} catch (ClassNotFoundException cnfe) {
|
} catch (ClassNotFoundException cnfe) {
|
||||||
throw new IOException("Could not load OutputFormat", cnfe);
|
throw new IOException("Could not load OutputFormat", cnfe);
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
mgr.close();
|
|
||||||
} catch (SQLException sqlE) {
|
|
||||||
LOG.warn("Error closing connection: " + sqlE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package com.cloudera.sqoop.mapreduce;
|
package com.cloudera.sqoop.mapreduce;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -33,7 +32,6 @@
|
|||||||
import com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat;
|
import com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat;
|
||||||
import org.apache.hadoop.mapreduce.lib.db.DBWritable;
|
import org.apache.hadoop.mapreduce.lib.db.DBWritable;
|
||||||
|
|
||||||
import com.cloudera.sqoop.ConnFactory;
|
|
||||||
import com.cloudera.sqoop.SqoopOptions;
|
import com.cloudera.sqoop.SqoopOptions;
|
||||||
import com.cloudera.sqoop.manager.ConnManager;
|
import com.cloudera.sqoop.manager.ConnManager;
|
||||||
import com.cloudera.sqoop.manager.MySQLUtils;
|
import com.cloudera.sqoop.manager.MySQLUtils;
|
||||||
@ -71,9 +69,7 @@ protected void configureInputFormat(Job job, String tableName,
|
|||||||
throw new IOException("null tableName for MySQLDumpImportJob.");
|
throw new IOException("null tableName for MySQLDumpImportJob.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnManager mgr = new ConnFactory(options.getConf()).getManager(options);
|
ConnManager mgr = getContext().getConnManager();
|
||||||
|
|
||||||
try {
|
|
||||||
String username = options.getUsername();
|
String username = options.getUsername();
|
||||||
if (null == username || username.length() == 0) {
|
if (null == username || username.length() == 0) {
|
||||||
DBConfiguration.configureDB(job.getConfiguration(),
|
DBConfiguration.configureDB(job.getConfiguration(),
|
||||||
@ -127,13 +123,6 @@ protected void configureInputFormat(Job job, String tableName,
|
|||||||
|
|
||||||
LOG.debug("Using InputFormat: " + inputFormatClass);
|
LOG.debug("Using InputFormat: " + inputFormatClass);
|
||||||
job.setInputFormatClass(getInputFormatClass());
|
job.setInputFormatClass(getInputFormatClass());
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
mgr.close();
|
|
||||||
} catch (SQLException sqlE) {
|
|
||||||
LOG.warn("Error closing connection: " + sqlE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
package com.cloudera.sqoop.mapreduce;
|
package com.cloudera.sqoop.mapreduce;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -32,7 +31,6 @@
|
|||||||
import com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat;
|
import com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat;
|
||||||
import org.apache.hadoop.mapreduce.lib.db.DBWritable;
|
import org.apache.hadoop.mapreduce.lib.db.DBWritable;
|
||||||
|
|
||||||
import com.cloudera.sqoop.ConnFactory;
|
|
||||||
import com.cloudera.sqoop.manager.ConnManager;
|
import com.cloudera.sqoop.manager.ConnManager;
|
||||||
import com.cloudera.sqoop.manager.ExportJobContext;
|
import com.cloudera.sqoop.manager.ExportJobContext;
|
||||||
import com.cloudera.sqoop.manager.MySQLUtils;
|
import com.cloudera.sqoop.manager.MySQLUtils;
|
||||||
@ -74,9 +72,7 @@ protected void configureInputFormat(Job job, String tableName,
|
|||||||
conf.setStrings(MySQLUtils.EXTRA_ARGS_KEY, extraArgs);
|
conf.setStrings(MySQLUtils.EXTRA_ARGS_KEY, extraArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnManager mgr = null;
|
ConnManager mgr = context.getConnManager();
|
||||||
try {
|
|
||||||
mgr = new ConnFactory(conf).getManager(options);
|
|
||||||
String username = options.getUsername();
|
String username = options.getUsername();
|
||||||
if (null == username || username.length() == 0) {
|
if (null == username || username.length() == 0) {
|
||||||
DBConfiguration.configureDB(job.getConfiguration(),
|
DBConfiguration.configureDB(job.getConfiguration(),
|
||||||
@ -103,13 +99,6 @@ protected void configureInputFormat(Job job, String tableName,
|
|||||||
// Note that mysqldump also does *not* want a quoted table name.
|
// Note that mysqldump also does *not* want a quoted table name.
|
||||||
DataDrivenDBInputFormat.setInput(job, DBWritable.class,
|
DataDrivenDBInputFormat.setInput(job, DBWritable.class,
|
||||||
tableName, null, null, sqlColNames);
|
tableName, null, null, sqlColNames);
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
mgr.close();
|
|
||||||
} catch (SQLException sqlE) {
|
|
||||||
LOG.warn("Error closing connection manager: " + sqlE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure the actual InputFormat to use.
|
// Configure the actual InputFormat to use.
|
||||||
super.configureInputFormat(job, tableName, tableClassName, splitByCol);
|
super.configureInputFormat(job, tableName, tableClassName, splitByCol);
|
||||||
|
Loading…
Reference in New Issue
Block a user