sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kathl...@apache.org
Subject git commit: SQOOP-959: Use CredentialsUtil.fetchPasswordFromFile in BaseSqoopTool (Jarek Jarcec Cecho via Kathleen Ting)
Date Thu, 21 Mar 2013 16:27:22 GMT
Updated Branches:
  refs/heads/trunk f2ba7eaae -> e93ec9f39


SQOOP-959: Use CredentialsUtil.fetchPasswordFromFile in BaseSqoopTool
(Jarek Jarcec Cecho via Kathleen Ting)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/e93ec9f3
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/e93ec9f3
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/e93ec9f3

Branch: refs/heads/trunk
Commit: e93ec9f39f9c0893e58f61f17fa031af4b54c35e
Parents: f2ba7ea
Author: Kate <kathleen@apache.org>
Authored: Thu Mar 21 04:27:44 2013 -0400
Committer: Kate <kathleen@apache.org>
Committed: Thu Mar 21 04:27:44 2013 -0400

----------------------------------------------------------------------
 src/java/org/apache/sqoop/tool/BaseSqoopTool.java |   44 ++--------------
 1 files changed, 4 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/e93ec9f3/src/java/org/apache/sqoop/tool/BaseSqoopTool.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/sqoop/tool/BaseSqoopTool.java b/src/java/org/apache/sqoop/tool/BaseSqoopTool.java
index e687137..9874bae 100644
--- a/src/java/org/apache/sqoop/tool/BaseSqoopTool.java
+++ b/src/java/org/apache/sqoop/tool/BaseSqoopTool.java
@@ -22,7 +22,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.StringWriter;
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Properties;
@@ -31,11 +30,8 @@ import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.util.StringUtils;
 
 import com.cloudera.sqoop.ConnFactory;
@@ -47,6 +43,7 @@ import com.cloudera.sqoop.cli.ToolOptions;
 import com.cloudera.sqoop.lib.DelimiterSet;
 import com.cloudera.sqoop.manager.ConnManager;
 import com.cloudera.sqoop.metastore.JobData;
+import org.apache.sqoop.util.CredentialsUtil;
 import org.apache.sqoop.util.LoggingUtils;
 
 /**
@@ -447,7 +444,7 @@ public abstract class BaseSqoopTool extends com.cloudera.sqoop.tool.SqoopTool
{
         .create());
     hiveOpts.addOption(OptionBuilder
         .withDescription("Drop Hive record \\0x01 and row delimiters "
-            + "(\\n\\r) from imported string fields")
+          + "(\\n\\r) from imported string fields")
         .withLongOpt(HIVE_DROP_DELIMS_ARG)
         .create());
     hiveOpts.addOption(OptionBuilder
@@ -510,7 +507,7 @@ public abstract class BaseSqoopTool extends com.cloudera.sqoop.tool.SqoopTool
{
         .create());
     formatOpts.addOption(OptionBuilder
         .withDescription("Uses MySQL's default delimiter set: "
-        + "fields: ,  lines: \\n  escaped-by: \\  optionally-enclosed-by: '")
+          + "fields: ,  lines: \\n  escaped-by: \\  optionally-enclosed-by: '")
         .withLongOpt(MYSQL_DELIMITERS_ARG)
         .create());
 
@@ -781,7 +778,7 @@ public abstract class BaseSqoopTool extends com.cloudera.sqoop.tool.SqoopTool
{
       try {
         out.setPasswordFilePath(in.getOptionValue(PASSWORD_PATH_ARG));
         // apply password from file into password in options
-        out.setPassword(fetchPasswordFromFile(out));
+        out.setPassword(CredentialsUtil.fetchPasswordFromFile(out));
       } catch (IOException ex) {
         LOG.warn("Failed to load connection parameter file", ex);
         throw new InvalidOptionsException(
@@ -791,39 +788,6 @@ public abstract class BaseSqoopTool extends com.cloudera.sqoop.tool.SqoopTool
{
     }
   }
 
-  private String fetchPasswordFromFile(SqoopOptions options)
-    throws IOException {
-    String passwordFilePath = options.getPasswordFilePath();
-    if (passwordFilePath == null) {
-      return options.getPassword();
-    }
-
-    LOG.debug("Fetching password from specified path: " + passwordFilePath);
-    FileSystem fs = FileSystem.get(options.getConf());
-    Path path = new Path(passwordFilePath);
-
-    if (!fs.exists(path)) {
-      throw new IOException("The password file does not exist! "
-        + passwordFilePath);
-    }
-
-    if (!fs.isFile(path)) {
-      throw new IOException("The password file cannot be a directory! "
-        + passwordFilePath);
-    }
-
-    InputStream is = fs.open(path);
-    StringWriter writer = new StringWriter();
-    try {
-      IOUtils.copy(is, writer);
-      return writer.toString();
-    } finally {
-      IOUtils.closeQuietly(is);
-      IOUtils.closeQuietly(writer);
-      fs.close();
-    }
-  }
-
   protected void applyHiveOptions(CommandLine in, SqoopOptions out)
       throws InvalidOptionsException {
 


Mime
View raw message