Apache Nutch is an extensible and scalable web crawler
NUTCH-2533 Injector: NullPointerException if seed URL dir contains non-file entries - read directory explicitely and log all non-file entries - exit early if no seed URL files are present
Sebastian Nagel5781fce1b81d
diff --git a/src/java/org/apache/nutch/crawl/Injector.java b/src/java/org/apache/nutch/crawl/Injector.javaindex 093d483fd..1f3098905 100644--- a/src/java/org/apache/nutch/crawl/Injector.java+++ b/src/java/org/apache/nutch/crawl/Injector.java@@ -18,6 +18,7 @@package org.apache.nutch.crawl;import org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.fs.FileStatus;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import org.apache.hadoop.io.FloatWritable;@@ -41,6 +42,7 @@ import org.apache.nutch.net.URLNormalizers;import org.apache.nutch.scoring.ScoringFilterException;import org.apache.nutch.scoring.ScoringFilters;import org.apache.nutch.service.NutchServer;+import org.apache.nutch.util.LockUtil;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;import org.apache.nutch.util.NutchTool;@@ -409,7 +411,24 @@ public class Injector extends NutchTool implements Tool {// set input and output paths of the jobMultipleInputs.addInputPath(job, current, SequenceFileInputFormat.class);- MultipleInputs.addInputPath(job, urlDir, KeyValueTextInputFormat.class);+ FileStatus[] seedFiles = urlDir.getFileSystem(getConf()).listStatus(urlDir);+ int numSeedFiles = 0;+ for (FileStatus seedFile : seedFiles) {+ if (seedFile.isFile()) {+ MultipleInputs.addInputPath(job, seedFile.getPath(),+ KeyValueTextInputFormat.class);+ numSeedFiles++;+ LOG.info("Injecting seed URL file {}", seedFile.getPath());+ } else {+ LOG.warn("Skipped non-file input in {}: {}", urlDir,+ seedFile.getPath());+ }+ }+ if (numSeedFiles == 0) {+ LOG.error("No seed files to inject found in {}", urlDir);+ LockUtil.removeLockFile(fs, lock);+ return;+ }FileOutputFormat.setOutputPath(job, tempCrawlDb);try {@@ -461,8 +480,8 @@ public class Injector extends NutchTool implements Tool {LOG.info("Injector: finished at " + sdf.format(end) + ", elapsed: "+ TimingUtil.elapsedTime(start, end));}- } catch (IOException | InterruptedException | ClassNotFoundException e) {- LOG.error("Injector job failed", e);+ } catch (IOException | InterruptedException | ClassNotFoundException | NullPointerException e) {+ LOG.error("Injector job failed: {}", e.getMessage());NutchJob.cleanupAfterFailure(tempCrawlDb, lock, fs);throw e;}