mirror of
https://github.com/apache/sqoop.git
synced 2025-05-02 07:40:40 +08:00
SQOOP-118. Sqoop should work without HBase where possible.
From: Jonathan Hsieh <jon@cloudera.com> git-svn-id: https://svn.apache.org/repos/asf/incubator/sqoop/trunk@1150029 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f38e40e760
commit
34b7c72165
@ -44,12 +44,12 @@ if [ ! -d "${HADOOP_HOME}" ]; then
|
|||||||
echo 'Please set $HADOOP_HOME to the root of your Hadoop installation.'
|
echo 'Please set $HADOOP_HOME to the root of your Hadoop installation.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ ! -d "${HBASE_HOME}" ]; then
|
|
||||||
echo "Error: $HBASE_HOME does not exist!"
|
|
||||||
echo 'Please set $HBASE_HOME to the root of your HBase installation.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
## Moved to be a runtime check in sqoop.
|
||||||
|
if [ ! -d "${HBASE_HOME}" ]; then
|
||||||
|
echo "Warning: $HBASE_HOME does not exist! HBase imports will fail."
|
||||||
|
echo 'Please set $HBASE_HOME to the root of your HBase installation.'
|
||||||
|
fi
|
||||||
|
|
||||||
# Where to find the main Sqoop jar
|
# Where to find the main Sqoop jar
|
||||||
SQOOP_JAR_DIR=$SQOOP_HOME
|
SQOOP_JAR_DIR=$SQOOP_HOME
|
||||||
@ -76,7 +76,9 @@ if [ -d "$SQOOP_HOME/lib" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Add HBase to dependency list
|
# Add HBase to dependency list
|
||||||
SQOOP_CLASSPATH=`$HBASE_HOME/bin/hbase classpath`:${SQOOP_CLASSPATH}
|
if [ -e "$HBASE_HOME/bin/hbase" ]; then
|
||||||
|
SQOOP_CLASSPATH=`$HBASE_HOME/bin/hbase classpath`:${SQOOP_CLASSPATH}
|
||||||
|
fi
|
||||||
|
|
||||||
ZOOCFGDIR=${ZOOCFGDIR:-/etc/zookeeper}
|
ZOOCFGDIR=${ZOOCFGDIR:-/etc/zookeeper}
|
||||||
if [ -d "${ZOOCFGDIR}" ]; then
|
if [ -d "${ZOOCFGDIR}" ]; then
|
||||||
|
51
src/java/com/cloudera/sqoop/hbase/HBaseUtil.java
Normal file
51
src/java/com/cloudera/sqoop/hbase/HBaseUtil.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cloudera.sqoop.hbase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class provides a method that checks if HBase jars are present in the
|
||||||
|
* current classpath. It also provides a setAlwaysNoHBaseJarMode mechanism for
|
||||||
|
* testing and simulation the condition where the is on HBase jar (since hbase
|
||||||
|
* is pulled automatically by ivy)
|
||||||
|
*/
|
||||||
|
public final class HBaseUtil {
|
||||||
|
private static boolean testingMode = false;
|
||||||
|
|
||||||
|
private HBaseUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a way to make this always return false for testing.
|
||||||
|
*/
|
||||||
|
public static void setAlwaysNoHBaseJarMode(boolean mode) {
|
||||||
|
testingMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isHBaseJarPresent() {
|
||||||
|
if (testingMode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Class.forName("org.apache.hadoop.hbase.client.HTable");
|
||||||
|
} catch (ClassNotFoundException cnfe) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@
|
|||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
import com.cloudera.sqoop.SqoopOptions;
|
import com.cloudera.sqoop.SqoopOptions;
|
||||||
|
import com.cloudera.sqoop.hbase.HBaseUtil;
|
||||||
import com.cloudera.sqoop.hive.HiveTypes;
|
import com.cloudera.sqoop.hive.HiveTypes;
|
||||||
import com.cloudera.sqoop.lib.BlobRef;
|
import com.cloudera.sqoop.lib.BlobRef;
|
||||||
import com.cloudera.sqoop.lib.ClobRef;
|
import com.cloudera.sqoop.lib.ClobRef;
|
||||||
@ -369,7 +370,6 @@ protected void checkTableImportOptions(ImportJobContext context)
|
|||||||
+ tableName + ". Please specify one with --split-by or perform "
|
+ tableName + ". Please specify one with --split-by or perform "
|
||||||
+ "a sequential import with '-m 1'.");
|
+ "a sequential import with '-m 1'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,6 +387,10 @@ public void importTable(ImportJobContext context)
|
|||||||
ImportJobBase importer;
|
ImportJobBase importer;
|
||||||
if (opts.getHBaseTable() != null) {
|
if (opts.getHBaseTable() != null) {
|
||||||
// Import to HBase.
|
// Import to HBase.
|
||||||
|
if (!HBaseUtil.isHBaseJarPresent()) {
|
||||||
|
throw new ImportException("HBase jars are not present in "
|
||||||
|
+ "classpath, cannot import to HBase!");
|
||||||
|
}
|
||||||
importer = new HBaseImportJob(opts, context);
|
importer = new HBaseImportJob(opts, context);
|
||||||
} else {
|
} else {
|
||||||
// Import to HDFS.
|
// Import to HDFS.
|
||||||
@ -415,6 +419,10 @@ public void importQuery(ImportJobContext context)
|
|||||||
ImportJobBase importer;
|
ImportJobBase importer;
|
||||||
if (opts.getHBaseTable() != null) {
|
if (opts.getHBaseTable() != null) {
|
||||||
// Import to HBase.
|
// Import to HBase.
|
||||||
|
if (!HBaseUtil.isHBaseJarPresent()) {
|
||||||
|
throw new ImportException("HBase jars are not present in classpath,"
|
||||||
|
+ " cannot import to HBase!");
|
||||||
|
}
|
||||||
importer = new HBaseImportJob(opts, context);
|
importer = new HBaseImportJob(opts, context);
|
||||||
} else {
|
} else {
|
||||||
// Import to HDFS.
|
// Import to HDFS.
|
||||||
|
@ -93,4 +93,23 @@ public void testNulls() throws IOException {
|
|||||||
// This cell should not be placed in the results..
|
// This cell should not be placed in the results..
|
||||||
verifyHBaseCell("nullT", "0", "nullF", getColName(2), null);
|
verifyHBaseCell("nullT", "0", "nullF", getColName(2), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExitFailure() throws IOException {
|
||||||
|
String [] types = { "INT", "INT", "INT" };
|
||||||
|
String [] vals = { "0", "42", "43" };
|
||||||
|
createTableWithColTypes(types, vals);
|
||||||
|
|
||||||
|
String [] argv = getArgv(true, "NoHBaseT", "NoHBaseF", true, null);
|
||||||
|
try {
|
||||||
|
HBaseUtil.setAlwaysNoHBaseJarMode(true);
|
||||||
|
runImport(argv);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
HBaseUtil.setAlwaysNoHBaseJarMode(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
fail("should have gotten exception");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,4 +44,24 @@ public void testImportFromQuery() throws IOException {
|
|||||||
// This cell should not be placed in the results..
|
// This cell should not be placed in the results..
|
||||||
verifyHBaseCell("queryT", "0", "queryF", getColName(2), null);
|
verifyHBaseCell("queryT", "0", "queryF", getColName(2), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testExitFailure() throws IOException {
|
||||||
|
String [] types = { "INT", "INT", "INT" };
|
||||||
|
String [] vals = { "0", "42", "43" };
|
||||||
|
createTableWithColTypes(types, vals);
|
||||||
|
|
||||||
|
String [] argv = getArgv(true, "queryT", "queryF", true,
|
||||||
|
"SELECT " + getColName(0) + ", " + getColName(1) + " FROM "
|
||||||
|
+ getTableName() + " WHERE $CONDITIONS");
|
||||||
|
try {
|
||||||
|
HBaseUtil.setAlwaysNoHBaseJarMode(true);
|
||||||
|
runImport(argv);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
HBaseUtil.setAlwaysNoHBaseJarMode(false);
|
||||||
|
}
|
||||||
|
fail("should have gotten exception");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
44
src/test/com/cloudera/sqoop/hbase/TestHBaseUtil.java
Normal file
44
src/test/com/cloudera/sqoop/hbase/TestHBaseUtil.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.cloudera.sqoop.hbase;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This tests to verify that HBase is present (default when running test cases)
|
||||||
|
* and that when in fake not present mode, the method return false.
|
||||||
|
*/
|
||||||
|
public class TestHBaseUtil extends TestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHBasePresent() {
|
||||||
|
assertTrue(HBaseUtil.isHBaseJarPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHBaseNotPresent() {
|
||||||
|
HBaseUtil.setAlwaysNoHBaseJarMode(true);
|
||||||
|
boolean present = HBaseUtil.isHBaseJarPresent();
|
||||||
|
HBaseUtil.setAlwaysNoHBaseJarMode(false);
|
||||||
|
assertFalse(present);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user