exit the initilization groovy if graph exist
Discussed in:
https://groups.google.com/g/gremlin-users/c/BEA6b8CWryI |
|
Yingjie Li
Hello, 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. Thanks, Yingjie //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" return } else { map = new HashMap(); map.put("storage.backend", "cql"); map.put("storage.hostname", "127.0.0.1") map.put("index.search.backend", "elasticsearch") map.put("index.search.hostname", "127.0.0.1") .... 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) != ")") { mgmt.forceCloseInstance(it) } } .... 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() .... mgmt.commit() ConfiguredGraphFactory.close(graph_name) } |
|