Last active
November 18, 2017 00:10
-
-
Save aaur0/c7f50f02b43a40809eac617c96dd74e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// an init script that returns a Map allows explicit setting of global bindings. | |
def globals = [:] | |
// defines a sample LifeCycleHook that prints some output to the Gremlin Server console. | |
// note that the name of the key in the "global" map is unimportant. | |
globals << [hook : [ | |
onStartUp: { ctx -> | |
ctx.logger.info("Executed once at startup of Gremlin Server.") | |
}, | |
onShutDown: { ctx -> | |
ctx.logger.info("Executed once at shutdown of Gremlin Server.") | |
} | |
] as LifeCycleHook] | |
// define the default TraversalSource to bind queries to - this one will be named "g". | |
//globals << [g : graph.traversal()] | |
globals << [g : DynamicBindingTool.getBoundGraphTraversal()] | |
class DynamicBindingTool { | |
static def createTemplate() { | |
ConfiguredGraphFactory.removeTemplateConfiguration(); | |
Map map = new HashMap(); | |
map.put("storage.backend", "cassandrathrift"); | |
map.put("storage.hostname", "[X.X.X.X]"); | |
ConfiguredGraphFactory.createTemplateConfiguration(new | |
MapConfiguration(map)); | |
} | |
static def setBoundGraph(graphName) { | |
def managementGraph = ConfiguredGraphFactory.open("managementGraph"); | |
managementGraph.traversal().V().has("boundGraph", true).remove(); | |
def v = managementGraph.addVertex(); | |
v.property("boundGraph", true); | |
v.property("graph.graphname", graphName); | |
} | |
static def getBoundGraphTraversal() { | |
createTemplate(); | |
def managementGraph = ConfiguredGraphFactory.open("managementGraph"); | |
def graphName = managementGraph.traversal().V().has("boundGraph", true).values("graph.graphname"); | |
return ConfiguredGraphFactory.open(graphName).traversal(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment