Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added policy-based storage strategy hint provider
added testing config with four stores unit test passes integration test needs work
- Loading branch information
Showing
16 changed files
with
671 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<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> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo</artifactId> | ||
<version>4.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>fcrepo-storage-policy</artifactId> | ||
<name>fcrepo store strategy</name> | ||
|
||
<packaging>bundle</packaging> | ||
|
||
<description>Provides store strategy hints based on policy evaluation.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-commons</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-kernel</artifactId> | ||
<version>${project.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
|
||
<!-- test gear --> | ||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-api</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.fcrepo</groupId> | ||
<artifactId>fcrepo-http-commons</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<type>test-jar</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.0.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.grizzly</groupId> | ||
<artifactId>grizzly-servlet-webserver</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.jersey</groupId> | ||
<artifactId>jersey-grizzly</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.mail</groupId> | ||
<artifactId>mail</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.jersey.contribs</groupId> | ||
<artifactId>jersey-spring</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<!-- This dependency is for compile-time: it keeps this module independent | ||
of any given choice of JAX-RS implementation. It must be _after_ the test | ||
gear. Otherwise it will get loaded during test phase, but because this is | ||
just an API, the tests will not be able to execute. --> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-api</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd"> | ||
<modules> | ||
<c disabled="true"/> | ||
<csharp disabled="true"/> | ||
<cxf disabled="true"/> | ||
<jaxws-ri disabled="true"/> | ||
</modules> | ||
</enunciate> |
27 changes: 27 additions & 0 deletions
27
fcrepo-store-strategy/src/main/java/org/fcrepo/store/strategy/NamedStoreStrategyHint.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,27 @@ | ||
package org.fcrepo.store.strategy; | ||
|
||
import java.util.List; | ||
|
||
import org.modeshape.jcr.value.binary.StrategyHint; | ||
|
||
|
||
/** | ||
* @author Gregory Jansen | ||
* | ||
*/ | ||
public class NamedStoreStrategyHint implements StrategyHint { | ||
private List<String> storeNameHint = null; | ||
|
||
NamedStoreStrategyHint(List<String> storeNameHint) { | ||
this.storeNameHint = storeNameHint; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.modeshape.jcr.value.binary.StrategyHint#getHint() | ||
*/ | ||
@Override | ||
public Object getHint() { | ||
return this.storeNameHint; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
fcrepo-store-strategy/src/main/java/org/fcrepo/store/strategy/NoopStrategyHint.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,24 @@ | ||
package org.fcrepo.store.strategy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.modeshape.jcr.value.binary.StrategyHint; | ||
|
||
|
||
/** | ||
* @author Gregory Jansen | ||
* | ||
*/ | ||
public class NoopStrategyHint implements StrategyHint { | ||
private static final List<String> HINT = new ArrayList<String>(); | ||
|
||
/* (non-Javadoc) | ||
* @see org.modeshape.jcr.value.binary.StrategyHint#getHint() | ||
*/ | ||
@Override | ||
public Object getHint() { | ||
return HINT; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
fcrepo-store-strategy/src/main/java/org/fcrepo/store/strategy/PreferredStorePolicy.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,43 @@ | ||
package org.fcrepo.store.strategy; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import javax.jcr.Node; | ||
|
||
import org.modeshape.jcr.value.binary.StrategyHint; | ||
|
||
|
||
/** | ||
* This policy always returned the name of the same store. | ||
* | ||
* @author Gregory Jansen | ||
* | ||
*/ | ||
public class PreferredStorePolicy implements StoragePolicy { | ||
|
||
public List<String> preferredStores; | ||
|
||
/** | ||
* @return the preferredStores | ||
*/ | ||
public List<String> getPreferredStores() { | ||
return preferredStores; | ||
} | ||
|
||
/** | ||
* @param preferredStores the preferredStores to set | ||
*/ | ||
public void setPreferredStores(List<String> preferredStores) { | ||
this.preferredStores = preferredStores; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.fcrepo.store.strategy.StoragePolicy#getStrategyHint(javax.jcr.Node, org.modeshape.jcr.value.binary.StrategyHint) | ||
*/ | ||
@Override | ||
public StrategyHint getStrategyHint(Node node, StrategyHint chain) { | ||
return new NamedStoreStrategyHint(Collections.unmodifiableList(this.preferredStores)); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
fcrepo-store-strategy/src/main/java/org/fcrepo/store/strategy/StoragePolicy.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,25 @@ | ||
package org.fcrepo.store.strategy; | ||
|
||
import javax.jcr.Node; | ||
|
||
import org.modeshape.jcr.value.binary.StrategyHint; | ||
|
||
|
||
/** | ||
* A policy makes a strategy that suggests storage resources. | ||
* @author Gregory Jansen | ||
* | ||
*/ | ||
public interface StoragePolicy { | ||
|
||
/** | ||
* Creates a strategy that suggests appropriate stores. If there is no applicable | ||
* strategy in this policy, then it returns the chain. | ||
* | ||
* @param node the node being stored | ||
* @param chain the strategy so far | ||
* @return a strategy hint | ||
*/ | ||
public StrategyHint getStrategyHint(Node node, StrategyHint chain); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...o-store-strategy/src/main/java/org/fcrepo/store/strategy/StorageStrategyHintProvider.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,44 @@ | ||
|
||
package org.fcrepo.store.strategy; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.jcr.Node; | ||
|
||
import org.modeshape.jcr.value.binary.StrategyHint; | ||
|
||
/** | ||
* Provides strategies that will suggest hints for node storage. | ||
* | ||
* @author Gregory Jansen | ||
* | ||
*/ | ||
public class StorageStrategyHintProvider { | ||
|
||
List<StoragePolicy> policies = new ArrayList<StoragePolicy>(); | ||
|
||
/** | ||
* @return the policies | ||
*/ | ||
public List<StoragePolicy> getPolicies() { | ||
return policies; | ||
} | ||
|
||
|
||
/** | ||
* @param policies the policies to set | ||
*/ | ||
public void setPolicies(List<StoragePolicy> policies) { | ||
this.policies = policies; | ||
} | ||
|
||
public StrategyHint getStrategyHint(Node n) { | ||
StrategyHint result = new NoopStrategyHint(); | ||
for (StoragePolicy p : policies) { | ||
result = p.getStrategyHint(n, result); | ||
} | ||
return result; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
fcrepo-store-strategy/src/main/resources/META-INF/spring/store.xml
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:util="http://www.springframework.org/schema/util" | ||
xsi:schemaLocation=" | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd | ||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> | ||
|
||
<context:annotation-config/> | ||
|
||
<util:list value-type="org.fcrepo.generator.dublincore.DCGenerator"> | ||
<bean class="org.fcrepo.generator.dublincore.WellKnownDatastreamGenerator"> | ||
<property name="wellKnownDsid" value="DC"/> | ||
</bean> | ||
<bean class="org.fcrepo.generator.dublincore.JcrPropertiesGenerator"/> | ||
</util:list> | ||
|
||
</beans> |
Oops, something went wrong.