Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2569 ClassNotFoundException when running in (pseudo-)distributed mode - remove duplicate calls of setJarByClass(...) - fix unit test for CrawlDbFilter - fix webgraph package (also includes fix for NUTCH-2518)

Sebastian Nagelfb47207c3b11
diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.java
index a3ef91c89..9c22ee228 100644
--- a/src/java/org/apache/nutch/crawl/Generator.java
+++ b/src/java/org/apache/nutch/crawl/Generator.java
@@ -848,10 +848,9 @@ public class Generator extends NutchTool implements Tool {
}
FileInputFormat.addInputPath(job, new Path(dbDir, CrawlDb.CURRENT_NAME));
job.setInputFormatClass(SequenceFileInputFormat.class);
- job.setJarByClass(CrawlDbUpdater.class);
job.setMapperClass(CrawlDbUpdater.CrawlDbUpdateMapper.class);
job.setReducerClass(CrawlDbUpdater.CrawlDbUpdateReducer.class);
- //job.setJarByClass(CrawlDbUpdater.class);
+ job.setJarByClass(CrawlDbUpdater.class);
job.setOutputFormatClass(MapFileOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(CrawlDatum.class);
diff --git a/src/java/org/apache/nutch/hostdb/ReadHostDb.java b/src/java/org/apache/nutch/hostdb/ReadHostDb.java
index 81145d312..360b11932 100644
--- a/src/java/org/apache/nutch/hostdb/ReadHostDb.java
+++ b/src/java/org/apache/nutch/hostdb/ReadHostDb.java
@@ -37,7 +37,6 @@ import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.mapreduce.Mapper;
-import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
@@ -186,7 +185,6 @@ public class ReadHostDb extends Configured implements Tool {
FileInputFormat.addInputPath(job, new Path(hostDb, "current"));
FileOutputFormat.setOutputPath(job, output);
- job.setJarByClass(ReadHostDb.class);
job.setMapperClass(ReadHostDbMapper.class);
job.setInputFormatClass(SequenceFileInputFormat.class);
diff --git a/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java b/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java
index e134441dd..bde24cc33 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java
@@ -88,7 +88,6 @@ public class LinkDumper extends Configured implements Tool {
// open the readers for the linkdump directory
Configuration conf = NutchConfiguration.create();
Path webGraphDb = new Path(args[0]);
- FileSystem fs = webGraphDb.getFileSystem(conf);
String url = args[1];
MapFile.Reader[] readers = MapFileOutputFormat.getReaders(new Path(
webGraphDb, DUMP_DIR), conf);
@@ -351,10 +350,17 @@ public class LinkDumper extends Configured implements Tool {
try {
LOG.info("LinkDumper: running inverter");
- int complete = inverter.waitForCompletion(true)?0:1;
+ boolean success = inverter.waitForCompletion(true);
+ if (!success) {
+ String message = "LinkDumper inverter job did not succeed, job status:"
+ + inverter.getStatus().getState() + ", reason: "
+ + inverter.getStatus().getFailureInfo();
+ LOG.error(message);
+ throw new RuntimeException(message);
+ }
LOG.info("LinkDumper: finished inverter");
} catch (IOException | InterruptedException | ClassNotFoundException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("LinkDumper inverter job failed:", e);
throw e;
}
@@ -362,6 +368,7 @@ public class LinkDumper extends Configured implements Tool {
Job merger = NutchJob.getInstance(conf);
merger.setJobName("LinkDumper: merger");
FileInputFormat.addInputPath(merger, tempInverted);
+ merger.setJarByClass(Merger.class);
merger.setInputFormatClass(SequenceFileInputFormat.class);
merger.setReducerClass(Merger.class);
merger.setMapOutputKeyClass(Text.class);
@@ -373,10 +380,17 @@ public class LinkDumper extends Configured implements Tool {
try {
LOG.info("LinkDumper: running merger");
- int complete = merger.waitForCompletion(true)?0:1;
+ boolean success = merger.waitForCompletion(true);
+ if (!success) {
+ String message = "LinkDumper merger job did not succeed, job status:"
+ + merger.getStatus().getState() + ", reason: "
+ + merger.getStatus().getFailureInfo();
+ LOG.error(message);
+ throw new RuntimeException(message);
+ }
LOG.info("LinkDumper: finished merger");
} catch (IOException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("LinkDumper merger job failed:", e);
throw e;
}
diff --git a/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java b/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java
index 6b964eb0e..682992756 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java
@@ -111,9 +111,16 @@ public class LinkRank extends Configured implements Tool {
// run the counter job, outputs to a single reduce task and file
LOG.info("Starting link counter job");
try {
- int complete = counter.waitForCompletion(true)?0:1;
+ boolean success = counter.waitForCompletion(true);
+ if (!success) {
+ String message = "Link counter job did not succeed, job status:"
+ + counter.getStatus().getState() + ", reason: "
+ + counter.getStatus().getFailureInfo();
+ LOG.error(message);
+ throw new RuntimeException(message);
+ }
} catch (IOException | InterruptedException | ClassNotFoundException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("Link counter job failed:", e);
throw e;
}
@@ -122,7 +129,7 @@ public class LinkRank extends Configured implements Tool {
// read the first (and only) line from the file which should be the
// number of links in the web graph
LOG.info("Reading numlinks temp file");
- FSDataInputStream readLinks = fs.open(new Path(numLinksPath, "part-00000"));
+ FSDataInputStream readLinks = fs.open(new Path(numLinksPath, "part-r-00000"));
BufferedReader buffer = new BufferedReader(new InputStreamReader(readLinks));
String numLinksLine = buffer.readLine();
readLinks.close();
@@ -161,6 +168,7 @@ public class LinkRank extends Configured implements Tool {
initializer.setJobName("LinkAnalysis Initializer");
FileInputFormat.addInputPath(initializer, nodeDb);
FileOutputFormat.setOutputPath(initializer, output);
+ initializer.setJarByClass(Initializer.class);
initializer.setInputFormatClass(SequenceFileInputFormat.class);
initializer.setMapperClass(Initializer.class);
initializer.setMapOutputKeyClass(Text.class);
@@ -174,9 +182,16 @@ public class LinkRank extends Configured implements Tool {
// run the initializer
LOG.info("Starting initialization job");
try {
- int complete = initializer.waitForCompletion(true)?0:1;
+ boolean success = initializer.waitForCompletion(true);
+ if (!success) {
+ String message = "Initialization job did not succeed, job status:"
+ + initializer.getStatus().getState() + ", reason: "
+ + initializer.getStatus().getFailureInfo();
+ LOG.error(message);
+ throw new RuntimeException(message);
+ }
} catch (IOException | InterruptedException | ClassNotFoundException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("Initialization job failed:", e);
throw e;
}
LOG.info("Finished initialization job.");
@@ -221,9 +236,16 @@ public class LinkRank extends Configured implements Tool {
// run the inverter job
LOG.info("Starting inverter job");
try {
- int complete = inverter.waitForCompletion(true)?0:1;
+ boolean success = inverter.waitForCompletion(true);
+ if (!success) {
+ String message = "Inverter job did not succeed, job status:"
+ + inverter.getStatus().getState() + ", reason: "
+ + inverter.getStatus().getFailureInfo();
+ LOG.error(message);
+ throw new RuntimeException(message);
+ }
} catch (IOException | InterruptedException | ClassNotFoundException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("Inverter job failed:", e);
throw e;
}
LOG.info("Finished inverter job.");
@@ -278,9 +300,16 @@ public class LinkRank extends Configured implements Tool {
LOG.info("Starting analysis job");
try {
- int complete = analyzer.waitForCompletion(true)?0:1;
+ boolean success = analyzer.waitForCompletion(true);
+ if (!success) {
+ String message = "Analysis job did not succeed, job status:"
+ + analyzer.getStatus().getState() + ", reason: "
+ + analyzer.getStatus().getFailureInfo();
+ LOG.error(message);
+ throw new RuntimeException(message);
+ }
} catch (IOException | InterruptedException | ClassNotFoundException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("Analysis job failed:", e);
throw e;
}
LOG.info("Finished analysis job.");
@@ -331,8 +360,6 @@ public class LinkRank extends Configured implements Tool {
}
}
- public void close() {
- }
}
private static class Initializer extends Mapper<Text, Node, Text, Node> {
@@ -372,11 +399,8 @@ public class LinkRank extends Configured implements Tool {
public static class InvertMapper extends
Mapper<Text, Writable, Text, ObjectWritable> {
- private Configuration conf;
-
@Override
public void setup(Mapper<Text, Writable, Text, ObjectWritable>.Context context) {
- conf = context.getConfiguration();
}
@Override
@@ -502,19 +526,14 @@ public class LinkRank extends Configured implements Tool {
* needed values for analysis.
*/
@Override
- public void setup(Reducer<Text, ObjectWritable, Text, Node>.Context context) {
- try {
- conf = context.getConfiguration();
- dampingFactor = conf
- .getFloat("link.analyze.damping.factor", 0.85f);
- rankOne = conf.getFloat("link.analyze.rank.one", 0.0f);
- itNum = conf.getInt("link.analyze.iteration", 0);
- limitPages = conf.getBoolean("link.ignore.limit.page", true);
- limitDomains = conf.getBoolean("link.ignore.limit.domain", true);
- } catch (Exception e) {
- LOG.error(StringUtils.stringifyException(e));
- throw new IllegalArgumentException(e);
- }
+ public void setup(
+ Reducer<Text, ObjectWritable, Text, Node>.Context context) {
+ conf = context.getConfiguration();
+ dampingFactor = conf.getFloat("link.analyze.damping.factor", 0.85f);
+ rankOne = conf.getFloat("link.analyze.rank.one", 0.0f);
+ itNum = conf.getInt("link.analyze.iteration", 0);
+ limitPages = conf.getBoolean("link.ignore.limit.page", true);
+ limitDomains = conf.getBoolean("link.ignore.limit.domain", true);
}
@Override
diff --git a/src/java/org/apache/nutch/scoring/webgraph/NodeDumper.java b/src/java/org/apache/nutch/scoring/webgraph/NodeDumper.java
index 84216478b..61b2061d4 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/NodeDumper.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/NodeDumper.java
@@ -335,9 +335,16 @@ public class NodeDumper extends Configured implements Tool {
try {
LOG.info("NodeDumper: running");
- int complete = dumper.waitForCompletion(true)?0:1;
+ boolean success = dumper.waitForCompletion(true);
+ if (!success) {
+ String message = "NodeDumper job did not succeed, job status:"
+ + dumper.getStatus().getState() + ", reason: "
+ + dumper.getStatus().getFailureInfo();
+ LOG.error(message);
+ throw new RuntimeException(message);
+ }
} catch (IOException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("NodeDumper job failed:", e);
throw e;
}
long end = System.currentTimeMillis();
diff --git a/src/java/org/apache/nutch/scoring/webgraph/ScoreUpdater.java b/src/java/org/apache/nutch/scoring/webgraph/ScoreUpdater.java
index a5bb3f348..93a7c95dc 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/ScoreUpdater.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/ScoreUpdater.java
@@ -184,9 +184,21 @@ public class ScoreUpdater extends Configured implements Tool{
updater.setOutputFormatClass(MapFileOutputFormat.class);
try {
- int complete = updater.waitForCompletion(true)?0:1;
+ boolean success = updater.waitForCompletion(true);
+ if (!success) {
+ String message = "Update CrawlDb from WebGraph job did not succeed, job status:"
+ + updater.getStatus().getState() + ", reason: "
+ + updater.getStatus().getFailureInfo();
+ LOG.error(message);
+ // remove the temp crawldb on error
+ FileSystem fs = newCrawlDb.getFileSystem(conf);
+ if (fs.exists(newCrawlDb)) {
+ fs.delete(newCrawlDb, true);
+ }
+ throw new RuntimeException(message);
+ }
} catch (IOException | ClassNotFoundException | InterruptedException e) {
- LOG.error(StringUtils.stringifyException(e));
+ LOG.error("Update CrawlDb from WebGraph:", e);
// remove the temp crawldb on error
FileSystem fs = newCrawlDb.getFileSystem(conf);
diff --git a/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java b/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java
index cfef442c8..06728d1be 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java
@@ -153,14 +153,6 @@ public class WebGraph extends Configured implements Tool {
public static class OutlinkDbMapper extends
Mapper<Text, Writable, Text, NutchWritable> {
- // ignoring internal domains, internal hosts
- private boolean ignoreDomain = true;
- private boolean ignoreHost = true;
-
- // limiting urls out to a page or to a domain
- private boolean limitPages = true;
- private boolean limitDomains = true;
-
// using normalizers and/or filters
private boolean normalize = false;
private boolean filter = false;
@@ -230,10 +222,6 @@ public class WebGraph extends Configured implements Tool {
public void setup(Mapper<Text, Writable, Text, NutchWritable>.Context context) {
Configuration config = context.getConfiguration();
conf = config;
- ignoreHost = conf.getBoolean("link.ignore.internal.host", true);
- ignoreDomain = conf.getBoolean("link.ignore.internal.domain", true);
- limitPages = conf.getBoolean("link.ignore.limit.page", true);
- limitDomains = conf.getBoolean("link.ignore.limit.domain", true);
normalize = conf.getBoolean(URL_NORMALIZING, false);
filter = conf.getBoolean(URL_FILTERING, false);
@@ -336,13 +324,7 @@ public class WebGraph extends Configured implements Tool {
private boolean limitPages = true;
private boolean limitDomains = true;
- // using normalizers and/or filters
- private boolean normalize = false;
- private boolean filter = false;
-
// url normalizers, filters and job configuration
- private URLNormalizers urlNormalizers;
- private URLFilters filters;
private Configuration conf;
/**
@@ -356,16 +338,6 @@ public class WebGraph extends Configured implements Tool {
limitPages = conf.getBoolean("link.ignore.limit.page", true);
limitDomains = conf.getBoolean("link.ignore.limit.domain", true);
- normalize = conf.getBoolean(URL_NORMALIZING, false);
- filter = conf.getBoolean(URL_FILTERING, false);
-
- if (normalize) {
- urlNormalizers = new URLNormalizers(conf, URLNormalizers.SCOPE_DEFAULT);
- }
-
- if (filter) {
- filters = new URLFilters(conf);
- }
}
public void reduce(Text key, Iterable<NutchWritable> values,
@@ -376,7 +348,8 @@ public class WebGraph extends Configured implements Tool {
// which should be the timestamp for all of the most recent outlinks
long mostRecent = 0L;
List<LinkDatum> outlinkList = new ArrayList<>();
- for (Writable value : values) {
+ for (NutchWritable val : values) {
+ final Writable value = val.get();
if (value instanceof LinkDatum) {
// loop through, change out most recent timestamp if needed
@@ -447,9 +420,6 @@ public class WebGraph extends Configured implements Tool {
private static long timestamp;
- public void close() {
- }
-
/**
* Inverts the Outlink LinkDatum objects into new LinkDatum objects with a
* new system timestamp, type and to and from url switched.
@@ -488,9 +458,6 @@ public class WebGraph extends Configured implements Tool {
*/
private static class NodeDb extends Configured {
- public void close() {
- }
-
/**
* Counts the number of inlinks and outlinks for each url and sets a default
* score of 0.0 for each url (node) in the webgraph.
@@ -634,7 +601,15 @@ public class WebGraph extends Configured implements Tool {
// run the outlinkdb job and replace any old outlinkdb with the new one
try {
LOG.info("OutlinkDb: running");
- int complete = outlinkJob.waitForCompletion(true)?0:1;
+ boolean success = outlinkJob.waitForCompletion(true);
+ if (!success) {
+ String message = "OutlinkDb job did not succeed, job status:"
+ + outlinkJob.getStatus().getState() + ", reason: "
+ + outlinkJob.getStatus().getFailureInfo();
+ LOG.error(message);
+ NutchJob.cleanupAfterFailure(tempOutlinkDb, lock, fs);
+ throw new RuntimeException(message);
+ }
LOG.info("OutlinkDb: installing " + outlinkDb);
FSUtils.replace(fs, oldOutlinkDb, outlinkDb, true);
FSUtils.replace(fs, outlinkDb, tempOutlinkDb, true);
@@ -642,13 +617,9 @@ public class WebGraph extends Configured implements Tool {
fs.delete(oldOutlinkDb, true);
LOG.info("OutlinkDb: finished");
} catch (IOException | InterruptedException | ClassNotFoundException e) {
-
+ LOG.error("OutlinkDb failed:", e);
// remove lock file and and temporary directory if an error occurs
- LockUtil.removeLockFile(fs, lock);
- if (fs.exists(tempOutlinkDb)) {
- fs.delete(tempOutlinkDb, true);
- }
- LOG.error(StringUtils.stringifyException(e));
+ NutchJob.cleanupAfterFailure(tempOutlinkDb, lock, fs);
throw e;
}
@@ -677,18 +648,22 @@ public class WebGraph extends Configured implements Tool {
// run the inlink and replace any old with new
LOG.info("InlinkDb: running");
- int complete = inlinkJob.waitForCompletion(true)?0:1;
+ boolean success = inlinkJob.waitForCompletion(true);
+ if (!success) {
+ String message = "InlinkDb job did not succeed, job status:"
+ + inlinkJob.getStatus().getState() + ", reason: "
+ + inlinkJob.getStatus().getFailureInfo();
+ LOG.error(message);
+ NutchJob.cleanupAfterFailure(tempInlinkDb, lock, fs);
+ throw new RuntimeException(message);
+ }
LOG.info("InlinkDb: installing " + inlinkDb);
FSUtils.replace(fs, inlinkDb, tempInlinkDb, true);
LOG.info("InlinkDb: finished");
} catch (IOException | InterruptedException | ClassNotFoundException e) {
-
+ LOG.error("InlinkDb failed:", e);
// remove lock file and and temporary directory if an error occurs
- LockUtil.removeLockFile(fs, lock);
- if (fs.exists(tempInlinkDb)) {
- fs.delete(tempInlinkDb, true);
- }
- LOG.error(StringUtils.stringifyException(e));
+ NutchJob.cleanupAfterFailure(tempInlinkDb, lock, fs);
throw e;
}
@@ -719,18 +694,23 @@ public class WebGraph extends Configured implements Tool {
// run the node job and replace old nodedb with new
LOG.info("NodeDb: running");
- int complete = nodeJob.waitForCompletion(true)?0:1;
+ boolean success = nodeJob.waitForCompletion(true);
+ if (!success) {
+ String message = "NodeDb job did not succeed, job status:"
+ + nodeJob.getStatus().getState() + ", reason: "
+ + nodeJob.getStatus().getFailureInfo();
+ LOG.error(message);
+ // remove lock file and and temporary directory if an error occurs
+ NutchJob.cleanupAfterFailure(tempNodeDb, lock, fs);
+ throw new RuntimeException(message);
+ }
LOG.info("NodeDb: installing " + nodeDb);
FSUtils.replace(fs, nodeDb, tempNodeDb, true);
LOG.info("NodeDb: finished");
} catch (IOException | InterruptedException | ClassNotFoundException e) {
-
+ LOG.error("NodeDb failed:", e);
// remove lock file and and temporary directory if an error occurs
- LockUtil.removeLockFile(fs, lock);
- if (fs.exists(tempNodeDb)) {
- fs.delete(tempNodeDb, true);
- }
- LOG.error(StringUtils.stringifyException(e));
+ NutchJob.cleanupAfterFailure(tempNodeDb, lock, fs);
throw e;
}
diff --git a/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.java b/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.java
index 1ef3e3b44..db083804d 100644
--- a/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.java
+++ b/src/test/org/apache/nutch/crawl/TestCrawlDbFilter.java
@@ -108,6 +108,7 @@ public class TestCrawlDbFilter {
job.setOutputFormatClass(MapFileOutputFormat.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(CrawlDatum.class);
+ job.setJarByClass(CrawlDbFilter.class);
job.waitForCompletion(true);
Path fetchlist = new Path(new Path(newCrawlDb, "part-r-00000"), "data");