Search code examples
gremlintinkerpopjanusgraph

How to load a graphml file into a remote instance of Janusgraph, from a local gremlin-console


How to load a graphml file into a remote instance of Janusgraph, from a local gremlin-console

Eventually, I want to create JanusGraph on a remote VM but for this PoT, I've created a local docker image with

docker run --rm --name janusgraph-default janusgraph/janusgraph:latest

Which works fine. I then started gremlin-console with:

docker run --rm --link janusgraph-default:janusgraph -e GREMLIN_REMOTE_HOSTS=janusgraph \ -it janusgraph/janusgraph:latest ./bin/gremlin.sh

This also works fine. On the gremlin-console I ran

:remote connect tinkerpop.server conf/remote.yaml

Then

:> g.addV('person').property('name', 'chris')

to test it had worked, I ran :> g.V().values('name') which returned chris

Having (I think) proved that gremlin-console can control the gremlin-server in the docker image, I wanted to import K Lawrence's air-routes-latest.graphml, with a view to trying to create some CRUD operations in Node.js

All the docs I can find only deal with local import and not remote

I tried:

:> graph.io(graphml()).readGraph("/home/me/Downloads/air-routes.graphml"), which returned

/home/me/Downloads/air-routes.graphml (No such file or directory)

Stack Trace:

Display stack trace? [yN]y
java.io.FileNotFoundException: /home/greg/Downloads/air-routes.graphml (No such file or directory)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:195)
        at java.io.FileInputStream.<init>(FileInputStream.java:138)
        at java.io.FileInputStream.<init>(FileInputStream.java:93)
        at org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLIo.readGraph(GraphMLIo.java:91)
        at org.apache.tinkerpop.gremlin.structure.io.Io$readGraph.call(Unknown Source)
        at Script5.run(Script5.groovy:1)
        at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:674)
        at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:376)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
        at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:266)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

I'm confident that's really where it is (on the same machine as the console) but it made me wonder whether the import has a context of the remote server (in this case the docker image, but potentially a remote VM) or the local console? I can't find any help to shine a light on this help, please?

 Gremlin.version()
==>3.4.4

gremlin-console janusgraph tinkerpop gremlin


Solution

  • Following Stephen's response, I tried the following, which worked:

    Setting up Janusgraph server to import air-routes.graphml

    bash terminal 1 (su):

    docker run --name janusgraph-default --volume /home/greg/Downloads/gremlin:/dataImports janusgraph/janusgraph:latest
    

    (if necessary, remove a clashing container with docker container stop <pid> )

    This mounts the native folder /home/greg/Downloads/gremlin as /dataImports in the image, so the air-routes.graphml file can be imported (you'll need to download from this link and substitute your own native file path to the download) It's a useful graphml data-set to play with. Read about it here and here.

    To run the import, open a new bash terminal 2 (su):

    docker run --rm --link janusgraph-default:janusgraph -e GREMLIN_REMOTE_HOSTS=janusgraph -it janusgraph/janusgraph:latest ./bin/gremlin.sh
    

    This links to the janusgraph server (no port binding required) and opens the gremlin-console.

    On the console, run:

    :remote connect tinkerpop.server conf/remote.yaml
    

    Then import the graphml file with

    :> graph.io(graphml()).readGraph("/dataImports/air-routes.graphml")
    

    It should return null. Once it has, run queries like:

    :> g.V().has('airport','code','DFW').values()