From 359d4244753f8c1d6c6907224875280cd670f9d6 Mon Sep 17 00:00:00 2001 From: Andrew Bayer Date: Fri, 22 Jul 2011 20:03:58 +0000 Subject: [PATCH] 'conf' directory added to classpath bin/configure-sqoop now puts the 'conf' directory on the classpath. Users can override this by setting $SQOOP_CONF_DIR. Added src/perftest/ExtConnFactoryTest and ExtFactory, that demonstrates the configuration is being correctly read. From: Aaron Kimball git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1149921 13f79535-47bb-0310-9956-ffa450edef68 --- bin/configure-sqoop | 3 + src/perftest/ExtConnFactoryTest.java | 92 ++++++++++++++++++++++++++++ src/perftest/ExtFactory.java | 42 +++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 src/perftest/ExtConnFactoryTest.java create mode 100644 src/perftest/ExtFactory.java diff --git a/bin/configure-sqoop b/bin/configure-sqoop index 04a79cb3..bb022547 100755 --- a/bin/configure-sqoop +++ b/bin/configure-sqoop @@ -58,6 +58,9 @@ if [ -d "$SQOOP_HOME/lib" ]; then done fi +SQOOP_CONF_DIR=${SQOOP_CONF_DIR:-${SQOOP_HOME}/conf} +SQOOP_CLASSPATH=${SQOOP_CONF_DIR}:${SQOOP_CLASSPATH} + # If there's a build subdir, use Ivy-retrieved dependencies too. if [ -d "$SQOOP_HOME/build/ivy/lib/sqoop" ]; then for f in $SQOOP_HOME/build/ivy/lib/sqoop/*/*.jar; do diff --git a/src/perftest/ExtConnFactoryTest.java b/src/perftest/ExtConnFactoryTest.java new file mode 100644 index 00000000..ab406f7e --- /dev/null +++ b/src/perftest/ExtConnFactoryTest.java @@ -0,0 +1,92 @@ +/** + * Licensed to Cloudera, Inc. under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Cloudera, Inc. licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +import com.cloudera.sqoop.Sqoop; +import com.cloudera.sqoop.SqoopOptions; +import com.cloudera.sqoop.manager.ExportJobContext; +import com.cloudera.sqoop.manager.ImportJobContext; +import com.cloudera.sqoop.manager.SqlManager; +import com.cloudera.sqoop.util.ExportException; +import com.cloudera.sqoop.util.ImportException; + +/** + * Test external connection factory classes on the classpath. + * This adds a connection factory that will accept all connect strings, + * but then promptly throws an error message if you try to import or + * export a table. + * + * You'll need to specify the sqoop.connection.factories property + * (either in conf/sqoop-default.xml) or on the command line with -D; + * this should include the 'ExtConnFactoryTest.ExtFactory' class. + * + * Run with: src/scripts/run-perftest.sh ExtConnFactoryTest \ + * (normal sqoop arguments) + */ +public final class ExtConnFactoryTest { + private ExtConnFactoryTest() { + } + + /** + * A ConnManager that cannot satisfy any connection requests; + * all operations fail with an error message. + */ + public static class FailingManager extends SqlManager { + + public FailingManager(SqoopOptions options) { + super(options); + } + + @Override + public Connection getConnection() throws SQLException { + throw new SQLException("This manager cannot create a connection"); + } + + @Override + public void importTable(ImportJobContext context) + throws ImportException { + throw new ImportException("This manager cannot read tables."); + } + + @Override + protected ResultSet execute(String stmt, Object... args) + throws SQLException { + throw new SQLException("This manager cannot execute SQL statements"); + } + + @Override + public void exportTable(ExportJobContext context) throws ExportException { + throw new ExportException("This manager cannot write tables."); + } + + @Override + public String getDriverClass() { + return null; + } + } + + /** + * Run the connection factory test. + */ + public static void main(String [] args) throws Exception { + Sqoop.main(args); + } +} diff --git a/src/perftest/ExtFactory.java b/src/perftest/ExtFactory.java new file mode 100644 index 00000000..a9fc4d9e --- /dev/null +++ b/src/perftest/ExtFactory.java @@ -0,0 +1,42 @@ +/** + * Licensed to Cloudera, Inc. under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Cloudera, Inc. licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.cloudera.sqoop.SqoopOptions; +import com.cloudera.sqoop.manager.ConnManager; +import com.cloudera.sqoop.manager.ManagerFactory; + +/** + * An external ConnFactory used by ExtConnFactoryTest. + */ +public class ExtFactory extends ManagerFactory { + public static final Log LOG = + LogFactory.getLog(ExtFactory.class.getName()); + + public ExtFactory() { + LOG.info("Instantiating ExtFactory"); + } + + public ConnManager accept(SqoopOptions options) { + LOG.info("ExtFactory accepting manager for: " + + options.getConnectString()); + return new ExtConnFactoryTest.FailingManager(options); + } +}