Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1541 - rebase to current master - update to use new MapReduce API

Sebastian Nagela8e59ec2c6dc
diff --git a/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.java b/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.java
index e74655165..a2f7918fe 100644
--- a/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.java
+++ b/src/plugin/indexer-csv/src/java/org/apache/nutch/indexwriter/csv/CSVIndexWriter.java
@@ -22,14 +22,11 @@ import java.nio.charset.Charset;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
-import java.util.Random;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.mapred.FileOutputFormat;
-import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.ToolRunner;
import org.apache.nutch.indexer.IndexWriter;
import org.apache.nutch.indexer.IndexingJob;
@@ -44,6 +41,11 @@ import org.slf4j.LoggerFactory;
* index as CSV or tab-separated plain text table. Format (encoding, separators,
* etc.) is configurable by a couple of options, see output of
* {@link #describe()}.
+ *
+ * <p>
+ * Note: works only in local mode, to be used with index option
+ * <code>-noCommit</code>.
+ * </p>
*/
public class CSVIndexWriter implements IndexWriter {
@@ -226,26 +228,24 @@ public class CSVIndexWriter implements IndexWriter {
protected FSDataOutputStream csvout;
- private Path csvFSOutFile;
private Path csvLocalOutFile;
@Override
- public void open(JobConf job, String name) throws IOException {
- fs = FileSystem.get(job);
+ public void open(Configuration conf, String name) throws IOException {
+ fs = FileSystem.get(conf);
LOG.info("Writing output to {}", outputPath);
- csvLocalOutFile = job.getLocalPath("tmp_" + System.currentTimeMillis() + "-"
- + Integer.toString(new Random().nextInt()) + "/nutch.csv");
- csvFSOutFile = new Path(outputPath, "nutch.csv");
- if (fs.exists(csvFSOutFile)) {
+ Path outputDir = new Path(outputPath);
+ fs = outputDir.getFileSystem(conf);
+ csvLocalOutFile = new Path(outputDir, "nutch.csv");
+ if (!fs.exists(outputDir)) {
+ fs.mkdirs(outputDir);
+ }
+ if (fs.exists(csvLocalOutFile)) {
// clean-up
- LOG.warn("Removing existing output path {}", csvFSOutFile);
- fs.delete(csvFSOutFile, true);
- FileOutputFormat.setOutputPath(job, csvFSOutFile);
- job.getOutputFormat().checkOutputSpecs(fs, job);
-
+ LOG.warn("Removing existing output path {}", csvLocalOutFile);
+ fs.delete(csvLocalOutFile, true);
}
- Path file = fs.startLocalOutput(csvFSOutFile, csvLocalOutFile);
- csvout = fs.create(file);
+ csvout = fs.create(csvLocalOutFile);
if (withHeader) {
for (int i = 0; i < fields.length; i++) {
if (i > 0)
@@ -318,8 +318,7 @@ public class CSVIndexWriter implements IndexWriter {
@Override
public void close() throws IOException {
csvout.close();
- fs.completeLocalOutput(csvFSOutFile, csvLocalOutFile);
- LOG.info("Finished CSV index in {}", csvFSOutFile);
+ LOG.info("Finished CSV index in {}", csvLocalOutFile);
}
/** (nothing to commit) */
@@ -423,9 +422,4 @@ public class CSVIndexWriter implements IndexWriter {
System.exit(res);
}
- @Override
- public String describe() {
- return getClass().getSimpleName() + description;
- }
-
}
diff --git a/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.java b/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.java
index af6d71c88..b7b0a6c3a 100644
--- a/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.java
+++ b/src/plugin/indexer-csv/src/test/org/apache/nutch/indexwriter/csv/TestCSVIndexWriter.java
@@ -28,7 +28,6 @@ import java.util.Date;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.mapred.JobConf;
import org.apache.nutch.indexer.NutchDocument;
import org.apache.nutch.util.NutchConfiguration;
import org.junit.Test;
@@ -54,7 +53,7 @@ public class TestCSVIndexWriter {
protected FileSystem.Statistics fsStats;
@Override
- public void open(JobConf job, String name) throws IOException {
+ public void open(Configuration conf, String name) throws IOException {
byteBuffer = new ByteArrayOutputStream();
fsStats = new FileSystem.Statistics("testCSVIndexWriter");
csvout = new FSDataOutputStream(byteBuffer, fsStats);
@@ -88,7 +87,7 @@ public class TestCSVIndexWriter {
}
CSVByteArrayIndexWriter out = new CSVByteArrayIndexWriter();
out.setConf(conf);
- out.open(new JobConf(conf), "test");
+ out.open(conf, "test");
for (NutchDocument doc : docs) {
out.write(doc);
}