-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rewiring triplestore indexer * First pass after initial testing. Functional, but requires tests. * Triplestore indexer tests * Conding standards fixes * Removing dummy creds from config * Fixing config mis-deployment * Bumping activemq * Tests are now pointing to the same config * Found another missing .alpaca.
- Loading branch information
Showing
13 changed files
with
464 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...cfg/ca.islandora.indexing.triplestore.cfg → ...islandora.alpaca.indexing.triplestore.cfg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
# In the event of failure, the maximum number of times a redelivery will be attempted. | ||
error.maxRedeliveries=10 | ||
|
||
# The JMS connection URI, used for connecting to a local or remote ActiveMQ broker. | ||
jms.brokerUrl=tcp://localhost:61616 | ||
|
||
# The camel URI for the incoming message stream. | ||
input.stream=activemq:queue:islandora/triplestore/index | ||
input.stream=activemq:queue:islandora-indexing-triplestore | ||
|
||
# The base URL of the triplestore being used. | ||
triplestore.baseUrl=http://localhost:8080/bigdata/namespace/kb/sparql | ||
|
||
# Credentials for user with read privileges for the resource. | ||
drupal.username= | ||
drupal.password= |
106 changes: 106 additions & 0 deletions
106
...riplestore/src/main/java/ca/islandora/alpaca/indexing/triplestore/TriplestoreIndexer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Licensed to Islandora Foundation under one or more contributor license | ||
* agreements. See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* The Islandora Foundation licenses this file to you under the MIT License. | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/MIT | ||
* | ||
* 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 ca.islandora.alpaca.indexing.triplestore; | ||
|
||
import static org.apache.camel.LoggingLevel.ERROR; | ||
import static org.apache.camel.LoggingLevel.INFO; | ||
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import com.jayway.jsonpath.JsonPathException; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.Exchange; | ||
import org.fcrepo.camel.processor.SparqlUpdateProcessor; | ||
import org.fcrepo.camel.processor.SparqlDeleteProcessor; | ||
import org.slf4j.Logger; | ||
|
||
/** | ||
* @author dhlamb | ||
*/ | ||
public class TriplestoreIndexer extends RouteBuilder { | ||
|
||
private static final Logger LOGGER = getLogger(TriplestoreIndexer.class); | ||
|
||
@Override | ||
public void configure() { | ||
|
||
// Global exception handler for the indexer. | ||
// Just logs after retrying X number of times. | ||
onException(Exception.class) | ||
.maximumRedeliveries("{{error.maxRedeliveries}}") | ||
.handled(true) | ||
.log( | ||
ERROR, | ||
LOGGER, | ||
"Error indexing ${property.uri} in triplestore: ${exception.message}\n\n${exception.stacktrace}" | ||
); | ||
|
||
// Main router. | ||
from("{{input.stream}}") | ||
.routeId("IslandoraTriplestoreIndexerRouter") | ||
.to("direct:parse.event") | ||
.choice() | ||
.when(exchangeProperty("action").isEqualTo("Delete")) | ||
.to("direct:triplestore.delete") | ||
.otherwise() | ||
.to("direct:retrieve.resource") | ||
.to("direct:triplestore.index"); | ||
|
||
// Extracts info using jsonpath and stores it as properties on the exchange. | ||
from("direct:parse.event") | ||
.routeId("IslandoraTriplestoreIndexerParseEvent") | ||
// Custom exception handler. Doesn't retry if event is malformed. | ||
.onException(JsonPathException.class) | ||
.maximumRedeliveries(0) | ||
.handled(true) | ||
.log( | ||
ERROR, | ||
LOGGER, | ||
"Error extracting properties from event: ${exception.message}\n\n${exception.stacktrace}" | ||
) | ||
.end() | ||
.setProperty("action").jsonpath("$.type") | ||
.setProperty("uri").jsonpath("$.object"); | ||
|
||
// POSTs a SPARQL delete query for all triples with subject == uri. | ||
from("direct:triplestore.delete") | ||
.routeId("IslandoraTriplestoreIndexerDelete") | ||
.setHeader(FCREPO_URI, simple("${property.uri}?_format=jsonld")) | ||
.process(new SparqlDeleteProcessor()) | ||
.log(INFO, LOGGER, "Deleting ${property.uri} in triplestore") | ||
.to("{{triplestore.baseUrl}}"); | ||
|
||
// Retrieves the resource from Drupal. | ||
from("direct:retrieve.resource") | ||
.routeId("IslandoraTriplestoreIndexerRetrieveResource") | ||
.setHeader(Exchange.HTTP_METHOD, constant("GET")) | ||
.toD("${property.uri}?_format=jsonld&authUsername={{drupal.username}}" + | ||
"&authPassword={{drupal.password}}" | ||
); | ||
|
||
// Converts the resource to a SPARQL update query, POSTing it to the triplestore. | ||
from("direct:triplestore.index") | ||
.routeId("IslandoraTriplestoreIndexerIndex") | ||
.setHeader(FCREPO_URI, simple("${property.uri}?_format=jsonld")) | ||
.process(new SparqlUpdateProcessor()) | ||
.log(INFO, LOGGER, "Indexing ${property.uri} in triplestore") | ||
.to("{{triplestore.baseUrl}}"); | ||
|
||
} | ||
} |
71 changes: 0 additions & 71 deletions
71
...exing-triplestore/src/main/java/ca/islandora/indexing/triplestore/TriplestoreIndexer.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.