Getting Started with JanusGraph
JanusGraph Deprecation
As of September 2019, Compose will soon no longer support JanusGraph on the platform. Provisioning of new JanusGraph deployments is disabled.
Creating and Accessing Graphs
JanusGraph on Compose uses ConfiguredGraphFactory
; a dedicated graph factory for creating, opening and closing graphs.
You can list all the graphs in your JanusGraph deployment with:
ConfiguredGraphFactory.getGraphNames();
To create an "example" graph:
graph=ConfiguredGraphFactory.create("example");
To open the example graph:
graph=ConfiguredGraphFactory.open("example");
And finally to delete the example graph:
ConfiguredGraphFactory.drop("example")
Example: Graph of the Gods
As an example, there is a ready-made graph example called GraphOfTheGods
which can be loaded into a graph to traverse and explore. To use it, call the GraphOfTheGods.loadWithoutMixedIndex()
method, passing it an open graph, and that model is created for you.
graph=ConfiguredGraphFactory.create("example");
graph=ConfiguredGraphFactory.open("example");
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph,true);
Graph Traversal
Once you have created and opened the graph, you can traverse it using Gremlin.
graph=ConfiguredGraphFactory.open("example")
g=graph.traversal()
or, as a single line:
g=ConfiguredGraphFactory.open("example").traversal();
Gremlin is JanusGraph's query language and is how you access, modify, and traverse the data stored in the graph. Documentation and examples using the Graph of the Gods are in the JanusGraph Gremlin documentation.
Hosted JanusGraph - the Sandbox
To ensure that Gremlin queries do not access any functionality that may compromise the system, all queries are run in a sandbox. This means all function and method calls must have a signature that matches one of the following regular expressions:
java\.util.*
java\.lang\.Object.*
java\.lang\.Class <T extends java\.lang\.Object>#getSimpleName\(
java\.lang\.Iterable <T extends java\.lang\.Object>#iterator\(\)
java\.lang\.Boolean(?!#getBoolean\().*
java\.lang\.Double.*
java\.lang\.Float.*
java\.lang\.Integer(?!#getInteger\().*
java\.lang\.Long(?!#getLong\().*
java\.lang\.Math.*
java\.lang\.String(?!#intern\(\)).*
java\.lang\.StringBuilder.*
java\.lang\.Object#equals\(
java\.lang\.Object#hashCode\(
java\.util\.ArrayList#equals\(
org\.codehaus\.groovy\.runtime\.DefaultGroovyMethods.*
org\.codehaus\.groovy\.runtime\.StringGroovyMethods.*
org\.apache\.commons\.configuration\.MapConfiguration.*
org\.apache\.tinkerpop\.gremlin\.structure(?!\.io|\.Graph#toString\(|\.Graph#variables\(|\.Graph#configuration\(|\.Graph#io\(\)|\.util\.GraphFactory.*).*
org\.apache\.tinkerpop\.gremlin\.process\.traversal.*
org\.apache\.tinkerpop\.gremlin\.util\.Gremlin#version\(\)
org\.janusgraph\.core(?!\.JanusGraphFactory.*).*
org\.janusgraph\.graphdb(?!\.tinkerpop\.JanusGraphBlueprintsGraph#toString\(|\.tinkerpop\.JanusGraphBlueprintsGraph#variables\(|\.tinkerpop\.JanusGraphBlueprintsGraph#configuration\(|\.tinkerpop\.JanusGraphBlueprintsGraph#io\().*
org\.janusgraph\.example\.GraphOfTheGodsFactory(?!#create\(|#main\().*
org\.apache\.tinkerpop\.gremlin\.groovy\.plugin\.dsl\.credential\.CredentialGraph.*
Script\d+#.+\(?.+\)
groovy\.lang\.Closure <V extends java\.lang\.Object>#call\(?.+\)
org\.janusgraph\.util\.stats\.MetricManager#getRegistry\(\)
org\.janusgraph\.util\.stats\.MetricManager#INSTANCE
org\.apache\.tinkerpop\.gremlin\.util\.MetricManager#getRegistry\(\)
org\.apache\.tinkerpop\.gremlin\.util\.MetricManager#INSTANCE
Failing to be on the whitelist of functions results in an error:
[Static type checking] - Not authorized to call this method: ...
This will detail what method was not authorized.
Still Need Help?
If this article didn't solve things, summon a human and get some help!
Updated over 3 years ago