Commit e3dc0b84 authored by acoburn's avatar acoburn
Browse files

Add a file-backend for the linked data service

parent 37870263
......@@ -23,6 +23,7 @@ These modules provide particular services, independent of Fedora Resources.
* `acrepo-services-jsonld`: This service creates expanded or compact JSON-LD representations of input documents
* `acrepo-services-ldcache`: This service dereferences and caches URIs, retrieving the `object` of particular triples on demand
* `acrepo-services-ldcache-file`: A file-based backend for the `acrepo-services-ldcache` service
* `acrepo-services-mint`: This mints random (public) URIs for use with fedora resources
* `acrepo-services-validation`: An OSGi-based validation service
......@@ -69,6 +70,7 @@ command from its shell:
feature:install acrepo-services-mint
feature:install acrepo-services-jsonld
feature:install acrepo-services-ldcache
feature:install acrepo-services-ldcache-file
feature:install acrepo-services-mint
feature:install acrepo-services-validation
feature:install acrepo-xml-metadata
......
......@@ -55,6 +55,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-services-ldcache-file</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-services-ldcache</artifactId>
......
......@@ -15,9 +15,10 @@
*/
package edu.amherst.acdc.itests;
import static org.junit.Assume.assumeTrue;
import static edu.amherst.acdc.services.ldcache.file.LDCacheFileBackendFactory.createBackend;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.ops4j.pax.exam.CoreOptions.maven;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
......@@ -57,7 +58,7 @@ public class AcrepoLdCacheIT extends AbstractOSGiIT {
private static final String OFFICIAL_NAME = "http://www.geonames.org/ontology#officialName";
private static final Logger LOGGER = getLogger(AcrepoLdCacheIT.class);
private static final LDCacheService svc = new LDCacheServiceImpl("target/ldcache", 100000);
private static final LDCacheService svc = new LDCacheServiceImpl(createBackend("target/ldcache"), 100000);
@Configuration
public Option[] config() {
......@@ -81,7 +82,7 @@ public class AcrepoLdCacheIT extends AbstractOSGiIT {
.versionAsInProject().classifier("features").type("xml"), "scr", "wrap"),
features(maven().groupId("edu.amherst.acdc").artifactId("acrepo-karaf")
.type("xml").classifier("features").versionAsInProject(),
"acrepo-services-ldcache"),
"acrepo-services-ldcache", "acrepo-services-ldcache-file"),
systemProperty("fcrepo.port").value(fcrepoPort),
......@@ -94,6 +95,7 @@ public class AcrepoLdCacheIT extends AbstractOSGiIT {
@Test
public void testInstallation() throws Exception {
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-ldcache")));
assertTrue(featuresService.isInstalled(featuresService.getFeature("acrepo-services-ldcache-file")));
}
......
......@@ -63,6 +63,18 @@
<configfile finalname="/etc/edu.amherst.acdc.services.ldcache.cfg">mvn:edu.amherst.acdc/acrepo-services-ldcache/${project.version}/cfg/configuration</configfile>
</feature>
<feature name="acrepo-services-ldcache-file" version="${project.version}">
<details>Installs the LDCache service</details>
<bundle>mvn:edu.amherst.acdc/acrepo-services-ldcache-file/${project.version}</bundle>
<feature version="${project.version}">acrepo-marmotta-libs</feature>
<bundle>${wrapped.bundle.location}/org.apache.marmotta.ldcache-backend-file-${marmotta.version}.jar</bundle>
<configfile finalname="/etc/edu.amherst.acdc.services.ldcache.file.cfg">mvn:edu.amherst.acdc/acrepo-services-ldcache-file/${project.version}/cfg/configuration</configfile>
</feature>
<feature name="acrepo-services-mint" version="${project.version}">
<details>Installs the id minter</details>
......@@ -222,7 +234,6 @@
<bundle>${wrapped.bundle.location}/org.apache.marmotta.ldclient-provider-rdf-${marmotta.version}.jar</bundle>
<bundle>${wrapped.bundle.location}/org.apache.marmotta.ldclient-provider-rdfa-${marmotta.version}.jar</bundle>
<bundle>${wrapped.bundle.location}/org.apache.marmotta.ldclient-provider-xml-${marmotta.version}.jar</bundle>
<bundle>${wrapped.bundle.location}/org.apache.marmotta.ldcache-backend-file-${marmotta.version}.jar</bundle>
<bundle dependency="true">mvn:commons-collections/commons-collections/${commons-collections.version}</bundle>
<bundle dependency="true">mvn:com.google.guava/guava/${guava16.version}</bundle>
......
File Backend for the Linked Data Cache Service
==============================================
This module provides access to a linked data caching service.
Building
--------
To build this project use
mvn install
Deploying in OSGi
-----------------
Each of these projects can be deployed in an OSGi container. For example using
[Apache Karaf](http://karaf.apache.org) version 4.x and above, you can run the following
command from its shell:
feature:repo-add mvn:edu.amherst.acdc/acrepo-karaf/LATEST/xml/features
feature:install acrepo-services-ldcache-file
Configuration
-------------
The application can be configured by creating the following configuration
file `$KARAF_HOME/etc/edu.amherst.acdc.services.ldcache.file.cfg`. The following values
are available for configuration:
The directory in which to store the cache files
ldcache.cacheDir=/tmp/ldcache
By editing this file, this service will be immediately redeployed
with the new configuration.
For more help see the [Apache Camel](http://camel.apache.org/) documentation
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>repository-services</artifactId>
<groupId>edu.amherst.acdc</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<artifactId>acrepo-services-ldcache-file</artifactId>
<packaging>bundle</packaging>
<name>File backend for the Linked Data Caching Service</name>
<description>A file backend for the Linked Data Caching Service</description>
<properties>
<osgi.export.packages>edu.amherst.acdc.services.ldcache.file;version=${project.version}</osgi.export.packages>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.marmotta</groupId>
<artifactId>ldcache-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.marmotta</groupId>
<artifactId>ldcache-backend-file</artifactId>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- reserve network ports for integration testing -->
<!-- add configuration file to artifact set for OSGi deployment -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>src/main/cfg/edu.amherst.acdc.services.ldcache.file.cfg</file>
<type>cfg</type>
<classifier>configuration</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2016 Amherst College
*
* Licensed 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.
*/
package edu.amherst.acdc.services.ldcache.file;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.File;
import org.apache.marmotta.ldcache.api.LDCachingBackend;
import org.apache.marmotta.ldcache.backend.file.LDCachingFileBackend;
import org.slf4j.Logger;
/**
* @author acoburn
* @since 6/27/16
*/
public class LDCacheFileBackendFactory {
private static Logger LOGGER = getLogger(LDCacheFileBackendFactory.class);
/**
* Create a File-based LDCachingBackend
* @param storageDir the location where files will be stored
* @return a backend for linked data caching
*/
public static LDCachingBackend createBackend(final String storageDir) {
try {
final LDCachingBackend backend = new LDCachingFileBackend(new File(storageDir));
backend.initialize();
return backend;
} catch (final Exception ex) {
LOGGER.error("Error creating LDCachingBackend: {}", ex.getMessage());
throw new RuntimeException(ex);
}
}
private LDCacheFileBackendFactory() {
// prevent instantiation
}
}
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd"
default-activation="lazy">
<cm:property-placeholder persistent-id="edu.amherst.acdc.services.ldcache" update-strategy="reload" >
<cm:default-properties>
<cm:property name="ldcache.cacheDir" value="/tmp/ldcache"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="ldcacheBackendBean" class="edu.amherst.acdc.services.ldcache.file.LDCacheFileBackendFactory" factory-method="createBackend">
<argument value="${ldcache.cacheDir}"/>
</bean>
<service ref="ldcacheBackendBean" interface="org.apache.marmotta.ldcache.api.LDCachingBackend">
<service-properties>
<entry key="osgi.jndi.service.name" value="cachingbackend"/>
</service-properties>
</service>
</blueprint>
/*
* Copyright 2016 Amherst College
*
* Licensed 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.
*/
package edu.amherst.acdc.services.ldcache.file;
import static org.junit.Assert.assertNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import org.junit.Test;
import org.slf4j.Logger;
/**
* @author acoburn
* @since 9/14/15
*/
public class LdCacheFileBackendTest {
private static Logger LOGGER = getLogger(LdCacheFileBackendTest.class);
@Test
public void testCreate() throws Exception {
assertNotNull(LDCacheFileBackendFactory.createBackend("/tmp/ldcache"));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%p %d{HH:mm:ss.SSS} \(%c{0}\) %m%n</pattern>
</encoder>
</appender>
<logger name="edu.amherst.acdc.services.ldcache" additivity="false" level="INFO">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.apache.camel" additivity="false" level="INFO">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.fcrepo.camel" additivity="false" level="INFO">
<appender-ref ref="STDOUT"/>
</logger>
<root additivity="false" level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
Linked Data Cache Service
=========================
This module provides access to a linked data caching service.
This module provides access to a linked data caching service. A backend implementation
must also be installed (such as `acrepo-services-ldcache-file`).
Building
--------
......@@ -19,6 +20,7 @@ command from its shell:
feature:repo-add mvn:edu.amherst.acdc/acrepo-karaf/LATEST/xml/features
feature:install acrepo-services-ldcache
feature:install acrepo-services-ldcache-file
Configuration
-------------
......@@ -31,10 +33,6 @@ Set the number of seconds before items expire (0=default value: 1 day)
ldcache.timeout=0
The directory in which to store the cache files
ldcache.cacheDir=/tmp/ldcache
By editing this file, this service will be immediately redeployed
with the new configuration.
......
......@@ -16,7 +16,7 @@
<description>Simple Linked Data Caching Service, using Marmotta</description>
<properties>
<osgi.export.packages>edu.amherst.acdc.services.ldcache*;version=${project.version}</osgi.export.packages>
<osgi.export.packages>edu.amherst.acdc.services.ldcache;version=${project.version}</osgi.export.packages>
</properties>
<dependencies>
......@@ -45,11 +45,6 @@
<artifactId>ldclient-provider-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.marmotta</groupId>
<artifactId>ldcache-backend-file</artifactId>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
......@@ -62,6 +57,13 @@
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>edu.amherst.acdc</groupId>
<artifactId>acrepo-services-ldcache-file</artifactId>
<scope>test</scope>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
......
......@@ -19,7 +19,6 @@ import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import static org.slf4j.LoggerFactory.getLogger;
import java.io.File;
import java.util.List;
import com.github.jsonldjava.sesame.SesameJSONLDParserFactory;
......@@ -29,7 +28,6 @@ import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.apache.marmotta.ldcache.api.LDCachingBackend;
import org.apache.marmotta.ldcache.backend.file.LDCachingFileBackend;
import org.apache.marmotta.ldcache.model.CacheConfiguration;
import org.apache.marmotta.ldcache.services.LDCache;
import org.apache.marmotta.ldclient.endpoint.rdf.SPARQLEndpoint;
......@@ -87,16 +85,11 @@ public class LDCacheServiceImpl implements LDCacheService {
/**
* Create a LDCacheServiceImpl object with a backing filesystem cache
* @param storageDir the directory where data is stored
* @param backend the caching backend to use
* @param timeout the number of seconds before the cache is cleared
* TODO - this constructor should accept a LDCachingBackend that is defined separately
* as an OSGi service, but this is fine for now.
*/
public LDCacheServiceImpl(final String storageDir, final long timeout) {
public LDCacheServiceImpl(final LDCachingBackend backend, final long timeout) {
try {
final LDCachingBackend backend = new LDCachingFileBackend(new File(storageDir));
backend.initialize();
final CacheConfiguration config = new CacheConfiguration(buildClientConfiguration());
if (timeout > 0) {
config.setDefaultExpiry(timeout * 1000);
......@@ -111,11 +104,10 @@ public class LDCacheServiceImpl implements LDCacheService {
/**
* Create a LDCacheServiceImpl object with a backing filesystem cache
* @param storageDir the directory where data is stored
* TODO - this constructor should accept a LDCachingBackend object (see above)
* @param backend the caching backend to use
*/
public LDCacheServiceImpl(final String storageDir) {
this(storageDir, 0);
public LDCacheServiceImpl(final LDCachingBackend backend) {
this(backend, 0);
}
@Override
......
......@@ -9,13 +9,14 @@
<cm:property-placeholder persistent-id="edu.amherst.acdc.services.ldcache" update-strategy="reload" >
<cm:default-properties>
<cm:property name="ldcache.cacheDir" value="/tmp/ldcache"/>
<cm:property name="ldcache.timeout" value="0"/>
</cm:default-properties>
</cm:property-placeholder>
<reference id="cachingBackend" interface="org.apache.marmotta.ldcache.api.LDCachingBackend" filter="(osgi.jndi.service.name=cachingbackend)"/>
<bean id="ldcacheServiceBean" class="edu.amherst.acdc.services.ldcache.LDCacheServiceImpl">
<argument value="${ldcache.cacheDir}"/>
<argument ref="cachingBackend"/>
<argument value="${ldcache.timeout}"/>
</bean>
......
......@@ -15,6 +15,7 @@
*/
package edu.amherst.acdc.services.ldcache;
import static edu.amherst.acdc.services.ldcache.file.LDCacheFileBackendFactory.createBackend;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
......@@ -37,7 +38,7 @@ public class LdCacheServiceTest {
private static final String LABEL = "http://www.w3.org/2000/01/rdf-schema#label";
private static final String OFFICIAL_NAME = "http://www.geonames.org/ontology#officialName";
private static final LDCacheService svc = new LDCacheServiceImpl("/tmp/ldcache");
private static final LDCacheService svc = new LDCacheServiceImpl(createBackend("/tmp/ldcache"));
@Test
public void testFetchDbpedia() throws Exception {
......
......@@ -112,6 +112,7 @@
<module>acrepo-karaf</module>
<module>acrepo-services-jsonld</module>
<module>acrepo-services-ldcache</module>
<module>acrepo-services-ldcache-file</module>
<module>acrepo-services-mint</module>
<module>acrepo-services-validation</module>
<module>acrepo-xml-metadata</module>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment