Apache Nutch is an extensible and scalable web crawler
NUTCH-580 Remove deprecated hadoop api calls (FS)
Sami Siren251a2b458184
diff --git a/CHANGES.txt b/CHANGES.txtindex 0d24330b5..4f08e2044 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -191,6 +191,8 @@ Unreleased changes (1.0-dev)66. NUTCH-584 - urls missing from fetchlist (Ruslan Ermilov, ab)+67. NUTCH-580 - Remove deprecated hadoop api calls (FS) (siren)+Release 0.9 - 2007-04-02diff --git a/src/java/org/apache/nutch/crawl/Crawl.java b/src/java/org/apache/nutch/crawl/Crawl.javaindex 9eb198723..2cc2e443e 100644--- a/src/java/org/apache/nutch/crawl/Crawl.java+++ b/src/java/org/apache/nutch/crawl/Crawl.java@@ -32,6 +32,7 @@ import org.apache.nutch.parse.ParseSegment;import org.apache.nutch.indexer.DeleteDuplicates;import org.apache.nutch.indexer.IndexMerger;import org.apache.nutch.indexer.Indexer;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;@@ -131,9 +132,9 @@ public class Crawl {linkDbTool.invert(linkDb, segments, true, true, false); // invert links// index, dedup & merge- indexer.index(indexes, crawlDb, linkDb, fs.listPaths(segments));+ indexer.index(indexes, crawlDb, linkDb, fs.listPaths(segments, HadoopFSUtil.getPassAllFilter()));dedup.dedup(new Path[] { indexes });- merger.merge(fs.listPaths(indexes), index, tmpDir);+ merger.merge(fs.listPaths(indexes, HadoopFSUtil.getPassAllFilter()), index, tmpDir);} else {LOG.warn("No URLs to fetch - check your seed list and URL filters.");}diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.javaindex fd7d318a1..cc817ae5c 100644--- a/src/java/org/apache/nutch/crawl/CrawlDb.java+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java@@ -31,6 +31,7 @@ import org.apache.hadoop.mapred.*;import org.apache.hadoop.util.StringUtils;import org.apache.hadoop.util.ToolBase;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.LockUtil;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;@@ -181,15 +182,7 @@ public class CrawlDb extends ToolBase {} else if (args[i].equals("-noAdditions")) {additionsAllowed = false;} else if (args[i].equals("-dir")) {- Path[] paths = fs.listPaths(new Path(args[++i]), new PathFilter() {- public boolean accept(Path dir) {- try {- return fs.isDirectory(dir);- } catch (IOException ioe) {- return false;- }- }- });+ Path[] paths = fs.listPaths(new Path(args[++i]), HadoopFSUtil.getPassDirectoriesFilter(fs));dirs.addAll(Arrays.asList(paths));} else {dirs.add(new Path(args[i]));diff --git a/src/java/org/apache/nutch/crawl/LinkDb.java b/src/java/org/apache/nutch/crawl/LinkDb.javaindex 56e38d8b8..14f44ec38 100644--- a/src/java/org/apache/nutch/crawl/LinkDb.java+++ b/src/java/org/apache/nutch/crawl/LinkDb.java@@ -36,6 +36,7 @@ import org.apache.hadoop.util.ToolBase;import org.apache.nutch.net.URLFilters;import org.apache.nutch.net.URLNormalizers;import org.apache.nutch.parse.*;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.LockUtil;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;@@ -146,14 +147,7 @@ public class LinkDb extends ToolBase implements Mapper {public void invert(Path linkDb, final Path segmentsDir, boolean normalize, boolean filter, boolean force) throws IOException {final FileSystem fs = FileSystem.get(getConf());- Path[] files = fs.listPaths(segmentsDir, new PathFilter() {- public boolean accept(Path f) {- try {- if (fs.isDirectory(f)) return true;- } catch (IOException ioe) {};- return false;- }- });+ Path[] files = fs.listPaths(segmentsDir, HadoopFSUtil.getPassDirectoriesFilter(fs));invert(linkDb, files, normalize, filter, force);}@@ -283,7 +277,7 @@ public class LinkDb extends ToolBase implements Mapper {Path[] files = fs.listPaths(segDir, new PathFilter() {public boolean accept(Path f) {try {- if (fs.isDirectory(f)) return true;+ if (fs.getFileStatus(f).isDir()) return true;} catch (IOException ioe) {};return false;}diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.javaindex 54d743f9f..6a56691c9 100644--- a/src/java/org/apache/nutch/fetcher/Fetcher.java+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java@@ -63,7 +63,7 @@ public class Fetcher extends ToolBase implements MapRunnable {FileSystem fs = FileSystem.get(job);InputSplit[] splits = new InputSplit[files.length];for (int i = 0; i < files.length; i++) {- splits[i] = new FileSplit(files[i], 0, fs.getLength(files[i]), job);+ splits[i] = new FileSplit(files[i], 0, fs.getFileStatus(files[i]).getLen(), job);}return splits;}diff --git a/src/java/org/apache/nutch/fetcher/Fetcher2.java b/src/java/org/apache/nutch/fetcher/Fetcher2.javaindex 8d4558b7a..39d13ca35 100644--- a/src/java/org/apache/nutch/fetcher/Fetcher2.java+++ b/src/java/org/apache/nutch/fetcher/Fetcher2.java@@ -95,7 +95,7 @@ public class Fetcher2 extends Configured implements MapRunnable {FileSplit[] splits = new FileSplit[files.length];FileSystem fs = FileSystem.get(job);for (int i = 0; i < files.length; i++) {- splits[i] = new FileSplit(files[i], 0, fs.getLength(files[i]), job);+ splits[i] = new FileSplit(files[i], 0, fs.getFileStatus(files[i]).getLen(), job);}return splits;}diff --git a/src/java/org/apache/nutch/indexer/FsDirectory.java b/src/java/org/apache/nutch/indexer/FsDirectory.javaindex edeee60b1..b4b976840 100644--- a/src/java/org/apache/nutch/indexer/FsDirectory.java+++ b/src/java/org/apache/nutch/indexer/FsDirectory.java@@ -19,6 +19,7 @@ package org.apache.nutch.indexer;import java.io.*;import org.apache.lucene.store.*;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.hadoop.fs.*;import org.apache.hadoop.conf.Configuration;@@ -40,7 +41,7 @@ public class FsDirectory extends Directory {create();}- if (!fs.isDirectory(directory))+ if (!fs.getFileStatus(directory).isDir())throw new IOException(directory + " not a directory");}@@ -49,11 +50,11 @@ public class FsDirectory extends Directory {fs.mkdirs(directory);}- if (!fs.isDirectory(directory))+ if (!fs.getFileStatus(directory).isDir())throw new IOException(directory + " not a directory");// clear old files- Path[] files = fs.listPaths(directory);+ Path[] files = fs.listPaths(directory, HadoopFSUtil.getPassAllFilter());for (int i = 0; i < files.length; i++) {if (!fs.delete(files[i]))throw new IOException("Cannot delete " + files[i]);@@ -61,7 +62,7 @@ public class FsDirectory extends Directory {}public String[] list() throws IOException {- Path[] files = fs.listPaths(directory);+ Path[] files = fs.listPaths(directory, HadoopFSUtil.getPassAllFilter());if (files == null) return null;String[] result = new String[files.length];@@ -84,7 +85,7 @@ public class FsDirectory extends Directory {}public long fileLength(String name) throws IOException {- return fs.getLength(new Path(directory, name));+ return fs.getFileStatus(new Path(directory, name)).getLen();}public void deleteFile(String name) throws IOException {@@ -157,7 +158,7 @@ public class FsDirectory extends Directory {public DfsIndexInput(Path path, int ioFileBufferSize) throws IOException {descriptor = new Descriptor(path,ioFileBufferSize);- length = fs.getLength(path);+ length = fs.getFileStatus(path).getLen();}protected void readInternal(byte[] b, int offset, int len)diff --git a/src/java/org/apache/nutch/indexer/IndexMerger.java b/src/java/org/apache/nutch/indexer/IndexMerger.javaindex 3645c9752..fb9b87bd6 100644--- a/src/java/org/apache/nutch/indexer/IndexMerger.java+++ b/src/java/org/apache/nutch/indexer/IndexMerger.java@@ -29,6 +29,7 @@ import org.apache.hadoop.util.StringUtils;import org.apache.hadoop.util.ToolBase;import org.apache.hadoop.conf.*;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.LogUtil;import org.apache.nutch.util.NutchConfiguration;@@ -135,7 +136,7 @@ public class IndexMerger extends ToolBase {Path outputIndex = new Path(args[i++]);for (; i < args.length; i++) {- indexDirs.addAll(Arrays.asList(fs.listPaths(new Path(args[i]))));+ indexDirs.addAll(Arrays.asList(fs.listPaths(new Path(args[i]), HadoopFSUtil.getPassAllFilter())));}//diff --git a/src/java/org/apache/nutch/searcher/IndexSearcher.java b/src/java/org/apache/nutch/searcher/IndexSearcher.javaindex e73052242..5732ff89e 100644--- a/src/java/org/apache/nutch/searcher/IndexSearcher.java+++ b/src/java/org/apache/nutch/searcher/IndexSearcher.java@@ -82,7 +82,7 @@ public class IndexSearcher implements Searcher, HitDetailer {}private Directory getDirectory(Path file) throws IOException {- if ("local".equals(this.fs.getName())) {+ if ("file".equals(this.fs.getUri().getScheme())) {Path qualified = file.makeQualified(FileSystem.getLocal(conf));File fsLocal = new File(qualified.toUri());return FSDirectory.getDirectory(fsLocal.getAbsolutePath(), false);diff --git a/src/java/org/apache/nutch/searcher/NutchBean.java b/src/java/org/apache/nutch/searcher/NutchBean.javaindex 904a93682..68d0e5e56 100644--- a/src/java/org/apache/nutch/searcher/NutchBean.java+++ b/src/java/org/apache/nutch/searcher/NutchBean.java@@ -31,6 +31,7 @@ import org.apache.hadoop.util.StringUtils;import org.apache.nutch.parse.*;import org.apache.nutch.indexer.*;import org.apache.nutch.crawl.Inlinks;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.NutchConfiguration;/**@@ -121,8 +122,8 @@ public class NutchBean}Vector vDirs=new Vector();- Path [] directories = fs.listPaths(indexesDir);- for(int i = 0; i < fs.listPaths(indexesDir).length; i++) {+ Path [] directories = fs.listPaths(indexesDir, HadoopFSUtil.getPassDirectoriesFilter(fs));+ for(int i = 0; i < directories.length; i++) {Path indexdone = new Path(directories[i], Indexer.DONE_NAME);if(fs.isFile(indexdone)) {vDirs.add(directories[i]);diff --git a/src/java/org/apache/nutch/segment/SegmentMerger.java b/src/java/org/apache/nutch/segment/SegmentMerger.javaindex a86642468..1c3a218b0 100644--- a/src/java/org/apache/nutch/segment/SegmentMerger.java+++ b/src/java/org/apache/nutch/segment/SegmentMerger.java@@ -29,7 +29,6 @@ import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;-import org.apache.hadoop.fs.PathFilter;import org.apache.hadoop.io.MapFile;import org.apache.hadoop.io.SequenceFile;import org.apache.hadoop.io.Text;@@ -60,6 +59,7 @@ import org.apache.nutch.net.URLNormalizers;import org.apache.nutch.parse.ParseData;import org.apache.nutch.parse.ParseText;import org.apache.nutch.protocol.Content;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;@@ -626,15 +626,7 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {boolean normalize = false;for (int i = 1; i < args.length; i++) {if (args[i].equals("-dir")) {- Path[] files = fs.listPaths(new Path(args[++i]), new PathFilter() {- public boolean accept(Path f) {- try {- if (fs.isDirectory(f)) return true;- } catch (IOException e) {}- ;- return false;- }- });+ Path[] files = fs.listPaths(new Path(args[++i]), HadoopFSUtil.getPassDirectoriesFilter(fs));for (int j = 0; j < files.length; j++)segs.add(files[j]);} else if (args[i].equals("-filter")) {diff --git a/src/java/org/apache/nutch/segment/SegmentReader.java b/src/java/org/apache/nutch/segment/SegmentReader.javaindex 3e2a66d64..dc22bd0e6 100644--- a/src/java/org/apache/nutch/segment/SegmentReader.java+++ b/src/java/org/apache/nutch/segment/SegmentReader.java@@ -40,7 +40,6 @@ import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.conf.Configured;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;-import org.apache.hadoop.fs.PathFilter;import org.apache.hadoop.io.MapFile;import org.apache.hadoop.io.SequenceFile;import org.apache.hadoop.io.Text;@@ -64,6 +63,7 @@ import org.apache.nutch.crawl.NutchWritable;import org.apache.nutch.parse.ParseData;import org.apache.nutch.parse.ParseText;import org.apache.nutch.protocol.Content;+import org.apache.nutch.util.HadoopFSUtil;import org.apache.nutch.util.LogUtil;import org.apache.nutch.util.NutchConfiguration;import org.apache.nutch.util.NutchJob;@@ -220,7 +220,7 @@ public class SegmentReader extends Configured implements Reducer {// remove the old filefs.delete(dumpFile);- Path[] files = fs.listPaths(tempDir);+ Path[] files = fs.listPaths(tempDir, HadoopFSUtil.getPassAllFilter());PrintWriter writer = null;int currentRecordNumber = 0;@@ -451,7 +451,7 @@ public class SegmentReader extends Configured implements Reducer {}stats.generated = cnt;Path fetchDir = new Path(segment, CrawlDatum.FETCH_DIR_NAME);- if (fs.exists(fetchDir) && fs.isDirectory(fetchDir)) {+ if (fs.exists(fetchDir) && fs.getFileStatus(fetchDir).isDir()) {cnt = 0L;long start = Long.MAX_VALUE;long end = Long.MIN_VALUE;@@ -470,7 +470,7 @@ public class SegmentReader extends Configured implements Reducer {stats.fetched = cnt;}Path parseDir = new Path(segment, ParseData.DIR_NAME);- if (fs.exists(fetchDir) && fs.isDirectory(fetchDir)) {+ if (fs.exists(fetchDir) && fs.getFileStatus(fetchDir).isDir()) {cnt = 0L;long errors = 0L;ParseData value = new ParseData();@@ -559,14 +559,7 @@ public class SegmentReader extends Configured implements Reducer {if (args[i] == null) continue;if (args[i].equals("-dir")) {Path dir = new Path(args[++i]);- Path[] files = fs.listPaths(dir, new PathFilter() {- public boolean accept(Path pathname) {- try {- if (fs.isDirectory(pathname)) return true;- } catch (IOException e) {};- return false;- }- });+ Path[] files = fs.listPaths(dir, HadoopFSUtil.getPassDirectoriesFilter(fs));if (files != null && files.length > 0) {dirs.addAll(Arrays.asList(files));}diff --git a/src/java/org/apache/nutch/util/HadoopFSUtil.java b/src/java/org/apache/nutch/util/HadoopFSUtil.javanew file mode 100644index 000000000..98f0f1ccd--- /dev/null+++ b/src/java/org/apache/nutch/util/HadoopFSUtil.java@@ -0,0 +1,54 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You 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 java.io.IOException;++import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;+import org.apache.hadoop.fs.PathFilter;++public class HadoopFSUtil {++ /**+ * Returns PathFilter that passes all paths through.+ */+ public static PathFilter getPassAllFilter() {+ return new PathFilter() {+ public boolean accept(Path arg0) {+ return true;+ }+ };+ }++ /**+ * Returns PathFilter that passes directories through.+ */+ public static PathFilter getPassDirectoriesFilter(final FileSystem fs) {+ return new PathFilter() {+ public boolean accept(final Path path) {+ try {+ return fs.getFileStatus(path).isDir();+ } catch (IOException ioe) {+ return false;+ }+ }++ };+ }++}diff --git a/src/java/org/apache/nutch/util/LockUtil.java b/src/java/org/apache/nutch/util/LockUtil.javaindex d11d50485..62aa1d850 100644--- a/src/java/org/apache/nutch/util/LockUtil.java+++ b/src/java/org/apache/nutch/util/LockUtil.java@@ -42,7 +42,7 @@ public class LockUtil {if (fs.exists(lockFile)) {if(!accept)throw new IOException("lock file " + lockFile + " already exists.");- if (fs.isDirectory(lockFile))+ if (fs.getFileStatus(lockFile).isDir())throw new IOException("lock file " + lockFile + " already exists and is a directory.");// do nothing - the file already exists.} else {@@ -63,7 +63,7 @@ public class LockUtil {*/public static boolean removeLockFile(FileSystem fs, Path lockFile) throws IOException {if (!fs.exists(lockFile)) return false;- if (fs.isDirectory(lockFile))+ if (fs.getFileStatus(lockFile).isDir())throw new IOException("lock file " + lockFile + " exists but is a directory!");return fs.delete(lockFile);}