A few questions about JanusGraph.

1195 views
Skip to first unread message

Manoj Waikar

unread,
Aug 8, 2017, 11:54:15 AM8/8/17
to JanusGraph users list
Hi,

I have read the JanusGraph documentation and the GraphOfTheGodsFactory.java file, and I also have a small sample running, However, I am still not clear about the following doubts related to JanusGraph -

1) What is the relation between Gremlin server (bin/gremlin-server.bat) and the JanusGraph server (bin/janusgraph.sh)?

2) I've specified my Cassandra related configuration values in conf/gremlin-server/janusgraph-cassandra-es-server.properties file and this file is being used when running the gremlin server. While using the Java API (from Scala), I do the following -

val graph: JanusGraph = JanusGraphFactory.build().
 
set("storage.backend", "cassandra").
 
set("storage.hostname", "localhost").
 
set("storage.cassandra.keyspace", "MyJG").
 
set("storage.username", "username").
 
set("storage.password", "password").
  open
()

Should I be using the same (conf/gremlin-server/janusgraph-cassandra-es-server.properties) file which I use to start the gremlin server from my Java code?

3) In the above API, I haven't specified the JanusGraph server endpoint (the URL or the port), so which server is my Java code connecting to?

4) Does Java API use websockets, and can JanusGraph server run on a different machine (right now, my Cassandra and gremlin server run on the same machine)?

5) Is Java API the same as Gremlin language / API?

6) Where is the documentation / examples for REST API (for adding / querying vertices, edges)?

7) How can one achieve graph namespacing? So for example, I have to create three different graphs for employees, vehicles and cities, how can I segregate the data for these three graphs? Can I give a name / id to the graph? Or do these graphs have to be stored in different Cassandra keyspaces?

8) If the graphs have to be stored in different Cassandra keyspaces, how can I connect to these different graphs / keyspaces from the same Java application?

Thanks in advance for the help.

Jason Plurad

unread,
Aug 8, 2017, 1:54:39 PM8/8/17
to JanusGraph users list
Sounds like the documentation could use some improvements to help make this more clear. I've opened up an issue to track it.


1) What is the relation between Gremlin server (bin/gremlin-server.bat) and the JanusGraph server (bin/janusgraph.sh)?

The pre-packaged distribution of JanusGraph starts an instance of Cassandra, Elasticsearch, and Gremlin Server to allow users to get started quickly.

You can start a Gremlin Server manually with bin/gremlin-server.sh

2) Properties in janusgraph-cassandra-es-server.properties vs. JanusGraphFactory.build().set()...open()

If you want to connect to the same graph that the Gremlin Server has defined, yes, you should use the same properties. Using a properties file could make this easier for reuse JanusGraphFactory.open("conf/gremlin-server/janusgraph-cassandra-es-server.properties"), but if you JanusGraphFactory.build().set()...open() with the same properties, you'll be connecting to the same graph.

3) In the above API, I haven't specified the JanusGraph server endpoint (the URL or the port), so which server is my Java code connecting to?

Your code is connecting to the Cassandra server. When you configure a graph using JanusGraphFactory.open(), your application is creating an embedded graph instance. It is not connecting to the graph instance running on the JanusGraph server. The graph data is ultimately stored in Cassandra, so both the JanusGraph Server and your application are working with the same graph data.

That being said, you could connect to the graph instance on the Gremlin Server using a remote connection as described in the TinkerPop docs.


4) Does Java API use websockets, and can JanusGraph server run on a different machine (right now, my Cassandra and gremlin server run on the same machine)?

In the scenario where you have an embedded graph instance, your calls to the graph are not using WebSockets. Your application is communicating directly with the Cassandra storage backend using Thrift. A Gremlin Server can run on a different machine than the storage backend. The janusgraph-cassandra-es-server.properties lets the Gremlin Server know where to find the storage backend (see the storage.hostname property).


5) Is Java API the same as Gremlin language / API?

JanusGraph implements the Apache TinkerPop APIs, including Gremlin. When you are doing graph traversals, you are dealing with TinkerPop's Gremlin language -- i.e. g.V().has("name", "manoj").toList(). The schema and index APIs are specific to JanusGraph because these are not provided by the TinkerPop abstraction.


6) Where is the documentation / examples for REST API (for adding / querying vertices, edges)?

JanusGraph doesn't currently have much for that at the moment. Gremlin Server can be configured to support an HTTP endpoint which evaluates any Gremlin. It doesn't expose specific endpoints for /vertices or /edges, but you can do all that and more with the Gremlin endpoint.


7) How can one achieve graph namespacing?

If they are completely separate graphs, creating separate keyspaces works great. You could host them all within the same graph by making sure that you don't overlap labels and property names. You could also consider the Partition Strategy.


8) If the graphs have to be stored in different Cassandra keyspaces, how can I connect to these different graphs / keyspaces from the same Java application?

Create a separate graph instance for each keyspace using storage.cassandra.keyspace in the configuration. You can define multiple graphs in the gremlin-server.yaml configuration with different properties files. Similarly you can connect to multiple graph instance from your application.

Manoj Waikar

unread,
Aug 11, 2017, 7:01:23 AM8/11/17
to JanusGraph users list
Thanks so much Jason for the very detailed reply, and also for opening an issue for it.

There are still a few things which need clarification -

The Tinkerpop documentation of Connecting via withRemote that you pointed, mentions the use of gremlin-server-modern.yaml file, and that file is not included in the JanusGraph distribution.

Most of the examples, of connecting to JanusGraph show it through the Gremlin console, and very few using Java. The one which shows how to do it using Java, uses client.submit("[1,2,3,4]").all(); and when I tried to follow the same approach and submitted just "g.V()" I got the following error - No signature of method: org.janusgraph.graphdb.database.StandardJanusGraph.V() is applicable for argument types: ()

Can you please let me know what steps am I missing?

Jason Plurad

unread,
Aug 11, 2017, 9:37:02 AM8/11/17
to JanusGraph users list
There's a wealth of information in the Apache TinkerPop reference documentation. I would consider it prerequisite reading material because JanusGraph does not duplicate all of its information. As recent threads have pointed out, there's a balance there that we need to continue improving on.


> The Tinkerpop documentation of Connecting via withRemote that you pointed, mentions the use of gremlin-server-modern.yaml file, and that file is not included in the JanusGraph distribution.

Right that documentation link was in TinkerPop, and so is the gremlin-server-modern.yaml file it mentioned.


> I got the following error - No signature of method: org.janusgraph.graphdb.database.StandardJanusGraph.V() is applicable for argument types: ()

I'd guess you had a graphs definition in the gremlin-server.yaml like this:

graphs: {
    g
: conf/mygraph.properties
}

In this configuration, `g.V()` would throw the error you described because `g` is the Graph (specifically a StandardJanusGraph).

When the documentation (both TinkerPop and JanusGraph) use `g`, it is a GraphTraversalSource, not a Graph. Read also The Graph Process in the TinkerPop docs. Commonly in the all the examples, the GraphTraversalSource is defined in an initialization script file. Here's the relevant portion from JanusGraph's gremlin-server.yaml where the initialization script is referenced:

scriptEngines: {
  gremlin
-groovy: {
    imports
: [java.lang.Math],
    staticImports
: [java.lang.Math.PI],
    scripts
: [scripts/empty-sample.groovy]}}

Then if you look in scripts/empty-sample.groovy, you'll see where the GraphTraversalSource is defined:

// define the default TraversalSource to bind queries to - this one will be named "g".
globals
<< [g : graph.traversal()]

Thanks again for the questions and feedback. Keep in mind it's great to have these shared on the mailing list because it is a searchable archive which can be referenced.
Reply all
Reply to author
Forward
0 new messages