JanusGraph在Docker环境中不能与Cassandra后端通信



我需要你的帮助来配置docker撰写文件。

问题:创建了一个自定义构建docker文件(janusgraph),并试图使它与其他容器(cassandra)交谈,但它没有,因为它显示以下错误..

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

共享Dockerfile和docker compose文件

Dockerfile

FROM openjdk:8-jre-slim-buster
USER root
RUN mkdir -p /janusgraph
COPY . /janusgraph/.
WORKDIR /janusgraph/bin/
CMD ["./gremlin-server.sh"]

码头工人组成

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:

仅供参考:我已经通过给cassandra_container ip和localhost编辑了janusgraph的配置,如果我用cassandra作为docker服务手动启动janusgraph,它可以工作!!

但是无法使用janusgraph作为docker服务连接到cassandra。

stacktrace中的NoHostAvailableException表示JanusGraph使用的Cassandra Java驱动程序无法连接到集群:

...
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)
...

我怀疑问题是JanusGraph试图在Cassandra启动并准备好之前连接到集群。

尝试配置JanusGraph服务,使其依赖于Cassandra服务(使用depends_on)。这意味着DB将在应用程序之前启动。此外,要求Cassandra"健康"。在创建具有condition属性的JanusGraph服务之前。

你的Docker撰写文件应该是这样的:

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

具体操作请参考Docker Docsdepends_on官方规范。

作为旁注,容器links是一个遗留特性,已弃用。考虑在网络配置中使用默认的bridge。干杯!

networks:
jce-network:
driver: bridge

👉请支持Apache Cassandra社区,将鼠标悬停在Cassandra标签上,然后点击Watch tag按钮。🙏谢谢!

相关内容

  • 没有找到相关文章

最新更新