exit the initilization groovy if graph exist

Yingjie Li


I am using Janusgraph. 

In my graph initialization groovy script, I would like to do a simple check, if the graph already exists, exit the script, else continue with the rest of the initialization.

when I run below code,  it complains that 

groovysh_parse: 1: unexpected token: else @ line 1, column 1.

   else {

Also, is there a command equivalent to System.exit(0)? The return command does not work seems like.

In addition, any good reference on gremlin-groovy would be appreciated.



//Create a sessioned connection to the Gremlin Server

:remote connect tinkerpop.server conf/remote.yaml session

:remote console

//define graph name

graph_name = "graph1"

//check whether graph exists

if (ConfiguredGraphFactory.getGraphNames().contains("graph_name")) {

println "graph already exists"



else {

map = new HashMap();

map.put("storage.backend", "cql");

map.put("storage.hostname", "")

map.put("index.search.backend", "elasticsearch")

map.put("index.search.hostname", "")


map.put("graph.graphname", graph_name)

ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map))


graph = ConfiguredGraphFactory.open(graph_name)

//Create graph schema

//Close all transactions

graph.getOpenTransactions().forEach { tx -> tx.rollback() }

mgmt = graph.openManagement()

mgmt.getOpenInstances().forEach {

if (it.reverse().take(1) != ")") {





pk_id = mgmt.makePropertyKey('id').dataType(String.class).cardinality(org.janusgraph.core.Cardinality.LIST).make()

pk_name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(org.janusgraph.core.Cardinality.LIST).make()





Join janusgraph-users@lists.lfaidata.foundation to automatically receive all group messages.