Apache Nutch is an extensible and scalable web crawler
Fixes for NUTCH-2412: Exchange is optional now and package info.
r0ann3l4f4558f2b1f6
diff --git a/conf/exchanges.xml.template b/conf/exchanges.xml.templateindex dfe40de9c..ab2eb941a 100644--- a/conf/exchanges.xml.template+++ b/conf/exchanges.xml.template@@ -18,6 +18,7 @@<exchanges xmlns="http://lucene.apache.org/nutch"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://lucene.apache.org/nutch exchanges.xsd">+ <!--<exchange id="exchange_jexl_1" class="org.apache.nutch.exchange.jexl.JexlExchange"><writers><writer id="indexer_solr_1" />@@ -33,4 +34,5 @@</writers><params /></exchange>+ --></exchanges>\ No newline at end of filediff --git a/conf/exchanges.xsd b/conf/exchanges.xsdindex 3c6935bd0..42caeb709 100644--- a/conf/exchanges.xsd+++ b/conf/exchanges.xsd@@ -22,7 +22,7 @@<xs:element name="exchanges"><xs:complexType><xs:sequence>- <xs:element name="exchange" type="exchangeType" maxOccurs="unbounded" minOccurs="1"/>+ <xs:element name="exchange" type="exchangeType" maxOccurs="unbounded" minOccurs="0"/></xs:sequence></xs:complexType></xs:element>@@ -36,7 +36,7 @@</xs:complexType><xs:complexType name="writersType"><xs:sequence>- <xs:element type="writerType" name="writer" maxOccurs="unbounded" minOccurs="1" />+ <xs:element type="writerType" name="writer" maxOccurs="unbounded" minOccurs="0" /></xs:sequence></xs:complexType><xs:complexType name="writerType">diff --git a/conf/log4j.properties b/conf/log4j.propertiesindex 1939014dc..211dad5c6 100644--- a/conf/log4j.properties+++ b/conf/log4j.properties@@ -47,6 +47,7 @@ log4j.logger.org.apache.nutch.indexer.IndexingJob=INFO,cmdstdoutlog4j.logger.org.apache.nutch.indexer.IndexerOutputFormat=INFO,cmdstdoutlog4j.logger.org.apache.nutch.indexwriter.solr.SolrIndexWriter=INFO,cmdstdoutlog4j.logger.org.apache.nutch.indexwriter.solr.SolrUtils=INFO,cmdstdout+log4j.logger.org.apache.nutch.exchange.Exchanges=INFO,cmdstdoutlog4j.logger.org.apache.nutch.parse.ParserChecker=INFO,cmdstdoutlog4j.logger.org.apache.nutch.parse.ParseSegment=INFO,cmdstdoutlog4j.logger.org.apache.nutch.plugin.PluginRepository=WARNdiff --git a/src/java/org/apache/nutch/exchange/Exchanges.java b/src/java/org/apache/nutch/exchange/Exchanges.javaindex 349774835..1f443d4c1 100644--- a/src/java/org/apache/nutch/exchange/Exchanges.java+++ b/src/java/org/apache/nutch/exchange/Exchanges.java@@ -45,6 +45,8 @@ public class Exchanges {private ExchangeConfig defaultExchangeConfig;+ private boolean availableExchanges = true;+public Exchanges(Configuration conf) {try {ExtensionPoint point = PluginRepository.get(conf)@@ -63,16 +65,30 @@ public class Exchanges {ExchangeConfig[] exchangeConfigs = loadConfigurations(conf);for (ExchangeConfig exchangeConfig : exchangeConfigs) {- ExchangeConfigRelation exchangeConfigRelation = new ExchangeConfigRelation(- (Exchange) extensionMap.get(exchangeConfig.getClazz())- .getExtensionInstance(), exchangeConfig);- exchanges.put(exchangeConfig.getId(), exchangeConfigRelation);+ final String clazz = exchangeConfig.getClazz();++ // If was enabled in plugin.includes property+ if (extensionMap.containsKey(clazz)) {+ ExchangeConfigRelation exchangeConfigRelation = new ExchangeConfigRelation(+ (Exchange) extensionMap.get(clazz).getExtensionInstance(),+ exchangeConfig);+ exchanges.put(exchangeConfig.getId(), exchangeConfigRelation);+ }+ }++ if (exchanges.isEmpty() && defaultExchangeConfig == null) {+ availableExchanges = false;+ LOG.warn("No exchange was configured. The documents will be routed to all index writers.");}} catch (PluginRuntimeException e) {throw new RuntimeException(e);}}+ public boolean areAvailableExchanges() {+ return availableExchanges;+ }+/*** Loads the configuration of each exchange.*diff --git a/src/java/org/apache/nutch/exchange/package-info.java b/src/java/org/apache/nutch/exchange/package-info.javanew file mode 100644index 000000000..c7829f053--- /dev/null+++ b/src/java/org/apache/nutch/exchange/package-info.java@@ -0,0 +1,24 @@+/*+ * 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.+ */++/**+ * Control code for exchange component, which acts in indexing job and decides to+ * which index writer a document should be routed, based on plugins behavior.+ *+ * @since 1.15+ */+package org.apache.nutch.exchange;\ No newline at end of filediff --git a/src/java/org/apache/nutch/indexer/IndexWriters.java b/src/java/org/apache/nutch/indexer/IndexWriters.javaindex 8884a792e..db37d62f1 100644--- a/src/java/org/apache/nutch/indexer/IndexWriters.java+++ b/src/java/org/apache/nutch/indexer/IndexWriters.java@@ -18,6 +18,7 @@ package org.apache.nutch.indexer;import org.apache.hadoop.conf.Configuration;import org.apache.nutch.exchange.Exchanges;+import org.apache.nutch.metadata.Nutch;import org.apache.nutch.plugin.Extension;import org.apache.nutch.plugin.ExtensionPoint;import org.apache.nutch.plugin.PluginRepository;@@ -37,10 +38,7 @@ import javax.xml.parsers.ParserConfigurationException;import java.io.IOException;import java.io.InputStream;import java.lang.invoke.MethodHandles;-import java.util.HashMap;-import java.util.List;-import java.util.Map;-import java.util.WeakHashMap;+import java.util.*;/*** Creates and caches {@link IndexWriter} implementing plugins.@@ -186,6 +184,19 @@ public class IndexWriters {}}+ /**+ * Ensures if there are not available exchanges, the document will be routed to all configured index writers.+ *+ * @param doc Document to process.+ * @return Index writers IDs.+ */+ private Collection<String> getIndexWriters(NutchDocument doc) {+ if (this.exchanges.areAvailableExchanges()) {+ return Arrays.asList(this.exchanges.indexWriters(doc));+ }+ return this.indexWriters.keySet();+ }+/*** Initializes the internal variables of index writers.*@@ -203,7 +214,7 @@ public class IndexWriters {}public void write(NutchDocument doc) throws IOException {- for (String indexWriterId : this.exchanges.indexWriters(doc)) {+ for (String indexWriterId : getIndexWriters(doc)) {NutchDocument mappedDocument = mapDocument(doc,this.indexWriters.get(indexWriterId).getIndexWriterConfig().getMapping());@@ -213,7 +224,7 @@ public class IndexWriters {}public void update(NutchDocument doc) throws IOException {- for (String indexWriterId : this.exchanges.indexWriters(doc)) {+ for (String indexWriterId : getIndexWriters(doc)) {NutchDocument mappedDocument = mapDocument(doc,this.indexWriters.get(indexWriterId).getIndexWriterConfig().getMapping());@@ -223,13 +234,13 @@ public class IndexWriters {}public void delete(String key, NutchDocument doc) throws IOException {- for (String indexWriterId : this.exchanges.indexWriters(doc)) {+ for (String indexWriterId : getIndexWriters(doc)) {this.indexWriters.get(indexWriterId).getIndexWriter().delete(key);}}-public void delete(String key) throws IOException {-+ public void delete(String key) throws IOException {+}public void close() throws IOException {diff --git a/src/plugin/exchange-jexl/src/java/org/apache/nutch/exchange/jexl/package-info.java b/src/plugin/exchange-jexl/src/java/org/apache/nutch/exchange/jexl/package-info.javanew file mode 100644index 000000000..679306adb--- /dev/null+++ b/src/plugin/exchange-jexl/src/java/org/apache/nutch/exchange/jexl/package-info.java@@ -0,0 +1,23 @@+/*+ * 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.+ */++/**+ * Plugin of Exchange component based on JEXL expressions.+ *+ * @since 1.15+ */+package org.apache.nutch.exchange.jexl;\ No newline at end of file