You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/12/16 16:53:31 UTC
[17/50] tinkerpop git commit: TINKERPOP-1562 Add new
HadoopGremlinPlugin and deprecated the old.
TINKERPOP-1562 Add new HadoopGremlinPlugin and deprecated the old.
Had to add some capabilities to plugin system to allow for passing of console environment bits (like groovysh for example).
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d0c941e8
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d0c941e8
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d0c941e8
Branch: refs/heads/TINKERPOP-1581
Commit: d0c941e86ccd561576552cdda9c58424462def9d
Parents: 2e65a11
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Nov 22 13:41:58 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Dec 2 06:28:51 2016 -0500
----------------------------------------------------------------------
.../gremlin/console/plugin/PluggedIn.groovy | 2 +-
.../gremlin/jsr223/LazyBindingsCustomizer.java | 41 +++++
.../jsr223/console/ConsoleCustomizer.java | 7 +-
.../jsr223/console/LazyBindingsCustomizer.java | 41 -----
.../gremlin/jsr223/console/RemoteAcceptor.java | 3 +-
.../gremlin/groovy/plugin/PluginAcceptor.java | 2 +-
.../groovy/plugin/HadoopGremlinPlugin.java | 2 +
.../groovy/plugin/HadoopRemoteAcceptor.java | 2 +
.../hadoop/jsr223/HadoopGremlinPlugin.java | 154 +++++++++++++++++++
.../hadoop/jsr223/HadoopRemoteAcceptor.java | 127 +++++++++++++++
...pache.tinkerpop.gremlin.jsr223.GremlinPlugin | 1 +
.../neo4j/groovy/plugin/Neo4jGremlinPlugin.java | 1 +
.../spark/jsr223/SparkGremlinPlugin.java | 2 +-
13 files changed, 339 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
----------------------------------------------------------------------
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
index b707226..dc63a2f 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/plugin/PluggedIn.groovy
@@ -90,7 +90,7 @@ class PluggedIn {
} else if (it instanceof ScriptCustomizer) {
it.getScripts().collect { it.join(LINE_SEPARATOR) }.each { pluginAcceptor.eval(it) }
} else if (it instanceof BindingsCustomizer) {
- it.bindings.entrySet().each { k, v -> pluginAcceptor.addBinding(k,v) }
+ it.bindings.entrySet().each { kv -> pluginAcceptor.addBinding(kv.key, kv.value) }
}
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/LazyBindingsCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/LazyBindingsCustomizer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/LazyBindingsCustomizer.java
new file mode 100644
index 0000000..4117ae5
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/LazyBindingsCustomizer.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.apache.tinkerpop.gremlin.jsr223;
+
+import org.apache.tinkerpop.gremlin.jsr223.BindingsCustomizer;
+
+import javax.script.Bindings;
+import java.util.function.Supplier;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class LazyBindingsCustomizer implements BindingsCustomizer {
+
+ private final Supplier<Bindings> bindingsSupplier;
+
+ public LazyBindingsCustomizer(final Supplier<Bindings> bindingsSupplier) {
+ this.bindingsSupplier = bindingsSupplier;
+ }
+
+ @Override
+ public Bindings getBindings() {
+ return bindingsSupplier.get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
index 47771bc..7b3d788 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/ConsoleCustomizer.java
@@ -20,14 +20,19 @@ package org.apache.tinkerpop.gremlin.jsr223.console;
import org.apache.tinkerpop.gremlin.jsr223.Customizer;
+import java.util.Map;
+
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public interface ConsoleCustomizer extends Customizer {
+ public static final String ENV_CONSOLE_IO = "ConsolePluginAcceptor.io";
+ public static final String ENV_CONSOLE_SHELL = "ConsolePluginAcceptor.shell";
+
/**
* Allows a plugin to utilize features of the {@code :remote} and {@code :submit} commands of the Gremlin Console.
* This method does not need to be implemented if the plugin is not meant for the Console for some reason or
* if it does not intend to take advantage of those commands.
*/
- public RemoteAcceptor getRemoteAcceptor();
+ public RemoteAcceptor getRemoteAcceptor(final Map<String, Object> environment);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/LazyBindingsCustomizer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/LazyBindingsCustomizer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/LazyBindingsCustomizer.java
deleted file mode 100644
index f21a2ab..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/LazyBindingsCustomizer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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 org.apache.tinkerpop.gremlin.jsr223.console;
-
-import org.apache.tinkerpop.gremlin.jsr223.BindingsCustomizer;
-
-import javax.script.Bindings;
-import java.util.function.Supplier;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class LazyBindingsCustomizer implements BindingsCustomizer {
-
- private final Supplier<Bindings> bindingsSupplier;
-
- public LazyBindingsCustomizer(final Supplier<Bindings> bindingsSupplier) {
- this.bindingsSupplier = bindingsSupplier;
- }
-
- @Override
- public Bindings getBindings() {
- return bindingsSupplier.get();
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/RemoteAcceptor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/RemoteAcceptor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/RemoteAcceptor.java
index aee77ae..ab4c81d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/RemoteAcceptor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/RemoteAcceptor.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.jsr223.console;
import java.io.Closeable;
import java.util.List;
+import java.util.Map;
/**
* The Gremlin Console supports the {@code :remote} and {@code :submit} commands which provide standardized ways
@@ -27,7 +28,7 @@ import java.util.List;
* A "remote connection" does not necessarily have to be a remote server. It simply refers to a resource that is
* external to the console.
* <p/>
- * By implementing this interface and returning an instance of it through {@link ConsoleCustomizer#getRemoteAcceptor()}
+ * By implementing this interface and returning an instance of it through {@link ConsoleCustomizer#getRemoteAcceptor(Map)}
* a plugin can hook into those commands and provide remoting features.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/PluginAcceptor.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/PluginAcceptor.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/PluginAcceptor.java
index 9571381..9165237 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/PluginAcceptor.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/plugin/PluginAcceptor.java
@@ -31,7 +31,7 @@ import java.util.Set;
* and provides the abstractions required for a plugin to work regardless of the environmental implementations.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
- * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.console.PluginAcceptor}.
+ * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.jsr223.console.PluginAcceptor}.
*/
@Deprecated
public interface PluginAcceptor {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPlugin.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPlugin.java
index 021f9d3..ca446ef 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPlugin.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopGremlinPlugin.java
@@ -43,7 +43,9 @@ import java.util.Set;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.hadoop.jsr223.HadoopGremlinPlugin}.
*/
+@Deprecated
public final class HadoopGremlinPlugin extends AbstractGremlinPlugin {
protected static String NAME = "tinkerpop.hadoop";
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopRemoteAcceptor.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopRemoteAcceptor.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopRemoteAcceptor.java
index 558376e..acae442 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopRemoteAcceptor.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/groovy/plugin/HadoopRemoteAcceptor.java
@@ -39,7 +39,9 @@ import java.util.List;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.hadoop.jsr223.HadoopRemoteAcceptor}.
*/
+@Deprecated
public final class HadoopRemoteAcceptor implements RemoteAcceptor {
private static final String USE_SUGAR = "useSugar";
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
new file mode 100644
index 0000000..5e21027
--- /dev/null
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPlugin.java
@@ -0,0 +1,154 @@
+/*
+ * 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 org.apache.tinkerpop.gremlin.hadoop.jsr223;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.io.IOUtils;
+import org.apache.hadoop.io.compress.CodecPool;
+import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;
+import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
+import org.apache.hadoop.util.ToolRunner;
+import org.apache.tinkerpop.gremlin.hadoop.Constants;
+import org.apache.tinkerpop.gremlin.hadoop.process.computer.mapreduce.MapReduceGraphComputer;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopConfiguration;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopEdge;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopElement;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopProperty;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopVertex;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopVertexProperty;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.FileSystemStorage;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.graphson.GraphSONInputFormat;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.graphson.GraphSONOutputFormat;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.graphson.GraphSONRecordReader;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.graphson.GraphSONRecordWriter;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.GryoInputFormat;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.GryoOutputFormat;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.GryoRecordReader;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.gryo.GryoRecordWriter;
+import org.apache.tinkerpop.gremlin.hadoop.structure.io.script.ScriptInputFormat;
+import org.apache.tinkerpop.gremlin.hadoop.structure.util.ConfUtil;
+import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin;
+import org.apache.tinkerpop.gremlin.jsr223.BindingsCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.Customizer;
+import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.LazyBindingsCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.console.ConsoleCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor;
+import org.codehaus.groovy.tools.shell.Groovysh;
+
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class HadoopGremlinPlugin extends AbstractGremlinPlugin {
+
+ protected static String NAME = "tinkerpop.hadoop";
+
+ private static final BindingsCustomizer bindings;
+
+ private static final ImportCustomizer imports;
+
+ private static final Set<String> appliesTo = new HashSet<>(Collections.singletonList("gremlin-groovy"));
+
+ static {
+ try {
+ // TODO: most of the imports here were wildcarded, but we dont' allow that anymore - needs review
+ imports = DefaultImportCustomizer.build()
+ .addClassImports(
+ Configuration.class,
+ org.apache.hadoop.hdfs.DFSClient.class,
+ FileSystem.class,
+ ToolRunner.class,
+ IOUtils.class,
+ CodecPool.class,
+ SequenceFileInputFormat.class,
+ SequenceFileOutputFormat.class,
+ Constants.class,
+ HadoopConfiguration.class,
+ HadoopEdge.class,
+ HadoopElement.class,
+ HadoopGraph.class,
+ HadoopProperty.class,
+ HadoopVertex.class,
+ HadoopVertexProperty.class,
+ ConfUtil.class,
+ VertexWritable.class,
+ GraphSONInputFormat.class,
+ GraphSONOutputFormat.class,
+ GraphSONRecordReader.class,
+ GraphSONRecordWriter.class,
+ GryoInputFormat.class,
+ GryoOutputFormat.class,
+ GryoRecordReader.class,
+ GryoRecordWriter.class,
+ ScriptInputFormat.class,
+ MapReduceGraphComputer.class).create();
+
+ bindings = new LazyBindingsCustomizer(() -> {
+ try {
+ final Bindings bindings = new SimpleBindings();
+ bindings.put("hdfs", FileSystemStorage.open(FileSystem.get(new Configuration())));
+ bindings.put("fs", FileSystemStorage.open(FileSystem.getLocal(new Configuration())));
+ return bindings;
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ });
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public HadoopGremlinPlugin() {
+ super(NAME, appliesTo, imports, bindings, new HadoopConsoleCustomizer());
+ }
+
+ @Override
+ public Optional<Customizer[]> getCustomizers(final String scriptEngineName) {
+ if (null == System.getenv(Constants.HADOOP_GREMLIN_LIBS))
+ HadoopGraph.LOGGER.warn("Be sure to set the environmental variable: " + Constants.HADOOP_GREMLIN_LIBS);
+ else
+ HadoopGraph.LOGGER.info(Constants.HADOOP_GREMLIN_LIBS + " is set to: " + System.getenv(Constants.HADOOP_GREMLIN_LIBS));
+
+ return super.getCustomizers(scriptEngineName);
+ }
+
+ @Override
+ public boolean requireRestart() {
+ return true;
+ }
+
+ private static class HadoopConsoleCustomizer implements ConsoleCustomizer {
+ @Override
+ public RemoteAcceptor getRemoteAcceptor(final Map<String, Object> environment) {
+ return new HadoopRemoteAcceptor((Groovysh) environment.get(ConsoleCustomizer.ENV_CONSOLE_SHELL));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
new file mode 100644
index 0000000..f2367bd
--- /dev/null
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopRemoteAcceptor.java
@@ -0,0 +1,127 @@
+/*
+ * 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 org.apache.tinkerpop.gremlin.hadoop.jsr223;
+
+import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader;
+import org.apache.tinkerpop.gremlin.hadoop.structure.HadoopGraph;
+import org.apache.tinkerpop.gremlin.jsr223.console.RemoteAcceptor;
+import org.apache.tinkerpop.gremlin.jsr223.console.RemoteException;
+import org.apache.tinkerpop.gremlin.process.computer.ComputerResult;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ComputerResultStep;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
+import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
+import org.codehaus.groovy.tools.shell.Groovysh;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class HadoopRemoteAcceptor implements RemoteAcceptor {
+
+ private static final String USE_SUGAR = "useSugar";
+ private static final String USE_TRAVERSAL_SOURCE = "useTraversalSource";
+ private static final String SPACE = " ";
+
+ private HadoopGraph hadoopGraph;
+ private Groovysh shell;
+ private boolean useSugar = false;
+ private TraversalSource traversalSource;
+
+ public HadoopRemoteAcceptor(final Groovysh shell) {
+ this.shell = shell;
+ }
+
+ @Override
+ public Object connect(final List<String> args) throws RemoteException {
+ if (args.size() != 1 && args.size() != 2) {
+ throw new IllegalArgumentException("Usage: :remote connect " + HadoopGremlinPlugin.NAME + " <variable name of graph> <optional variable name of traversal source>");
+ }
+ this.hadoopGraph = (HadoopGraph) this.shell.getInterp().getContext().getVariable(args.get(0));
+ if (args.size() == 2)
+ this.traversalSource = ((TraversalSource) this.shell.getInterp().getContext().getVariable(args.get(1)));
+ else
+ this.traversalSource = this.hadoopGraph.traversal();
+ ///
+ final HashMap<String, Object> configuration = new HashMap<>();
+ configuration.put(USE_SUGAR, this.useSugar);
+ configuration.put(USE_TRAVERSAL_SOURCE, this.traversalSource);
+ return Collections.unmodifiableMap(configuration);
+ }
+
+ @Override
+ public Object configure(final List<String> args) throws RemoteException {
+ for (int i = 0; i < args.size(); i = i + 2) {
+ if (args.get(i).equals(USE_SUGAR))
+ this.useSugar = Boolean.valueOf(args.get(i + 1));
+ else if (args.get(i).equals(USE_TRAVERSAL_SOURCE)) {
+ this.traversalSource = ((TraversalSource) this.shell.getInterp().getContext().getVariable(args.get(i + 1)));
+ } else
+ throw new IllegalArgumentException("The provided configuration is unknown: " + args.get(i) + ":" + args.get(i + 1));
+ }
+ ///
+ final HashMap<String, Object> configuration = new HashMap<>();
+ configuration.put(USE_SUGAR, this.useSugar);
+ configuration.put(USE_TRAVERSAL_SOURCE, this.traversalSource);
+ return Collections.unmodifiableMap(configuration);
+ }
+
+ @Override
+ public Object submit(final List<String> args) throws RemoteException {
+ try {
+ String script = getScript(String.join(SPACE, args), this.shell);
+ if (this.useSugar)
+ script = SugarLoader.class.getCanonicalName() + ".load()\n" + script;
+ final TraversalVertexProgram program = TraversalVertexProgram.build().traversal(this.traversalSource, "gremlin-groovy", script).create(this.hadoopGraph);
+ final ComputerResult computerResult = VertexProgramStrategy.getComputer(this.traversalSource.getStrategies()).get().apply(this.hadoopGraph).program(program).submit().get();
+ this.shell.getInterp().getContext().setVariable(RESULT, computerResult);
+ ///
+ final Traversal.Admin<ComputerResult, ?> traversal = new DefaultTraversal<>(computerResult.graph());
+ traversal.addStep(new ComputerResultStep<>(traversal));
+ traversal.addStart(traversal.getTraverserGenerator().generate(computerResult, EmptyStep.instance(), 1l));
+ return traversal;
+ } catch (final Exception e) {
+ throw new RemoteException(e);
+ }
+ }
+
+ @Override
+ public boolean allowRemoteConsole() {
+ return true;
+ }
+
+ @Override
+ public void close() throws IOException {
+ this.hadoopGraph.close();
+ }
+
+ /**
+ * Retrieve a script as defined in the shell context. This allows for multi-line scripts to be submitted.
+ */
+ public static String getScript(final String submittedScript, final Groovysh shell) {
+ return submittedScript.startsWith("@") ? shell.getInterp().getContext().getProperty(submittedScript.substring(1)).toString() : submittedScript;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/hadoop-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin b/hadoop-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin
new file mode 100644
index 0000000..07223dd
--- /dev/null
+++ b/hadoop-gremlin/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.jsr223.GremlinPlugin
@@ -0,0 +1 @@
+org.apache.tinkerpop.gremlin.hadoop.jsr223.HadoopGremlinPlugin
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/groovy/plugin/Neo4jGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/groovy/plugin/Neo4jGremlinPlugin.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/groovy/plugin/Neo4jGremlinPlugin.java
index 9053cf3..68c0016 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/groovy/plugin/Neo4jGremlinPlugin.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/groovy/plugin/Neo4jGremlinPlugin.java
@@ -32,6 +32,7 @@ import java.util.Set;
* @author Stephen Mallette (http://stephen.genoprime.com)
* @deprecated As of release 3.2.4, replaced by {@link org.apache.tinkerpop.gremlin.neo4j.jsr223.Neo4jGremlinPlugin}.
*/
+@Deprecated
public final class Neo4jGremlinPlugin extends AbstractGremlinPlugin {
private static final Set<String> IMPORTS = new HashSet<String>() {{
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0c941e8/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/jsr223/SparkGremlinPlugin.java
----------------------------------------------------------------------
diff --git a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/jsr223/SparkGremlinPlugin.java b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/jsr223/SparkGremlinPlugin.java
index 840f593..9403fa4 100644
--- a/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/jsr223/SparkGremlinPlugin.java
+++ b/spark-gremlin/src/main/java/org/apache/tinkerpop/gremlin/spark/jsr223/SparkGremlinPlugin.java
@@ -23,7 +23,7 @@ import org.apache.tinkerpop.gremlin.jsr223.AbstractGremlinPlugin;
import org.apache.tinkerpop.gremlin.jsr223.BindingsCustomizer;
import org.apache.tinkerpop.gremlin.jsr223.DefaultImportCustomizer;
import org.apache.tinkerpop.gremlin.jsr223.ImportCustomizer;
-import org.apache.tinkerpop.gremlin.jsr223.console.LazyBindingsCustomizer;
+import org.apache.tinkerpop.gremlin.jsr223.LazyBindingsCustomizer;
import org.apache.tinkerpop.gremlin.spark.process.computer.CombineIterator;
import org.apache.tinkerpop.gremlin.spark.process.computer.MapIterator;
import org.apache.tinkerpop.gremlin.spark.process.computer.MemoryAccumulator;