-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Triplestsore indexer #28
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ffc8513
Rewiring triplestore indexer
dannylamb bc84be4
First pass after initial testing. Functional, but requires tests.
dannylamb d785695
Triplestore indexer tests
dannylamb 51453b2
Conding standards fixes
dannylamb b43f5a8
Removing dummy creds from config
dannylamb 2e61108
Fixing config mis-deployment
dannylamb 2a851f9
Bumping activemq
dannylamb e28c733
Tests are now pointing to the same config
dannylamb 5da158f
Found another missing .alpaca.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have already an
islandora.alpaca.indexing.triplestore.cfg
file that defines these properties' values, we should load them from here instead of hardcoding. See http://camel.apache.org/properties.html#Properties-Usinga.cfgor.propertiesFileForBlueprintPropertyPlaceholdersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DiegoPino The properties placeholder element in
blueprint.xml
is what loads the config file, and the 'hardcoded' values you're referring to are the defaults in case someone modifies a config file and removes an entry. It also is what bridges the gap and allows me to refer to values from config within routes, and not just in the blueprint file.