Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fix for NUTCH-209. Nutch now supplies all code to remote MapReduce daemons through a job jar file. So Hadoop daemons no longer need to be restarted when Nutch code changes.

Douglass Cuttingd6b9755fa599
diff --git a/bin/nutch b/bin/nutch
index aa5eef44f..5cfc30faa 100755
--- a/bin/nutch
+++ b/bin/nutch
@@ -82,13 +82,13 @@ fi
CLASSPATH=${NUTCH_CONF_DIR:=$NUTCH_HOME/conf}
CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
-# for developers, add Nutch classes to CLASSPATH
-if [ -d "$NUTCH_HOME/build/classes" ]; then
- CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/classes
-fi
+# for developers, add plugins, job & test code to CLASSPATH
if [ -d "$NUTCH_HOME/build/plugins" ]; then
CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build
fi
+for f in $NUTCH_HOME/build/nutch-*.job; do
+ CLASSPATH=${CLASSPATH}:$f;
+done
if [ -d "$NUTCH_HOME/build/test/classes" ]; then
CLASSPATH=${CLASSPATH}:$NUTCH_HOME/build/test/classes
fi
@@ -96,14 +96,14 @@ fi
# so that filenames w/ spaces are handled correctly in loops below
IFS=
-# for releases, add Nutch jar to CLASSPATH
-for f in $NUTCH_HOME/nutch-*.jar; do
+# for releases, add Nutch job to CLASSPATH
+for f in $NUTCH_HOME/nutch-*.job; do
CLASSPATH=${CLASSPATH}:$f;
done
# add plugins to classpath
if [ -d "$NUTCH_HOME/plugins" ]; then
- CLASSPATH=${CLASSPATH}:$NUTCH_HOME
+ CLASSPATH=${NUTCH_HOME}:${CLASSPATH}
fi
# add libs to CLASSPATH
diff --git a/build.xml b/build.xml
index 8e28765e8..7626841c0 100644
--- a/build.xml
+++ b/build.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
-<project name="Nutch" default="compile">
+<project name="Nutch" default="job">
<!-- Load all the default properties, and any the user wants -->
<!-- to contribute (without having to type -D or edit this file -->
@@ -100,7 +100,6 @@
<target name="dynamic" depends="generate-src, compile">
</target>
-
<!-- ================================================================== -->
<!-- Make nutch.jar -->
<!-- ================================================================== -->
@@ -118,6 +117,21 @@
</jar>
</target>
+ <!-- ================================================================== -->
+ <!-- Make job jar -->
+ <!-- ================================================================== -->
+ <!-- -->
+ <!-- ================================================================== -->
+ <target name="job" depends="compile">
+ <jar jarfile="${build.dir}/${final.name}.job">
+ <zipfileset dir="${build.classes}"/>
+ <zipfileset dir="${conf.dir}" excludes="*.template"/>
+ <zipfileset dir="${lib.dir}" prefix="lib"
+ includes="**/*.jar" excludes="hadoop-*.jar"/>
+ <zipfileset dir="${build.plugins}" prefix="plugins"/>
+ </jar>
+ </target>
+
<!-- ================================================================== -->
<!-- Make nutch.war -->
<!-- ================================================================== -->
@@ -385,7 +399,7 @@
<!-- ================================================================== -->
<!-- -->
<!-- ================================================================== -->
- <target name="package" depends="jar, war, javadoc">
+ <target name="package" depends="jar, job, war, javadoc">
<mkdir dir="${dist.dir}"/>
<mkdir dir="${dist.dir}/lib"/>
<mkdir dir="${dist.dir}/bin"/>
@@ -402,7 +416,7 @@
</copy>
<copy file="${build.dir}/${final.name}.jar" todir="${dist.dir}"/>
-
+ <copy file="${build.dir}/${final.name}.job" todir="${dist.dir}"/>
<copy file="${build.dir}/${final.name}.war" todir="${dist.dir}"/>
<copy todir="${dist.dir}/bin">
diff --git a/lib/hadoop-0.1-dev.jar b/lib/hadoop-0.1-dev.jar
index a7c43ca08..29ad88230 100644
Binary files a/lib/hadoop-0.1-dev.jar and b/lib/hadoop-0.1-dev.jar differ
diff --git a/src/java/org/apache/nutch/crawl/Crawl.java b/src/java/org/apache/nutch/crawl/Crawl.java
index 58e3035bd..47abd5a4b 100644
--- a/src/java/org/apache/nutch/crawl/Crawl.java
+++ b/src/java/org/apache/nutch/crawl/Crawl.java
@@ -31,6 +31,7 @@ import org.apache.nutch.indexer.DeleteDuplicates;
import org.apache.nutch.indexer.IndexMerger;
import org.apache.nutch.indexer.Indexer;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
public class Crawl {
public static final Logger LOG =
@@ -52,7 +53,7 @@ public class Crawl {
Configuration conf = NutchConfiguration.create();
conf.addDefaultResource("crawl-tool.xml");
- JobConf job = new JobConf(conf);
+ JobConf job = new NutchJob(conf);
File rootUrlDir = null;
File dir = new File("crawl-" + getDate());
diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.java
index c03066bb6..2bce1a98c 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDb.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.util.LogFormatter;
import org.apache.hadoop.mapred.*;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
/** This class takes a flat file of URLs and adds them to the of pages to be
* crawled. Useful for bootstrapping the system. */
@@ -61,7 +62,7 @@ public class CrawlDb extends Configured {
new File(crawlDb,
Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));
- JobConf job = new JobConf(config);
+ JobConf job = new NutchJob(config);
job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));
job.setInputFormat(SequenceFileInputFormat.class);
diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReader.java b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
index 038c7f5ba..a4fa9009b 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDbReader.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
@@ -44,6 +44,8 @@ import org.apache.hadoop.util.LogFormatter;
import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
+
/**
* Read utility for the CrawlDB.
*
@@ -137,7 +139,7 @@ public class CrawlDbReader {
LOG.info("CrawlDb statistics start: " + crawlDb);
File tmpFolder = new File(crawlDb, "stat_tmp" + System.currentTimeMillis());
- JobConf job = new JobConf(config);
+ JobConf job = new NutchJob(config);
job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));
job.setInputFormat(SequenceFileInputFormat.class);
@@ -224,7 +226,7 @@ public class CrawlDbReader {
LOG.info("CrawlDb db: " + crawlDb);
File outFolder = new File(output);
- JobConf job = new JobConf(config);
+ JobConf job = new NutchJob(config);
job.addInputDir(new File(crawlDb, CrawlDatum.DB_DIR_NAME));
job.setInputFormat(SequenceFileInputFormat.class);
diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.java
index 4eb2b0a03..19ce50ac4 100644
--- a/src/java/org/apache/nutch/crawl/Generator.java
+++ b/src/java/org/apache/nutch/crawl/Generator.java
@@ -29,6 +29,7 @@ import org.apache.hadoop.mapred.*;
import org.apache.hadoop.mapred.lib.*;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
/** Generates a subset of a crawl db to fetch. */
public class Generator extends Configured {
@@ -175,7 +176,7 @@ public class Generator extends Configured {
// map to inverted subset due for fetch, sort by link count
LOG.info("Generator: Selecting most-linked urls due for fetch.");
- JobConf job = new JobConf(getConf());
+ JobConf job = new NutchJob(getConf());
if (numLists == -1) { // for politeness make
numLists = job.getNumMapTasks(); // a partition per fetch task
@@ -201,7 +202,7 @@ public class Generator extends Configured {
// invert again, paritition by host, sort by url hash
LOG.info("Generator: Partitioning selected urls by host, for politeness.");
- job = new JobConf(getConf());
+ job = new NutchJob(getConf());
job.setInt("partition.url.by.host.seed", new Random().nextInt());
diff --git a/src/java/org/apache/nutch/crawl/Injector.java b/src/java/org/apache/nutch/crawl/Injector.java
index 9a09f7902..673017c67 100644
--- a/src/java/org/apache/nutch/crawl/Injector.java
+++ b/src/java/org/apache/nutch/crawl/Injector.java
@@ -28,6 +28,7 @@ import org.apache.hadoop.mapred.*;
import org.apache.nutch.net.*;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
/** This class takes a flat file of URLs and adds them to the of pages to be
* crawled. Useful for bootstrapping the system. */
@@ -101,7 +102,7 @@ public class Injector extends Configured {
// map text input file to a <url,CrawlDatum> file
LOG.info("Injector: Converting injected urls to crawl db entries.");
- JobConf sortJob = new JobConf(getConf());
+ JobConf sortJob = new NutchJob(getConf());
sortJob.setInputDir(urlDir);
sortJob.setMapperClass(InjectMapper.class);
sortJob.setReducerClass(InjectReducer.class);
diff --git a/src/java/org/apache/nutch/crawl/LinkDb.java b/src/java/org/apache/nutch/crawl/LinkDb.java
index e31b8291d..86b4e4015 100644
--- a/src/java/org/apache/nutch/crawl/LinkDb.java
+++ b/src/java/org/apache/nutch/crawl/LinkDb.java
@@ -29,6 +29,7 @@ import org.apache.hadoop.mapred.*;
import org.apache.nutch.parse.*;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
/** Maintains an inverted link map, listing incoming links for each url. */
public class LinkDb extends Configured implements Mapper, Reducer {
@@ -155,7 +156,7 @@ public class LinkDb extends Configured implements Mapper, Reducer {
new File(linkDb,
Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));
- JobConf job = new JobConf(config);
+ JobConf job = new NutchJob(config);
job.setInputFormat(SequenceFileInputFormat.class);
job.setInputKeyClass(UTF8.class);
diff --git a/src/java/org/apache/nutch/crawl/LinkDbReader.java b/src/java/org/apache/nutch/crawl/LinkDbReader.java
index e09eb8521..4b03a5c92 100644
--- a/src/java/org/apache/nutch/crawl/LinkDbReader.java
+++ b/src/java/org/apache/nutch/crawl/LinkDbReader.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.util.LogFormatter;
import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
import java.util.logging.Logger;
@@ -72,7 +73,7 @@ public class LinkDbReader {
LOG.info("LinkDb db: " + linkdb);
File outFolder = new File(output);
- JobConf job = new JobConf(config);
+ JobConf job = new NutchJob(config);
job.addInputDir(new File(linkdb, LinkDb.CURRENT_NAME));
job.setInputFormat(SequenceFileInputFormat.class);
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index 7ccc610c3..a1ff63488 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -341,7 +341,7 @@ public class Fetcher extends Configured implements MapRunnable {
LOG.info("Fetcher: starting");
LOG.info("Fetcher: segment: " + segment);
- JobConf job = new JobConf(getConf());
+ JobConf job = new NutchJob(getConf());
job.setInt("fetcher.threads.fetch", threads);
job.set(SEGMENT_NAME_KEY, segment.getName());
diff --git a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
index 4f91076d7..9c9b7adf7 100644
--- a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
+++ b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
@@ -27,6 +27,7 @@ import org.apache.hadoop.util.LogFormatter;
import org.apache.hadoop.mapred.*;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.document.Document;
@@ -296,7 +297,7 @@ public class DeleteDuplicates extends Configured
new File("dedup-hash-"+
Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));
- JobConf job = new JobConf(getConf());
+ JobConf job = new NutchJob(getConf());
for (int i = 0; i < indexDirs.length; i++) {
LOG.info("Dedup: adding indexes in: " + indexDirs[i]);
@@ -318,7 +319,7 @@ public class DeleteDuplicates extends Configured
JobClient.runJob(job);
- job = new JobConf(getConf());
+ job = new NutchJob(getConf());
job.addInputDir(hashDir);
diff --git a/src/java/org/apache/nutch/indexer/Indexer.java b/src/java/org/apache/nutch/indexer/Indexer.java
index bcd0059d8..c4937131d 100644
--- a/src/java/org/apache/nutch/indexer/Indexer.java
+++ b/src/java/org/apache/nutch/indexer/Indexer.java
@@ -31,6 +31,7 @@ import org.apache.nutch.protocol.*;
import org.apache.nutch.analysis.*;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
import org.apache.nutch.crawl.CrawlDatum;
import org.apache.nutch.crawl.Inlinks;
@@ -240,7 +241,7 @@ public class Indexer extends Configured implements Reducer {
LOG.info("Indexer: starting");
LOG.info("Indexer: linkdb: " + linkDb);
- JobConf job = new JobConf(getConf());
+ JobConf job = new NutchJob(getConf());
for (int i = 0; i < segments.length; i++) {
LOG.info("Indexer: adding segment: " + segments[i]);
diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.java
index 606fa9dc1..76dce6a9f 100644
--- a/src/java/org/apache/nutch/parse/ParseSegment.java
+++ b/src/java/org/apache/nutch/parse/ParseSegment.java
@@ -85,7 +85,7 @@ public class ParseSegment extends Configured implements Mapper, Reducer {
LOG.info("Parse: starting");
LOG.info("Parse: segment: " + segment);
- JobConf job = new JobConf(getConf());
+ JobConf job = new NutchJob(getConf());
job.setInputDir(new File(segment, Content.DIR_NAME));
job.setInputFormat(SequenceFileInputFormat.class);
diff --git a/src/java/org/apache/nutch/segment/SegmentReader.java b/src/java/org/apache/nutch/segment/SegmentReader.java
index a119a9231..ba320e1b8 100644
--- a/src/java/org/apache/nutch/segment/SegmentReader.java
+++ b/src/java/org/apache/nutch/segment/SegmentReader.java
@@ -50,6 +50,7 @@ import org.apache.hadoop.util.LogFormatter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.nutch.util.NutchConfiguration;
+import org.apache.nutch.util.NutchJob;
/** Dump the content of a segment. */
public class SegmentReader extends Configured implements Reducer {
@@ -149,7 +150,7 @@ public class SegmentReader extends Configured implements Reducer {
public void reader(File segment) throws IOException {
LOG.info("Reader: segment: " + segment);
- JobConf job = new JobConf(getConf());
+ JobConf job = new NutchJob(getConf());
job.addInputDir(new File(segment, CrawlDatum.GENERATE_DIR_NAME));
job.addInputDir(new File(segment, CrawlDatum.FETCH_DIR_NAME));
diff --git a/src/java/org/apache/nutch/util/NutchConfiguration.java b/src/java/org/apache/nutch/util/NutchConfiguration.java
index 4f1f48a63..33e47675b 100644
--- a/src/java/org/apache/nutch/util/NutchConfiguration.java
+++ b/src/java/org/apache/nutch/util/NutchConfiguration.java
@@ -22,6 +22,7 @@ import org.apache.hadoop.io.WritableName;
/** Utility to create Hadoop {@link Configuration}s that include Nutch-specific
* resources. */
public class NutchConfiguration {
+ private NutchConfiguration() {} // singleton
// for back-compatibility, add old aliases for these Writable classes
// this may be removed after the 0.8 release
diff --git a/src/java/org/apache/nutch/util/NutchJob.java b/src/java/org/apache/nutch/util/NutchJob.java
new file mode 100644
index 000000000..4d3a4d7f6
--- /dev/null
+++ b/src/java/org/apache/nutch/util/NutchJob.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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.nutch.util;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapred.JobConf;
+
+/** A {@link JobConf} for Nutch jobs. */
+public class NutchJob extends JobConf {
+
+ public NutchJob(Configuration conf) {
+ super(conf, NutchJob.class);
+ }
+
+}
+