Home | All Posts

[03 May 2012] Custom Graph Configuration In Rexster

Rexster is a graph server that is capable of exposing any Blueprints enabled graph through different interfaces, such as REST. Rexster is “packaged” with the common Blueprints implementations that are maintained by TinkerPop. At this time, given Rexster 0.8, those implementations include:

Outside of these implementations, there are others that are not maintained by TinkerPop, such as the one from InfiniteGraph. There is also the recently submitted pull request that implements Blueprints over Datomic, which, as of today, has not yet been merged. In addition, one might find themselves in a scenario where they have some sort of “private” Blueprints implementation over some other data store. Even though Rexster doesn’t have explicit, native understanding of these externalized implementations, it is capable of serving them if configured properly to do so.

Rexster is configured via its rexster.xml file. A typical configuration of a TinkerGraph looks like this:

<graphs>
  <graph>
    <graph-name>mygraph</graph-name>
    <graph-type>tinkergraph</graph-type>
  </graph>
</graphs>

This configuration could also be written as:

<graphs>
  <graph>
    <graph-name>mygraph</graph-name>
    <graph-type>com.tinkerpop.rexster.config.TinkerGraphGraphConfiguration</graph-type>
  </graph>
</graphs>

Note that the <graph-type> is now pointing to a specific com.tinkerpop.rexster.config.GraphConfiguration implementation. The GraphConfiguration interface looks like this:

public interface GraphConfiguration {
    Graph configureGraphInstance(Configuration properties) throws GraphConfigurationException;
}

Classes that implement this interface are responsible for constructing a Blueprints graph for Rexster, thereby allowing Rexster to extend itself to serve any Blueprints graph. To implement the configureGraphInstance method, simply construct a new graph using the properties passed to it. The properties are just the root level key/values within the <graph> element. For example, TinkerGraph configuration in Rexster allows for a parameter, as in:

<graph>
  <graph-name>gratefulgraph</graph-name>
  <graph-type>com.tinkerpop.rexster.config.TinkerGraphGraphConfiguration</graph-type>
  <graph-location>data/graph-example-2</graph-location>
</graph>

The following code extracts that value from the properties, returning null if it does not exist in the XML configuration:

String graphFile = properties.getString("graph-location", null);

Key/value pairs are great, but properties can also handle more complex parameters. A good example of that is shown in the Neo4jGraphConfiguration where an arbitrary set of sub-properties are passed to the GraphConfiguration implementation, which in turn is passed to the Neo4jGraph instance.

To expose the custom configuration to Rexster, the process is the same as a Rexster Extensions. Simple copy the compiled JAR containing the custom configuration in the REXSTER_HOME/ext directory. It will then be possible to reference the class within rexster.xml. While the built-in configurations for Rexster have short-hand configuration options, such as tinkergraph or neo4jgraph for the <graph-type>, it is not possible to alias a custom implementation.

Home | All Posts