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 2018/08/13 14:30:25 UTC
tinkerpop git commit: TINKERPOP-2024 Make server archetype use remote
traversal
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-2024 [created] 1a3549f72
TINKERPOP-2024 Make server archetype use remote traversal
Since we're promoting remote traversals over scripts it would be better for the archetype to use them.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1a3549f7
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1a3549f7
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1a3549f7
Branch: refs/heads/TINKERPOP-2024
Commit: 1a3549f7232ebe65cbba158c1442a567bc2dc695
Parents: 00cb9a8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Aug 13 10:28:53 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Aug 13 10:28:53 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../archetype-resources/README.asciidoc | 4 +--
.../src/main/java/Service.java | 30 ++++++++------------
.../src/test/java/ServiceTest.java | 2 +-
4 files changed, 16 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1a3549f7/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index a45f0f8..d3db46f 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Fixed problem with Gremlin Server sometimes returning an additional message after a failure.
* Allowed spaces in classpath for `gremlin-server.bat`.
+* Modified Maven archetype for Gremlin Server to use remote traversals rather than scripts.
* Added an system error code for failed plugin installs for Gremlin Server `-i` option.
* Match numbers in `choose()` options using `NumberHelper` (match values, ignore data type).
* Added support for GraphSON serialization of `Date` in Javascript.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1a3549f7/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/README.asciidoc
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/README.asciidoc b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/README.asciidoc
index 49d0f62..04ea28e 100644
--- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/README.asciidoc
+++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/README.asciidoc
@@ -18,8 +18,8 @@ limitations under the License.
This is a starter project that demonstrates how a basic
link:http://tinkerpop.apache.org/docs/${project.version}/reference/#gremlin-server[Gremlin Server] project is structured
-with Maven. This project demonstrates how to connect to Gremlin Server through Java using the
-link:http://tinkerpop.apache.org/docs/${project.version}/reference/#connecting-via-java[Gremlin Driver] that is
+with Maven. This project demonstrates how to connect to Gremlin Server with Java using remote traversals with the
+link:http://tinkerpop.apache.org/docs/${project.version}/reference/#connecting-via-remotegraph[Gremlin Driver] that is
distributed by TinkerPop.
== Prerequisites
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1a3549f7/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/Service.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/Service.java b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/Service.java
index 3479c30..a79bdaa 100644
--- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/Service.java
+++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/Service.java
@@ -19,13 +19,11 @@
package ${package};
import org.apache.tinkerpop.gremlin.driver.Cluster;
-import org.apache.tinkerpop.gremlin.driver.Client;
-import org.apache.tinkerpop.gremlin.driver.Result;
+import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
-import java.util.Map;
-import java.util.HashMap;
import java.util.List;
-import java.util.stream.Collectors;
public class Service implements AutoCloseable {
@@ -35,12 +33,12 @@ public class Service implements AutoCloseable {
private final Cluster cluster = Cluster.build().port(45940).create();
/**
- * Use the Cluster instance to construct different Client instances (e.g. one for sessionless communication
- * and one or more sessions). A sessionless Client should be thread-safe and typically no more than one is
- * needed unless there is some need to divide connection pools across multiple Client instances. In this case
- * there is just a single sessionless Client instance used for the entire App.
+ * Construct a remote GraphTraversalSource using the above created Cluster instance that will connect to Gremlin
+ * Server.
*/
- private final Client client = cluster.connect();
+ private final GraphTraversalSource g = EmptyGraph.instance().
+ traversal().
+ withRemote(DriverRemoteConnection.using(cluster));
/**
* Create Service as a singleton given the simplicity of App.
@@ -53,18 +51,14 @@ public class Service implements AutoCloseable {
return INSTANCE;
}
- public List<String> findCreatorsOfSoftware(String softwareName) throws Exception {
- // it is very important from a performance perspective to parameterize queries
- Map params = new HashMap();
- params.put("n", softwareName);
-
- return client.submit("g.V().hasLabel('software').has('name',n).in('created').values('name')", params)
- .all().get().stream().map(r -> r.getString()).collect(Collectors.toList());
+ public List<Object> findCreatorsOfSoftware(String softwareName) throws Exception {
+ return g.V().has("software", "name", softwareName).
+ in("created").
+ values("name").toList();
}
@Override
public void close() throws Exception {
- client.close();
cluster.close();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1a3549f7/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/java/ServiceTest.java
----------------------------------------------------------------------
diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/java/ServiceTest.java b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/java/ServiceTest.java
index e013671..cc3feaa 100644
--- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/java/ServiceTest.java
+++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/java/ServiceTest.java
@@ -78,7 +78,7 @@ public class ServiceTest {
@Test
public void shouldCreateGraph() throws Exception {
- final List<String> result = service.findCreatorsOfSoftware("lop");
+ final List<Object> result = service.findCreatorsOfSoftware("lop");
assertThat(result, is(Arrays.asList("marko", "josh", "peter")));
}
}
\ No newline at end of file