Skip to content
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 9 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ subprojects {
slf4jVersion = '1.7.12'
fcrepoCamelVersion = '4.5.0'
fcrepoCamelToolboxVersion = '4.7.0'
activemqVersion = '5.14.0'
activemqVersion = '5.14.1'
commonsIoVersion = '2.4'

camelVersionRange = '[2.18.0, 3)'
Expand Down
5 changes: 4 additions & 1 deletion islandora-connector-broadcast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description = 'Islandora CLAW Broadcaster'
dependencies {
compile group: 'org.apache.camel', name: 'camel-core', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion
compile group: 'org.apache.activemq', name: 'activemq-camel', version: activemqVersion
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
}
Expand All @@ -16,7 +17,9 @@ jar {
vendor project.vendor
license project.license

instruction 'Import-Package', "org.apache.camel;version=\"${camelVersionRange}\",${defaultOsgiImports}"
instruction 'Import-Package', 'org.apache.activemq.camel.component,' +
"org.apache.camel;version=\"${camelVersionRange}\"," +
defaultOsgiImports
instruction 'Export-Package', 'ca.islandora.alpaca.connector.broadcast'
}
}
Expand Down
9 changes: 7 additions & 2 deletions islandora-indexing-triplestore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ dependencies {
compile group: 'org.apache.camel', name: 'camel-core', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-blueprint', version: camelVersion
compile group: 'org.apache.camel', name: 'camel-http4', version: camelVersion
compile group: 'org.apache.activemq', name: 'activemq-camel', version: activemqVersion
compile group: 'org.apache.camel', name: 'camel-jsonpath', version: camelVersion
compile group: 'org.fcrepo.camel', name: 'fcrepo-camel', version: fcrepoCamelVersion
compile group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion
testCompile group: 'org.apache.camel', name: 'camel-test-blueprint', version: camelVersion
testCompile group: 'org.apache.activemq', name: 'activemq-camel', version: activemqVersion
testCompile group: 'org.apache.servicemix.bundles', name: 'org.apache.servicemix.bundles.xerces', version: '2.11.0_1'
testCompile group: 'org.ow2.asm', name: 'asm-commons', version: '5.0.3'


}

jar {
Expand All @@ -20,8 +25,8 @@ jar {
license project.license

instruction 'Import-Package', 'org.apache.camel.component.http4,' +
'org.apache.activemq.camel.component,' +
"org.apache.camel;version=\"${camelVersionRange}\"," +
"org.fcrepo.camel.processor," +
defaultOsgiImports
instruction 'Export-Package', 'ca.islandora.indexing.triplestore'
}
Expand Down
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=
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}}");

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

<!-- OSGI blueprint property placeholder -->
<cm:property-placeholder id="properties" persistent-id="ca.islandora.indexing.triplestore" update-strategy="reload" />
<cm:property-placeholder id="properties" persistent-id="ca.islandora.alpaca.indexing.triplestore" update-strategy="reload" >

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.propertiesFileForBlueprintPropertyPlaceholders

Copy link
Contributor Author

@dannylamb dannylamb Feb 8, 2017

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.

<cm:default-properties>
<cm:property name="error.maxRedeliveries" value="5"/>
<cm:property name="input.stream" value="activemq:queue:islandora-indexing-triplestore"/>
<cm:property name="triplestore.baseUrl" value="http://localhost:8080/bigdata/namespace/kb/sparql"/>
<cm:property name="drupal.username" value=""/>
<cm:property name="drupal.password" value=""/>
</cm:default-properties>
</cm:property-placeholder>

<!-- configuration of activemq component -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${jms.brokerUrl}"/>
</bean>
<reference id="broker" interface="org.apache.camel.Component" filter="(osgi.jndi.service.name=fcrepo/Broker)"/>

<bean id="http" class="org.apache.camel.component.http4.HttpComponent"/>
<bean id="https" class="org.apache.camel.component.http4.HttpComponent"/>

<camelContext id="IslandoraTriplestoreIndexer" xmlns="http://camel.apache.org/schema/blueprint">
<package>ca.islandora.indexing.triplestore</package>
<package>ca.islandora.alpaca.indexing.triplestore</package>
</camelContext>

</blueprint>
Loading