Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mchandrasekar/5aa505d8dafc2ea836c0f6b71a31cac4 to your computer and use it in GitHub Desktop.
Save mchandrasekar/5aa505d8dafc2ea836c0f6b71a31cac4 to your computer and use it in GitHub Desktop.
/** input args:
1) https://github.com/JanusGraph/janusgraph/blob/master/janusgraph-examples/example-remotegraph/conf/jgex-remote.properties
2) https://github.com/JanusGraph/janusgraph/blob/master/janusgraph-dist/src/assembly/cfilter/conf/janusgraph-cassandra-configurationgraph.properties
** /
public static void main(String[] args) throws ConfigurationException {
JanusGraph janusgraph1;
JanusGraph janusgraph2;
Cluster cluster;
Client client;
Configuration remoteConf = new PropertiesConfiguration(args[0]);
// using the remote driver for schema
try {
cluster = Cluster.open(remoteConf.getString("gremlin.remote.driver.clusterFile"));
client = cluster.connect();
} catch (Exception e) {
throw new ConfigurationException(e);
}
JanusGraph janusgraph1;
// This is needed for the ConfiguredGraphFactory as it does a getInstance()
JanusGraphManager gm = new JanusGraphManager(new Settings());
Configuration graphConf = new PropertiesConfiguration(args[1]);
// ConfiguredGraphFactory needs a graph configuration to store configurations
StandardJanusGraph graph =
new StandardJanusGraph(new GraphDatabaseConfiguration(new CommonsConfiguration(graphConf)));
new ConfigurationManagementGraph(graph);
// Creating template configuration or updating if one already exists
if (null == ConfiguredGraphFactory.getTemplateConfiguration()) {
Configuration templaceConfiguration = ConfigurationUtils.cloneConfiguration(graphConf);
templaceConfiguration.clearProperty("graph.graphname");
ConfiguredGraphFactory.createTemplateConfiguration(templaceConfiguration);
} else {
ConfiguredGraphFactory.updateConfiguration(graphConf.getString("graph.graphname"), graphConf);
}
if (!ConfiguredGraphFactory.getGraphNames().contains("graph1")) {
ConfiguredGraphFactory.create("graph1");
}
if (!ConfiguredGraphFactory.getGraphNames().contains("graph1")) {
ConfiguredGraphFactory.create("graph1");
}
janusgraph1 = ConfiguredGraphFactory.open("graph1");
janusgraph2 = ConfiguredGraphFactory.open("graph2");
ConfiguredGraphFactory.getGraphNames().stream().forEach(System.out::println);
// Mandatory to have "alias" defined in here "graph1_traversal". Alias should be graphname + "_traversal"
GraphTraversalSource graph1 = janusgraph1.traversal().withRemote(DriverRemoteConnection.using(cluster, "graph1_traversal"));
GraphTraversalSource graph2 = janusgraph2.traversal().withRemote(DriverRemoteConnection.using(cluster, "graph2_traversal"));
try {
graph1.addV("e").as("e").addV("f").addE("to").from("e").next();
graph2.addV("g").as("g").addV("h").addE("to").from("g").next();
List list = graph1.V().valueMap(true).toList();
System.out.println("Vertices in graph 1");
list.forEach((v) -> LOGGER.info(v.toString()));
list = graph2.V().valueMap(true).toList();
System.out.println("Vertices in graph 2");
list.forEach((v) -> LOGGER.info(v.toString()));
System.out.println("Edges in graph 1");
list = graph1.E().valueMap(true).toList();
list.forEach((e) -> LOGGER.info(e.toString()));
System.out.println("Edges in graph 2");
list = graph1.E().valueMap(true).toList();
list.forEach((e) -> LOGGER.info(e.toString()));
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
}
@baughmann
Copy link

This is good stuff, I just wish so much hadn't changed

@baughmann
Copy link

If anyone needs an updated example, I made one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment