Home > OS >  JanusGraph not communicating with Cassandra backend in Docker environment
JanusGraph not communicating with Cassandra backend in Docker environment

Time:01-18

I need your help on configuiring a docker compose file.

Problem : Created a custom build docker file ( janusgraph ) and trying to make it talk to other containers ( cassandra ) but it doesn't as it shows the below error..

janusgraph-es  | 2449 [main] ERROR org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor  - Could not invoke constructor on class org.janusgraph.graphdb.management.JanusGraphManager (defined by the 'graphManager' setting) with one argument of class Settings
janusgraph-es  | Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
janusgraph-es  |    at org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor.<init>(ServerGremlinExecutor.java:91)
janusgraph-es  |    at org.apache.tinkerpop.gremlin.server.GremlinServer.<init>(GremlinServer.java:122)
janusgraph-es  |    at org.apache.tinkerpop.gremlin.server.GremlinServer.<init>(GremlinServer.java:86)
janusgraph-es  |    at org.apache.tinkerpop.gremlin.server.GremlinServer.main(GremlinServer.java:345)
janusgraph-es  | Caused by: java.lang.reflect.InvocationTargetException
janusgraph-es  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
janusgraph-es  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
janusgraph-es  |    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
janusgraph-es  |    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
janusgraph-es  |    at org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor.<init>(ServerGremlinExecutor.java:80)
janusgraph-es  |    ... 3 more
janusgraph-es  | Caused by: java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.cql.CQLStoreManager
janusgraph-es  |    at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:64)
janusgraph-es  |    at org.janusgraph.diskstorage.Backend.getImplementationClass(Backend.java:440)
janusgraph-es  |    at org.janusgraph.diskstorage.Backend.getStorageManager(Backend.java:411)
janusgraph-es  |    at org.janusgraph.graphdb.configuration.builder.GraphDatabaseConfigurationBuilder.build(GraphDatabaseConfigurationBuilder.java:50)
janusgraph-es  |    at org.janusgraph.core.JanusGraphFactory.lambda$open$0(JanusGraphFactory.java:150)
janusgraph-es  |    at org.janusgraph.graphdb.management.JanusGraphManager.openGraph(JanusGraphManager.java:243)
janusgraph-es  |    at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:150)
janusgraph-es  |    at org.janusgraph.core.JanusGraphFactory.open(JanusGraphFactory.java:100)
janusgraph-es  |    at org.janusgraph.graphdb.management.JanusGraphManager.lambda$new$0(JanusGraphManager.java:75)
janusgraph-es  |    at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
janusgraph-es  |    at org.janusgraph.graphdb.management.JanusGraphManager.<init>(JanusGraphManager.java:74)
janusgraph-es  |    ... 8 more
janusgraph-es  | Caused by: java.lang.reflect.InvocationTargetException
janusgraph-es  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
janusgraph-es  |    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
janusgraph-es  |    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
janusgraph-es  |    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
janusgraph-es  |    at org.janusgraph.util.system.ConfigurationUtil.instantiate(ConfigurationUtil.java:58)
janusgraph-es  |    ... 18 more
janusgraph-es  | Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [/127.0.0.1:9042] Cannot connect))
janusgraph-es  |    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:268)
janusgraph-es  |    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:107)
janusgraph-es  |    at com.datastax.driver.core.Cluster$Manager.negotiateProtocolVersionAndConnect(Cluster.java:1813)
janusgraph-es  |    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1726)
janusgraph-es  |    at com.datastax.driver.core.Cluster.init(Cluster.java:214)
janusgraph-es  |    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:387)
janusgraph-es  |    at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:366)
janusgraph-es  |    at com.datastax.driver.core.Cluster.connect(Cluster.java:311)
janusgraph-es  |    at org.janusgraph.diskstorage.cql.CQLStoreManager.initializeSession(CQLStoreManager.java:320)
janusgraph-es  |    at org.janusgraph.diskstorage.cql.CQLStoreManager.<init>(CQLStoreManager.java:182)
janusgraph-es  |    ... 23 more

Sharing the Dockerfile and the docker compose file

Dockerfile

FROM openjdk:8-jre-slim-buster

USER root
RUN mkdir -p /janusgraph

COPY . /janusgraph/.

WORKDIR /janusgraph/bin/

CMD ["./gremlin-server.sh"]

docker compose

version: "3.3"
services:
  cassandra:
    image: cassandra:3
    container_name: cassandra
    ports:
      - "9042:9042"
      - "9160:9160"
    healthcheck:
      test: ["CMD-SHELL", "[ $$(nodetool statusgossip) = running ]"]
      interval: 30s
      timeout: 10s
    networks:
      - jce-network
    volumes:
      - app-volume:/var/lib/cassandra
  janusgraph-es:
#    image: docker.io/janusgraph/janusgraph:0.5.3
    build: ./janusgraph-full-0.5.3
    container_name: janusgraph-es
#    environment:
#      JANUS_PROPS_TEMPLATE: cql-es
#      janusgraph.storage.hostname: cassandra
#      janusgraph.index.search.hostname: elastic
#      graph.replace-instance-if-exists: true
    ports:
      - "8182:8182"
    healthcheck:
      test: ["CMD", "bin/gremlin.sh", "-e", "scripts/remote-connect.groovy"]
      interval: 10000s
      timeout: 3000s
      retries: 3
    links:
      - "cassandra"
    networks:
      - jce-network
networks:
  jce-network:
volumes:
  app-volume:

FYI : I have edited the config of janusgraph by giving cassandra_container ip and also localhost and also if I start janusgraph manually with cassandra as docker service, it works!!

But not able to connect with using janusgraph as a docker service to cassandra.

CodePudding user response:

The NoHostAvailableException in the stacktrace indicates that the Cassandra Java driver used by JanusGraph can't connect to the cluster:

    ...
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [/127.0.0.1:9042] Cannot connect))
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:268)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:107)
    at com.datastax.driver.core.Cluster$Manager.negotiateProtocolVersionAndConnect(Cluster.java:1813)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1726)
    at com.datastax.driver.core.Cluster.init(Cluster.java:214)
    ...

I suspect that the problem is JanusGraph attempts to connect to the cluster before Cassandra is up and ready.

Try configuring your JanusGraph service to have a dependency on your Cassandra service (with depends_on). This means that the DB will be started before the app. Additionally, require that Cassandra is "healthy" before creating the JanusGraph service with the condition property.

Your Docker compose file should look like:

  ...
  janusgraph-es:
    ...
    depends_on:
      cassandra:
        condition: service_healthy
  ...

For details, see the official Docker Docs depends_on specification.

As a side note, container links is a legacy feature and is deprecated. Consider using the default bridge in your network configuration. Cheers!

networks:
  jce-network:
    driver: bridge

  • Related