Use the Gremlin console to connect to a Graph Database instance

Updated at:

This topic describes how to use the Gremlin console to connect to and manage a Graph Database (GDB) instance.

Preparations

Before you perform the following operations, make sure that your GDB instance and your Elastic Compute Service (ECS) instance are deployed in the same virtual private cloud (VPC):

  1. The Gremlin console requires Java 8. If Java 8 is not installed, run the following command.

    sudo yum install java-1.8.0-devel
  2. If your ECS instance has multiple Java versions, set Java 8 as the default. For example:

    sudo /usr/sbin/alternatives --config java

    There are four programs that provide Java.

    + 1          java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java)
      2          java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-0.el7_5.x86_64-debug/jre/bin/java)
      3          java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java)
      4          /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
  3. Download the latest version of the Gremlin console from the official Apache Tinkerpop website.

    wget https://archive.apache.org/dist/tinkerpop/3.4.4/apache-tinkerpop-gremlin-console-3.4.4-bin.zip
  4. Unzip the file and change to the apache-tinkerpop-gremlin-console-3.4.4 folder.

    unzip apache-tinkerpop-gremlin-console-3.4.4-bin.zip
    cd apache-tinkerpop-gremlin-console-3.4.4
  5. Create a configuration file named conf/gdb-remote.yaml to connect the Gremlin console to the GDB instance. In the file:

    • Replace ${your_gdb_endpoint} with the domain name of your GDB instance.

    • Replace ${username} with the username for your GDB instance.

    • Replace ${password} with the password for your GDB instance.

      hosts: [ ${your_gdb_endpoint} ]
      port: 8182
      username: ${username}
      password: ${password}
      serializer: {
        className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0,
        config: { serializeResultToString: true }
      }

Establish a connection

  1. From the Gremlin console home directory, run the ./bin/gremlin.sh command to start the console. The output is similar to the following:

     \,,,/
            (o o)
    -----oOOo-(3)-oOOo-----
    plugin activated: tinkerpop.server
    plugin activated: tinkerpop.utilities
    plugin activated: tinkerpop.tinkergraph
    gremlin>
  2. Run the following command to connect to the GDB instance. Do not omit the leading colon.

    :remote connect tinkerpop.server conf/gdb-remote.yaml

    The output shows the host and port of the connected GDB instance.

    ==>Configured gds-uf6rge6e35594khg150010.graphdb.rds.aliyuncs.com/192.X.X.X:XXXX
  3. Run the following command to switch to remote mode. In remote mode, all Gremlin Domain-Specific Language (DSL) statements that you enter in the console are sent to the remote GDB instance. Do not omit the leading colon.

    :remote console

    The output is similar to the following:

    ==>All scripts will now be sent to Gremlin Server - [iz2ze30qqhwn3ba5mu2qgiz/172.X.X.X:XXXX]
    - type ':remote console' to return to local mode
  4. You can now run Gremlin statements. To analyze the performance of a statement, append .profile() to it. For example:

    g.V().count().profile()

    The default timeout is 30 seconds. To change the timeout period, run the following command. The time unit is milliseconds.

    :remote config timeout 60000