LoginSignup
2

More than 5 years have passed since last update.

gremlin-consoleを入れたDockerイメージからNeptuneに接続する

Posted at

昨年あたりから、はじめてグラフDBであるNeo4jを触った身としては、Neo4jのCypherQLは書きやすかった反面、gremlinは非常にとっつきにくいです(個人的に)

リファレンスもありますが、どのような関数を使えば、どのように動くかは実際試してみるしかないと思っています。

ですので、今回Private SubnetにあるNeptuneにgremlin-consoleをいれたコンテナ内から接続したみたいと思います。

基本的な接続周りの設定は、過去に記事化したDocker内からPrivateサブネットに配置したNeptuneに接続するとほぼ同じです。

大きく違う点は、設定ファイルの用意です。

用意するもの

Dockerfileの用意

下記のようなDockerfileを用意します。

FROM openjdk:8-jre-stretch

RUN apt-get update -y && apt-get -y upgrade

RUN wget https://archive.apache.org/dist/tinkerpop/3.3.2/apache-tinkerpop-gremlin-console-3.3.2-bin.zip
RUN unzip apache-tinkerpop-gremlin-console-3.3.2-bin.zip

RUN apt-get install -y net-tools
RUN apt-get install -y openssh-server
RUN apt-get install autossh

RUN mkdir /root/.ssh

docker-compose.ymlの設定

足りないところは補完してください

  gremlin-console:
    build: さっきのDockerfileがあるところ
    volumes:
      - gremlin-consoleの設定ファイルがあるところ:/myconf
      - ~/.ssh:/root/.sshdummy
    extra_hosts:
      - "あなたのNeptuneクラスターエンドポイント:127.0.0.1"
    command: >
      /bin/bash -c "cp /root/.sshdummy/config /root/.ssh/ && 
      cp /root/.sshdummy/踏み台の鍵ファイル.pem /root/.ssh/ && 
      chmod 600 /root/.ssh/踏み台の鍵ファイル.pem &&
      autossh neptune -f -N &&
      /apache-tinkerpop-gremlin-console-3.3.2/bin/gremlin.sh"

接続周りの設定はほぼ同じです。→Docker内からPrivateサブネットに配置したNeptuneに接続する

特筆すべきは gremlin-consoleの設定ファイルがあるところ の部分です。

今回用意するものは、

  • neptune-remote.yml
  • SFSRootCAG2.pem

この2つは、公式ドキュメントにもあるのでご一読ください。

実際にneptune-remote.yml今回の設定内容ですが、以下となります。

hosts: [あなたのNeptuneのクラスターエンドポイント]
port: 8182
connectionPool: { enableSsl: true, trustCertChainFile: "/myconf/SFSRootCAG2.pem"}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0, config: { serializeResultToString: true }}

実際に起動してみる

以下をうつと

docker-compose run gremlin-console

スクリーンショット 2019-02-05 13.29.00.png

起動しました。

Neptuneと接続してみましょう。

:remote connect tinkerpop.server /myconf/neptune-remote.yaml

==>Configured あなたのクラスターエンドポイント/127.0.0.1:8182
:remote console

==>All scripts will now be sent to Gremlin Server - [あなたのクラスターエンドポイント/127.0.0.1:8182] - type ':remote console' to return to local mode

下記のコマンドで失敗するようであれば、接続に失敗しています。

g


==>neptunegraphtraversalsource[neptunegraph[org.apache.commons.configuration.PropertiesConfiguration@42a809b7], standard]

試しに頂点数のチェック

gremlin> g.V().count()
==>168721

オッケーですね。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2