Skip to content

Commit

Permalink
added policy-based storage strategy hint provider
Browse files Browse the repository at this point in the history
added testing config with four stores
unit test passes
integration test needs work
  • Loading branch information
gregjan committed Apr 25, 2013
1 parent 75e327d commit 39ec4f1
Show file tree
Hide file tree
Showing 16 changed files with 671 additions and 0 deletions.
123 changes: 123 additions & 0 deletions fcrepo-store-strategy/pom.xml
@@ -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>
10 changes: 10 additions & 0 deletions fcrepo-store-strategy/src/main/enunciate/enunciate.xml
@@ -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>
@@ -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;
}

}
@@ -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;
}

}
@@ -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));
}

}
@@ -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);

}
@@ -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 fcrepo-store-strategy/src/main/resources/META-INF/spring/store.xml
@@ -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>

0 comments on commit 39ec4f1

Please sign in to comment.