0

Problem

How do you get Connecting to JanusGraph > Using Java to work?
Connecting to JanusGraph Using Java = Connecting from Java = Getting Started with JanusGraph and Gremlin-Java in this question. I don't know what I'm doing wrong.

This is with:

  1. Docker-Image: janusgraph/janusgraph:latest 2023-04-11
  2. SDK: corretto-17 "17.0.7"
  3. Maven: 3.8.1

Reproduction

Steps

  1. Download and Install Docker

  2. Startup a JanusGraph Docker-container

    $ docker run -it -p 8182:8182 janusgraph/janusgraph
    
  3. Copy-Paste into CMD terminal

    mvn archetype:generate -DgroupId=com.mycompany.project
        -DartifactId=gremlin-example
        -DarchetypeArtifactId=maven-archetype-quickstart
        -DinteractiveMode=false
    
    1. PowerShell doesn't work on Guide-Step-1 without adding quotation-marks
  4. Open Project in IDE

    1. e.g. IntelliJ
  5. Upsert Maven Packages for JanusGraph and Gremlin-Driver

    <dependency>
        <groupId>org.janusgraph</groupId>
        <artifactId>janusgraph-driver</artifactId>
        <version>1.0.0-rc2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tinkerpop</groupId>
        <artifactId>gremlin-driver</artifactId>
        <version>3.6.2</version>
    </dependency>
    
    1. Guide-Step-2 at time of recording
  6. Create-and-Add conf/remote-graph.properties and conf/remote-objects.yaml

    gremlin.remote.remoteConnectionClass=org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection
    gremlin.remote.driver.clusterFile=conf/remote-objects.yaml
    gremlin.remote.driver.sourceName=g
    
    hosts: [localhost]
    port: 8182
    serializer: { 
        className: org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1,
        config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
    
  7. Update App.main with GraphTraversalSource

    import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
    import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
    public class App {
        public static void main(String[] args) throws Exception {
            GraphTraversalSource g = traversal().withRemote("conf/remote-graph.properties");
            // Reuse 'g' across the application
            // and close it on shut-down to close open connections with g.close()
            Object herculesAge = g.V().has("name", "hercules").values("age").next();
            System.out.println("Hercules is " + herculesAge + " years old.");
            g.close();
        }
    }
    
  8. Run Project

Results

Expected

Program would run and printout Hercules's age.

Actual

Runtime Exception Error.

Exception in thread "main" java.util.concurrent.CompletionException: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: The traversal source [g] for alias [g] is not configured on the server.
    at java.base/java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:413)
    at java.base/java.util.concurrent.CompletableFuture.join(CompletableFuture.java:2118)
    at org.apache.tinkerpop.gremlin.driver.ResultSet.one(ResultSet.java:123)
    at org.apache.tinkerpop.gremlin.driver.ResultSet$1.hasNext(ResultSet.java:175)
    at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:182)
    at org.apache.tinkerpop.gremlin.driver.ResultSet$1.next(ResultSet.java:169)
    at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal$TraverserIterator.next(DriverRemoteTraversal.java:115)
    at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal$TraverserIterator.next(DriverRemoteTraversal.java:100)
    at org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteTraversal.nextTraverser(DriverRemoteTraversal.java:92)
    at org.apache.tinkerpop.gremlin.process.remote.traversal.step.map.RemoteStep.processNextStart(RemoteStep.java:80)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:135)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:40)
    at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.next(DefaultTraversal.java:249)
    at com.mycompany.project.App.main(App.java:15)
Caused by: org.apache.tinkerpop.gremlin.driver.exception.ResponseException: The traversal source [g] for alias [g] is not configured on the server.
    at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:245)
    at org.apache.tinkerpop.gremlin.driver.Handler$GremlinResponseHandler.channelRead0(Handler.java:200)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at org.apache.tinkerpop.gremlin.driver.Handler$GremlinSaslAuthenticationHandler.channelRead0(Handler.java:126)
    at org.apache.tinkerpop.gremlin.driver.Handler$GremlinSaslAuthenticationHandler.channelRead0(Handler.java:68)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
    at io.netty.handler.codec.http.websocketx.Utf8FrameValidator.channelRead(Utf8FrameValidator.java:89)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:833)

org.apache.tinkerpop.gremlin.driver.exception.ResponseException: The traversal source [g] for alias [g] is not configured on the server.

Tried

  1. Executing Guide.Step.1 PowerShell
    1. Results in BUILD FAILURE for Maven
  2. Changing conf folder locations
    1. Runtime Exception Error: Exception in thread "main" org.apache.commons.configuration2.ex.ConfigurationException: Could not locate: FileLocator [basePath=null, encoding=ISO-8859-1, fileName=conf/remote-graph.properties, fileSystem=null, locationStrategy=null, sourceURL=null, urlConnectionOptions=null]
  3. Running Local Installation JanusGraph on Windows with git-bash shell
    1. No change in error
│   pom.xml
│   
├───src
│   ├───main
│   │   ├───java
│   │   │   └───com
│   │   │       └───mycompany
│   │   │           └───project
│   │   │                   App.java
│   │   │
│   │   └───resources
│   │       └───conf
│   │               remote-graph.properties
│   │               remote-objects.yaml
Zach
  • 539
  • 1
  • 4
  • 22
  • Does the graph have the data (pre)loaded? If you change the `next` to `toList` do you at least get an empty list back? – Kelvin Lawrence May 01 '23 at 15:36
  • @KelvinLawrence No I seem to only have got that on a fluke. Just tried to reopen and run the project and getting the same error about gremlin traversal again now. – Zach May 01 '23 at 15:46
  • Even with `toList` instead of `next` ? If the graph is empty, `next` will not return anything. `toList` will give you an empty list. – Kelvin Lawrence May 01 '23 at 15:50
  • Both are giving me this error message now...! – Zach May 01 '23 at 15:54

1 Answers1

0

3-Part Problem: JanusGraph Container, Data Does Not Exist, and JanusGraph Example Does Not Load Data.

  1. Delete JanusGraph container and remake a new one
    1. JanusGraph-Server is in a bad-state, as noted by GitHub-Issues: #1826 and #2868
  2. Load Data in
    1. I don't know where JanusGraph's Graph Of The Gods data is saved
    2. D3.js's Graph Of The Gods is pretty barebones
      1. And JanusGraph doesn't readily give an explanation of their import method
    3. JanusGraph does not start with data like Neo4j, OrientDB, or ArcadeDB
  3. JanusGraph documentation does not have preloaded nor steps-to-load this data in for their example

Update

Here's an example loading into JanusGraph with AnonymousTraversalSource.

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.apache.tinkerpop.gremlin.structure.Vertex;

import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;

public class Main {
    private static final Logger logger = LogManager.getLogger(Main.class);
    public static void main(String[] args) throws Exception {
        GraphTraversalSource g = traversal().withRemote("conf/remote-graph.properties");
        Transaction tx = g.tx();
        tx.open();
        Vertex v1 = g.addV("person").property("name","marko").next();
        Vertex v2 = g.addV("person").property("name","stephen").next();
        g.V(v1).addE("knows").to(v2).property("weight",0.75).iterate();
        tx.commit();
        logger.info(g.V().count().next());
        g.close();
    }
}
Zach
  • 539
  • 1
  • 4
  • 22
  • The `GraphOfTheGodsFactory` class holds the data. So you can do things like `GraphOfTheGodsFactory.load(graph)` - the source code for it is [here](https://github.com/JanusGraph/janusgraph/blob/master/janusgraph-core/src/main/java/org/janusgraph/example/GraphOfTheGodsFactory.java) and the documentation is [here](https://docs.janusgraph.org/getting-started/basic-usage/) – Kelvin Lawrence May 01 '23 at 18:58
  • Bummer, that's still going to make me need to setup a in-between storage-backend. This is what I've been trying to avoid dipping my toes in. – Zach May 01 '23 at 19:09
  • Yes, unless you can live with in-memory for dev/test/learning, at least as far as JanusGraph goes, you will need to setup some sort of storage backend. The quickest way I have found is to use a single node of Cassandra running out of the Cassandra docker image. That's pretty quick to setup. It really depends on what you are looking to achieve. – Kelvin Lawrence May 01 '23 at 19:21
  • Say I just want to import with `g.V().addV()` instead, so I'm using just `AnonymousTraversalSource`. [How do I get past `Could not establish serializer`](https://stackoverflow.com/questions/76131305/how-to-connect-to-janusgraph-in-java-with-anonymoustraversalsource)? – Zach May 01 '23 at 19:26