连接到在Docker容器上运行的DSE Graph导致未找到主机

时间:2018-11-09 12:55:54

标签: scala docker gremlin tinkerpop3 datastax-enterprise-graph

我正在使用此命令在Docker容器中运行我的DSE图。

docker run -e DS_LICENSE=accept -p 9042:9042 --name my-dse -d datastax/dse-server -g -k -s

在我的Scala代码上,我按如下方式引用它

object GrDbConnection {

  val dseCluster = DseCluster.builder()
    .addContactPoints("127.0.0.1").withPort(9042)
    .build()


  val graphName = "graphName"
  val graphOptions = new GraphOptions()
    .setGraphName(graphName)
  var graph:ScalaGraph = null

  try {
    val session = dseCluster.connect()

    // The following uses the DSE graph schema API, which is currently only supported by the string-based
    // execution interface.  Eventually there will be a programmatic API for making schema changes, but until
    // then this needs to be used.

    // Create graph
    session.executeGraph("system.graph(name).ifNotExists().create()", ImmutableMap.of("name", graphName))


    // Clear the schema to drop any existing data and schema
    session.executeGraph(new SimpleGraphStatement("schema.clear()").setGraphName(graphName))

    // Note: typically you would not want to use development mode and allow scans, but it is good for convenience
    // and experimentation during development.

    // Enable development mode and allow scans
    session.executeGraph(new SimpleGraphStatement("schema.config().option('graph.schema_mode').set('development')")
      .setGraphName(graphName))
    session.executeGraph(new SimpleGraphStatement("schema.config().option('graph.allow_scan').set('true')")
      .setGraphName(graphName))

    // Create a ScalaGraph from a remote Traversal Source using withRemote
    // See: http://tinkerpop.apache.org/docs/current/reference/#connecting-via-remotegraph for more details
    val connection = DseRemoteConnection.builder(session)
      .withGraphOptions(graphOptions)
      .build()
     graph = EmptyGraph.instance().asScala
      .configure(_.withRemote(connection))

  } finally {
    dseCluster.close()
  }
}

然后在我的一个控制器中,我使用它来调用对DSE图形的查询。

 def test = Action {
    val r = GrDbConnection.graph.V().count()
    print(r.iterate())
    Ok
  }

这将返回错误

lay.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[NoHostAvailableException: All host(s) tried for query failed (no host was tried)]]
    at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:251)
    at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:178)
    at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:363)
    at play.core.server.AkkaHttpServer$$anonfun$1.applyOrElse(AkkaHttpServer.scala:361)
    at scala.concurrent.Future.$anonfun$recoverWith$1(Future.scala:413)
    at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
    at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
    at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
    at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (no host was tried)
    at com.datastax.driver.core.RequestHandler.reportNoMoreHosts(RequestHandler.java:221)
    at com.datastax.driver.core.RequestHandler.access$1000(RequestHandler.java:41)
    at com.datastax.driver.core.RequestHandler$SpeculativeExecution.findNextHostAndQuery(RequestHandler.java:292)
    at com.datastax.driver.core.RequestHandler.startNewExecution(RequestHandler.java:109)
    at com.datastax.driver.core.RequestHandler.sendRequest(RequestHandler.java:89)
    at com.datastax.driver.core.SessionManager.executeAsync(SessionManager.java:124)
    at com.datastax.driver.dse.DefaultDseSession.executeGraphAsync(DefaultDseSession.java:123)
    at com.datastax.dse.graph.internal.DseRemoteConnection.submitAsync(DseRemoteConnection.java:74)
    at org.apache.tinkerpop.gremlin.process.remote.traversal.step.map.RemoteStep.promise(RemoteStep.java:89)
    at org.apache.tinkerpop.gremlin.process.remote.traversal.step.map.RemoteStep.processNextStart(RemoteStep.java:65)

1 个答案:

答案 0 :(得分:0)

原来我要做的就是删除

finally {
    dseCluster.close()
  }