sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject svn commit: r1221127 - in /incubator/sqoop/trunk/src/java/org/apache/sqoop: config/ConfigurationHelper.java metastore/JobStorageFactory.java tool/SqoopTool.java
Date Tue, 20 Dec 2011 07:27:12 GMT
Author: jarcec
Date: Tue Dec 20 07:27:12 2011
New Revision: 1221127

URL: http://svn.apache.org/viewvc?rev=1221127&view=rev
Log:
SQOOP-412. Create our own implementation of org.apache.hadoop.conf.Configuration.getInstances

(Eric Wadsworth via Jarek Jarcec Cecho)

Modified:
    incubator/sqoop/trunk/src/java/org/apache/sqoop/config/ConfigurationHelper.java
    incubator/sqoop/trunk/src/java/org/apache/sqoop/metastore/JobStorageFactory.java
    incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/SqoopTool.java

Modified: incubator/sqoop/trunk/src/java/org/apache/sqoop/config/ConfigurationHelper.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/trunk/src/java/org/apache/sqoop/config/ConfigurationHelper.java?rev=1221127&r1=1221126&r2=1221127&view=diff
==============================================================================
--- incubator/sqoop/trunk/src/java/org/apache/sqoop/config/ConfigurationHelper.java (original)
+++ incubator/sqoop/trunk/src/java/org/apache/sqoop/config/ConfigurationHelper.java Tue Dec
20 07:27:12 2011
@@ -19,6 +19,8 @@
 package org.apache.sqoop.config;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.mapreduce.Job;
@@ -26,6 +28,7 @@ import org.apache.hadoop.mapreduce.JobCo
 import org.apache.hadoop.util.GenericOptionsParser;
 
 import com.cloudera.sqoop.mapreduce.db.DBConfiguration;
+import org.apache.hadoop.util.ReflectionUtils;
 
 /**
  * This class provides static helper methods that allow access and manipulation
@@ -164,6 +167,30 @@ public final class ConfigurationHelper {
     return genericParser.getRemainingArgs();
   }
 
+  /**
+   * Get the value of the <code>name</code> property as a <code>List</code>
+   * of objects implementing the interface specified by <code>xface</code>.
+   *
+   * An exception is thrown if any of the classes does not exist, or if it does
+   * not implement the named interface.
+   *
+   * @param name the property name.
+   * @param xface the interface implemented by the classes named by
+   *        <code>name</code>.
+   * @return a <code>List</code> of objects implementing <code>xface</code>.
+   */
+  @SuppressWarnings("unchecked")
+  public static <U> List<U> getInstances(Configuration conf, String name, Class<U>
xface) {
+    List<U> ret = new ArrayList<U>();
+    Class<?>[] classes = conf.getClasses(name);
+    for (Class<?> cl: classes) {
+      if (!xface.isAssignableFrom(cl)) {
+        throw new RuntimeException(cl + " does not implement " + xface);
+      }
+      ret.add((U) ReflectionUtils.newInstance(cl, conf));
+    }
+    return ret;
+  }
 
   private ConfigurationHelper() {
     // Disable explicit object creation

Modified: incubator/sqoop/trunk/src/java/org/apache/sqoop/metastore/JobStorageFactory.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/trunk/src/java/org/apache/sqoop/metastore/JobStorageFactory.java?rev=1221127&r1=1221126&r2=1221127&view=diff
==============================================================================
--- incubator/sqoop/trunk/src/java/org/apache/sqoop/metastore/JobStorageFactory.java (original)
+++ incubator/sqoop/trunk/src/java/org/apache/sqoop/metastore/JobStorageFactory.java Tue Dec
20 07:27:12 2011
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.hadoop.conf.Configuration;
+import org.apache.sqoop.config.ConfigurationHelper;
 import com.cloudera.sqoop.metastore.JobStorage;
 
 /**
@@ -59,8 +60,8 @@ public class JobStorageFactory {
    * instance of it -- or null if no JobStorage instance is appropriate.
    */
   public JobStorage getJobStorage(Map<String, String> descriptor) {
-    List<JobStorage> storages = this.conf.getInstances(
-        AVAILABLE_STORAGES_KEY, JobStorage.class);
+    List<JobStorage> storages = ConfigurationHelper.getInstances(
+        conf, AVAILABLE_STORAGES_KEY, JobStorage.class);
     for (JobStorage stor : storages) {
       if (stor.canAccept(descriptor)) {
         return stor;

Modified: incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/SqoopTool.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/SqoopTool.java?rev=1221127&r1=1221126&r2=1221127&view=diff
==============================================================================
--- incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/SqoopTool.java (original)
+++ incubator/sqoop/trunk/src/java/org/apache/sqoop/tool/SqoopTool.java Tue Dec 20 07:27:12
2011
@@ -40,12 +40,12 @@ import org.apache.hadoop.conf.Configurat
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.ToolRunner;
 import org.apache.sqoop.util.ClassLoaderStack;
+import org.apache.sqoop.config.ConfigurationHelper;
 
 import com.cloudera.sqoop.SqoopOptions;
 import com.cloudera.sqoop.SqoopOptions.InvalidOptionsException;
 import com.cloudera.sqoop.cli.SqoopParser;
 import com.cloudera.sqoop.cli.ToolOptions;
-import com.cloudera.sqoop.config.ConfigurationHelper;
 import com.cloudera.sqoop.tool.ToolDesc;
 
 /**
@@ -136,8 +136,9 @@ public abstract class SqoopTool {
    */
   public static Configuration loadPlugins(Configuration conf) {
     conf = loadPluginsFromConfDir(conf);
-    List<ToolPlugin> plugins = conf.getInstances(TOOL_PLUGINS_KEY,
-        ToolPlugin.class);
+    List<ToolPlugin> plugins =
+        org.apache.sqoop.config.ConfigurationHelper.getInstances(
+            conf, TOOL_PLUGINS_KEY, ToolPlugin.class);
     for (ToolPlugin plugin : plugins) {
       LOG.debug("Loading plugin: " + plugin.getClass().getName());
       List<ToolDesc> descriptions = plugin.getTools();



Mime
View raw message