Open pluradj opened 7 years ago
Hey, i want to know sixth! Where is the documentation / examples for REST API (for adding/ querying vertices, edges)?I am really confused!
@StanYaha There currently isn't any specific JanusGraph docs for that (will be addressed with this issue), but in the meantime you can refer to the TinkerPop docs http://tinkerpop.apache.org/docs/3.2.5/reference/#_connecting_via_rest
I am also interested in the REST API documentation. Currently only simple queries like count works for me.
Any references?
You can submit any gremlin queries over HTTP (It's not actually REST). Official docs: http://tinkerpop.apache.org/docs/3.2.6/reference/#_connecting_via_rest
Robert Dale
On Tue, Aug 29, 2017 at 5:38 AM, Yair Ogen notifications@github.com wrote:
I am also interested in the REST API documentation. Currently only simple queries like count works for me.
Any references?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JanusGraph/janusgraph/issues/452#issuecomment-325611096, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHdXogLFoaG3tB0J4vcS1rzaFKPobohks5sc9wjgaJpZM4OxE7d .
so - I tried this:
curl -X POST -Hcontent-type:application/json -d '{"gremlin":"g.V().count()"}' http://10.193.1.33:8182
and got:
{"requestId":"0e2e1e1c-42d4-4745-ae46-718f220cc8ea","status":{"message":"","code":200,"attributes":{}},"result":{"data":[1],"meta":{}}}
Looks good.
Now I tried:
curl -X POST -Hcontent-type:application/json -d '{"gremlin":"g.addVertex('name', 'stephen')"}' http://10.193.1.33:8182
but got:
{"message":"No such property: name for class: Script4","Exception-Class":"groovy.lang.MissingPropertyException"}
So - I am doing something wrong - but I don't know what.
Looks like you are confusing the graph api with the traversal api.
graph
is usually the graph.
g
is usually the traversal.
In gremlin, g.addV('person').property('name','stephen')
See also http://tinkerpop.apache.org/docs/3.2.6/reference/#addvertex-step
Robert Dale
On Tue, Aug 29, 2017 at 8:02 AM, Yair Ogen notifications@github.com wrote:
so - I tried this: curl -X POST -Hcontent-type:application/json -d '{"gremlin":"g.V().count()"}' http://10.193.1.33:8182
and got:
{"requestId":"0e2e1e1c-42d4-4745-ae46-718f220cc8ea"," status":{"message":"","code":200,"attributes":{}},"result": {"data":[1],"meta":{}}}
Looks good.
Now I tried:
curl -X POST -Hcontent-type:application/json -d '{"gremlin":"g.addVertex('name', 'stephen')"}' http://10.193.1.33:8182
but got:
{"message":"No such property: name for class: Script4","Exception-Class":" groovy.lang.MissingPropertyException"}
So - I am doing something wrong - but I don't know what.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JanusGraph/janusgraph/issues/452#issuecomment-325642359, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHdXqpj8TbSPftZ95GqT-wzByXVInvAks5sc_3jgaJpZM4OxE7d .
Thanks. I'm newbie.
Still error:
curl -X POST -Hcontent-type:application/json -d '{"gremlin":"g.addV('person').property('name','stephen')"}' http://10.193.1.33:8182
{"message":"No such property: person for class: Script5","Exception-Class":"groovy.lang.MissingPropertyException"}
You'll need to escape your quotes properly...
$ curl -X POST -d "{\"gremlin\":\"g.addV('person').property('name','stephen')\"}" http://localhost:8182
{"requestId":"34dbdd70-7aa7-412c-a8ac-313781bfa106","status":{"message":"","code":200,"attributes":{}},"result":{"data":[{"id":13,"label":"person","type":"vertex","properties":{"name":[{"id":14,"value":"stephen"}]}}],"meta":{}}}
Robert Dale
On Tue, Aug 29, 2017 at 8:41 AM, Yair Ogen notifications@github.com wrote:
Thanks. I'm newbie.
Still error:
` curl -X POST -Hcontent-type:application/json -d '{"gremlin":"g.addV('person').property('name','stephen')"}' http://10.193.1.33:8182
{"message":"No such property: person for class: Script5","Exception-Class":"groovy.lang.MissingPropertyException"}`
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JanusGraph/janusgraph/issues/452#issuecomment-325651356, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHdXq5aL0NSCTtNuvoziszlSGPAJDGmks5sdAb_gaJpZM4OxE7d .
curl -XPOST -Hcontent-type:application/json -d '{"gremlin":"g.V().count()"}' http://10.2.5.205:8182
{"message":"No such property: g for class: Script4","Exception-Class":"groovy.lang.MissingPropertyException","exceptions":["groovy.lang.MissingPropertyException"],"stackTrace":"groovy.lang.MissingPropertyException: No such property: g for class: Script4\n\tat org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)\n\tat org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)\n\tat org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)\n\tat Script4.run(Script4.groovy:1)\n\tat org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:843)\n\tat org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:548)\n\tat javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)\n\tat org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines.eval(ScriptEngines.java:120)\n\tat org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:290)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat java.lang.Thread.run(Thread.java:748)\n"}
curl -X POST -d "{\"gremlin\":\"g.addV('person').property('name','stephen')\"}" http://10.2.5.205:8182
`{"message":"No such property: g for class: Script5","Exception-Class":"groovy.lang.MissingPropertyException","exceptions":["groovy.lang.MissingPropertyException"],"stackTrace":"groovy.lang.MissingPropertyException: No such property: g for class: Script5\n\tat org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)\n\tat org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)\n\tat org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)\n\tat Script5.run(Script5.groovy:1)\n\tat org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:843)\n\tat org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:548)\n\tat javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)\n\tat org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines.eval(ScriptEngines.java:120)\n\tat org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:290)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat java.lang.Thread.run(Thread.java:748)\n"
`
@KevinGong What steps did you follow?? Are there any errors in gremlin-server.log?
@KevinGong it says g
is not defined. So either you can change your gremlin query to graph.traversal().V().count()
or you could globally define g
like the packaged gremlin-server.yaml
does via the empty-sample.groovy
script.
@robertdale follow :7.3. JanusGraph Server as a REST-style Endpoint http://docs.janusgraph.org/latest/server.html
59089015 [gremlin-server-worker-1] WARN org.apache.tinkerpop.gremlin.server.handler.HttpGremlinEndpointHandler - Invalid request - responding with 500 Internal Server Error and No such property: g for class: Script8
groovy.lang.MissingPropertyException: No such property: g for class: Script8
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script8.run(Script8.groovy:1)
at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:843)
at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:548)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
at org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines.eval(ScriptEngines.java:120)
at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:290)
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)`
[ggp@graph02 conf]$ cat gremlin-server/janusgraph-hbase.properties
gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=hbase
storage.hostname=10.2.5.43
cache.db-cache = true
cache.db-cache-clean-wait = 20
cache.db-cache-time = 180000
cache.db-cache-size = 0.5
[ggp@graph02 conf]$ cat gremlin-server/rest-gremlin-server.yaml
host: 0.0.0.0
port: 8182
scriptEvaluationTimeout: 30000
channelizer: org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer
graphs: {
graph: conf/gremlin-server/janusgraph-hbase.properties
}
plugins:
- janusgraph.imports
scriptEngines: {
gremlin-groovy: {
imports: [java.lang.Math],
staticImports: [java.lang.Math.PI],
scripts: [scripts/empty-sample.groovy]}}
serializers:
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0, config: {ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry] }}
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistryV1d0] }}
processors:
- { className: org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor, config: { sessionTimeout: 28800000 }}
- { className: org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor, config: { cacheExpirationTime: 600000, cacheMaxSize: 1000 }}
metrics: {
consoleReporter: {enabled: true, interval: 180000},
csvReporter: {enabled: true, interval: 180000, fileName: /tmp/gremlin-server-metrics.csv},
jmxReporter: {enabled: true},
slf4jReporter: {enabled: true, interval: 180000},
gangliaReporter: {enabled: false, interval: 180000, addressingMode: MULTICAST},
graphiteReporter: {enabled: false, interval: 180000}}
maxInitialLineLength: 4096
maxHeaderSize: 8192
maxChunkSize: 8192
maxContentLength: 65536
maxAccumulationBufferComponents: 1024
resultIterationBatchSize: 64
writeBufferLowWaterMark: 32768
writeBufferHighWaterMark: 65536
@pluradj graph.traversal().V().count()
,not ok 。。。I do not know how to define g
From which directory are you starting the Gremlin Server?
The variable g
is defined in the last line of the file scripts/empty-sample.groovy
. If you didn't modify this file from the distribution zip, it should look like this:
$ tail -n 2 scripts/empty-sample.groovy
// define the default TraversalSource to bind queries to - this one will be named "g".
globals << [g : graph.traversal()]
This Groovy file is referenced in your conf/gremlin-server/rest-gremlin-server.yaml
above under the gremlin-groovy
script engine definition:
scriptEngines: {
gremlin-groovy: {
imports: [java.lang.Math],
staticImports: [java.lang.Math.PI],
scripts: [scripts/empty-sample.groovy]}}
Notice that scripts/empty-sample.groovy
is a relative path. You should be starting the server from the janusgraph-0.1.1-hadoop2 directory like this:
$ cd /path/to/janusgraph-0.1.1-hadoop2
$ bin/gremlin-server.sh conf/gremlin-server/rest-gremlin-server.yaml
... snip ...
0 [main] INFO org.apache.tinkerpop.gremlin.server.GremlinServer -
\,,,/
(o o)
-----oOOo-(3)-oOOo-----
103 [main] INFO org.apache.tinkerpop.gremlin.server.GremlinServer - Configuring Gremlin Server from conf/gremlin-server/rest-gremlin-server.yaml
168 [main] INFO org.apache.tinkerpop.gremlin.server.util.MetricManager - Configured Metrics ConsoleReporter configured with report interval=180000ms
170 [main] INFO org.apache.tinkerpop.gremlin.server.util.MetricManager - Configured Metrics CsvReporter configured with report interval=180000ms to fileName=/tmp/gremlin-server-metrics.csv
230 [main] INFO org.apache.tinkerpop.gremlin.server.util.MetricManager - Configured Metrics JmxReporter configured with domain= and agentId=
231 [main] INFO org.apache.tinkerpop.gremlin.server.util.MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
704 [main] INFO org.janusgraph.core.util.ReflectiveConfigOptionLoader - Loaded and initialized config classes: 12 OK out of 12 attempts in PT0.035S
757 [main] INFO org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager - Closed Thrift connection pooler.
947 [main] INFO org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration - Generated unique-instance-id=642d976090166-pluradj-mbp-2-local1
955 [main] INFO org.janusgraph.diskstorage.Backend - Configuring index [search]
1035 [main] INFO org.elasticsearch.plugins - [Adrian Corbo] loaded [], sites []
1442 [main] INFO org.janusgraph.diskstorage.es.ElasticSearchIndex - Configured remote host: 127.0.0.1 : 9300
1548 [main] INFO org.janusgraph.diskstorage.Backend - Initiated backend operations thread pool of size 16
1568 [main] INFO org.janusgraph.diskstorage.Backend - Configuring total store cache size: 110732666
1636 [main] INFO org.janusgraph.diskstorage.log.kcvs.KCVSLog - Loaded unidentified ReadMarker start time 2017-10-19T06:14:58.704Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@15bc339
>> 1636 [main] INFO org.apache.tinkerpop.gremlin.server.GremlinServer - Graph [graph] was successfully configured via [conf/gremlin-server/janusgraph-cassandra-es-server.properties].
1636 [main] INFO org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor - Initialized Gremlin thread pool. Threads in pool named with pattern gremlin-*
1965 [main] INFO org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines - Loaded gremlin-groovy ScriptEngine
2482 [main] INFO org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor - Initialized gremlin-groovy ScriptEngine with scripts/empty-sample.groovy
2482 [main] INFO org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor - Initialized GremlinExecutor and configured ScriptEngines.
>> 2485 [main] INFO org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[standardjanusgraph[cassandrathrift:[127.0.0.1]], standard]
2498 [main] INFO org.apache.tinkerpop.gremlin.server.op.OpLoader - Adding the standard OpProcessor.
2499 [main] INFO org.apache.tinkerpop.gremlin.server.op.OpLoader - Adding the control OpProcessor.
2501 [main] INFO org.apache.tinkerpop.gremlin.server.op.OpLoader - Adding the session OpProcessor.
2648 [main] INFO org.apache.tinkerpop.gremlin.server.op.OpLoader - Adding the traversal OpProcessor.
2763 [main] INFO org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor - Initialized cache for TraversalOpProcessor with size 1000 and expiration time of 600000 ms
2779 [main] INFO org.apache.tinkerpop.gremlin.server.GremlinServer - Executing start up LifeCycleHook
2791 [main] INFO org.apache.tinkerpop.gremlin.server.GremlinServer - Executed once at startup of Gremlin Server.
2829 [main] INFO org.apache.tinkerpop.gremlin.server.AbstractChannelizer - Configured application/vnd.gremlin-v1.0+gryo with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0
2831 [main] INFO org.apache.tinkerpop.gremlin.server.AbstractChannelizer - Configured application/vnd.gremlin-v1.0+gryo-lite with org.apache.tinkerpop.gremlin.driver.ser.GryoLiteMessageSerializerV1d0
2831 [main] INFO org.apache.tinkerpop.gremlin.server.AbstractChannelizer - Configured application/vnd.gremlin-v1.0+gryo-stringd with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0
2836 [main] INFO org.apache.tinkerpop.gremlin.server.AbstractChannelizer - Configured application/vnd.gremlin-v1.0+json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0
2850 [main] INFO org.apache.tinkerpop.gremlin.server.AbstractChannelizer - Configured application/vnd.gremlin-v2.0+json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV2d0
2851 [main] INFO org.apache.tinkerpop.gremlin.server.AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0
2896 [gremlin-server-boss-1] INFO org.apache.tinkerpop.gremlin.server.GremlinServer - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.
2896 [gremlin-server-boss-1] INFO org.apache.tinkerpop.gremlin.server.GremlinServer - Channel started at port 8182.
Notice the lines I marked with >>
where it says that [graph]
was successfully configured and graph traversal source [g]
was bound. If you could include the complete Gremlin Server log output, that would be helpful.
remote.yaml sample for 3.2.6 gremlin-driver:
graph.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"))
hosts: [0.0.0.0]
port: 8182
serializer: {
className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0,
config: {
ioRegistries: [org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry]
}
}
connectionPool: {
# Determines if SSL should be enabled or not. If enabled on the server then it must be enabled on the client.
enableSsl: false,
# The maximum length in bytes that a message can be sent to the server. This number can be no greater than the
# setting of the same name in the server configuration.
maxContentLength: 65536000,
# The maximum number of in-flight requests that can occur on a connection.
maxInProcessPerConnection: 4,
# The maximum number of times that a connection can be borrowed from the pool simultaneously.
maxSimultaneousUsagePerConnection: 16,
# The maximum size of a connection pool for a host.
maxSize: 16,
# The amount of time in milliseconds to wait for a new connection before timing out.
maxWaitForConnection: 3000,
# The amount of time in milliseconds to wait for a session to close before timing out (does not apply to
# sessionless connections).
maxWaitForSessionClose: 3000,
# The minimum number of in-flight requests that can occur on a connection.
minInProcessPerConnection: 1,
# The maximum number of times that a connection can be borrowed from the pool simultaneously.
minSimultaneousUsagePerConnection: 8,
# The minimum size of a connection pool for a host.
minSize: 8,
# The amount of time in milliseconds to wait before trying to reconnect to a dead host.
reconnectInterval: 1000,
# The override value for the size of the result batches to be returned from the server.
resultIterationBatchSize: 64
}
# Size of the pool for handling background work. default : available processors * 2
workerPoolSize: 4
# Size of the pool for handling request/response operations. # default : available processors
nioPoolSize: 4
Several questions listed here from the users mailing list can be added to the docs to help on-board new users.
1) What is the relation between Gremlin server (bin/gremlin-server.bat) and the JanusGraph server (bin/janusgraph.sh)?
2) I've specified my Cassandra related configuration values in conf/gremlin-server/janusgraph-cassandra-es-server.properties file and this file is being used when running the gremlin server. While using the Java API (from Scala), I do the following -
Should I be using the same (conf/gremlin-server/janusgraph-cassandra-es-server.properties) file which I use to start the gremlin server from my Java code?
3) In the above API, I haven't specified the JanusGraph server endpoint (the URL or the port), so which server is my Java code connecting to?
4) Does Java API use websockets, and can JanusGraph server run on a different machine (right now, my Cassandra and gremlin server run on the same machine)?
5) Is Java API the same as Gremlin language / API?
6) Where is the documentation / examples for REST API (for adding / querying vertices, edges)?
7) How can one achieve graph namespacing? So for example, I have to create three different graphs for employees, vehicles and cities, how can I segregate the data for these three graphs? Can I give a name / id to the graph? Or do these graphs have to be stored in different Cassandra keyspaces?
8) If the graphs have to be stored in different Cassandra keyspaces, how can I connect to these different graphs / keyspaces from the same Java application?