Permalink
Browse files

Remove JobContext class dependency

Hadoop v2.0.4 changed JobContext from a class to an interface, which
means that a rubydoop.jar compiled against an old version cannot be
used in the new version if any methods on this class is executed.

See #9

This resolves the issue by duplicating the code in the mapper and
the reducer, as Mapper.Context and Reducer.Context are still classes.
  • Loading branch information...
1 parent 3482a9b commit 1db2054246fced0cba0f48ef330adf1b0a8c2f85 @grddev grddev committed Jun 5, 2013
Showing with 15 additions and 22 deletions.
  1. +5 −16 ext/src/rubydoop/InstanceContainer.java
  2. +5 −3 ext/src/rubydoop/MapperProxy.java
  3. +5 −3 ext/src/rubydoop/ReducerProxy.java
@@ -1,7 +1,6 @@
package rubydoop;
-import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.conf.Configuration;
import org.jruby.CompatVersion;
@@ -36,13 +35,6 @@ public static ScriptingContainer getRuntime() {
return globalRuntime;
}
- public void setup(JobContext ctx) {
- setup(ctx.getConfiguration());
- if (respondsTo("setup")) {
- callMethod("setup", ctx);
- }
- }
-
public void setup(Configuration conf) {
String jobConfigScript = conf.get(JOB_SETUP_SCRIPT_KEY);
try {
@@ -54,13 +46,6 @@ public void setup(Configuration conf) {
throw new RubydoopConfigurationException(String.format("Cannot create instance: \"%s\"", e.getMessage()), e);
}
}
-
- public void cleanup(JobContext ctx) {
- if (respondsTo("cleanup")) {
- callMethod("cleanup", ctx);
- }
- cleanup(ctx.getConfiguration());
- }
public void cleanup(Configuration conf) {
instance = null;
@@ -81,4 +66,8 @@ public Object callMethod(String name) {
public Object callMethod(String name, Object... args) {
return getRuntime().callMethod(instance, name, args);
}
-}
+
+ public Object maybeCallMethod(String name, Object... args) {
+ return respondsTo(name) ? callMethod(name, args) : null;
+ }
+}
@@ -22,11 +22,13 @@ protected void setup(Context ctx) throws IOException, InterruptedException {
if (instance == null) {
instance = new InstanceContainer("create_mapper");
}
- instance.setup(ctx);
+ instance.setup(ctx.getConfiguration());
+ instance.maybeCallMethod("setup", ctx);
}
protected void cleanup(Context ctx) throws IOException, InterruptedException {
super.cleanup(ctx);
- instance.cleanup(ctx);
+ instance.maybeCallMethod("cleanup", ctx);
+ instance.cleanup(ctx.getConfiguration());
}
-}
+}
@@ -31,11 +31,13 @@ protected void setup(Context ctx) throws IOException, InterruptedException {
if (instance == null) {
instance = new InstanceContainer(factoryMethodName);
}
- instance.setup(ctx);
+ instance.setup(ctx.getConfiguration());
+ instance.maybeCallMethod("setup", ctx);
}
protected void cleanup(Context ctx) throws IOException, InterruptedException {
super.cleanup(ctx);
- instance.cleanup(ctx);
+ instance.cleanup(ctx.getConfiguration());
+ instance.maybeCallMethod("cleanup", ctx);
}
-}
+}

0 comments on commit 1db2054

Please sign in to comment.