tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject tinkerpop git commit: Intermediate commit for getting websockets running under python RemoteGraph
Date Mon, 15 Aug 2016 18:05:56 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 5049caaea -> 7056b5ea9


Intermediate commit for getting websockets running under python RemoteGraph


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/7056b5ea
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/7056b5ea
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/7056b5ea

Branch: refs/heads/TINKERPOP-1278
Commit: 7056b5ea982b04555079fc1b958bfc5c8e99fe90
Parents: 5049caa
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Mon Aug 15 14:05:22 2016 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Mon Aug 15 14:05:22 2016 -0400

----------------------------------------------------------------------
 .../DefaultRemoteTraverserSerializers.java      | 23 ++++++++++++++++++++
 .../structure/io/graphson/GraphSONModule.java   |  3 +++
 .../io/graphson/GraphSONMapperTest.java         |  8 +++++++
 gremlin-python/pom.xml                          |  1 +
 .../driver/websocket_remote_connection.py       |  9 ++++----
 gremlin-python/src/main/jython/setup.py         |  3 ++-
 .../python/driver/RESTRemoteConnectionTest.java | 15 ++++++-------
 .../python/jsr223/JythonScriptEngineSetup.java  |  2 +-
 8 files changed, 50 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/DefaultRemoteTraverserSerializers.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/DefaultRemoteTraverserSerializers.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/DefaultRemoteTraverserSerializers.java
index 292bfc5..c5fd33e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/DefaultRemoteTraverserSerializers.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/DefaultRemoteTraverserSerializers.java
@@ -18,10 +18,16 @@
  */
 package org.apache.tinkerpop.gremlin.process.remote.traversal;
 
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.InputShim;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.KryoShim;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.OutputShim;
 import org.apache.tinkerpop.gremlin.structure.io.gryo.kryoshim.SerializerShim;
+import org.apache.tinkerpop.shaded.jackson.core.JsonGenerator;
+import org.apache.tinkerpop.shaded.jackson.databind.SerializerProvider;
+import org.apache.tinkerpop.shaded.jackson.databind.ser.std.StdSerializer;
+
+import java.io.IOException;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -46,4 +52,21 @@ public final class DefaultRemoteTraverserSerializers {
             return new DefaultRemoteTraverser<>(o, input.readLong());
         }
     }
+
+    public final static class GraphSONSerializer extends StdSerializer<Traverser> {
+
+        public GraphSONSerializer() {
+            super(Traverser.class);
+        }
+
+        @Override
+        public void serialize(final Traverser traverserInstance, final JsonGenerator jsonGenerator,
final SerializerProvider serializerProvider)
+                throws IOException {
+            jsonGenerator.writeStartObject();
+            jsonGenerator.writeObjectField("bulk", traverserInstance.bulk());
+            jsonGenerator.writeObjectField("value", traverserInstance.get());
+            jsonGenerator.writeEndObject();
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index a4850f7..bf8c513 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -18,6 +18,7 @@
  */
 package org.apache.tinkerpop.gremlin.structure.io.graphson;
 
+import org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverserSerializers;
 import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
 import org.apache.tinkerpop.gremlin.process.traversal.Operator;
 import org.apache.tinkerpop.gremlin.process.traversal.Order;
@@ -27,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Pop;
 import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
 import org.apache.tinkerpop.gremlin.process.traversal.Scope;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalExplanation;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics;
@@ -141,6 +143,7 @@ abstract class GraphSONModule extends SimpleModule {
             addSerializer(P.class, new GraphSONTraversalSerializers.PJacksonSerializer());
             addSerializer(Lambda.class, new GraphSONTraversalSerializers.LambdaJacksonSerializer());
             addSerializer(Bytecode.Binding.class, new GraphSONTraversalSerializers.BindingJacksonSerializer());
+            addSerializer(Traverser.class, new DefaultRemoteTraverserSerializers.GraphSONSerializer());
             // -- deserializers for traversal
             addDeserializer(Bytecode.class, new GraphSONTraversalSerializers.BytecodeJacksonDeserializer());
             addDeserializer(Enum.class, new GraphSONTraversalSerializers.EnumJacksonDeserializer());

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperTest.java
index 41e24c6..02c4b56 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.tinkerpop.gremlin.structure.io.graphson;
 
+import org.apache.tinkerpop.gremlin.process.remote.traversal.DefaultRemoteTraverser;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalExplanation;
 import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
 import org.junit.Test;
@@ -139,4 +140,11 @@ public class GraphSONMapperTest {
         final String json = mapper.writeValueAsString(o);
         assertEquals("\"" + o.toString() + "\"", json);
     }
+
+    @Test
+    public void shouldHandleDefaultRemoteTraverser() throws Exception {
+        final DefaultRemoteTraverser<String> traverser = new DefaultRemoteTraverser<>("test",
100);
+        final String json = mapper.writeValueAsString(traverser);
+        // TODO: ASSERTION~~
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-python/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-python/pom.xml b/gremlin-python/pom.xml
index 7e6030c..a16c0b9 100644
--- a/gremlin-python/pom.xml
+++ b/gremlin-python/pom.xml
@@ -166,6 +166,7 @@
                             <libraries>
                                 <param>aenum</param>
                                 <param>requests</param>
+                                <param>tornado</param>
                             </libraries>
                         </configuration>
                     </execution>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-python/src/main/jython/gremlin_python/driver/websocket_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/websocket_remote_connection.py
b/gremlin-python/src/main/jython/gremlin_python/driver/websocket_remote_connection.py
index 52a9a88..1ccd38d 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/websocket_remote_connection.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/websocket_remote_connection.py
@@ -26,6 +26,7 @@ from tornado import websocket
 from ..process.traversal import Traverser
 from .remote_connection import RemoteConnection
 from .remote_connection import RemoteResponse
+from ..process.graphson import GraphSONWriter
 
 
 class GremlinServerError(Exception):
@@ -48,8 +49,8 @@ class WebSocketRemoteConnection(RemoteConnection):
     def submit(self,
                target_language,
                bytecode,
-               op="eval",
-               processor="",
+               op="bytecode",
+               processor="traversal",
                session=None):
         traversers = self._loop.run_sync(lambda: self._submit(
             target_language, bytecode, op, processor, session))
@@ -107,7 +108,7 @@ class WebSocketRemoteConnection(RemoteConnection):
             "op": op,
             "processor": processor,
             "args": {
-                "gremlin": gremlin,
+                "gremlin": GraphSONWriter.writeObject(gremlin),
                 "bindings": bindings,
                 "language":  lang,
                 "aliases": {'g': self.traversal_source}
@@ -178,7 +179,7 @@ class Response:
         elif status_code in [200, 206]:
             traversers = []
             for result in data:
-                traversers.append(Traverser(result, 1))
+                traversers.append(Traverser(result['value'], result['bulk']))
             if status_code == 200:
                 self._closed = True
         else:

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-python/src/main/jython/setup.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/setup.py b/gremlin-python/src/main/jython/setup.py
index 4d9b8a8..4d474ab 100644
--- a/gremlin-python/src/main/jython/setup.py
+++ b/gremlin-python/src/main/jython/setup.py
@@ -53,6 +53,7 @@ setup(
     long_description=open("README").read(),
     install_requires=[
         'aenum',
-        'requests'
+        'requests',
+        'tornado'
     ]
 )

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
index 0468e90..0796401 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/driver/RESTRemoteConnectionTest.java
@@ -24,7 +24,6 @@ import org.apache.tinkerpop.gremlin.server.GremlinServer;
 import org.apache.tinkerpop.gremlin.server.Settings;
 import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import javax.script.ScriptContext;
@@ -50,9 +49,9 @@ public class RESTRemoteConnectionTest {
         try {
             JythonScriptEngineSetup.setup();
             jython.getContext().getBindings(ScriptContext.ENGINE_SCOPE)
-                    .put("g", jython.eval("RemoteGraph(RESTRemoteConnection('http://localhost:8182','g')).traversal()"));
+                    .put("g", jython.eval("RemoteGraph(WebSocketRemoteConnection('http://localhost:8182','g')).traversal()"));
             jython.getContext().getBindings(ScriptContext.ENGINE_SCOPE)
-                    .put("j", jython.eval("RemoteGraph(RESTRemoteConnection('http://localhost:8182','g')).traversal()"));
+                    .put("j", jython.eval("RemoteGraph(WebSocketRemoteConnection('http://localhost:8182','g')).traversal()"));
             new GremlinServer(Settings.read(RESTRemoteConnectionTest.class.getResourceAsStream("gremlin-server-rest-modern.yaml"))).start().join();
         } catch (final Exception ex) {
             ex.printStackTrace();
@@ -60,7 +59,7 @@ public class RESTRemoteConnectionTest {
     }
 
     @Test
-    @Ignore
+    @org.junit.Ignore
     public void testGraphTraversalNext() throws Exception {
         for (final String alias : this.aliases) {
             final String result = (String) jython.eval(alias + ".V().repeat(__.out()).times(2).name.next()");
@@ -69,7 +68,7 @@ public class RESTRemoteConnectionTest {
     }
 
     @Test
-    @Ignore
+    @org.junit.Ignore
     public void testGraphTraversalToList() throws Exception {
         for (final String alias : this.aliases) {
             final List<String> results = (List) jython.eval(alias + ".V().repeat(__.out()).times(2).name.toList()");
@@ -80,7 +79,7 @@ public class RESTRemoteConnectionTest {
     }
 
     @Test
-    @Ignore
+    @org.junit.Ignore
     public void testGraphTraversalToSet() throws Exception {
         for (final String alias : this.aliases) {
             final Set<String> results = (Set) jython.eval(alias + ".V().repeat(__.both()).times(4).hasLabel('software').name.toSet()");
@@ -91,7 +90,7 @@ public class RESTRemoteConnectionTest {
     }
 
     @Test
-    @Ignore
+    @org.junit.Ignore
     public void testGraphTraversalNextAmount() throws Exception {
         for (final String alias : this.aliases) {
             List<String> results = (List) jython.eval(alias + ".V().repeat(__.out()).times(2).name.next(2)");
@@ -107,7 +106,7 @@ public class RESTRemoteConnectionTest {
     }
 
     @Test
-    @Ignore
+    @org.junit.Ignore
     public void testRemoteConnectionBindings() throws Exception {
         for (final String alias : this.aliases) {
             final String traversalScript = jython.eval(alias + ".V().out(('a','knows'),'created')").toString();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/7056b5ea/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
index 7992da4..2a61666 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
@@ -39,7 +39,7 @@ public class JythonScriptEngineSetup {
             jythonEngine.eval("from gremlin_python.process.traversal import *");
             jythonEngine.eval("from gremlin_python.process.graph_traversal import *");
             jythonEngine.eval("from gremlin_python.process.graph_traversal import __");
-            jythonEngine.eval("from gremlin_python.driver.rest_remote_connection import RESTRemoteConnection");
+            jythonEngine.eval("from gremlin_python.driver.websocket_remote_connection import
WebSocketRemoteConnection");
             jythonEngine.eval("from gremlin_python.process.traversal import Bytecode");
             jythonEngine.eval("from gremlin_python.structure.remote_graph import RemoteGraph");
             jythonEngine.eval("from gremlin_python.process.graphson import GraphSONWriter");


Mime
View raw message