Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Merge branch 'NUTCH-2375' of https://github.com/Omkar20895/nutch into NUTCH-2375

Lewis John McGibbney405682ea3686
diff --cc src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java
index 121a825db,5c449db73..9117e4bb6
--- a/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java
+++ b/src/java/org/apache/nutch/fetcher/FetcherOutputFormat.java
@@@ -42,28 -47,32 +47,34 @@@ import org.apache.nutch.parse.ParseOutp
import org.apache.nutch.protocol.Content;
/** Splits FetcherOutput entries into multiple map files. */
- public class FetcherOutputFormat implements OutputFormat<Text, NutchWritable> {
+ public class FetcherOutputFormat extends FileOutputFormat<Text, NutchWritable> {
- public void checkOutputSpecs(FileSystem ignored, JobConf job)
- throws IOException {
+ @Override
+ public void checkOutputSpecs(JobContext job) throws IOException {
+ Configuration conf = job.getConfiguration();
+ FileSystem fs = FileSystem.get(conf);
Path out = FileOutputFormat.getOutputPath(job);
if ((out == null) && (job.getNumReduceTasks() != 0)) {
- throw new InvalidJobConfException("Output directory not set in JobConf.");
+ throw new InvalidJobConfException("Output directory not set in conf.");
}
+
- if (out != null) {
- FileSystem fs = out.getFileSystem(job);
- if (fs.exists(new Path(out, CrawlDatum.FETCH_DIR_NAME))) {
- throw new IOException("Segment already fetched!");
- }
+ if (fs == null) {
+ fs = out.getFileSystem(conf);
+ }
- if (fs.exists(new Path(out, CrawlDatum.FETCH_DIR_NAME)))
++ if (fs.exists(new Path(out, CrawlDatum.FETCH_DIR_NAME))) {
+ throw new IOException("Segment already fetched!");
+ }
}
- public RecordWriter<Text, NutchWritable> getRecordWriter(final FileSystem fs,
- final JobConf job, final String name, final Progressable progress)
+ @Override
+ public RecordWriter<Text, NutchWritable> getRecordWriter(TaskAttemptContext context)
throws IOException {
- Path out = FileOutputFormat.getOutputPath(job);
+ Configuration conf = context.getConfiguration();
+ String name = getUniqueFile(context, "part", "");
+ Path dir = FileOutputFormat.getOutputPath(context);
+ FileSystem fs = dir.getFileSystem(context.getConfiguration());
+ Path out = FileOutputFormat.getOutputPath(context);
final Path fetch = new Path(new Path(out, CrawlDatum.FETCH_DIR_NAME), name);
final Path content = new Path(new Path(out, Content.DIR_NAME), name);
diff --cc src/java/org/apache/nutch/parse/ParseOutputFormat.java
index 722ad7d7f,8d7e8459b..2a454eb9b
--- a/src/java/org/apache/nutch/parse/ParseOutputFormat.java
+++ b/src/java/org/apache/nutch/parse/ParseOutputFormat.java
@@@ -79,39 -97,63 +97,64 @@@ public class ParseOutputFormat extends
}
}
- public void checkOutputSpecs(FileSystem ignored, JobConf job)
+ public OutputCommitter getOutputCommitter(TaskAttemptContext context)
throws IOException {
- Path out = FileOutputFormat.getOutputPath(job);
- if ((out == null) && (job.getNumReduceTasks() != 0)) {
- throw new InvalidJobConfException("Output directory not set in JobConf.");
- }
+ Path path = FileOutputFormat.getOutputPath(context);
+ return new FileOutputCommitter(path, context);
+ }
- if (out != null) {
- FileSystem fs = out.getFileSystem(job);
- if (fs.exists(new Path(out, CrawlDatum.PARSE_DIR_NAME)))
- throw new IOException("Segment already parsed!");
+ @Override
- public void checkOutputSpecs(JobContext context) throws IOException{
++ public void checkOutputSpecs(JobContext context) throws IOException {
+ Configuration conf = context.getConfiguration();
+ Path out = FileOutputFormat.getOutputPath(context);
+ FileSystem fs = out.getFileSystem(context.getConfiguration());
+ if ((out == null) && (context.getNumReduceTasks() != 0)) {
- throw new IOException("Output directory not set in JobConf.");
++ throw new IOException("Output directory not set in JobContext.");
+ }
+ if (fs == null) {
+ fs = out.getFileSystem(conf);
+ }
- if (fs.exists(new Path(out, CrawlDatum.PARSE_DIR_NAME)))
++ if (fs.exists(new Path(out, CrawlDatum.PARSE_DIR_NAME))) {
+ throw new IOException("Segment already parsed!");
+ }
}
- public RecordWriter<Text, Parse> getRecordWriter(FileSystem fs, JobConf job,
- String name, Progressable progress) throws IOException {
+ public String getUniqueFile(TaskAttemptContext context, String name){
+ TaskID taskId = context.getTaskAttemptID().getTaskID();
+ int partition = taskId.getId();
+ StringBuilder result = new StringBuilder();
+ result.append(name);
+ result.append('-');
+ result.append(
+ TaskID.getRepresentingCharacter(taskId.getTaskType()));
+ result.append('-');
+ result.append(NUMBER_FORMAT.format(partition));
+ return result.toString();
+ }
- if (job.getBoolean("parse.filter.urls", true)) {
- filters = new URLFilters(job);
- exemptionFilters = new URLExemptionFilters(job);
+ public RecordWriter<Text, Parse> getRecordWriter(TaskAttemptContext context)
+ throws IOException {
+ Configuration conf = context.getConfiguration();
+ String name = getUniqueFile(context, "part");
+ Path dir = FileOutputFormat.getOutputPath(context);
+ FileSystem fs = dir.getFileSystem(context.getConfiguration());
+
+ if (conf.getBoolean("parse.filter.urls", true)) {
+ filters = new URLFilters(conf);
+ exemptionFilters = new URLExemptionFilters(conf);
}
- if (job.getBoolean("parse.normalize.urls", true)) {
- normalizers = new URLNormalizers(job, URLNormalizers.SCOPE_OUTLINK);
+ if (conf.getBoolean("parse.normalize.urls", true)) {
+ normalizers = new URLNormalizers(conf, URLNormalizers.SCOPE_OUTLINK);
}
- this.scfilters = new ScoringFilters(job);
- final int interval = job.getInt("db.fetch.interval.default", 2592000);
- final boolean ignoreInternalLinks = job.getBoolean(
+ this.scfilters = new ScoringFilters(conf);
+ final int interval = conf.getInt("db.fetch.interval.default", 2592000);
+ final boolean ignoreInternalLinks = conf.getBoolean(
"db.ignore.internal.links", false);
- final boolean ignoreExternalLinks = job.getBoolean(
+ final boolean ignoreExternalLinks = conf.getBoolean(
"db.ignore.external.links", false);
- final String ignoreExternalLinksMode = job.get(
+ final String ignoreExternalLinksMode = conf.get(
"db.ignore.external.links.mode", "byHost");
// NUTCH-2435 - parameter "parser.store.text" allowing to choose whether to
// store 'parse_text' directory or not: