【发布时间】:2017-09-04 16:10:33
【问题描述】:
我正在尝试将 Gremlin/Java 图形模式与 cosmossDB 模拟器结合使用,但遇到了麻烦。
模拟器已全部安装,正在运行并将证书导入我的 Java 密钥库(我可以使用文档界面进行连接,所以我知道它正在工作)。
模拟器 Web 控制台目前显示的是集合而不是图表。
我的简单代码(在 Groovy 脚本中)如下所示
Cluster cluster
Client client
try {
def builder = Cluster.build()
builder.addContactPoint("localhost")
.port(8081)
.protocol ("https")
.keyPassword("C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==")
.enableSsl(true)
cluster = builder.create()
} catch (Exception ex) {
ex.printStackTrace()
}
client = cluster.connect()
String[] gremlinQueries = [
"g.V().drop()",
"g.addV('person').property('id', 'thomas').property('firstName', 'Thomas').property('age', 44)",
"g.addV('person').property('id', 'mary').property('firstName', 'Mary').property('lastName', 'Andersen').property('age', 39)",
"g.addV('person').property('id', 'ben').property('firstName', 'Ben').property('lastName', 'Miller')",
"g.addV('person').property('id', 'robin').property('firstName', 'Robin').property('lastName', 'Wakefield')",
"g.V('thomas').addE('knows').to(g.V('mary'))",
"g.V('thomas').addE('knows').to(g.V('ben'))",
"g.V('ben').addE('knows').to(g.V('robin'))",
"g.V('thomas').property('age', 44)",
"g.V().count()",
"g.V().hasLabel('person').has('age', gt(40))",
"g.V().hasLabel('person').order().by('firstName', decr)",
"g.V('thomas').outE('knows').inV().hasLabel('person')",
"g.V('thomas').outE('knows').inV().hasLabel('person').outE('knows').inV().hasLabel('person')",
"g.V('thomas').repeat(out()).until(has('id', 'robin')).path()",
"g.V('thomas').outE('knows').where(inV().has('id', 'mary')).drop()",
"g.E().count()",
"g.V('thomas').drop()"
]
for (gremlin in gremlinQueries) {
ResultSet results = client.submit(gremlin);
CompletableFuture<List<Result>> completableFutureResults = results.all()
List<Result> resultList = completableFutureResults.get()
for (Result result : resultList) {
println(result.toString())
}
}
当我在调试器中观看时,构建器创建并连接客户端,但是当我尝试客户端提交时,我得到以下堆栈跟踪。
Connected to the target VM, address: '127.0.0.1:59992', transport: 'socket'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Caught: java.lang.RuntimeException: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
Disconnected from the target VM, address: '127.0.0.1:59992', transport: 'socket'
java.lang.RuntimeException: java.lang.RuntimeException:
java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:214)
at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:198)
at org.apache.tinkerpop.gremlin.driver.Client$submit.call(Unknown Source)
at playpen.TinkerPop-Example.run(TinkerPop-Example.groovy:64)
Caused by: java.lang.RuntimeException: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists
at org.apache.tinkerpop.gremlin.driver.Client.submitAsync(Client.java:310)
at org.apache.tinkerpop.gremlin.driver.Client.submitAsync(Client.java:242)
at org.apache.tinkerpop.gremlin.driver.Client.submit(Client.java:212)
我有几个想法。我从以前的文档数据库原型中得到了一个“familyDB”,但我不知道用户的构建器中的 gremlin 配置方法是什么来表达这一点。
如果您想从头开始创建 dbs 名称,并且相当于为图形顶点创建集合等。
有没有人为本地 cosmossDB 模拟器提供工作图配置,我做错了什么/错过了什么导致此超时。附件是我开始发出客户端命令之前的调试器截图
PS - 尝试根据来自 GitHub 的 Azure graph zip 中的示例配置集群。
我的配置文件是这样的
hosts: [localhost] port: 8081 username: /dbs/familyDB/colls/FamilyCollection password: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== connectionPool: { enableSsl: true} serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}
现在获取连接的修改代码如下
try {
File config = new File("D:/Intellij - Azure/quickstart-java/graph/src/main/cosmossDB-config.yaml")
assert config.exists()
Cluster.Builder builder = Cluster.build(config)
cluster = builder.create()
println cluster.dump()
} catch (FileNotFoundException e) {
e.printStackTrace()
return
}
并且我已经从返回以下内容的集群实例中转储了运行时值
prop: maxWaitForConnection, with value 3000 prop: nioPoolSize, with value 8 prop: keepAliveInterval, with value 1800000 prop: loadBalancingStrategy, with value class org.apache.tinkerpop.gremlin.driver.LoadBalancingStrategy$RoundRobin prop: resultIterationBatchSize, with value 64 prop: port, with value 8081 prop: serializers, with value [application/json] prop: maxInProcessPerConnection, with value 4 prop: maxWaitForSessionClose, with value 3000 prop: reconnectInterval, with value 1000 prop: workerPoolSize, with value 16 prop: minInProcessPerConnection, with value 1 prop: class, with value class org.apache.tinkerpop.gremlin.driver.Cluster prop: sslEnabled, with value true prop: maxContentLength, with value 65536 prop: serializer, with value org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0@119020fb prop: factory, with value org.apache.tinkerpop.gremlin.driver.Cluster$Factory@3d9f6567 prop: closing, with value false prop: channelizer, with value org.apache.tinkerpop.gremlin.driver.Channelizer$WebSocketChannelizer prop: closed, with value false
但是 TimeoutExcption 仍然发生。
我已经下载了 gremlin 控制台并尝试:remote connect,但是当我运行命令时,我得到了这个,它警告你没有及时响应。
`gremlin> :remote connect tinkerpop.server conf/remote-cosmossDB.yaml
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
==>Configured localhost/127.0.0.1:8081
gremlin>
gremlin> g.V()
No such property: g for class: groovysh_evaluate
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> :remote list
==>*0 - Gremlin Server - [localhost/127.0.0.1:8081]
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8081] - type ':remote console' to return to local mode
gremlin> g.V()
Host did not respond in a timely fashion - check the server status and submit again.
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> y
Host did not respond in a timely fashion - check the server status and submit again.
Type ':help' or ':h' for help.
`
我仍然卡住了,无法让它工作 - 接下来我可以尝试什么?
【问题讨论】:
-
如果帮助任何人回答 - 尝试通过 conf 文件打开集群,而不是文件读取
hosts: [localhost] port: 8081 username: /dbs/familyDB/colls/FamilyCollection password: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== connectionPool: { enableSsl: true} serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}
标签: java groovy graph azure-cosmosdb nosql