You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/08/22 20:40:09 UTC

[24/48] tinkerpop git commit: TINKERPOP-1407 More default serializers for Gremlin Server.

TINKERPOP-1407 More default serializers for Gremlin Server.

If no serializers are configured then Gremlin Server will set up graphson and gryo as the standard to ensure the server can deal with at least the most common serialization formats. CTR


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

Branch: refs/heads/TINKERPOP-1278
Commit: da47a21cf8d7bed2f7f198c6cf91165d38bd957f
Parents: 848e367
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Aug 19 12:43:06 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 19 12:43:06 2016 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../src/reference/gremlin-applications.asciidoc |  4 ++--
 .../AbstractGraphSONMessageSerializerV1d0.java  |  2 +-
 gremlin-server/conf/gremlin-server-min.yaml     | 14 ------------
 .../gremlin/server/AbstractChannelizer.java     | 23 +++++++++++++++++---
 .../tinkerpop/gremlin/server/Settings.java      | 21 ++++++++++--------
 6 files changed, 36 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da47a21c/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index d4eff5d..1b93ecd 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.2 (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Included GraphSON as a default serializer (in addition to Gryo, which was already present) in Gremlin Server if none are defined
 * Defaulted the `gremlinPool` setting in Gremlin Server to be zero, which will instructs it to use `Runtime.availableProcessors()` for that settings.
 * Changed scope of log4j dependencies so that they would only be used in tests and the binary distributions of Gremlin Console and Server.
 * Deprecated `Io.Builder.registry()` in favor of the newly introduced `Io.Builder.onMapper()`.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da47a21c/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 7b84b43..76dd45e 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -955,13 +955,13 @@ The following table describes the various configuration options that Gremlin Ser
 |processors[X].className |The full class name of the `OpProcessor` implementation. |_none_
 |processors[X].config |A `Map` containing `OpProcessor` specific configurations. |_none_
 |resultIterationBatchSize |Defines the size in which the result of a request is "batched" back to the client.  In other words, if set to `1`, then a result that had ten items in it would get each result sent back individually.  If set to `2` the same ten results would come back in five batches of two each. |64
-|scriptEngines |A `Map` of `ScriptEngine` implementations to expose through Gremlin Server, where the key is the name given by the `ScriptEngine` implementation.  The key must match the name exactly for the `ScriptEngine` to be constructed.  The value paired with this key is itself a `Map` of configuration for that `ScriptEngine`.  |_none_
+|scriptEngines |A `Map` of `ScriptEngine` implementations to expose through Gremlin Server, where the key is the name given by the `ScriptEngine` implementation.  The key must match the name exactly for the `ScriptEngine` to be constructed.  The value paired with this key is itself a `Map` of configuration for that `ScriptEngine`.  If this value is not set, it will default to "gremlin-groovy". |_gremlin-groovy_
 |scriptEngines.<name>.imports |A comma separated list of classes/packages to make available to the `ScriptEngine`. |_none_
 |scriptEngines.<name>.staticImports |A comma separated list of "static" imports to make available to the `ScriptEngine`. |_none_
 |scriptEngines.<name>.scripts |A comma separated list of script files to execute on `ScriptEngine` initialization. `Graph` and `TraversalSource` instance references produced from scripts will be stored globally in Gremlin Server, therefore it is possible to use initialization scripts to add Traversal Strategies or create entirely new `Graph` instances all together. Instantiating a `LifeCycleHook` in a script provides a way to execute scripts when Gremlin Server starts and stops.|_none_
 |scriptEngines.<name>.config |A `Map` of configuration settings for the `ScriptEngine`.  These settings are dependent on the `ScriptEngine` implementation being used. |_none_
 |scriptEvaluationTimeout |The amount of time in milliseconds before a script evaluation times out. The notion of "script evaluation" refers to the time it takes for the `ScriptEngine` to do its work and *not* any additional time it takes for the result of the evaluation to be iterated and serialized. This feature can be turned off by setting the value to `0`. |30000
-|serializers |A `List` of `Map` settings, where each `Map` represents a `MessageSerializer` implementation to use along with its configuration. |_none_
+|serializers |A `List` of `Map` settings, where each `Map` represents a `MessageSerializer` implementation to use along with its configuration. If this value is not set, then Gremlin Server will configure with GraphSON and Gryo but will not register any `ioRegistries` for configured graphs. |_empty_
 |serializers[X].className |The full class name of the `MessageSerializer` implementation. |_none_
 |serializers[X].config |A `Map` containing `MessageSerializer` specific configurations. |_none_
 |ssl.enabled |Determines if SSL is turned on or not. |false

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da47a21c/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
index 810220b..ac6a74f 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/AbstractGraphSONMessageSerializerV1d0.java
@@ -55,7 +55,7 @@ public abstract class AbstractGraphSONMessageSerializerV1d0 extends AbstractMess
 
     protected ObjectMapper mapper;
 
-    protected static final String TOKEN_USE_MAPPER_FROM_GRAPH = "useMapperFromGraph";
+    public static final String TOKEN_USE_MAPPER_FROM_GRAPH = "useMapperFromGraph";
 
     protected final TypeReference<Map<String, Object>> mapTypeReference = new TypeReference<Map<String, Object>>() {
     };

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da47a21c/gremlin-server/conf/gremlin-server-min.yaml
----------------------------------------------------------------------
diff --git a/gremlin-server/conf/gremlin-server-min.yaml b/gremlin-server/conf/gremlin-server-min.yaml
index d4471f5..9ce6b5e 100644
--- a/gremlin-server/conf/gremlin-server-min.yaml
+++ b/gremlin-server/conf/gremlin-server-min.yaml
@@ -17,23 +17,9 @@
 
 host: localhost
 port: 8182
-scriptEvaluationTimeout: 30000
 graphs: {
   graph: conf/tinkergraph-empty.properties}
 plugins:
   - tinkerpop.tinkergraph
-scriptEngines: {
-  gremlin-groovy: {
-    imports: []}}
-serializers:
-  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerGremlinV1d0, config: { useMapperFromGraph: graph }}  # application/vnd.gremlin-v1.0+json
-  - { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { useMapperFromGraph: graph }}         # application/json
 metrics: {
   slf4jReporter: {enabled: true, interval: 180000}}
-strictTransactionManagement: false
-maxInitialLineLength: 4096
-maxHeaderSize: 8192
-maxChunkSize: 8192
-maxContentLength: 65536
-maxAccumulationBufferComponents: 1024
-resultIterationBatchSize: 64

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da47a21c/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
index 829a3ee..10dbc1c 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/AbstractChannelizer.java
@@ -24,9 +24,11 @@ import io.netty.handler.ssl.SslContextBuilder;
 import io.netty.handler.ssl.SslProvider;
 import io.netty.handler.ssl.util.SelfSignedCertificate;
 import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
+import org.apache.tinkerpop.gremlin.driver.ser.AbstractGraphSONMessageSerializerV1d0;
+import org.apache.tinkerpop.gremlin.driver.ser.AbstractGryoMessageSerializerV1d0;
+import org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0;
+import org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0;
 import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
-import org.apache.tinkerpop.gremlin.server.auth.AllowAllAuthenticator;
-import org.apache.tinkerpop.gremlin.server.handler.SaslAuthenticationHandler;
 import org.apache.tinkerpop.gremlin.server.auth.Authenticator;
 import org.apache.tinkerpop.gremlin.server.handler.IteratorHandler;
 import org.apache.tinkerpop.gremlin.server.handler.OpExecutorHandler;
@@ -42,7 +44,10 @@ import org.slf4j.LoggerFactory;
 import javax.net.ssl.SSLException;
 import java.io.File;
 import java.security.cert.CertificateException;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ExecutorService;
@@ -62,6 +67,14 @@ import java.util.stream.Stream;
  */
 public abstract class AbstractChannelizer extends ChannelInitializer<SocketChannel> implements Channelizer {
     private static final Logger logger = LoggerFactory.getLogger(AbstractChannelizer.class);
+    protected static final List<Settings.SerializerSettings> DEFAULT_SERIALIZERS = Arrays.asList(
+            new Settings.SerializerSettings(GryoMessageSerializerV1d0.class.getName(), Collections.emptyMap()),
+            new Settings.SerializerSettings(GryoMessageSerializerV1d0.class.getName(), new HashMap<String,Object>(){{
+                put(AbstractGryoMessageSerializerV1d0.TOKEN_SERIALIZE_RESULT_TO_STRING, true);
+            }}),
+            new Settings.SerializerSettings(GraphSONMessageSerializerV1d0.class.getName(), Collections.emptyMap())
+    );
+
     protected Settings settings;
     protected GremlinExecutor gremlinExecutor;
     protected Optional<SslContext> sslContext;
@@ -153,7 +166,11 @@ public abstract class AbstractChannelizer extends ChannelInitializer<SocketChann
     }
 
     private void configureSerializers() {
-        this.settings.serializers.stream().map(config -> {
+        // grab some sensible defaults if no serializers are present in the config
+        final List<Settings.SerializerSettings> serializerSettings =
+                (null == this.settings.serializers || this.settings.serializers.isEmpty()) ? DEFAULT_SERIALIZERS : settings.serializers;
+
+        serializerSettings.stream().map(config -> {
             try {
                 final Class clazz = Class.forName(config.className);
                 if (!MessageSerializer.class.isAssignableFrom(clazz)) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da47a21c/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
index b36bd6a..8b9fe89 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java
@@ -54,15 +54,9 @@ import java.util.UUID;
 public class Settings {
 
     public Settings() {
-        // setup some sensible defaults like gremlin-groovy and gryo serialization
+        // setup some sensible defaults like gremlin-groovy
         scriptEngines = new HashMap<>();
         scriptEngines.put("gremlin-groovy", new ScriptEngineSettings());
-
-        serializers = new ArrayList<>();
-        final SerializerSettings gryoSerializerSettings = new SerializerSettings();
-        gryoSerializerSettings.className = GryoMessageSerializerV1d0.class.getName();
-        gryoSerializerSettings.config = Collections.emptyMap();
-        serializers.add(gryoSerializerSettings);
     }
 
     /**
@@ -195,9 +189,10 @@ public class Settings {
     public Map<String, ScriptEngineSettings> scriptEngines;
 
     /**
-     * List of {@link MessageSerializer} to configure.
+     * List of {@link MessageSerializer} to configure. If no serializers are specified then default serializers for
+     * the most current versions of "application/json" and "application/vnd.gremlin-v1.0+gryo" are applied.
      */
-    public List<SerializerSettings> serializers;
+    public List<SerializerSettings> serializers = Collections.emptyList();
 
     /**
      * Configures settings for SSL.
@@ -348,6 +343,14 @@ public class Settings {
      * Settings for the {@link MessageSerializer} implementations.
      */
     public static class SerializerSettings {
+
+        public SerializerSettings() {}
+
+        SerializerSettings(final String className, final Map<String, Object> config) {
+            this.className = className;
+            this.config = config;
+        }
+
         /**
          * The fully qualified class name of the {@link MessageSerializer} implementation. This class name will be
          * used to load the implementation from the classpath.