Skip to content

Commit ff9a18a

Browse files
committed
cleanups and fixes
1 parent 4aec190 commit ff9a18a

5 files changed

Lines changed: 80 additions & 80 deletions

File tree

docs/src/reference/gremlin-applications.asciidoc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,22 @@ $ bin/gremlin-server.sh conf/gremlin-server-modern.yaml
444444
(o o)
445445
-----oOOo-(4)-oOOo-----
446446
447-
[INFO] GremlinServer - Configuring Gremlin Server from conf/gremlin-server-modern.yaml
448-
[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
449-
[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
450-
[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool. Threads in pool named with pattern gremlin-*
451-
[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.
452-
[INFO] ServerGremlinExecutor - A GraphTraversalSource is now auto-bound to [g] for graph [graph]
453-
[INFO] ServerGremlinExecutor - Instantiated LifeCycleHook: org.apache.tinkerpop.gremlin.server.util.TinkerFactoryDataLoader
454-
[INFO] GremlinServer - Executing start up LifeCycleHook
455-
[INFO] TinkerFactoryDataLoader - TinkerFactoryDataLoader loaded [modern] dataset into graph [graph]
456-
[INFO] GremlinServer - idleConnectionTimeout was set to 0 which resolves to 0 seconds when configuring this value - this feature will be disabled
457-
[INFO] GremlinServer - keepAliveInterval was set to 0 which resolves to 0 seconds when configuring this value - this feature will be disabled
458-
[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v4.0+json with org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV4
459-
[INFO] AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV4
460-
[INFO] AbstractChannelizer - Configured application/vnd.graphbinary-v4.0 with org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV4
461-
[INFO] GremlinServer$1 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 4 and boss thread pool of 1.
462-
[INFO] GremlinServer$1 - Channel started at port 8182.
447+
[INFO] o.a.t.g.s.GremlinServer - Configuring Gremlin Server from conf/gremlin-server-modern.yaml
448+
[INFO] o.a.t.g.s.u.MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics
449+
[INFO] o.a.t.g.s.u.DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].
450+
[INFO] o.a.t.g.s.u.ServerGremlinExecutor - Initialized Gremlin thread pool. Threads in pool named with pattern gremlin-*
451+
[INFO] o.a.t.g.s.u.ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.
452+
[INFO] o.a.t.g.s.u.ServerGremlinExecutor - Initialized gremlin-lang GremlinScriptEngine and registered metrics
453+
[INFO] o.a.t.g.s.u.ServerGremlinExecutor - A GraphTraversalSource is now auto-bound to [g] for graph [graph]
454+
[INFO] o.a.t.g.s.u.ServerGremlinExecutor - Instantiated LifeCycleHook: org.apache.tinkerpop.gremlin.server.util.TinkerFactoryDataLoader
455+
[INFO] o.a.t.g.s.h.TransactionManager - TransactionManager initialized with timeout=600000ms, maxTransactions=1000
456+
[INFO] o.a.t.g.s.GremlinServer - Executing start up LifeCycleHook
457+
[INFO] o.a.t.g.s.u.TinkerFactoryDataLoader - TinkerFactoryDataLoader loaded [modern] dataset into graph [graph]
458+
[INFO] o.a.t.g.s.AbstractChannelizer - Configured application/vnd.gremlin-v4.0+json with org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV4
459+
[INFO] o.a.t.g.s.AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.util.ser.GraphSONMessageSerializerV4
460+
[INFO] o.a.t.g.s.AbstractChannelizer - Configured application/vnd.graphbinary-v4.0 with org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV4
461+
[INFO] o.a.t.g.s.GremlinServer - Gremlin Server configured with worker thread pool of 1, gremlin pool of 10 and boss thread pool of 1.
462+
[INFO] o.a.t.g.s.GremlinServer - Channel started at port 8182.
463463
----
464464
465465
Gremlin Server is configured by the provided link:http://www.yaml.org/[YAML] file `conf/gremlin-server-modern.yaml`.
@@ -505,16 +505,16 @@ strategy configuration via a Gremlin query:
505505
----
506506
traversalSources: {
507507
g: {graph: graph},
508-
gReadOnly: {graph: graph, query: "g.withStrategies(ReadOnlyStrategy)"}}
508+
gReadOnly: {graph: graph, query: "g.withStrategies(ReadOnlyStrategy)", language: "gremlin-lang"}}
509509
----
510510
511511
Each entry supports:
512512
513513
* `graph` (required) — references a key in the `graphs` section
514514
* `query` (optional) — a Gremlin expression evaluated with a base traversal source bound as `g`; the result becomes
515515
the final `TraversalSource`
516-
* `language` (optional) — which script engine to use for query evaluation; defaults to `gremlin-lang` or the single
517-
configured non-`gremlin-lang` engine
516+
* `language` (optional) — which script engine to use for query evaluation; defaults to `gremlin-lang`, or the sole
517+
configured engine if only one is present
518518
519519
Graphs with explicit `traversalSources` entries are excluded from auto-creation.
520520
@@ -899,7 +899,7 @@ The following table describes the various YAML configuration options that Gremli
899899
|traversalSources |A `Map` of `TraversalSource` configurations keyed by binding name. Each entry specifies a `graph` reference and optionally a `query` to configure strategies. See <<server-traversal-sources>>. |_none (auto-created from graphs)_
900900
|traversalSources.<name>.graph |The name of the graph (as defined in `graphs`) to create the traversal source from. |_none_
901901
|traversalSources.<name>.query |An optional Gremlin query evaluated with a base traversal source bound as `g`. The result becomes the final `TraversalSource`. |_none_
902-
|traversalSources.<name>.language |The script engine language to use for evaluating `query`. Falls back to the single configured non-`gremlin-lang` engine or `gremlin-lang`. |_auto-detected_
902+
|traversalSources.<name>.language |The script engine language to use for evaluating `query`. Falls back to the sole configured engine if only one is present, or `gremlin-lang` otherwise. |_auto-detected_
903903
|lifecycleHooks |A `List` of Java-based `LifeCycleHook` implementations to instantiate and execute during server startup and shutdown. See <<server-lifecycle-hooks>>. |_none_
904904
|lifecycleHooks[X].className |The fully qualified class name of the `LifeCycleHook` implementation. |_none_
905905
|lifecycleHooks[X].config |A `Map` of configuration passed to the hook's `init(Map)` method. |_none_

docs/src/upgrade/release-4.x.x.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ A new `traversalSources` YAML section allows explicit `TraversalSource` creation
8080
----
8181
traversalSources: {
8282
g: {graph: graph},
83-
gReadOnly: {graph: graph, query: "g.withStrategies(ReadOnlyStrategy)"}}
83+
gReadOnly: {graph: graph, query: "g.withStrategies(ReadOnlyStrategy)", language: "gremlin-lang"}}
8484
----
8585
8686
Each entry specifies:
8787
8888
- `graph` (required) — references a key in the `graphs` section
8989
- `query` (optional) — a Gremlin expression evaluated with a base traversal source bound as `g`
90-
- `language` (optional) — which script engine to use for the query (defaults to `gremlin-lang`, or the single
91-
configured non-`gremlin-lang` engine if only one exists)
90+
- `language` (optional) — which script engine to use for the query (defaults to `gremlin-lang`, or the sole
91+
configured engine if only one is present)
9292
9393
===== Java-Based `lifecycleHooks`
9494

gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,8 @@ public ServerGremlinExecutor(final Settings settings, final ExecutorService grem
235235
// bind a base traversal source as 'g' for the query to operate on
236236
final SimpleBindings bindings = new SimpleBindings();
237237
bindings.put("g", graph.traversal());
238-
final GremlinExecutor.LifeCycle lifeCycle = GremlinExecutor.LifeCycle.build()
239-
.evaluationTimeoutOverride(0L).create();
240238
final TraversalSource ts = (TraversalSource) gremlinExecutor.eval(
241-
tsSettings.query, language, bindings, lifeCycle).join();
239+
tsSettings.query, language, bindings).join();
242240
this.graphManager.putTraversalSource(tsName, ts);
243241
logger.info("A {} is now bound to [{}] via query", ts.getClass().getSimpleName(), tsName);
244242
} catch (Exception ex) {
@@ -309,18 +307,15 @@ private void registerMetrics(final String engineName) {
309307

310308
/**
311309
* Resolves the script engine language to use for evaluating a traversal source query. If an explicit language
312-
* is provided, it is used directly. Otherwise, if only one non-{@code gremlin-lang} script engine is configured,
313-
* that engine is used. Falls back to {@code gremlin-lang}.
310+
* is provided, it is used directly. Otherwise, if exactly one script engine is configured, that engine is used.
311+
* Falls back to {@code gremlin-lang}.
314312
*/
315313
private String resolveLanguage(final String explicitLanguage) {
316314
if (explicitLanguage != null && !explicitLanguage.isEmpty())
317315
return explicitLanguage;
318316

319-
final List<String> nonLangEngines = settings.scriptEngines.keySet().stream()
320-
.filter(name -> !name.equals("gremlin-lang"))
321-
.collect(Collectors.toList());
322-
if (nonLangEngines.size() == 1)
323-
return nonLangEngines.get(0);
317+
if (settings.scriptEngines.size() == 1)
318+
return settings.scriptEngines.keySet().iterator().next();
324319

325320
return "gremlin-lang";
326321
}

gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerConfigIntegrateTest.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.tinkerpop.gremlin.driver.Cluster;
2323
import org.apache.tinkerpop.gremlin.driver.Result;
2424
import org.apache.tinkerpop.gremlin.tinkergraph.structure.AbstractTinkerGraph;
25-
import org.apache.tinkerpop.gremlin.util.ser.GraphBinaryMessageSerializerV4;
2625
import org.junit.Test;
2726
import org.junit.runner.RunWith;
2827
import org.junit.runners.Parameterized;
@@ -31,9 +30,9 @@
3130

3231
import java.io.File;
3332
import java.io.FileInputStream;
34-
import java.util.ArrayList;
3533
import java.util.Arrays;
3634
import java.util.Collection;
35+
import java.util.Collections;
3736
import java.util.List;
3837

3938
import static org.hamcrest.MatcherAssert.assertThat;
@@ -47,7 +46,6 @@
4746
public class GremlinServerConfigIntegrateTest {
4847

4948
private static final Logger logger = LoggerFactory.getLogger(GremlinServerConfigIntegrateTest.class);
50-
private static final int TEST_PORT = 45950;
5149

5250
@Parameterized.Parameter
5351
public String configName;
@@ -70,24 +68,15 @@ public void shouldStartAndServeQuery() throws Exception {
7068
final File confDir = new File(System.getProperty("build.dir"), "../conf");
7169
final Settings settings = Settings.read(new FileInputStream(new File(confDir, configName)));
7270

73-
settings.port = TEST_PORT;
71+
settings.serializers = Collections.emptyList();
7472
ServerTestHelper.rewritePathsInGremlinServerSettings(settings);
7573

76-
// ensure a V4 serializer is available so the V4 client can connect
77-
if (!hasV4Serializer(settings)) {
78-
final Settings.SerializerSettings v4 = new Settings.SerializerSettings();
79-
v4.className = GraphBinaryMessageSerializerV4.class.getName();
80-
final List<Settings.SerializerSettings> serializers = new ArrayList<>(settings.serializers);
81-
serializers.add(v4);
82-
settings.serializers = serializers;
83-
}
84-
8574
final GremlinServer server = new GremlinServer(settings);
8675
try {
8776
server.start().join();
8877
logger.info("Started server with config: {}", configName);
8978

90-
final Cluster cluster = Cluster.build("localhost").port(TEST_PORT).create();
79+
final Cluster cluster = Cluster.build("localhost").port(settings.port).create();
9180
final Client client = cluster.connect();
9281
try {
9382
final List<Result> results = client.submit("g.inject(1)").all().get();
@@ -104,9 +93,4 @@ public void shouldStartAndServeQuery() throws Exception {
10493
server.stop().join();
10594
}
10695
}
107-
108-
private static boolean hasV4Serializer(final Settings settings) {
109-
return settings.serializers.stream()
110-
.anyMatch(s -> s.className.contains("V4"));
111-
}
11296
}

gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutorTest.java

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
import org.junit.After;
2323
import org.junit.Test;
2424

25-
import java.io.InputStream;
2625
import java.lang.reflect.Method;
27-
import java.util.HashMap;
26+
import java.util.ArrayList;
2827
import java.util.LinkedHashMap;
29-
import java.util.Map;
28+
import java.util.List;
3029

3130
import static org.hamcrest.MatcherAssert.assertThat;
3231
import static org.hamcrest.Matchers.is;
@@ -35,6 +34,10 @@
3534

3635
public class ServerGremlinExecutorTest {
3736

37+
private static final String TINKERGRAPH_PROPERTIES =
38+
new java.io.File(System.getProperty("build.dir"), "../src/test/scripts/tinkergraph-empty.properties")
39+
.getAbsolutePath();
40+
3841
private ServerGremlinExecutor serverGremlinExecutor;
3942

4043
@After
@@ -50,48 +53,59 @@ public void tearDown() {
5053
}
5154
}
5255

53-
private Settings readSettings(final String resource) {
54-
final InputStream stream = ServerGremlinExecutorTest.class.getResourceAsStream("../" + resource);
55-
final Settings settings = Settings.read(stream);
56+
private Settings baseSettings() {
57+
final Settings settings = new Settings();
58+
settings.graphs.put("graph", TINKERGRAPH_PROPERTIES);
5659
settings.gremlinPool = 1;
5760
return settings;
5861
}
5962

6063
@Test
6164
public void shouldAutoCreateTraversalSourceForSingleGraph() {
62-
final Settings settings = readSettings("gremlin-server-minimal.yaml");
63-
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
65+
serverGremlinExecutor = new ServerGremlinExecutor(baseSettings(), null, null);
6466

65-
// graph named "graph" should auto-create traversal source named "g"
6667
assertThat(serverGremlinExecutor.getGraphManager().getTraversalSource("g"), is(notNullValue()));
6768
}
6869

6970
@Test
7071
public void shouldAutoCreateTraversalSourceWithPrefixForNonDefaultGraph() {
71-
final Settings settings = readSettings("gremlin-server-minimal.yaml");
72-
settings.graphs.put("myGraph", settings.graphs.get("graph"));
72+
final Settings settings = baseSettings();
73+
settings.graphs.put("myGraph", TINKERGRAPH_PROPERTIES);
7374
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
7475

75-
// "graph" -> "g", "myGraph" -> "g_myGraph"
7676
assertThat(serverGremlinExecutor.getGraphManager().getTraversalSource("g"), is(notNullValue()));
7777
assertThat(serverGremlinExecutor.getGraphManager().getTraversalSource("g_myGraph"), is(notNullValue()));
7878
}
7979

8080
@Test
8181
public void shouldNotAutoCreateTraversalSourceWhenExplicitEntryExists() {
82-
final Settings settings = readSettings("gremlin-server-with-traversal-sources.yaml");
83-
// this YAML has explicit traversalSources for "g" referencing "graph"
82+
final Settings settings = baseSettings();
83+
final Settings.TraversalSourceSettings tsSettings = new Settings.TraversalSourceSettings();
84+
tsSettings.graph = "graph";
85+
settings.traversalSources.put("g", tsSettings);
8486
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
8587

86-
// "g" should exist from the explicit config
8788
assertThat(serverGremlinExecutor.getGraphManager().getTraversalSource("g"), is(notNullValue()));
88-
// "g_graph" should NOT exist because "graph" had an explicit traversalSources entry
8989
assertThat(serverGremlinExecutor.getGraphManager().getTraversalSource("g_graph"), is(nullValue()));
9090
}
9191

9292
@Test
9393
public void shouldInstantiateLifecycleHooksFromYaml() {
94-
final Settings settings = readSettings("gremlin-server-with-traversal-sources.yaml");
94+
final Settings settings = baseSettings();
95+
final Settings.LifeCycleHookSettings hook1 = new Settings.LifeCycleHookSettings();
96+
hook1.className = TinkerFactoryDataLoader.class.getName();
97+
hook1.config = new LinkedHashMap<>();
98+
hook1.config.put("graph", "graph");
99+
hook1.config.put("dataset", "modern");
100+
final Settings.LifeCycleHookSettings hook2 = new Settings.LifeCycleHookSettings();
101+
hook2.className = TinkerFactoryDataLoader.class.getName();
102+
hook2.config = new LinkedHashMap<>();
103+
hook2.config.put("graph", "graph");
104+
hook2.config.put("dataset", "classic");
105+
final List<Settings.LifeCycleHookSettings> hooks = new ArrayList<>();
106+
hooks.add(hook1);
107+
hooks.add(hook2);
108+
settings.lifecycleHooks = hooks;
95109
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
96110

97111
assertThat(serverGremlinExecutor.getHooks().size(), is(2));
@@ -101,17 +115,14 @@ public void shouldInstantiateLifecycleHooksFromYaml() {
101115

102116
@Test
103117
public void shouldHaveEmptyHooksWhenNoneConfigured() {
104-
final Settings settings = readSettings("gremlin-server-minimal.yaml");
105-
settings.lifecycleHooks.clear();
106-
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
118+
serverGremlinExecutor = new ServerGremlinExecutor(baseSettings(), null, null);
107119

108120
assertThat(serverGremlinExecutor.getHooks().isEmpty(), is(true));
109121
}
110122

111123
@Test
112124
public void resolveLanguageShouldReturnExplicitLanguage() throws Exception {
113-
final Settings settings = readSettings("gremlin-server-minimal.yaml");
114-
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
125+
serverGremlinExecutor = new ServerGremlinExecutor(baseSettings(), null, null);
115126

116127
final Method resolveLanguage = ServerGremlinExecutor.class.getDeclaredMethod("resolveLanguage", String.class);
117128
resolveLanguage.setAccessible(true);
@@ -121,9 +132,7 @@ public void resolveLanguageShouldReturnExplicitLanguage() throws Exception {
121132

122133
@Test
123134
public void resolveLanguageShouldFallBackToGremlinLangWhenNoExplicitLanguage() throws Exception {
124-
final Settings settings = readSettings("gremlin-server-minimal.yaml");
125-
// minimal YAML has no scriptEngines, so constructor default is just gremlin-lang
126-
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
135+
serverGremlinExecutor = new ServerGremlinExecutor(baseSettings(), null, null);
127136

128137
final Method resolveLanguage = ServerGremlinExecutor.class.getDeclaredMethod("resolveLanguage", String.class);
129138
resolveLanguage.setAccessible(true);
@@ -133,15 +142,27 @@ public void resolveLanguageShouldFallBackToGremlinLangWhenNoExplicitLanguage() t
133142
}
134143

135144
@Test
136-
public void resolveLanguageShouldUseSingleNonLangEngine() throws Exception {
137-
final Settings settings = readSettings("gremlin-server-minimal.yaml");
145+
public void resolveLanguageShouldFallBackToGremlinLangWhenMultipleEngines() throws Exception {
146+
final Settings settings = baseSettings();
147+
settings.scriptEngines.put("gremlin-groovy", new Settings.ScriptEngineSettings());
148+
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
149+
150+
final Method resolveLanguage = ServerGremlinExecutor.class.getDeclaredMethod("resolveLanguage", String.class);
151+
resolveLanguage.setAccessible(true);
152+
153+
assertThat(resolveLanguage.invoke(serverGremlinExecutor, (String) null), is("gremlin-lang"));
154+
}
155+
156+
@Test
157+
public void resolveLanguageShouldUseSoleConfiguredEngine() throws Exception {
158+
final Settings settings = baseSettings();
159+
settings.scriptEngines.clear();
138160
settings.scriptEngines.put("gremlin-groovy", new Settings.ScriptEngineSettings());
139161
serverGremlinExecutor = new ServerGremlinExecutor(settings, null, null);
140162

141163
final Method resolveLanguage = ServerGremlinExecutor.class.getDeclaredMethod("resolveLanguage", String.class);
142164
resolveLanguage.setAccessible(true);
143165

144-
// with one non-gremlin-lang engine configured, should resolve to it
145166
assertThat(resolveLanguage.invoke(serverGremlinExecutor, (String) null), is("gremlin-groovy"));
146167
}
147168
}

0 commit comments

Comments
 (0)