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 name property as a List + * of objects implementing the interface specified by xface. + * + * 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 + * name. + * @return a List of objects implementing xface. + */ + @SuppressWarnings("unchecked") + public static List getInstances(Configuration conf, String name, Class xface) { + List ret = new ArrayList(); + 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 descriptor) { - List storages = this.conf.getInstances( - AVAILABLE_STORAGES_KEY, JobStorage.class); + List 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 plugins = conf.getInstances(TOOL_PLUGINS_KEY, - ToolPlugin.class); + List 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 descriptions = plugin.getTools();