From bb3bf09f57ba2ceb40565f2f9cefa886718d241d Mon Sep 17 00:00:00 2001 From: Stephen Mallette Date: Tue, 23 Feb 2016 10:01:15 -0500 Subject: [PATCH 1/2] Added gremlin-archetypes and related submodules. Established the model for "examples" in TinkerPop using Maven archetypes. Provided two archetypes: gremlin-archetype-server and gremlin-archetype-tinkergraph. --- CHANGELOG.asciidoc | 3 + .../reference/gremlin-applications.asciidoc | 22 +++++ .../upgrade/release-3.1.x-incubating.asciidoc | 15 +++- .../gremlin-archetype-server/pom.xml | 59 +++++++++++++ .../META-INF/maven/archetype-metadata.xml | 47 +++++++++++ .../archetype-resources/README.asciidoc | 67 +++++++++++++++ .../archetype-resources/conf/log4j.properties | 21 +++++ .../conf/tinkergraph-empty.properties | 18 ++++ .../resources/archetype-resources/pom.xml | 80 ++++++++++++++++++ .../scripts/generate-modern.groovy | 33 ++++++++ .../src/main/java/App.java | 35 ++++++++ .../src/main/java/Service.java | 70 ++++++++++++++++ .../src/main/resources/gremlin-server.yaml | 45 ++++++++++ .../src/test/java/ServiceTest.java | 84 +++++++++++++++++++ .../projects/standard/archetype.properties | 21 +++++ .../test/resources/projects/standard/goal.txt | 1 + .../gremlin-archetype-tinkergraph/pom.xml | 59 +++++++++++++ .../META-INF/maven/archetype-metadata.xml | 38 +++++++++ .../archetype-resources/README.asciidoc | 35 ++++++++ .../resources/archetype-resources/pom.xml | 58 +++++++++++++ .../src/main/java/App.java | 78 +++++++++++++++++ .../src/test/java/AppTest.java | 40 +++++++++ .../projects/standard/archetype.properties | 21 +++++ .../test/resources/projects/standard/goal.txt | 1 + gremlin-archetype/pom.xml | 70 ++++++++++++++++ pom.xml | 2 + 26 files changed, 1022 insertions(+), 1 deletion(-) create mode 100644 gremlin-archetype/gremlin-archetype-server/pom.xml create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/README.asciidoc create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/tinkergraph-empty.properties create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/scripts/generate-modern.groovy create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/Service.java create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/resources/gremlin-server.yaml create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/java/ServiceTest.java create mode 100644 gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/archetype.properties create mode 100644 gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/goal.txt create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/pom.xml create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/README.asciidoc create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/pom.xml create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/main/java/App.java create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/test/java/AppTest.java create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/archetype.properties create mode 100644 gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/goal.txt create mode 100644 gremlin-archetype/pom.xml diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index b35efcb9fd4..67965cfa7a5 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,9 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/ TinkerPop 3.1.2 (NOT OFFICIALLY RELEASED YET) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Added the `gremlin-archetype-driver` archetype that demonstrates +* Added the `gremlin-archetype-tinkergraph` archetype that demonstrates a basic project that uses TinkerGraph. +* Added `gremlin-archetype` module to house TinkerPop "examples". * Fixed a bug where multiple "close" requests were being sent by the driver on `Client.close()`. * Fixed an `Property` attach bug that shows up in serialization-based `GraphComputer` implementations. * Fixed a pom.xml bug where Gremlin Console/Server were not pulling the latest Neo4j 2.3.2. diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc index 43608b12dd4..02bf1f0d822 100644 --- a/docs/src/reference/gremlin-applications.asciidoc +++ b/docs/src/reference/gremlin-applications.asciidoc @@ -1880,3 +1880,25 @@ The following shows the output for `HadoopGraph`: ---- describeGraph(HadoopGraph) ---- + +[[gremlin-archetypes]] +Gremlin Archetypes +================== + +TinkerPop has a number of link:https://maven.apache.org/guides/introduction/introduction-to-archetypes.html[Maven archetypes], +which provide example project templates to quickly get started with TinkerPop. The available archetypes are as follows: + +* `gremlin-archetype-server` - An example project that demonstrates the basic structure of a +<> project, how to connect with the Gremlin Driver, and how to embed Gremlin Server in +a testing framework. +* `gremlin-archetype-tinkergraph` - A basic example of how to structure a TinkerPop project with Maven. + +You can use Maven to generate these example projects with a command like: + +[source,shell] +$ mvn archetype:generate -DarchetypeGroupId=org.apache.tinkerpop -DarchetypeArtifactId=gremlin-archetype-server + -DarchetypeVersion=3.1.2-incubating -DgroupId=com.my -DartifactId=app + +This command will generate a new Maven project in a directory called "app" with a `pom.xml` specifying a `groupId` of +`com.my`. Please see the `README.asciidoc` in the root of each generated project for information on how to build and +execute it. \ No newline at end of file diff --git a/docs/src/upgrade/release-3.1.x-incubating.asciidoc b/docs/src/upgrade/release-3.1.x-incubating.asciidoc index 1b7425c1022..97760588e89 100644 --- a/docs/src/upgrade/release-3.1.x-incubating.asciidoc +++ b/docs/src/upgrade/release-3.1.x-incubating.asciidoc @@ -27,11 +27,24 @@ TinkerPop 3.1.2 *Release Date: NOT OFFICIALLY RELEASED YET* -Please see the link:https://github.com/apache/incubator-tinkerpop/blob/3.1.1-incubating/CHANGELOG.asciidoc#tinkerpop-312-release-date-XXXXXXXXXXXXXXXXXXXXXXXXXX[changelog] for a complete list of all the modifications that are part of this release. +Please see the link:https://github.com/apache/incubator-tinkerpop/blob/3.1.2-incubating/CHANGELOG.asciidoc#tinkerpop-312-release-date-XXXXXXXXXXXXXXXXXXXXXXXXXX[changelog] for a complete list of all the modifications that are part of this release. Upgrading for Users ~~~~~~~~~~~~~~~~~~~ +TinkerPop Archetypes +^^^^^^^^^^^^^^^^^^^^ + +TinkerPop now offers link:https://maven.apache.org/guides/introduction/introduction-to-archetypes.html[Maven archetypes], +which provide example project templates to quickly get started with TinkerPop. The available archetypes are as follows: + +* `gremlin-archetype-server` - An example project that demonstrates the basic structure of a Gremlin Server project, +how to connect with the Gremlin Driver, and how to embed Gremlin Server in a testing framework. +* `gremlin-archetype-tinkergraph` - A basic example of how to structure a TinkerPop project with Maven. + +See: link:https://issues.apache.org/jira/browse/TINKERPOP-1085[TINKERPOP-1085], +link:http://tinkerpop.apache.org/docs/3.1.2-incubating/reference/#gremlin-archetypes[Reference Documentation - Archetypes] + Session Transaction Management ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/gremlin-archetype/gremlin-archetype-server/pom.xml b/gremlin-archetype/gremlin-archetype-server/pom.xml new file mode 100644 index 00000000000..c5efbf7a653 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + org.apache.tinkerpop + gremlin-archetype + 3.1.2-SNAPSHOT + + + gremlin-archetype-server + Apache TinkerPop :: Archetype - Server + jar + + + + + maven-archetype-plugin + 2.4 + + + + + + + src/main/resources + true + + archetype-resources/pom.xml + archetype-resources/README.asciidoc + + + + src/main/resources + false + + archetype-resources/pom.xml + archetype-resources/README.asciidoc + + + + + \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml b/gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 00000000000..a6c9d46b262 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,47 @@ + + + + + + + README.asciidoc + + + **/*.xml + + + + conf/ + + + scripts/ + + + src/main/java + + + src/main/resources + + + src/test/java + + + + \ No newline at end of file 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 new file mode 100644 index 00000000000..42f369dc733 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/README.asciidoc @@ -0,0 +1,67 @@ +//// +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +//// +Gremlin Server Application +========================== + +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 +distributed by TinkerPop. + +Prerequisites +------------- + +* Java 8 Update 40+ +* link:https://maven.apache.org/[Maven 3.x] +* Gremlin Server is link:http://archive.apache.org/dist/incubator/tinkerpop/[downloaded] and unpackaged + +Building and Running +-------------------- + +Start Gremlin Server in the directory it was unpackaged and specify usage of the "modern" graph configuration: + +[source,text] +$ bin/gremlin-server.sh conf/gremlin-server-modern.yaml +[INFO] GremlinServer - + \,,,/ + (o o) +-----oOOo-(3)-oOOo----- + +[INFO] GremlinServer - Configuring Gremlin Server from conf/gremlin-server-modern.yaml +[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics +[INFO] Graphs - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties]. +[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool. Threads in pool named with pattern gremlin-* +[INFO] ScriptEngines - Loaded gremlin-groovy ScriptEngine +[INFO] GremlinExecutor - Initialized gremlin-groovy ScriptEngine with scripts/generate-modern.groovy +[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and configured ScriptEngines. +[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard] +[INFO] OpLoader - Adding the standard OpProcessor. +[INFO] OpLoader - Adding the control OpProcessor. +[INFO] OpLoader - Adding the session OpProcessor. +[INFO] GremlinServer - Executing start up LifeCycleHook +[INFO] Logger$info - Loading 'modern' graph data. +[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v1.0+gryo with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0 +[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v1.0+gryo-stringd with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0 +[INFO] GremlinServer$1 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1. +[INFO] GremlinServer$1 - Channel started at port 8182. + +Build and run this project as follows: + +[source,text] +mvn clean package +mvn exec:java -Dexec.mainClass="${package}.App" \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties new file mode 100644 index 00000000000..ef436fe4799 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +log4j.rootLogger=WARN, stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/tinkergraph-empty.properties b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/tinkergraph-empty.properties new file mode 100644 index 00000000000..e09a13d1a5e --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/tinkergraph-empty.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +gremlin.graph=org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph +gremlin.tinkergraph.vertexIdManager=LONG \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 00000000000..5c47aea454d --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + \${groupId} + \${artifactId} + \${version} + + Getting started with Gremlin Server + + jar + + UTF-8 + + + + org.apache.tinkerpop + gremlin-driver + ${project.version} + + + org.apache.tinkerpop + gremlin-server + ${project.version} + test + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + test + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.17 + + + file:conf/log4j.properties + + + + + + \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/scripts/generate-modern.groovy b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/scripts/generate-modern.groovy new file mode 100644 index 00000000000..23b4a6150a3 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/scripts/generate-modern.groovy @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// an init script that returns a Map allows explicit setting of global bindings. +def globals = [:] + +// Generates the modern graph into an "empty" TinkerGraph via LifeCycleHook. +// Note that the name of the key in the "global" map is unimportant. +globals << [hook : [ + onStartUp: { ctx -> + ctx.logger.info("Loading 'modern' graph data.") + TinkerFactory.generateModern(graph) + } +] as LifeCycleHook] + +// define the default TraversalSource to bind queries to - this one will be named "g". +globals << [g : graph.traversal()] \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java new file mode 100644 index 00000000000..d1761c7a0d1 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import org.apache.tinkerpop.gremlin.driver.Result; + +public class App { + + public static void main(String[] args) throws Exception { + Service service = Service.getInstance(); + try { + service.findCreatorsOfSoftware("lop").iterator().forEachRemaining(r -> System.out.println(r)); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + service.close(); + } + } +} \ No newline at end of file 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 new file mode 100644 index 00000000000..b2e9de65a5f --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/Service.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import org.apache.tinkerpop.gremlin.driver.Cluster; +import org.apache.tinkerpop.gremlin.driver.Client; +import org.apache.tinkerpop.gremlin.driver.Result; + +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +public class Service implements AutoCloseable { + + /** + * There typically needs to be only one Cluster instance in an application. + */ + private final Cluster cluster = Cluster.open(); + + /** + * 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. + */ + private final Client client = cluster.connect(); + + /** + * Create Service as a singleton given the simplicity of App. + */ + private static final Service INSTANCE = new Service(); + + private Service() {} + + public static Service getInstance() { + return INSTANCE; + } + + public List 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()); + } + + @Override + public void close() throws Exception { + client.close(); + cluster.close(); + } +} \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/resources/gremlin-server.yaml b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/resources/gremlin-server.yaml new file mode 100644 index 00000000000..5744d29fd98 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/resources/gremlin-server.yaml @@ -0,0 +1,45 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +host: localhost +port: 8182 +threadPoolWorker: 1 +gremlinPool: 8 +scriptEvaluationTimeout: 30000 +serializedResponseTimeout: 30000 +graphs: { + graph: conf/tinkergraph-empty.properties} +plugins: + - tinkerpop.tinkergraph +scriptEngines: { + gremlin-groovy: { + imports: [java.lang.Math], + staticImports: [java.lang.Math.PI], + scripts: [scripts/generate-modern.groovy]}} +serializers: + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { useMapperFromGraph: graph }} # application/vnd.gremlin-v1.0+gryo + - { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }} # application/vnd.gremlin-v1.0+gryo-stringd +metrics: { + slf4jReporter: {enabled: true, interval: 180000}} +strictTransactionManagement: false +threadPoolBoss: 1 +maxInitialLineLength: 4096 +maxHeaderSize: 8192 +maxChunkSize: 8192 +maxContentLength: 65536 +maxAccumulationBufferComponents: 1024 +resultIterationBatchSize: 64 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 new file mode 100644 index 00000000000..6f7d5c3743c --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/java/ServiceTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import org.apache.tinkerpop.gremlin.server.GremlinServer; +import org.apache.tinkerpop.gremlin.server.Settings; + +import java.io.InputStream; +import java.util.List; +import java.util.Arrays; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.hamcrest.CoreMatchers.is; + +/** + * Basic test class that demonstrates how to start and stop an embedded Gremlin Server instance in a test. Note that + * the server instance is not started or stopped in a thread-safe manner, but typically this is acceptable for most + * testing use cases. + */ +public class ServiceTest { + private GremlinServer server; + + private static Service service = Service.getInstance(); + + @Before + public void setUp() throws Exception { + startServer(); + } + + /** + * Starts a new instance of Gremlin Server. + */ + public void startServer() throws Exception { + final InputStream stream = ServiceTest.class.getResourceAsStream("gremlin-server.yaml"); + this.server = new GremlinServer(Settings.read(stream)); + + server.start().join(); + } + + @After + public void tearDown() throws Exception { + stopServer(); + } + + /** + * Stops a current instance of Gremlin Server. + */ + public void stopServer() throws Exception { + server.stop().join(); + } + + @AfterClass + public static void tearDownCase() throws Exception { + service.close(); + } + + @Test + public void shouldCreateGraph() throws Exception { + List result = service.findCreatorsOfSoftware("lop"); + assertThat(result, is(Arrays.asList("marko", "josh", "peter"))); + } +} \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/archetype.properties b/gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/archetype.properties new file mode 100644 index 00000000000..26067b7b13e --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/archetype.properties @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +groupId=org.apache.tinkerpop +artifactId=gremlin-archetype-server +package=com.test.example +version=1.0.0-SNAPSHOT \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/goal.txt b/gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/goal.txt new file mode 100644 index 00000000000..4a1a71d3364 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/test/resources/projects/standard/goal.txt @@ -0,0 +1 @@ +verify \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/pom.xml b/gremlin-archetype/gremlin-archetype-tinkergraph/pom.xml new file mode 100644 index 00000000000..078071dfdfe --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + org.apache.tinkerpop + gremlin-archetype + 3.1.2-SNAPSHOT + + + gremlin-archetype-tinkergraph + Apache TinkerPop :: Archetype - TinkerGraph + jar + + + + + maven-archetype-plugin + 2.4 + + + + + + + src/main/resources + true + + archetype-resources/pom.xml + archetype-resources/README.asciidoc + + + + src/main/resources + false + + archetype-resources/pom.xml + archetype-resources/README.asciidoc + + + + + \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/META-INF/maven/archetype-metadata.xml b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 00000000000..a159ee3ad51 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,38 @@ + + + + + + + README.asciidoc + + + **/*.xml + + + + src/main/java + + + src/test/java + + + + \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/README.asciidoc b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/README.asciidoc new file mode 100644 index 00000000000..59d5aff1f14 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/README.asciidoc @@ -0,0 +1,35 @@ +//// +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +//// +Simple TinkerPop Application +============================ + +This is a simple starter project that demonstrates how a basic TinkerPop project is structured with Maven. This project +uses link:http://tinkerpop.apache.org/docs/${project.version}/reference/#tinkergraph-gremlin[TinkerGraph] as an +embedded graph database, loads it with some data and then executes a shortest path calculation, printing the results. + +Prerequisites +------------- + +* Java 8 Update 40+ +* link:https://maven.apache.org/[Maven 3.x] + +Building and Running +-------------------- + +[source,text] +mvn clean package +mvn exec:java -Dexec.mainClass="${package}.App" \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/pom.xml b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 00000000000..271f9ddd424 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + \${groupId} + \${artifactId} + \${version} + + Getting started with TinkerGraph + + jar + + UTF-8 + + + + org.apache.tinkerpop + tinkergraph-gremlin + ${project.version} + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/main/java/App.java b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/main/java/App.java new file mode 100644 index 00000000000..dd97224377e --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/main/java/App.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*; + +import java.util.List; +import java.util.ArrayList; + +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; + +public class App { + + public static void main(String[] args) { + // Create a new TinkerGraph and load some test data. The Graph instance is typically named "graph" as a + // variable name. You will see this pattern consistently in TinkerPop documentation, the mailing list, etc. + Graph graph = TinkerGraph.open(); + loadData(graph); + + // Create a GraphTraversalSource instance that is used to query the data in the Graph instance. This variable + // is typically denoted as "g". In TinkerPop documentation you can always count on references to "g" as + // being a object of this type. + GraphTraversalSource g = graph.traversal(); + + Vertex fromNode = findByName(g, "marko"); + Vertex toNode = findByName(g, "peter"); + + List list = calculateShortestPathBetween(g, fromNode, toNode); + System.out.println(list.toString()); + System.exit(0); + } + + public static Vertex findByName(GraphTraversalSource g, String name) { + return g.V().has("name", name).next(); + } + + public static List calculateShortestPathBetween(GraphTraversalSource g, Vertex fromNode, Vertex toNode) { + ArrayList list = new ArrayList(); + g.V(fromNode).repeat(both().simplePath()).until(is(toNode)).limit(1).path().fill(list); + return list; + } + + public static void loadData(Graph graph) { + // see org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateModern() + final Vertex marko = graph.addVertex(T.id, 1, T.label, "person", "name", "marko", "age", 29); + final Vertex vadas = graph.addVertex(T.id, 2, T.label, "person", "name", "vadas", "age", 27); + final Vertex lop = graph.addVertex(T.id, 3, T.label, "software", "name", "lop", "lang", "java"); + final Vertex josh = graph.addVertex(T.id, 4, T.label, "person", "name", "josh", "age", 32); + final Vertex ripple = graph.addVertex(T.id, 5, T.label, "software", "name", "ripple", "lang", "java"); + final Vertex peter = graph.addVertex(T.id, 6, T.label, "person", "name", "peter", "age", 35); + marko.addEdge("knows", vadas, T.id, 7, "weight", 0.5d); + marko.addEdge("knows", josh, T.id, 8, "weight", 1.0d); + marko.addEdge("created", lop, T.id, 9, "weight", 0.4d); + josh.addEdge("created", ripple, T.id, 10, "weight", 1.0d); + josh.addEdge("created", lop, T.id, 11, "weight", 0.4d); + peter.addEdge("created", lop, T.id, 12, "weight", 0.2d); + } +} \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/test/java/AppTest.java b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/test/java/AppTest.java new file mode 100644 index 00000000000..7b400b76bd5 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package ${package}; + +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class AppTest { + + @Test + public void shouldCreateGraph() { + TinkerGraph graph = TinkerGraph.open(); + App.loadData(graph); + + GraphTraversalSource g = graph.traversal(); + + assertEquals(6, g.V().count().next().intValue()); + assertEquals(6, g.E().count().next().intValue()); + } +} \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/archetype.properties b/gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/archetype.properties new file mode 100644 index 00000000000..9c3e51cbe77 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/archetype.properties @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +groupId=org.apache.tinkerpop +artifactId=gremlin-archetype-tinkergraph +package=com.test.example +version=1.0.0-SNAPSHOT \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/goal.txt b/gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/goal.txt new file mode 100644 index 00000000000..4a1a71d3364 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-tinkergraph/src/test/resources/projects/standard/goal.txt @@ -0,0 +1 @@ +verify \ No newline at end of file diff --git a/gremlin-archetype/pom.xml b/gremlin-archetype/pom.xml new file mode 100644 index 00000000000..fdfe35f3b10 --- /dev/null +++ b/gremlin-archetype/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + tinkerpop + org.apache.tinkerpop + 3.1.2-SNAPSHOT + + + gremlin-archetype + Apache TinkerPop :: Gremlin Archetype + pom + + gremlin-archetype-tinkergraph + gremlin-archetype-server + + + + + + + maven-archetype-plugin + 2.4 + + + integration-test + + integration-test + + + + + + ${skipTests} + + + + + + org.apache.maven.plugins + maven-resources-plugin + + \ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 311ddad4ba2..a8f1cfa6ae8 100644 --- a/pom.xml +++ b/pom.xml @@ -118,6 +118,7 @@ limitations under the License. gremlin-driver gremlin-console gremlin-server + gremlin-archetype scm:git:git@git-wip-us.apache.org:repos/asf/incubator-tinkerpop.git @@ -277,6 +278,7 @@ limitations under the License. **/*.json **/*.xml **/*.ldjson + **/goal.txt **/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/*.txt **/src/main/resources/META-INF/services/** **/src/main/ext/** From 68b16eb90570c4ed4cd36ab9b93e650bddc568ae Mon Sep 17 00:00:00 2001 From: Stephen Mallette Date: Wed, 24 Feb 2016 13:54:30 -0500 Subject: [PATCH 2/2] Made some adjustments based on pull request feedback. Fixed changelog to use the right name of the archetype. Better logging control/output for the server archetype. Documentation improvements. Included log4j as a compile time dependency. --- CHANGELOG.asciidoc | 2 +- .../reference/gremlin-applications.asciidoc | 2 +- .../META-INF/maven/archetype-metadata.xml | 4 ++-- .../archetype-resources/README.asciidoc | 10 ++++++--- .../conf/log4j-test.properties | 21 +++++++++++++++++++ .../archetype-resources/conf/log4j.properties | 2 +- .../resources/archetype-resources/pom.xml | 13 ++++++------ .../src/main/java/App.java | 11 ++++++++-- .../resources/gremlin-server.yaml | 0 9 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j-test.properties rename gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/{main => test}/resources/gremlin-server.yaml (100%) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 67965cfa7a5..910d9b671f9 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,7 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/ TinkerPop 3.1.2 (NOT OFFICIALLY RELEASED YET) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -* Added the `gremlin-archetype-driver` archetype that demonstrates +* Added the `gremlin-archetype-server` archetype that demonstrates * Added the `gremlin-archetype-tinkergraph` archetype that demonstrates a basic project that uses TinkerGraph. * Added `gremlin-archetype` module to house TinkerPop "examples". * Fixed a bug where multiple "close" requests were being sent by the driver on `Client.close()`. diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc index 02bf1f0d822..06fe0cc8015 100644 --- a/docs/src/reference/gremlin-applications.asciidoc +++ b/docs/src/reference/gremlin-applications.asciidoc @@ -1897,7 +1897,7 @@ You can use Maven to generate these example projects with a command like: [source,shell] $ mvn archetype:generate -DarchetypeGroupId=org.apache.tinkerpop -DarchetypeArtifactId=gremlin-archetype-server - -DarchetypeVersion=3.1.2-incubating -DgroupId=com.my -DartifactId=app + -DarchetypeVersion=x.y.z -DgroupId=com.my -DartifactId=app -Dversion=0.1 -DinteractiveMode=false This command will generate a new Maven project in a directory called "app" with a `pom.xml` specifying a `groupId` of `com.my`. Please see the `README.asciidoc` in the root of each generated project for information on how to build and diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml b/gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml index a6c9d46b262..93d66a8395f 100644 --- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -37,10 +37,10 @@ limitations under the License. src/main/java - src/main/resources + src/test/java - src/test/java + src/test/resources 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 42f369dc733..fd543bc96bf 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 @@ -33,6 +33,11 @@ Prerequisites Building and Running -------------------- +Build the project as follows: + +[source,text] +mvn clean package + Start Gremlin Server in the directory it was unpackaged and specify usage of the "modern" graph configuration: [source,text] @@ -60,8 +65,7 @@ $ bin/gremlin-server.sh conf/gremlin-server-modern.yaml [INFO] GremlinServer$1 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1. [INFO] GremlinServer$1 - Channel started at port 8182. -Build and run this project as follows: +Run this project as follows: [source,text] -mvn clean package -mvn exec:java -Dexec.mainClass="${package}.App" \ No newline at end of file +mvn exec:java -Dexec.mainClass="${package}.App" -Dlog4j.configuration=file:conf/log4j.properties \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j-test.properties b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j-test.properties new file mode 100644 index 00000000000..ef436fe4799 --- /dev/null +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j-test.properties @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +log4j.rootLogger=WARN, stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties index ef436fe4799..2b58359c75b 100644 --- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/conf/log4j.properties @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -log4j.rootLogger=WARN, stdout +log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml index 5c47aea454d..ca2960478aa 100644 --- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/pom.xml @@ -34,16 +34,15 @@ limitations under the License. gremlin-driver ${project.version} - - org.apache.tinkerpop - gremlin-server - ${project.version} - test - org.slf4j slf4j-log4j12 ${slf4j.version} + + + org.apache.tinkerpop + gremlin-server + ${project.version} test @@ -71,7 +70,7 @@ limitations under the License. 2.17 - file:conf/log4j.properties + file:conf/log4j-test.properties diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java index d1761c7a0d1..1e111e38210 100644 --- a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java +++ b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/java/App.java @@ -19,17 +19,24 @@ package ${package}; import org.apache.tinkerpop.gremlin.driver.Result; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class App { + private static final Logger logger = LoggerFactory.getLogger(App.class); public static void main(String[] args) throws Exception { Service service = Service.getInstance(); try { - service.findCreatorsOfSoftware("lop").iterator().forEachRemaining(r -> System.out.println(r)); + logger.info("Sending request...."); + + // should print marko, josh and peter to the logs + service.findCreatorsOfSoftware("lop").iterator().forEachRemaining(r -> logger.info(String.format(" - %s", r))); } catch (Exception ex) { - ex.printStackTrace(); + logger.error("Could not execute traversal", ex); } finally { service.close(); + logger.info("Service closed and resources released"); } } } \ No newline at end of file diff --git a/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/resources/gremlin-server.yaml b/gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/resources/gremlin-server.yaml similarity index 100% rename from gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/main/resources/gremlin-server.yaml rename to gremlin-archetype/gremlin-archetype-server/src/main/resources/archetype-resources/src/test/resources/gremlin-server.yaml