Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fixes for NUTCH-2602: Description as a table with columns: KEY, DESCRIPTION, VALUE.

r0ann3l4e70af25e918
diff --git a/ivy/ivy.xml b/ivy/ivy.xml
index 9b8d667b8..e4247ea9d 100644
--- a/ivy/ivy.xml
+++ b/ivy/ivy.xml
@@ -142,6 +142,8 @@
<dependency org="org.apache.httpcomponents" name="httpcore" rev="4.4.9"/>
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.5.5"/>
+ <dependency org="de.vandermeer" name="asciitable" rev="0.3.2"/>
+
<!--global exclusion -->
<exclude module="jmxtools" />
<exclude module="jms" />
diff --git a/src/java/org/apache/nutch/indexer/IndexWriter.java b/src/java/org/apache/nutch/indexer/IndexWriter.java
index 4413699d5..603af9335 100644
--- a/src/java/org/apache/nutch/indexer/IndexWriter.java
+++ b/src/java/org/apache/nutch/indexer/IndexWriter.java
@@ -21,8 +21,10 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.plugin.Pluggable;
import java.io.IOException;
+import java.util.Map;
public interface IndexWriter extends Pluggable, Configurable {
+
/**
* The name of the extension point.
*/
@@ -50,9 +52,9 @@ public interface IndexWriter extends Pluggable, Configurable {
public void close() throws IOException;
/**
- * Returns a String describing the IndexWriter instance and the specific parameters it can take.
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
*
- * @return The full description.
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
*/
- public String describe();
+ Map<String, Map.Entry<String, Object>> describe();
}
diff --git a/src/java/org/apache/nutch/indexer/IndexWriters.java b/src/java/org/apache/nutch/indexer/IndexWriters.java
index 3ac20bfea..9fac2e2fe 100644
--- a/src/java/org/apache/nutch/indexer/IndexWriters.java
+++ b/src/java/org/apache/nutch/indexer/IndexWriters.java
@@ -16,6 +16,10 @@
*/
package org.apache.nutch.indexer;
+import de.vandermeer.asciitable.AT_ColumnWidthCalculator;
+import de.vandermeer.asciitable.AT_Row;
+import de.vandermeer.asciitable.AsciiTable;
+import de.vandermeer.skb.interfaces.document.TableRowType;
import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.exchange.Exchanges;
import org.apache.nutch.plugin.Extension;
@@ -265,8 +269,52 @@ public class IndexWriters {
builder.append("Active IndexWriters :\n");
for (IndexWriterWrapper indexWriterWrapper : this.indexWriters.values()) {
- builder.append(indexWriterWrapper.getIndexWriter().describe())
- .append("\n");
+ // Getting the class name
+ builder.append(
+ indexWriterWrapper.getIndexWriter().getClass().getSimpleName())
+ .append(":\n");
+
+ // Building the table
+ AsciiTable at = new AsciiTable();
+ at.getRenderer().setCWC((rows, colNumbers, tableWidth) -> {
+ int maxLengthFirstColumn = 0;
+ int maxLengthLastColumn = 0;
+ for (AT_Row row : rows) {
+ if (row.getType() == TableRowType.CONTENT) {
+ // First column
+ int lengthFirstColumn = row.getCells().get(0).toString().length();
+ if (lengthFirstColumn > maxLengthFirstColumn) {
+ maxLengthFirstColumn = lengthFirstColumn;
+ }
+
+ // Last column
+ int lengthLastColumn = row.getCells().get(2).toString().length();
+ if (lengthLastColumn > maxLengthLastColumn) {
+ maxLengthLastColumn = lengthLastColumn;
+ }
+ }
+ }
+ return new int[] { maxLengthFirstColumn,
+ tableWidth - maxLengthFirstColumn - maxLengthLastColumn,
+ maxLengthLastColumn };
+ });
+
+ // Getting the properties
+ Map<String, Map.Entry<String, Object>> properties = indexWriterWrapper
+ .getIndexWriter().describe();
+
+ // Adding the rows
+ properties.forEach((key, value) -> {
+ at.addRule();
+ at.addRow(key, value.getKey(),
+ value.getValue() != null ? value.getValue() : "");
+ });
+
+ // Last rule
+ at.addRule();
+
+ // Rendering the table
+ builder.append(at.render(150)).append("\n\n");
}
return builder.toString();
diff --git a/src/plugin/indexer-cloudsearch/src/java/org/apache/nutch/indexwriter/cloudsearch/CloudSearchIndexWriter.java b/src/plugin/indexer-cloudsearch/src/java/org/apache/nutch/indexwriter/cloudsearch/CloudSearchIndexWriter.java
index 3392787d9..1379db21a 100644
--- a/src/plugin/indexer-cloudsearch/src/java/org/apache/nutch/indexwriter/cloudsearch/CloudSearchIndexWriter.java
+++ b/src/plugin/indexer-cloudsearch/src/java/org/apache/nutch/indexwriter/cloudsearch/CloudSearchIndexWriter.java
@@ -23,9 +23,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
+import java.util.AbstractMap;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -341,18 +343,28 @@ public class CloudSearchIndexWriter implements IndexWriter {
this.conf = conf;
}
- public String describe() {
- StringBuffer sb = new StringBuffer(this.getClass().getSimpleName())
- .append("\n");
- sb.append("\t").append(CloudSearchConstants.ENDPOINT).append(": ")
- .append(this.endpoint).append("\n");
- sb.append("\t").append(CloudSearchConstants.REGION).append(": ")
- .append(this.regionName).append("\n");
- sb.append("\t").append(CloudSearchConstants.BATCH_DUMP).append(": ")
- .append(this.dumpBatchFilesToTemp).append("\n");
- sb.append("\t").append(CloudSearchConstants.MAX_DOCS_BATCH).append(": ")
- .append(this.maxDocsInBatch).append("\n");
- return sb.toString();
+ /**
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
+ *
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
+ */
+ @Override
+ public Map<String, Entry<String, Object>> describe() {
+ Map<String, Map.Entry<String, Object>> properties = new LinkedHashMap<>();
+
+ properties.put(CloudSearchConstants.ENDPOINT, new AbstractMap.SimpleEntry<>(
+ "Endpoint where service requests should be submitted.", this.endpoint));
+ properties.put(CloudSearchConstants.REGION,
+ new AbstractMap.SimpleEntry<>("Region name.", this.regionName));
+ properties.put(CloudSearchConstants.BATCH_DUMP,
+ new AbstractMap.SimpleEntry<>("true to send documents to a local file.",
+ this.dumpBatchFilesToTemp));
+ properties.put(CloudSearchConstants.MAX_DOCS_BATCH,
+ new AbstractMap.SimpleEntry<>(
+ "Maximum number of documents to send as a batch to CloudSearch.",
+ this.maxDocsInBatch));
+
+ return properties;
}
/**
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 c17467aa0..0f83a0d6e 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
@@ -19,16 +19,23 @@ package org.apache.nutch.indexwriter.csv;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.util.AbstractMap;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
+import java.util.Map;
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.util.ToolRunner;
-import org.apache.nutch.indexer.*;
+import org.apache.nutch.indexer.IndexWriter;
+import org.apache.nutch.indexer.IndexWriterParams;
+import org.apache.nutch.indexer.IndexingJob;
+import org.apache.nutch.indexer.NutchDocument;
+import org.apache.nutch.indexer.NutchField;
import org.apache.nutch.util.NutchConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -178,35 +185,6 @@ public class CSVIndexWriter implements IndexWriter {
private String outputPath = "csvindexwriter";
- private static final String description =
- " - write index as CSV file (comma separated values)"
- + String.format("\n %-24s : %s", CSVConstants.CSV_FIELDS,
- "ordered list of fields (columns) in the CSV file")
- + String.format("\n %-24s : %s", CSVConstants.CSV_FIELD_SEPARATOR,
- "separator between fields (columns), default: , (U+002C, comma)")
- + String.format("\n %-24s : %s", CSVConstants.CSV_QUOTECHARACTER,
- "quote character used to quote fields containing separators or quotes, "
- + "default: \" (U+0022, quotation mark)")
- + String.format("\n %-24s : %s", CSVConstants.CSV_ESCAPECHARACTER,
- "escape character used to escape a quote character, "
- + "default: \" (U+0022, quotation mark)")
- + String.format("\n %-24s : %s", CSVConstants.CSV_VALUESEPARATOR,
- "separator between multiple values of one field, "
- + "default: | (U+007C)")
- + String.format("\n %-24s : %s", CSVConstants.CSV_MAXFIELDVALUES,
- "max. number of values of one field, useful for, "
- + " e.g., the anchor texts field, default: 12")
- + String.format("\n %-24s : %s", CSVConstants.CSV_MAXFIELDLENGTH,
- "max. length of a single field value in characters, default: 4096.")
- + String.format("\n %-24s : %s", CSVConstants.CSV_CHARSET,
- "encoding of CSV file, default: UTF-8")
- + String.format("\n %-24s : %s", CSVConstants.CSV_WITHHEADER,
- "write CSV column headers, default: true")
- + String.format("\n %-24s : %s", CSVConstants.CSV_OUTPATH,
- "output path / directory, default: csvindexwriter. "
- + "\n CAVEAT: existing output directories are removed!") + "\n";
-
-
private FileSystem fs;
protected FSDataOutputStream csvout;
@@ -345,9 +323,47 @@ public class CSVIndexWriter implements IndexWriter {
return config;
}
+ /**
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
+ *
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
+ */
@Override
- public String describe() {
- return getClass().getSimpleName() + description;
+ public Map<String, Map.Entry<String, Object>> describe() {
+ Map<String, Map.Entry<String, Object>> properties = new LinkedHashMap<>();
+
+ properties.put(CSVConstants.CSV_FIELDS, new AbstractMap.SimpleEntry<>(
+ "Ordered list of fields (columns) in the CSV file",
+ this.fields == null ? "" : String.join(",", this.fields)));
+ properties.put(CSVConstants.CSV_FIELD_SEPARATOR, new AbstractMap.SimpleEntry<>(
+ "Separator between fields (columns), default: , (U+002C, comma)",
+ this.fieldSeparator));
+ properties.put(CSVConstants.CSV_QUOTECHARACTER, new AbstractMap.SimpleEntry<>(
+ "Quote character used to quote fields containing separators or quotes, default: \" (U+0022, quotation mark)",
+ this.quoteCharacter));
+ properties.put(CSVConstants.CSV_ESCAPECHARACTER, new AbstractMap.SimpleEntry<>(
+ "Escape character used to escape a quote character, default: \" (U+0022, quotation mark)",
+ this.escapeCharacter));
+ properties.put(CSVConstants.CSV_VALUESEPARATOR, new AbstractMap.SimpleEntry<>(
+ "Separator between multiple values of one field, default: | (U+007C)",
+ this.valueSeparator));
+ properties.put(CSVConstants.CSV_MAXFIELDVALUES, new AbstractMap.SimpleEntry<>(
+ "Max. number of values of one field, useful for, e.g., the anchor texts field, default: 12",
+ this.maxFieldValues));
+ properties.put(CSVConstants.CSV_MAXFIELDLENGTH, new AbstractMap.SimpleEntry<>(
+ "Max. length of a single field value in characters, default: 4096",
+ this.maxFieldLength));
+ properties.put(CSVConstants.CSV_CHARSET, new AbstractMap.SimpleEntry<>(
+ "Encoding of CSV file, default: UTF-8",
+ this.encoding));
+ properties.put(CSVConstants.CSV_WITHHEADER, new AbstractMap.SimpleEntry<>(
+ "Write CSV column headers, default: true",
+ this.withHeader));
+ properties.put(CSVConstants.CSV_OUTPATH, new AbstractMap.SimpleEntry<>(
+ "Output path / directory, default: csvindexwriter. ",
+ this.outputPath));
+
+ return properties;
}
@Override
diff --git a/src/plugin/indexer-dummy/src/java/org/apache/nutch/indexwriter/dummy/DummyIndexWriter.java b/src/plugin/indexer-dummy/src/java/org/apache/nutch/indexwriter/dummy/DummyIndexWriter.java
index ef338c309..d809f66b1 100644
--- a/src/plugin/indexer-dummy/src/java/org/apache/nutch/indexwriter/dummy/DummyIndexWriter.java
+++ b/src/plugin/indexer-dummy/src/java/org/apache/nutch/indexwriter/dummy/DummyIndexWriter.java
@@ -21,6 +21,9 @@ import java.io.BufferedWriter;
import java.io.IOException;
import java.io.FileWriter;
import java.io.Writer;
+import java.util.AbstractMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.StringUtils;
@@ -120,13 +123,20 @@ public class DummyIndexWriter implements IndexWriter {
config = conf;
}
- public String describe() {
- StringBuffer sb = new StringBuffer(this.getClass().getSimpleName())
- .append("\n");
- sb.append("\t").append(DummyConstants.DELETE).append(": ")
- .append(this.delete).append("\n");
- sb.append("\t").append(DummyConstants.PATH).append(": ").append(this.path)
- .append("\n");
- return sb.toString();
+ /**
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
+ *
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
+ */
+ @Override
+ public Map<String, Map.Entry<String, Object>> describe() {
+ Map<String, Map.Entry<String, Object>> properties = new LinkedHashMap<>();
+
+ properties.put(DummyConstants.DELETE, new AbstractMap.SimpleEntry<>(
+ "If delete operations should be written to the file.", this.delete));
+ properties.put(DummyConstants.PATH, new AbstractMap.SimpleEntry<>(
+ "Path where the file will be created.", this.path));
+
+ return properties;
}
}
diff --git a/src/plugin/indexer-elastic-rest/src/java/org/apache/nutch/indexwriter/elasticrest/ElasticRestIndexWriter.java b/src/plugin/indexer-elastic-rest/src/java/org/apache/nutch/indexwriter/elasticrest/ElasticRestIndexWriter.java
index 912efffb0..39f4c724b 100644
--- a/src/plugin/indexer-elastic-rest/src/java/org/apache/nutch/indexwriter/elasticrest/ElasticRestIndexWriter.java
+++ b/src/plugin/indexer-elastic-rest/src/java/org/apache/nutch/indexwriter/elasticrest/ElasticRestIndexWriter.java
@@ -54,13 +54,13 @@ import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
-import java.util.ArrayList;
+import java.util.AbstractMap;
+import java.util.Date;
import java.util.HashMap;
-import java.util.Map;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
-import java.util.List;
+import java.util.Map;
import java.util.Set;
-import java.util.Date;
import java.util.concurrent.ExecutionException;
/**
@@ -377,40 +377,74 @@ public class ElasticRestIndexWriter implements IndexWriter {
client.shutdownClient();
}
+ /**
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
+ *
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
+ */
@Override
- public String describe() {
- StringBuffer sb = new StringBuffer(this.getClass().getSimpleName())
- .append("\n");
- sb.append("\t").append(ElasticRestConstants.HOST).append(": ")
- .append(this.host).append("\n");
- sb.append("\t").append(ElasticRestConstants.PORT).append(": ")
- .append(this.port).append("\n");
- sb.append("\t").append(ElasticRestConstants.INDEX).append(": ")
- .append(this.defaultIndex).append("\n");
- sb.append("\t").append(ElasticRestConstants.MAX_BULK_DOCS).append(": ")
- .append(this.maxBulkDocs).append("\n");
- sb.append("\t").append(ElasticRestConstants.MAX_BULK_LENGTH).append(": ")
- .append(this.maxBulkLength).append("\n");
-
- sb.append("\t").append(ElasticRestConstants.USER).append(": ")
- .append(this.user).append("\n");
- sb.append("\t").append(ElasticRestConstants.PASSWORD).append(": ")
- .append(this.password).append("\n");
- sb.append("\t").append(ElasticRestConstants.TYPE).append(": ")
- .append(this.defaultType).append("\n");
- sb.append("\t").append(ElasticRestConstants.HTTPS).append(": ")
- .append(this.https).append("\n");
- sb.append("\t").append(ElasticRestConstants.HOSTNAME_TRUST).append(": ")
- .append(this.trustAllHostnames).append("\n");
-
- sb.append("\t").append(ElasticRestConstants.LANGUAGES).append(": ")
- .append(this.languages == null ? "null" : String.join(",", languages))
- .append("\n");
- sb.append("\t").append(ElasticRestConstants.SEPARATOR).append(": ")
- .append(this.separator).append("\n");
- sb.append("\t").append(ElasticRestConstants.SINK).append(": ")
- .append(this.sink).append("\n");
- return sb.toString();
+ public Map<String, Map.Entry<String, Object>> describe() {
+ Map<String, Map.Entry<String, Object>> properties = new LinkedHashMap<>();
+
+ properties.put(ElasticRestConstants.HOST, new AbstractMap.SimpleEntry<>(
+ "The hostname or a list of comma separated hostnames to send documents "
+ + "to using Elasticsearch Jest. Both host and port must be defined.",
+ this.host));
+ properties.put(ElasticRestConstants.PORT, new AbstractMap.SimpleEntry<>(
+ "The port to connect to using Elasticsearch Jest.", this.port));
+ properties.put(ElasticRestConstants.INDEX,
+ new AbstractMap.SimpleEntry<>("Default index to send documents to.",
+ this.defaultIndex));
+ properties.put(ElasticRestConstants.MAX_BULK_DOCS,
+ new AbstractMap.SimpleEntry<>(
+ "Maximum size of the bulk in number of documents.",
+ this.maxBulkDocs));
+ properties.put(ElasticRestConstants.MAX_BULK_LENGTH,
+ new AbstractMap.SimpleEntry<>("Maximum size of the bulk in bytes.",
+ this.maxBulkLength));
+
+ properties.put(ElasticRestConstants.USER, new AbstractMap.SimpleEntry<>(
+ "Username for auth credentials (only used when https is enabled)",
+ this.user));
+ properties.put(ElasticRestConstants.PASSWORD, new AbstractMap.SimpleEntry<>(
+ "Password for auth credentials (only used when https is enabled)",
+ this.password));
+ properties.put(ElasticRestConstants.TYPE,
+ new AbstractMap.SimpleEntry<>("Default type to send documents to.",
+ this.defaultType));
+ properties.put(ElasticRestConstants.HTTPS, new AbstractMap.SimpleEntry<>(
+ "true to enable https, false to disable https. If you've disabled http "
+ + "access (by forcing https), be sure to set this to true, otherwise "
+ + "you might get \"connection reset by peer\".", this.https));
+ properties.put(ElasticRestConstants.HOSTNAME_TRUST,
+ new AbstractMap.SimpleEntry<>(
+ "true to trust elasticsearch server's certificate even if its listed "
+ + "domain name does not match the domain they are hosted or false "
+ + "to check if the elasticsearch server's certificate's listed "
+ + "domain is the same domain that it is hosted on, and if "
+ + "it doesn't, then fail to index (only used when https is enabled)",
+ this.trustAllHostnames));
+
+ properties.put(ElasticRestConstants.LANGUAGES,
+ new AbstractMap.SimpleEntry<>(
+ "A list of strings denoting the supported languages (e.g. en, de, fr, it). "
+ + "If this value is empty all documents will be sent to index property. "
+ + "If not empty the Rest client will distribute documents in different "
+ + "indices based on their languages property. Indices are named with the "
+ + "following schema: index separator language (e.g. nutch_de). "
+ + "Entries with an unsupported languages value will be added to "
+ + "index index separator sink (e.g. nutch_others).",
+ this.languages == null ? "" : String.join(",", languages)));
+ properties.put(ElasticRestConstants.SEPARATOR,
+ new AbstractMap.SimpleEntry<>(
+ "Is used only if languages property is defined to build the index name "
+ + "(i.e. index separator lang).", this.separator));
+ properties.put(ElasticRestConstants.SINK, new AbstractMap.SimpleEntry<>(
+ "Is used only if languages property is defined to build the index name "
+ + "where to store documents with unsupported languages "
+ + "(i.e. index separator sink).", this.sink));
+
+ return properties;
}
@Override
diff --git a/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java b/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java
index 9b24f0e48..91a085e3a 100644
--- a/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java
+++ b/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticIndexWriter.java
@@ -21,7 +21,9 @@ import java.lang.invoke.MethodHandles;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.InetAddress;
+import java.util.AbstractMap;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -262,29 +264,49 @@ public class ElasticIndexWriter implements IndexWriter {
}
}
+ /**
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
+ *
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
+ */
@Override
- public String describe() {
- StringBuffer sb = new StringBuffer(this.getClass().getSimpleName())
- .append("\n");
- sb.append("\t").append(ElasticConstants.CLUSTER).append(": ")
- .append(this.cluster).append("\n");
- sb.append("\t").append(ElasticConstants.HOSTS).append(": ")
- .append(this.hosts == null ? "null" : String.join(",", hosts)).append("\n");
- sb.append("\t").append(ElasticConstants.PORT).append(": ")
- .append(this.port).append("\n");
- sb.append("\t").append(ElasticConstants.INDEX).append(": ")
- .append(this.defaultIndex).append("\n");
- sb.append("\t").append(ElasticConstants.MAX_BULK_DOCS).append(": ")
- .append(this.maxBulkDocs).append("\n");
- sb.append("\t").append(ElasticConstants.MAX_BULK_LENGTH).append(": ")
- .append(this.maxBulkLength).append("\n");
- sb.append("\t").append(ElasticConstants.EXPONENTIAL_BACKOFF_MILLIS).append(": ")
- .append(this.expBackoffMillis).append("\n");
- sb.append("\t").append(ElasticConstants.EXPONENTIAL_BACKOFF_RETRIES).append(": ")
- .append(this.expBackoffRetries).append("\n");
- sb.append("\t").append(ElasticConstants.BULK_CLOSE_TIMEOUT).append(": ")
- .append(this.bulkCloseTimeout).append("\n");
- return sb.toString();
+ public Map<String, Map.Entry<String, Object>> describe() {
+ Map<String, Map.Entry<String, Object>> properties = new LinkedHashMap<>();
+
+ properties.put(ElasticConstants.CLUSTER, new AbstractMap.SimpleEntry<>(
+ "The cluster name to discover. Either host and port must be defined or cluster.",
+ this.cluster));
+ properties.put(ElasticConstants.HOSTS, new AbstractMap.SimpleEntry<>(
+ "Ordered list of fields (columns) in the CSV fileComma-separated list of "
+ + "hostnames to send documents to using TransportClient. "
+ + "Either host and port must be defined or cluster.",
+ this.hosts == null ? "" : String.join(",", hosts)));
+ properties.put(ElasticConstants.PORT, new AbstractMap.SimpleEntry<>(
+ "The port to connect to using TransportClient.", this.port));
+ properties.put(ElasticConstants.INDEX,
+ new AbstractMap.SimpleEntry<>("Default index to send documents to.",
+ this.defaultIndex));
+ properties.put(ElasticConstants.MAX_BULK_DOCS,
+ new AbstractMap.SimpleEntry<>(
+ "Maximum size of the bulk in number of documents.",
+ this.maxBulkDocs));
+ properties.put(ElasticConstants.MAX_BULK_LENGTH,
+ new AbstractMap.SimpleEntry<>("Maximum size of the bulk in bytes.",
+ this.maxBulkLength));
+ properties.put(ElasticConstants.EXPONENTIAL_BACKOFF_MILLIS,
+ new AbstractMap.SimpleEntry<>(
+ "Initial delay for the BulkProcessor exponential backoff policy.",
+ this.expBackoffMillis));
+ properties.put(ElasticConstants.EXPONENTIAL_BACKOFF_RETRIES,
+ new AbstractMap.SimpleEntry<>(
+ "Number of times the BulkProcessor exponential backoff policy should retry bulk operations.",
+ this.expBackoffRetries));
+ properties.put(ElasticConstants.BULK_CLOSE_TIMEOUT,
+ new AbstractMap.SimpleEntry<>(
+ "Number of seconds allowed for the BulkProcessor to complete its last operation.",
+ this.bulkCloseTimeout));
+
+ return properties;
}
@Override
diff --git a/src/plugin/indexer-rabbit/src/java/org/apache/nutch/indexwriter/rabbit/RabbitIndexWriter.java b/src/plugin/indexer-rabbit/src/java/org/apache/nutch/indexwriter/rabbit/RabbitIndexWriter.java
index fdf5cf2e3..616ee8d9c 100644
--- a/src/plugin/indexer-rabbit/src/java/org/apache/nutch/indexwriter/rabbit/RabbitIndexWriter.java
+++ b/src/plugin/indexer-rabbit/src/java/org/apache/nutch/indexwriter/rabbit/RabbitIndexWriter.java
@@ -30,7 +30,9 @@ import org.apache.nutch.rabbitmq.RabbitMQMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.AbstractMap;
import java.util.Arrays;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -209,34 +211,71 @@ public class RabbitIndexWriter implements IndexWriter {
client.close();
}
- public String describe() {
- StringBuffer sb = new StringBuffer(this.getClass().getSimpleName())
- .append("\n");
- sb.append("\t").append(RabbitMQConstants.SERVER_URI).append(": ")
- .append(this.uri).append("\n");
- sb.append("\t").append(RabbitMQConstants.BINDING).append(": ")
- .append(this.binding).append("\n");
- sb.append("\t").append(RabbitMQConstants.BINDING_ARGUMENTS).append(": ")
- .append(this.bindingArguments).append("\n");
- sb.append("\t").append(RabbitMQConstants.EXCHANGE_NAME).append(": ")
- .append(this.exchange).append("\n");
- sb.append("\t").append(RabbitMQConstants.EXCHANGE_OPTIONS).append(": ")
- .append(this.exchangeOptions).append("\n");
- sb.append("\t").append(RabbitMQConstants.QUEUE_NAME).append(": ")
- .append(this.queueName).append("\n");
- sb.append("\t").append(RabbitMQConstants.QUEUE_OPTIONS).append(": ")
- .append(this.queueOptions).append("\n");
- sb.append("\t").append(RabbitMQConstants.ROUTING_KEY).append(": ")
- .append(this.routingKey).append("\n");
- sb.append("\t").append(RabbitMQConstants.COMMIT_SIZE).append(": ")
- .append(this.commitSize).append("\n");
- sb.append("\t").append(RabbitMQConstants.COMMIT_MODE).append(": ")
- .append(this.commitMode).append("\n");
- sb.append("\t").append(RabbitMQConstants.HEADERS_STATIC).append(": ")
- .append(this.headersStatic).append("\n");
- sb.append("\t").append(RabbitMQConstants.HEADERS_DYNAMIC).append(": ")
- .append(this.headersDynamic).append("\n");
- return sb.toString();
+ /**
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
+ *
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
+ */
+ @Override
+ public Map<String, Map.Entry<String, Object>> describe() {
+ Map<String, Map.Entry<String, Object>> properties = new LinkedHashMap<>();
+
+ properties.put(RabbitMQConstants.SERVER_URI, new AbstractMap.SimpleEntry<>(
+ "URI with connection parameters in the form amqp://<username>:<password>@<hostname>:<port>/<virtualHost>",
+ this.uri));
+ properties.put(RabbitMQConstants.BINDING, new AbstractMap.SimpleEntry<>(
+ "Whether the relationship between an exchange and a queue is created automatically. "
+ + "NOTE: Binding between exchanges is not supported.",
+ this.binding));
+ properties.put(RabbitMQConstants.BINDING_ARGUMENTS,
+ new AbstractMap.SimpleEntry<>(
+ "Arguments used in binding. It must have the form key1=value1,key2=value2. "
+ + "This value is only used when the exchange's type is headers and "
+ + "the value of binding property is true. In other cases is ignored.",
+ this.bindingArguments));
+ properties.put(RabbitMQConstants.EXCHANGE_NAME,
+ new AbstractMap.SimpleEntry<>(
+ "Name for the exchange where the messages will be sent.",
+ this.exchange));
+ properties.put(RabbitMQConstants.EXCHANGE_OPTIONS,
+ new AbstractMap.SimpleEntry<>(
+ "Options used when the exchange is created. Only used when the value of binding property is true. "
+ + "It must have the form type=<type>,durable=<durable>",
+ this.exchangeOptions));
+ properties.put(RabbitMQConstants.QUEUE_NAME, new AbstractMap.SimpleEntry<>(
+ "Name of the queue used to create the binding. Only used when the value "
+ + "of binding property is true.", this.queueName));
+ properties.put(RabbitMQConstants.QUEUE_OPTIONS,
+ new AbstractMap.SimpleEntry<>(
+ "Options used when the queue is created. Only used when the value of "
+ + "binding property is true. It must have the form "
+ + "durable=<durable>,exclusive=<exclusive>,auto-delete=<auto-delete>,arguments=<arguments>",
+ this.queueOptions));
+ properties.put(RabbitMQConstants.ROUTING_KEY, new AbstractMap.SimpleEntry<>(
+ "The routing key used to route messages in the exchange. "
+ + "It only makes sense when the exchange type is topic or direct.",
+ this.routingKey));
+ properties.put(RabbitMQConstants.COMMIT_MODE, new AbstractMap.SimpleEntry<>(
+ "single if a message contains only one document. "
+ + "In this case, a header with the action (write, update or delete) will be added. "
+ + "multiple if a message contains all documents.",
+ this.commitMode));
+ properties.put(RabbitMQConstants.COMMIT_SIZE, new AbstractMap.SimpleEntry<>(
+ "Amount of documents to send into each message if the value of commit.mode "
+ + "property is multiple. In single mode this value represents "
+ + "the amount of messages to be sent.", this.commitSize));
+ properties.put(RabbitMQConstants.HEADERS_STATIC,
+ new AbstractMap.SimpleEntry<>(
+ "Headers to add to each message. It must have the form key1=value1,key2=value2.",
+ this.headersStatic));
+ properties.put(RabbitMQConstants.HEADERS_DYNAMIC,
+ new AbstractMap.SimpleEntry<>(
+ "Document's fields to add as headers to each message. "
+ + "It must have the form field1,field2. "
+ + "Only used when the value of commit.mode property is single",
+ this.headersDynamic));
+
+ return properties;
}
private void addHeaders(final RabbitMQMessage message,
diff --git a/src/plugin/indexer-solr/src/java/org/apache/nutch/indexwriter/solr/SolrIndexWriter.java b/src/plugin/indexer-solr/src/java/org/apache/nutch/indexwriter/solr/SolrIndexWriter.java
index 05b638036..475d313d7 100644
--- a/src/plugin/indexer-solr/src/java/org/apache/nutch/indexwriter/solr/SolrIndexWriter.java
+++ b/src/plugin/indexer-solr/src/java/org/apache/nutch/indexwriter/solr/SolrIndexWriter.java
@@ -21,10 +21,13 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.time.format.DateTimeFormatter;
+import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import org.apache.hadoop.conf.Configuration;
@@ -292,31 +295,43 @@ public class SolrIndexWriter implements IndexWriter {
}
/**
- * Returns a String describing the IndexWriter instance and the specific parameters it can take.
+ * Returns {@link Map} with the specific parameters the IndexWriter instance can take.
*
- * @return The full description.
+ * @return The values of each row. It must have the form <KEY,<DESCRIPTION,VALUE>>.
*/
@Override
- public String describe() {
- StringBuffer sb = new StringBuffer(this.getClass().getSimpleName())
- .append("\n");
- sb.append("\t").append(SolrConstants.SERVER_TYPE).append(": ")
- .append(this.type).append("\n");
- sb.append("\t").append(SolrConstants.SERVER_URLS).append(": ")
- .append(this.urls == null ? "null" : String.join(",", urls))
- .append("\n");
- sb.append("\t").append(SolrConstants.COLLECTION).append(": ")
- .append(this.collection).append("\n");
- sb.append("\t").append(SolrConstants.COMMIT_SIZE).append(": ")
- .append(this.batchSize).append("\n");
- sb.append("\t").append(SolrConstants.WEIGHT_FIELD).append(": ")
- .append(this.weightField).append("\n");
- sb.append("\t").append(SolrConstants.USE_AUTH).append(": ")
- .append(this.auth).append("\n");
- sb.append("\t").append(SolrConstants.USERNAME).append(": ")
- .append(this.username).append("\n");
- sb.append("\t").append(SolrConstants.PASSWORD).append(": ")
- .append(this.password).append("\n");
- return sb.toString();
+ public Map<String, Entry<String, Object>> describe() {
+ Map<String, Entry<String, Object>> properties = new LinkedHashMap<>();
+
+ properties.put(SolrConstants.SERVER_TYPE, new AbstractMap.SimpleEntry<>(
+ "Specifies the SolrClient implementation to use. This is a string value of one of the following \"cloud\" or \"http\"."
+ + " The values represent CloudSolrServer or HttpSolrServer respectively.",
+ this.type));
+ properties.put(SolrConstants.SERVER_URLS, new AbstractMap.SimpleEntry<>(
+ "Defines the fully qualified URL of Solr into which data should be indexed. Multiple URL can be provided using comma as a delimiter."
+ + " When the value of type property is cloud, the URL should not include any collections or cores; just the root Solr path.",
+ this.urls == null ? "" : String.join(",", urls)));
+ properties.put(SolrConstants.COLLECTION, new AbstractMap.SimpleEntry<>(
+ "The collection used in requests. Only used when the value of type property is cloud.",
+ this.collection));
+ properties.put(SolrConstants.COMMIT_SIZE, new AbstractMap.SimpleEntry<>(
+ "Defines the number of documents to send to Solr in a single update batch. "
+ + "Decrease when handling very large documents to prevent Nutch from running out of memory.\n"
+ + "Note: It does not explicitly trigger a server side commit.",
+ this.batchSize));
+ properties.put(SolrConstants.WEIGHT_FIELD, new AbstractMap.SimpleEntry<>(
+ "Field's name where the weight of the documents will be written. If it is empty no field will be used.",
+ this.weightField));
+ properties.put(SolrConstants.USE_AUTH, new AbstractMap.SimpleEntry<>(
+ "Whether to enable HTTP basic authentication for communicating with Solr. Use the username and password properties to configure your credentials.",
+ this.auth));
+ properties.put(SolrConstants.USERNAME,
+ new AbstractMap.SimpleEntry<>("The username of Solr server.",
+ this.username));
+ properties.put(SolrConstants.PASSWORD,
+ new AbstractMap.SimpleEntry<>("The password of Solr server.",
+ this.password));
+
+ return properties;
}
}