Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2903 indexer-elastic: allow to connect to Elastic server via HTTPS - add index writer param "scheme" to configure whether "http" or "https" is used - fix deprecation in using es.BulkProcessor

Sebastian Nagel6393cac72c75
diff --git a/conf/index-writers.xml.template b/conf/index-writers.xml.template
index ad8bb75f5..9f5d7916c 100644
--- a/conf/index-writers.xml.template
+++ b/conf/index-writers.xml.template
@@ -108,6 +108,7 @@
<parameters>
<param name="host" value="localhost"/>
<param name="port" value="9200"/>
+ <param name="scheme" value="http"/><!-- http or https -->
<param name="index" value="nutch"/>
<param name="username" value="elastic"/>
<param name="password" value=""/>
diff --git a/src/java/org/apache/nutch/indexer/IndexWriterParams.java b/src/java/org/apache/nutch/indexer/IndexWriterParams.java
index 52cc4f9c9..2f138ee1e 100644
--- a/src/java/org/apache/nutch/indexer/IndexWriterParams.java
+++ b/src/java/org/apache/nutch/indexer/IndexWriterParams.java
@@ -24,12 +24,9 @@ import java.util.Map;
public class IndexWriterParams extends HashMap<String, String> {
/**
- * Constructs a new <code>HashMap</code> with the same mappings as the
- * specified <code>Map</code>. The <code>HashMap</code> is created with
- * default load factor (0.75) and an initial capacity sufficient to
- * hold the mappings in the specified <code>Map</code>.
+ * Fill IndexWriterParams from map.
*
- * @param m the map whose mappings are to be placed in this map
+ * @param m the map to take params from
* @throws NullPointerException if the specified map is null
*/
public IndexWriterParams(Map<? extends String, ? extends String> m) {
diff --git a/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticConstants.java b/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticConstants.java
index c0d1a6177..a64566d4d 100644
--- a/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticConstants.java
+++ b/src/plugin/indexer-elastic/src/java/org/apache/nutch/indexwriter/elastic/ElasticConstants.java
@@ -19,6 +19,7 @@ package org.apache.nutch.indexwriter.elastic;
public interface ElasticConstants {
String HOSTS = "host";
String PORT = "port";
+ String SCHEME = "scheme";
String USER = "username";
String PASSWORD = "password";
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 e81e968b0..549b62027 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
@@ -76,10 +76,10 @@ public class ElasticIndexWriter implements IndexWriter {
private String[] hosts;
private int port;
- private Boolean https = null;
+ private String scheme = HttpHost.DEFAULT_SCHEME_NAME;
private String user = null;
private String password = null;
- private Boolean auth;
+ private boolean auth;
private int maxBulkDocs;
private int maxBulkLength;
@@ -139,8 +139,10 @@ public class ElasticIndexWriter implements IndexWriter {
LOG.debug("Creating BulkProcessor with maxBulkDocs={}, maxBulkLength={}",
maxBulkDocs, maxBulkLength);
bulkProcessor = BulkProcessor
- .builder((request, bulkListener) -> client.bulkAsync(request,
- RequestOptions.DEFAULT, bulkListener), bulkProcessorListener())
+ .builder(
+ (request, bulkListener) -> client.bulkAsync(request,
+ RequestOptions.DEFAULT, bulkListener),
+ bulkProcessorListener(), "nutch-indexer-elastic")
.setBulkActions(maxBulkDocs)
.setBulkSize(new ByteSizeValue(maxBulkLength, ByteSizeUnit.BYTES))
.setConcurrentRequests(1)
@@ -160,7 +162,7 @@ public class ElasticIndexWriter implements IndexWriter {
throws IOException {
hosts = parameters.getStrings(ElasticConstants.HOSTS);
port = parameters.getInt(ElasticConstants.PORT, DEFAULT_PORT);
-
+ scheme = parameters.get(ElasticConstants.SCHEME, HttpHost.DEFAULT_SCHEME_NAME);
auth = parameters.getBoolean(ElasticConstants.USE_AUTH, false);
user = parameters.get(ElasticConstants.USER, DEFAULT_USER);
password = parameters.get(ElasticConstants.PASSWORD, "");
@@ -175,7 +177,7 @@ public class ElasticIndexWriter implements IndexWriter {
HttpHost[] hostsList = new HttpHost[hosts.length];
int i = 0;
for (String host : hosts) {
- hostsList[i++] = new HttpHost(host, port);
+ hostsList[i++] = new HttpHost(host, port, scheme);
}
RestClientBuilder restClientBuilder = RestClient.builder(hostsList);
if (auth) {
@@ -301,6 +303,8 @@ public class ElasticIndexWriter implements IndexWriter {
this.hosts == null ? "" : String.join(",", hosts)));
properties.put(ElasticConstants.PORT, new AbstractMap.SimpleEntry<>(
"The port to connect to elastic server.", this.port));
+ properties.put(ElasticConstants.SCHEME, new AbstractMap.SimpleEntry<>(
+ "The scheme (http or https) to connect to elastic server.", this.scheme));
properties.put(ElasticConstants.INDEX, new AbstractMap.SimpleEntry<>(
"Default index to send documents to.", this.defaultIndex));
properties.put(ElasticConstants.USER, new AbstractMap.SimpleEntry<>(