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 2020/10/27 16:56:06 UTC

[tinkerpop] 02/03: A few minor fixes to #1342

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 079cb1a372210420aac09c3b07c1734df79179ae
Author: Stephen Mallette <st...@amazon.com>
AuthorDate: Tue Oct 27 12:21:06 2020 -0400

    A few minor fixes to #1342
---
 CHANGELOG.asciidoc                                   |  1 +
 docs/src/reference/gremlin-applications.asciidoc     |  2 +-
 docs/src/upgrade/release-3.4.x.asciidoc              | 12 ++++++------
 .../gremlin/server/util/CheckedGraphManager.java     | 20 +++++++++++---------
 .../gremlin/server/util/DefaultGraphManager.java     |  2 +-
 .../gremlin/server/util/CheckedGraphManagerTest.java |  2 +-
 6 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f6c2807..5049d90 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Bumped to Jackson 2.11.x.
 * Bumped Netty 4.1.52.
 * Moved `Translator` instances to `gremlin-core`.
+* Added `CheckedGraphManager` to prevent Gremlin Server from starting if there are no graphs configured.
 * Fixed bug in bytecode `Bindings` where calling `of()` prior to calling a child traversal in the same parent would cause the initial binding to be lost.
 * Established a default read and write timeout for the `TornadoTransport` in Python, allowing it to be configurable.
 * Delegated handling of erroneous response to the worker thread pool instead of event loop thread pool in Java Driver.
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index f469199..17733a8 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -949,7 +949,7 @@ The following table describes the various YAML configuration options that Gremli
 |authentication.config |A `Map` of configuration settings to be passes to the `Authenticator` when it is constructed.  The settings available are dependent on the implementation. |_none_
 |authentication.enableAuditLog |The available authenticators can issue audit logging messages, binding the authenticated user to his remote socket address and binding requests with a gremlin query to the remote socket address. For privacy reasons, the default value of this setting is false. The audit logging messages are logged at the INFO level via the `audit.org.apache.tinkerpop.gremlin.server` logger, which can be configured using the log4j.properties file. |false
 |channelizer |The fully qualified classname of the `Channelizer` implementation to use.  A `Channelizer` is a "channel initializer" which Gremlin Server uses to define the type of processing pipeline to use.  By allowing different `Channelizer` implementations, Gremlin Server can support different communication protocols (e.g. WebSocket). |`WebSocketChannelizer`
-|graphManager |The fully qualified classname of the `GraphManager` implementation to use.  A `GraphManager` is a class that adheres to the TinkerPop `GraphManager` interface, allowing custom implementations for storing and managing graph references, as well as defining custom methods to open and close graphs instantiations. It is important to note that the TinkerPop HTTP and WebSocketChannelizers auto-commit and auto-rollback based on the graphs stored in the graphManager upon script exe [...]
+|graphManager |The fully qualified classname of the `GraphManager` implementation to use.  A `GraphManager` is a class that adheres to the TinkerPop `GraphManager` interface, allowing custom implementations for storing and managing graph references, as well as defining custom methods to open and close graphs instantiations. It is important to note that the TinkerPop HTTP and WebSocketChannelizers auto-commit and auto-rollback based on the graphs stored in the graphManager upon script exe [...]
 |graphs |A `Map` of `Graph` configuration files where the key of the `Map` becomes the name to which the `Graph` will be bound and the value is the file name of a `Graph` configuration file. |_none_
 |gremlinPool |The number of "Gremlin" threads available to execute actual scripts in a `ScriptEngine`. This pool represents the workers available to handle blocking operations in Gremlin Server. When set to `0`, Gremlin Server will use the value provided by `Runtime.availableProcessors()`. |0
 |host |The name of the host to bind the server to. |localhost
diff --git a/docs/src/upgrade/release-3.4.x.asciidoc b/docs/src/upgrade/release-3.4.x.asciidoc
index 2f4aec3..19ae29e 100644
--- a/docs/src/upgrade/release-3.4.x.asciidoc
+++ b/docs/src/upgrade/release-3.4.x.asciidoc
@@ -28,15 +28,15 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 Please see the link:https://github.com/apache/tinkerpop/blob/3.4.9/CHANGELOG.asciidoc#release-3-4-9[changelog] for a
 complete list of all the modifications that are part of this release.
 
-=== Graph manager extension
+=== GraphManager Extension
 
 The `org.apache.tinkerpop.gremlin.server.util.CheckedGraphManager` can be used instead of 
-`org.apache.tinkerpop.gremlin.server.util.DefaultGraphManager` (in gremlin-server.yml  to ensures that gremlin server 
-fails to start if all graphs fails. This can be usefull for instance on a kubernetes cluster
-to ensure that pop wil be restarted as it cannot handle properly requests. 
-DefaultGraphManager is no more final and thus can be extended.
+`org.apache.tinkerpop.gremlin.server.util.DefaultGraphManager` (in gremlin-server.yml  to ensures that Gremlin Server
+fails to start if all graphs fails. This configuration option can be useful for a number of different situations (e.g.
+use `CheckedGraphManager` on a Kubernetes cluster to ensure that a pod will be restarted when it cannot properly handle
+requests.) As a final note, `DefaultGraphManager` is no longer `final` and thus can be extended.
 
-link:https://issues.apache.org/jira/browse/TINKERPOP-2436[TINKERPOP-2436]
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-2436[TINKERPOP-2436]
 
 === withEmbedded()
 
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManager.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManager.java
index 0f877fd..9f7608c 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManager.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManager.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.server.util;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.tinkerpop.gremlin.server.GraphManager;
 import org.apache.tinkerpop.gremlin.server.Settings;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
@@ -28,13 +29,16 @@ import org.apache.tinkerpop.shaded.minlog.Log;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * A {@link GraphManager} that will prevent Gremlin Server from starting if all configured graphs fail.
+ */
 public class CheckedGraphManager extends DefaultGraphManager {
 
     private static final Logger logger = LoggerFactory.getLogger(CheckedGraphManager.class);
 
     private List<StartupFailure> startupFailures;
 
-    public CheckedGraphManager(Settings settings) {
+    public CheckedGraphManager(final Settings settings) {
         super(settings);
         if (getGraphNames().isEmpty()) {
             if (getStartupFailures().isEmpty()) {
@@ -58,13 +62,13 @@ public class CheckedGraphManager extends DefaultGraphManager {
     }
 
     @Override
-    protected void addGraph(String name, String configurationFile) {
+    protected void addGraph(final String name, final String configurationFile) {
         try {
             final Graph newGraph = GraphFactory.open(configurationFile);
             putGraph(name, newGraph);
             logger.info("Graph [{}] was successfully configured via [{}].", name, configurationFile);
         } catch (Throwable e) {
-            StartupFailure failure = new StartupFailure(name, configurationFile, e);
+            final StartupFailure failure = new StartupFailure(name, configurationFile, e);
             if (logger.isDebugEnabled()) {
                 Log.debug(failure.toString(), e);
             }
@@ -73,11 +77,11 @@ public class CheckedGraphManager extends DefaultGraphManager {
     }
 
     private static class StartupFailure {
-        private String name;
-        private String configurationFile;
-        private Throwable exception;
+        private final String name;
+        private final String configurationFile;
+        private final Throwable exception;
 
-        public StartupFailure(String name, String configurationFile, Throwable exception) {
+        public StartupFailure(final String name, final String configurationFile, final Throwable exception) {
             this.name = name;
             this.configurationFile = configurationFile;
             this.exception = exception;
@@ -88,7 +92,5 @@ public class CheckedGraphManager extends DefaultGraphManager {
                     "Graph [%s] configured at [%s] could not be instantiated and will not be available in Gremlin Server.  GraphFactory message: %s",
                     name, configurationFile, exception.getMessage());
         }
-
     }
-
 }
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/DefaultGraphManager.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/DefaultGraphManager.java
index c32c9e3..47f7832 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/DefaultGraphManager.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/DefaultGraphManager.java
@@ -58,7 +58,7 @@ public class DefaultGraphManager implements GraphManager {
         settings.graphs.forEach(this::addGraph);
     }
     
-    protected void addGraph(String name, String configurationFile) {
+    protected void addGraph(final String name, final String configurationFile) {
         try {
             final Graph newGraph = GraphFactory.open(configurationFile);
             putGraph(name, newGraph);
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManagerTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManagerTest.java
index 9d2a2f8..53900fc 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManagerTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/CheckedGraphManagerTest.java
@@ -65,7 +65,7 @@ public class CheckedGraphManagerTest {
     @Test
     public void justAGraphFails() {
         settings.graphs.put("invalid", "conf/invalidPath");
-        GraphManager manager = new CheckedGraphManager(settings);
+        final GraphManager manager = new CheckedGraphManager(settings);
         assertThat(manager.getGraphNames(), hasSize(6));
     }