Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fixes a few cleanup()'s and some cleanup of code

Jurian Broertjes602ff0b4af0d
diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReader.java b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
index 73dd1b402..7b8b13aa6 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDbReader.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
@@ -192,14 +192,13 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
NutchWritable COUNT_1 = new NutchWritable(new LongWritable(1));
private boolean sort = false;
+ @Override
public void setup(Mapper<Text, CrawlDatum, Text, NutchWritable>.Context context) {
Configuration conf = context.getConfiguration();
sort = conf.getBoolean("db.reader.stats.sort", false);
}
- public void close() {
- }
-
+ @Override
public void map(Text key, CrawlDatum value, Context context)
throws IOException, InterruptedException {
context.write(new Text("T"), COUNT_1);
@@ -242,9 +241,7 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
public void setup(Reducer<Text, NutchWritable, Text, NutchWritable>.Context context) {
}
- public void close() {
- }
-
+ @Override
public void reduce(Text key, Iterable<NutchWritable> values,
Context context)
throws IOException, InterruptedException {
@@ -329,14 +326,13 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
private static final FloatWritable fw = new FloatWritable();
private float min = 0.0f;
+ @Override
public void setup(Mapper<Text, CrawlDatum, FloatWritable, Text>.Context context) {
Configuration conf = context.getConfiguration();
min = conf.getFloat("db.reader.topn.min", 0.0f);
}
- public void close() {
- }
-
+ @Override
public void map(Text key, CrawlDatum value,
Context context)
throws IOException, InterruptedException {
@@ -352,6 +348,7 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
private long topN;
private long count = 0L;
+ @Override
public void reduce(FloatWritable key, Iterable<Text> values,
Context context)
throws IOException, InterruptedException {
@@ -364,13 +361,11 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
}
}
+ @Override
public void setup(Reducer<FloatWritable, Text, FloatWritable, Text>.Context context) {
Configuration conf = context.getConfiguration();
topN = conf.getLong("db.reader.topn", 100) / Integer.parseInt(conf.get("mapreduce.job.reduces"));
}
-
- public void close() {
- }
}
public void close() {
@@ -401,24 +396,25 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
// https://issues.apache.org/jira/browse/NUTCH-1029
config.setBoolean("mapreduce.fileoutputcommitter.marksuccessfuljobs", false);
- FileSystem fileSystem = tmpFolder.getFileSystem(config);
- try {
- boolean success = job.waitForCompletion(true);
- if (!success) {
- String message = "CrawlDbReader job did not succeed, job status:"
- + job.getStatus().getState() + ", reason: "
- + job.getStatus().getFailureInfo();
- LOG.error(message);
- fileSystem.delete(tmpFolder, true);
- throw new RuntimeException(message);
- }
- } catch (IOException | InterruptedException | ClassNotFoundException e) {
- LOG.error(StringUtils.stringifyException(e));
- fileSystem.delete(tmpFolder, true);
- throw e;
- }
- // reading the result
- SequenceFile.Reader[] readers = SegmentReaderUtil.getReaders(tmpFolder, config);
+ FileSystem fileSystem = tmpFolder.getFileSystem(config);
+ try {
+ boolean success = job.waitForCompletion(true);
+ if (!success) {
+ String message = "CrawlDbReader job did not succeed, job status:"
+ + job.getStatus().getState() + ", reason: "
+ + job.getStatus().getFailureInfo();
+ LOG.error(message);
+ fileSystem.delete(tmpFolder, true);
+ throw new RuntimeException(message);
+ }
+ } catch (IOException | InterruptedException | ClassNotFoundException e) {
+ LOG.error(StringUtils.stringifyException(e));
+ fileSystem.delete(tmpFolder, true);
+ throw e;
+ }
+
+ // reading the result
+ SequenceFile.Reader[] readers = SegmentReaderUtil.getReaders(tmpFolder, config);
Text key = new Text();
NutchWritable value = new NutchWritable();
@@ -629,6 +625,7 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
return res;
}
+ @Override
protected int process(String line, StringBuilder output) throws Exception {
Job job = NutchJob.getInstance(getConf());
Configuration config = job.getConfiguration();
@@ -720,6 +717,7 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
Expression expr = null;
float sample;
+ @Override
public void setup(Mapper<Text, CrawlDatum, Text, CrawlDatum>.Context context) {
Configuration config = context.getConfiguration();
if (config.get("regex", null) != null) {
@@ -734,9 +732,7 @@ public class CrawlDbReader extends AbstractChecker implements Closeable {
sample = config.getFloat("sample", 1);
}
- public void close() {
- }
-
+ @Override
public void map(Text key, CrawlDatum value,
Context context)
throws IOException, InterruptedException {
diff --git a/src/java/org/apache/nutch/crawl/LinkDb.java b/src/java/org/apache/nutch/crawl/LinkDb.java
index 3cf08ff8c..2d1160234 100644
--- a/src/java/org/apache/nutch/crawl/LinkDb.java
+++ b/src/java/org/apache/nutch/crawl/LinkDb.java
@@ -99,9 +99,6 @@ public class LinkDb extends NutchTool implements Tool {
}
}
- public void cleanup(){
- }
-
public void map(Text key, ParseData parseData,
Context context)
throws IOException, InterruptedException {
diff --git a/src/java/org/apache/nutch/crawl/LinkDbReader.java b/src/java/org/apache/nutch/crawl/LinkDbReader.java
index cc0b6f614..9ee57ba1e 100644
--- a/src/java/org/apache/nutch/crawl/LinkDbReader.java
+++ b/src/java/org/apache/nutch/crawl/LinkDbReader.java
@@ -109,6 +109,7 @@ public class LinkDbReader extends AbstractChecker implements Closeable {
Pattern pattern = null;
Matcher matcher = null;
+ @Override
public void setup(Mapper<Text, Inlinks, Text, Inlinks>.Context context) {
Configuration conf = context.getConfiguration();
if (conf.get("linkdb.regex", null) != null) {
@@ -116,8 +117,7 @@ public class LinkDbReader extends AbstractChecker implements Closeable {
}
}
- public void cleanup() {}
-
+ @Override
public void map(Text key, Inlinks value, Context context)
throws IOException, InterruptedException {
diff --git a/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java b/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
index 1c3c8c323..15a7e3793 100644
--- a/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
+++ b/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
@@ -58,11 +58,10 @@ public class UpdateHostDbMapper
protected URLFilters filters = null;
protected URLNormalizers normalizers = null;
- public void cleanup() {}
-
/**
* @param job
*/
+ @Override
public void setup(Mapper<Text, Writable, Text, NutchWritable>.Context context) {
Configuration conf = context.getConfiguration();
readingCrawlDb = conf.getBoolean("hostdb.reading.crawldb", false);
@@ -110,6 +109,7 @@ public class UpdateHostDbMapper
* @param value
* @param context
*/
+ @Override
public void map(Text key, Writable value,
Context context)
throws IOException, InterruptedException {
diff --git a/src/java/org/apache/nutch/indexer/CleaningJob.java b/src/java/org/apache/nutch/indexer/CleaningJob.java
index 74a6803a6..7a0f70e78 100644
--- a/src/java/org/apache/nutch/indexer/CleaningJob.java
+++ b/src/java/org/apache/nutch/indexer/CleaningJob.java
@@ -64,14 +64,6 @@ public class CleaningJob implements Tool {
Mapper<Text, CrawlDatum, ByteWritable, Text> {
private ByteWritable OUT = new ByteWritable(CrawlDatum.STATUS_DB_GONE);
- @Override
- public void setup(Mapper<Text, CrawlDatum, ByteWritable, Text>.Context context) {
- }
-
- @Override
- public void cleanup(Context context) throws IOException {
- }
-
@Override
public void map(Text key, CrawlDatum value,
Context context) throws IOException, InterruptedException {
diff --git a/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java b/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java
index bde24cc33..71fe42f52 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/LinkDumper.java
@@ -272,9 +272,6 @@ public class LinkDumper extends Configured implements Tool {
}
}
}
-
- public void cleanup() {
- }
}
/**