Search code examples
gremlingraph-databasesdocker-containerjanusgraphjava-17

Connecting To JanusGraph Using Java


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

Solution

  • 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();
        }
    }