From ffe137becc524954183b5f68b385f9aaf58927a7 Mon Sep 17 00:00:00 2001
From: Todd Lipcon <todd@cloudera.com>
Date: Mon, 14 Sep 2009 23:29:06 -0700
Subject: [PATCH] MAPREDUCE-461 (incomplete on trunk). Add plugin support to JobTracker

(Relies on HADOOP-5640)
---
 src/mapred/mapred-default.xml                      |    7 +++++
 .../org/apache/hadoop/mapred/JobInProgress.java    |    2 +-
 .../org/apache/hadoop/mapred/JobTracker.java       |   15 +++++++++-
 .../org/apache/hadoop/mapred/JobTrackerPlugin.java |   29 ++++++++++++++++++++
 4 files changed, 50 insertions(+), 3 deletions(-)
 create mode 100644 src/mapred/org/apache/hadoop/mapred/JobTrackerPlugin.java

diff --git a/src/mapred/mapred-default.xml b/src/mapred/mapred-default.xml
index 259ee03..1f0de86 100644
--- a/src/mapred/mapred-default.xml
+++ b/src/mapred/mapred-default.xml
@@ -321,6 +321,13 @@
 </property>
 
 <property>
+  <name>mapred.jobtracker.plugins</name>
+  <value></value>
+  <description>Comma-separated list of jobtracker plug-ins to be activated.
+  </description>
+</property>
+
+<property>
   <name>mapred.child.java.opts</name>
   <value>-Xmx200m</value>
   <description>Java opts for the task tracker child processes.  
diff --git a/src/mapred/org/apache/hadoop/mapred/JobInProgress.java b/src/mapred/org/apache/hadoop/mapred/JobInProgress.java
index 17139f0..85310ee 100644
--- a/src/mapred/org/apache/hadoop/mapred/JobInProgress.java
+++ b/src/mapred/org/apache/hadoop/mapred/JobInProgress.java
@@ -53,7 +53,7 @@ import org.apache.hadoop.util.StringUtils;
  * doing bookkeeping of its Tasks.
  * ***********************************************************
  */
-class JobInProgress {
+public class JobInProgress {
   /**
    * Used when the a kill is issued to a job which is initializing.
    */
diff --git a/src/mapred/org/apache/hadoop/mapred/JobTracker.java b/src/mapred/org/apache/hadoop/mapred/JobTracker.java
index a74c6e4..03ae8f8 100644
--- a/src/mapred/org/apache/hadoop/mapred/JobTracker.java
+++ b/src/mapred/org/apache/hadoop/mapred/JobTracker.java
@@ -77,6 +77,7 @@ import org.apache.hadoop.security.authorize.PolicyProvider;
 import org.apache.hadoop.security.authorize.RefreshAuthorizationPolicyProtocol;
 import org.apache.hadoop.security.authorize.ServiceAuthorizationManager;
 import org.apache.hadoop.util.HostsFileReader;
+import org.apache.hadoop.util.PluginDispatcher;
 import org.apache.hadoop.util.ReflectionUtils;
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.util.VersionInfo;
@@ -155,6 +156,8 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
   private int nextJobId = 1;
 
   public static final Log LOG = LogFactory.getLog(JobTracker.class);
+  
+  private PluginDispatcher<JobTrackerPlugin> pluginDispatcher;
     
   /**
    * Start the JobTracker with given configuration.
@@ -198,7 +201,7 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
     }
     if (result != null) {
       JobEndNotifier.startNotifier();
-    }
+    }    
     return result;
   }
 
@@ -1733,6 +1736,10 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
 
     //initializes the job status store
     completedJobStatusStore = new CompletedJobStatusStore(conf);
+    
+    pluginDispatcher = PluginDispatcher.createFromConfiguration(
+            conf, "mapred.jobtracker.plugins", JobTrackerPlugin.class);
+    pluginDispatcher.dispatchStart(this);
   }
 
   private static SimpleDateFormat getDateFormat() {
@@ -1799,7 +1806,7 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
   }
 
   public static InetSocketAddress getAddress(Configuration conf) {
-    String jobTrackerStr =
+    String jobTrackerStr = 
       conf.get("mapred.job.tracker", "localhost:8012");
     return NetUtils.createSocketAddr(jobTrackerStr);
   }
@@ -1857,6 +1864,10 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
   }
 
   void close() throws IOException {
+    if (this.pluginDispatcher != null) {
+        LOG.info("Stopping pluginDispatcher");
+        pluginDispatcher.dispatchStop();
+      }
     if (this.infoServer != null) {
       LOG.info("Stopping infoServer");
       try {
diff --git a/src/mapred/org/apache/hadoop/mapred/JobTrackerPlugin.java b/src/mapred/org/apache/hadoop/mapred/JobTrackerPlugin.java
new file mode 100644
index 0000000..dd8c74c
--- /dev/null
+++ b/src/mapred/org/apache/hadoop/mapred/JobTrackerPlugin.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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 org.apache.hadoop.mapred;
+
+import org.apache.hadoop.util.ServicePlugin;
+
+/**
+ * JobTrackerPlugins are found in mapred.jobtracker.plugins, and are started 
+ * and stopped by a PluginDispatcher during JobTracker start-up. 
+ */
+abstract public class JobTrackerPlugin implements ServicePlugin {
+  abstract public void start(Object service);
+  abstract public void stop();
+}
-- 
1.6.0.4

