http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/plugin/ArtifactTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/plugin/ArtifactTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/plugin/ArtifactTest.java deleted file mode 100644 index f3c96f9..0000000 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/plugin/ArtifactTest.java +++ /dev/null @@ -1,85 +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.groovy.plugin; - -import org.junit.Test; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; - -/** - * @author Nghia Tran (https://github.com/n-tran) - */ -public class ArtifactTest { - @Test - public void shouldBeEqualIfSame() { - final Artifact a = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - final Artifact b = a; - - assertThat(a.equals(b), is(true)); - } - - @Test - public void shouldNotBeEqualIfArgumentIsNull() { - final Artifact a = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - final Artifact b = null; - - assertThat(a.equals(b), is(false)); - } - - @Test - public void shouldNotBeEqualIfArgumentIsNotAnArtifact() { - final Artifact a = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - final String b = " "; - - assertThat(a.equals(b), is(false)); - } - - @Test - public void shouldNotBeEqualIfTheGroupIsNotEqual() { - final Artifact a = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - final Artifact b = new Artifact("com.apacheTest.tinkerpop2","tinkergraph-gremlin","3.0.0"); - - assertThat(a.equals(b), is(false)); - } - - @Test - public void shouldNotBeEqualIfTheArtifactIsNotEqual() { - final Artifact a = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - final Artifact b = new Artifact("org.apache.tinkerpop","tinkergraph-artifact","3.0.0"); - - assertThat(a.equals(b), is(false)); - } - - @Test - public void shouldNotBeEqualIfTheVersionIsNotEqual() { - final Artifact a = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - final Artifact b = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","4.0.0"); - - assertThat(a.equals(b), is(false)); - } - - @Test - public void shouldBeEqual() { - final Artifact a = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - final Artifact b = new Artifact("org.apache.tinkerpop","tinkergraph-gremlin","3.0.0"); - - assertThat(a.equals(b), is(true)); - } -}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabberIntegrateTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabberIntegrateTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabberIntegrateTest.java index 517ce8f..4f1c900 100644 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabberIntegrateTest.java +++ b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/groovy/util/DependencyGrabberIntegrateTest.java @@ -22,7 +22,6 @@ import groovy.lang.GroovyClassLoader; import java.io.File; import org.apache.commons.io.FileUtils; import org.apache.tinkerpop.gremlin.TestHelper; -import org.apache.tinkerpop.gremlin.groovy.plugin.Artifact; import org.junit.AfterClass; import org.junit.Test; import static org.junit.Assert.assertFalse; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/plugin/dsl/credential/CredentialGraphTest.java ---------------------------------------------------------------------- diff --git a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/plugin/dsl/credential/CredentialGraphTest.java b/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/plugin/dsl/credential/CredentialGraphTest.java deleted file mode 100644 index 0ea9b2b..0000000 --- a/gremlin-groovy/src/test/java/org/apache/tinkerpop/gremlin/plugin/dsl/credential/CredentialGraphTest.java +++ /dev/null @@ -1,118 +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.plugin.dsl.credential; - -import org.apache.tinkerpop.gremlin.structure.Graph; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; -import org.hamcrest.MatcherAssert; -import org.junit.Test; - -import static org.apache.tinkerpop.gremlin.groovy.plugin.dsl.credential.CredentialGraph.credentials; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - */ -public class CredentialGraphTest { - - @Test - public void shouldCreateUser() { - final Graph graph = TinkerGraph.open(); - final Vertex v = credentials(graph).createUser("stephen", "secret"); - assertEquals("stephen", v.value("username")); - assertEquals("user", v.label()); - assertNotEquals("secret", v.value("password")); // hashed to something - assertThat(v.value("password").toString().length(), greaterThan(0)); - } - - @Test - public void shouldRemoveUser() { - final Graph graph = TinkerGraph.open(); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(false)); - credentials(graph).createUser("stephen", "secret"); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(true)); - - assertEquals(1, credentials(graph).removeUser("stephen")); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(false)); - } - - @Test - public void shouldNotRemoveUser() { - final Graph graph = TinkerGraph.open(); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(false)); - credentials(graph).createUser("stephen", "secret"); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(true)); - - assertEquals(0, credentials(graph).removeUser("stephanie")); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(true)); - } - - @Test - public void shouldFindUser() { - final Graph graph = TinkerGraph.open(); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(false)); - credentials(graph).createUser("marko", "secret"); - final Vertex stephen = credentials(graph).createUser("stephen", "secret"); - credentials(graph).createUser("daniel", "secret"); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(true)); - - assertEquals(stephen, credentials(graph).findUser("stephen")); - } - - @Test - public void shouldNotFindUser() { - final Graph graph = TinkerGraph.open(); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(false)); - credentials(graph).createUser("marko", "secret"); - credentials(graph).createUser("stephen", "secret"); - credentials(graph).createUser("daniel", "secret"); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(true)); - - assertNull(credentials(graph).findUser("stephanie")); - } - - @Test - public void shouldCountUsers() { - final Graph graph = TinkerGraph.open(); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(false)); - credentials(graph).createUser("marko", "secret"); - credentials(graph).createUser("stephen", "secret"); - credentials(graph).createUser("daniel", "secret"); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(true)); - - assertEquals(3, credentials(graph).countUsers()); - } - - @Test(expected = IllegalStateException.class) - public void shouldThrowIfFindingMultipleUsers() { - final Graph graph = TinkerGraph.open(); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(false)); - credentials(graph).createUser("stephen", "secret"); - credentials(graph).createUser("stephen", "secret"); - MatcherAssert.assertThat(graph.vertices().hasNext(), is(true)); - - assertNull(credentials(graph).findUser("stephen")); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java index b87092e..53aa1fb 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/Settings.java @@ -204,15 +204,6 @@ public class Settings { public AuthenticationSettings authentication = new AuthenticationSettings(); /** - * The list of plugins to enable for the server. Plugins may be available on the classpath, but with this - * configuration it is possible to explicitly include or omit them. - * - * @deprecated As of release 3.2.5, replaced by specific {@link GremlinPlugin} settings on {@link #scriptEngines} - */ - @Deprecated - public List<String> plugins = new ArrayList<>(); - - /** * Custom settings for {@link OpProcessor} implementations. Implementations are loaded via * {@link ServiceLoader} but custom configurations can be supplied through this configuration. */ http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticator.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticator.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticator.java index 10c3531..c3b1f87 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticator.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticator.java @@ -35,8 +35,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import static org.apache.tinkerpop.gremlin.groovy.plugin.dsl.credential.CredentialGraphTokens.PROPERTY_PASSWORD; -import static org.apache.tinkerpop.gremlin.groovy.plugin.dsl.credential.CredentialGraphTokens.PROPERTY_USERNAME; +import static org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraphTokens.PROPERTY_PASSWORD; +import static org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraphTokens.PROPERTY_USERNAME; /** * A simple implementation of an {@link Authenticator} that uses a {@link Graph} instance as a credential store. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java index d8cbd5c..0ff899d 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/HttpBasicAuthenticationHandler.java @@ -38,8 +38,8 @@ import java.util.Map; import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; -import static org.apache.tinkerpop.gremlin.groovy.plugin.dsl.credential.CredentialGraphTokens.PROPERTY_PASSWORD; -import static org.apache.tinkerpop.gremlin.groovy.plugin.dsl.credential.CredentialGraphTokens.PROPERTY_USERNAME; +import static org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraphTokens.PROPERTY_PASSWORD; +import static org.apache.tinkerpop.gremlin.groovy.jsr223.dsl.credential.CredentialGraphTokens.PROPERTY_USERNAME; /** * Implements basic HTTP authentication for use with the {@link HttpGremlinEndpointHandler} and HTTP based API calls. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java index 2b12406..727f02d 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/AbstractEvalOpProcessor.java @@ -25,7 +25,7 @@ import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage; import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode; import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor; -import org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptTimeoutException; +import org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException; import org.apache.tinkerpop.gremlin.process.traversal.Operator; import org.apache.tinkerpop.gremlin.process.traversal.Order; import org.apache.tinkerpop.gremlin.process.traversal.Pop; @@ -289,11 +289,6 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor { final String errorMessage = String.format("A timeout occurred within the script during evaluation of [%s] - consider increasing the limit given to TimedInterruptCustomizerProvider", msg); logger.warn(errorMessage); ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider").create()); - } else if (t instanceof org.apache.tinkerpop.gremlin.groovy.jsr223.TimedInterruptTimeoutException) { - // occurs when the TimedInterruptCustomizerProvider is in play - final String errorMessage = String.format("A timeout occurred within the script during evaluation of [%s] - consider increasing the limit given to TimedInterruptCustomizerProvider", msg); - logger.warn(errorMessage); - ctx.writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage("Timeout during script evaluation triggered by TimedInterruptCustomizerProvider").create()); } else if (t instanceof TimeoutException) { final String errorMessage = String.format("Script evaluation exceeded the configured threshold for request [%s] - %s", msg, t.getMessage()); logger.warn(errorMessage, t); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOpProcessor.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOpProcessor.java deleted file mode 100644 index 4d588ae..0000000 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOpProcessor.java +++ /dev/null @@ -1,168 +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.server.op.control; - -import com.codahale.metrics.Meter; -import org.apache.tinkerpop.gremlin.driver.Tokens; -import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; -import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage; -import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode; -import org.apache.tinkerpop.gremlin.server.Context; -import org.apache.tinkerpop.gremlin.server.GremlinServer; -import org.apache.tinkerpop.gremlin.server.OpProcessor; -import org.apache.tinkerpop.gremlin.server.op.OpProcessorException; -import org.apache.tinkerpop.gremlin.server.util.MetricManager; -import org.apache.tinkerpop.gremlin.util.function.ThrowingConsumer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -import static com.codahale.metrics.MetricRegistry.name; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As for release 3.2.2, not replaced as this feature was never really published as official. - */ -@Deprecated -public class ControlOpProcessor implements OpProcessor { - private static final Logger logger = LoggerFactory.getLogger(ControlOpProcessor.class); - private static final Meter controlOpMeter = MetricManager.INSTANCE.getMeter(name(GremlinServer.class, "op", "control")); - public static final String OP_PROCESSOR_NAME = "control"; - - @Override - public String getName() { - return OP_PROCESSOR_NAME; - } - - @Override - public ThrowingConsumer<Context> select(final Context ctx) throws OpProcessorException { - final RequestMessage message = ctx.getRequestMessage(); - logger.debug("Selecting processor for RequestMessage {}", message); - - final ThrowingConsumer<Context> op; - switch (message.getOp()) { - case Tokens.OPS_VERSION: - op = ControlOps::versionOp; - break; - case Tokens.OPS_IMPORT: - op = validateImportMessage(message).orElse(ControlOps::importOp); - break; - case Tokens.OPS_RESET: - op = ControlOps::resetOp; - break; - case Tokens.OPS_SHOW: - op = validateShowMessage(message).orElse(ControlOps::showOp); - break; - case Tokens.OPS_USE: - op = validateUseMessage(message).orElse(ControlOps::useOp); - break; - case Tokens.OPS_INVALID: - final String msgInvalid = String.format("Message could not be parsed. Check the format of the request. [%s]", message); - throw new OpProcessorException(msgInvalid, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_MALFORMED_REQUEST).statusMessage(msgInvalid).create()); - default: - final String msgDefault = String.format("Message with op code [%s] is not recognized.", message.getOp()); - throw new OpProcessorException(msgDefault, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_MALFORMED_REQUEST).statusMessage(msgDefault).create()); - } - - controlOpMeter.mark(); - return op; - } - - @Override - public void close() throws Exception { - // do nothing = no resources to release - } - - private static Optional<ThrowingConsumer<Context>> validateImportMessage(final RequestMessage message) throws OpProcessorException { - final Optional<List> l = message.optionalArgs(Tokens.ARGS_IMPORTS); - if (!l.isPresent()) { - final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", Tokens.OPS_IMPORT, Tokens.ARGS_IMPORTS); - throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); - } - - if (l.orElse(new ArrayList()).size() == 0) { - final String msg = String.format( - "A message with an [%s] op code requires that the [%s] argument has at least one import string specified.", - Tokens.OPS_IMPORT, Tokens.ARGS_IMPORTS); - throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); - } - - return Optional.empty(); - } - - private static Optional<ThrowingConsumer<Context>> validateShowMessage(final RequestMessage message) throws OpProcessorException { - final Optional<String> infoType = message.optionalArgs(Tokens.ARGS_INFO_TYPE); - if (!infoType.isPresent()) { - final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", - Tokens.OPS_SHOW, Tokens.ARGS_INFO_TYPE); - throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); - } - - if (!Tokens.INFO_TYPES.contains(infoType.get())) { - final String msg = String.format("A message with an [%s] op code requires a [%s] argument with one of the following values [%s].", - Tokens.OPS_SHOW, Tokens.ARGS_INFO_TYPE, Tokens.INFO_TYPES); - throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); - } - - - return Optional.empty(); - - } - - private static Optional<ThrowingConsumer<Context>> validateUseMessage(final RequestMessage message) throws OpProcessorException { - final Optional<List> l = message.optionalArgs(Tokens.ARGS_COORDINATES); - if (!l.isPresent()) { - final String msg = String.format("A message with an [%s] op code requires a [%s] argument.", - Tokens.OPS_USE, Tokens.ARGS_COORDINATES); - throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); - } - - final List coordinates = l.orElse(new ArrayList()); - if (coordinates.size() == 0) { - final String msg = String.format( - "A message with an [%s] op code requires that the [%s] argument has at least one set of valid maven coordinates specified.", - Tokens.OPS_USE, Tokens.ARGS_COORDINATES); - throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); - } - - if (!coordinates.stream().allMatch(ControlOpProcessor::validateCoordinates)) { - final String msg = String.format( - "A message with an [%s] op code requires that all [%s] specified are valid maven coordinates with a group, artifact, and version.", - Tokens.OPS_USE, Tokens.ARGS_COORDINATES); - throw new OpProcessorException(msg, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_INVALID_REQUEST_ARGUMENTS).statusMessage(msg).create()); - } - - return Optional.empty(); - } - - private static boolean validateCoordinates(final Object coordinates) { - if (!(coordinates instanceof Map)) - return false; - - final Map m = (Map) coordinates; - return m.containsKey(Tokens.ARGS_COORDINATES_GROUP) - && m.containsKey(Tokens.ARGS_COORDINATES_ARTIFACT) - && m.containsKey(Tokens.ARGS_COORDINATES_VERSION); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOps.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOps.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOps.java deleted file mode 100644 index be89552..0000000 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/control/ControlOps.java +++ /dev/null @@ -1,123 +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.server.op.control; - -import io.netty.channel.ChannelHandlerContext; -import org.apache.tinkerpop.gremlin.driver.Tokens; -import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; -import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage; -import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode; -import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor; -import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines; -import org.apache.tinkerpop.gremlin.server.Context; -import org.apache.tinkerpop.gremlin.util.Gremlin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -/** - * @author Stephen Mallette (http://stephen.genoprime.com) - * @deprecated As for release 3.2.2, not replaced as this feature was never really published as official. - */ -@Deprecated -class ControlOps { - private static final Logger logger = LoggerFactory.getLogger(ControlOps.class); - - public static void versionOp(final Context context) { - final ChannelHandlerContext ctx = context.getChannelHandlerContext(); - final RequestMessage msg = context.getRequestMessage(); - context.getChannelHandlerContext().writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SUCCESS).result(Gremlin.version()), ctx.voidPromise()); - } - - /** - * Modify the imports on the {@code ScriptEngine}. - */ - public static void importOp(final Context context) { - final RequestMessage msg = context.getRequestMessage(); - final List<String> l = (List<String>) msg.getArgs().get(Tokens.ARGS_IMPORTS); - context.getGremlinExecutor().getScriptEngines().addImports(new HashSet<>(l)); - } - - /** - * List the dependencies, imports, or variables in the {@code ScriptEngine}. - */ - public static void showOp(final Context context) { - final ChannelHandlerContext ctx = context.getChannelHandlerContext(); - final RequestMessage msg = context.getRequestMessage(); - final String infoType = msg.<String>optionalArgs(Tokens.ARGS_INFO_TYPE).get(); - final GremlinExecutor executor = context.getGremlinExecutor(); - final ScriptEngines scriptEngines = executor.getScriptEngines(); - - final Object infoToShow; - if (infoType.equals(Tokens.ARGS_INFO_TYPE_DEPDENENCIES)) - infoToShow = scriptEngines.dependencies(); - else if (infoType.equals(Tokens.ARGS_INFO_TYPE_IMPORTS)) - infoToShow = scriptEngines.imports(); - else { - // this shouldn't happen if validations are working properly. will bomb and log as error to server logs - // thus killing the connection - throw new RuntimeException(String.format("Validation for the show operation is not properly checking the %s", Tokens.ARGS_INFO_TYPE)); - } - - try { - context.getChannelHandlerContext().writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SUCCESS).result(infoToShow).create(), ctx.voidPromise()); - } catch (Exception ex) { - logger.warn("The result [{}] in the request {} could not be serialized and returned.", - infoToShow, context.getRequestMessage(), ex); - } - } - - /** - * Resets the {@code ScriptEngine} thus forcing a reload of scripts and classes. - */ - public static void resetOp(final Context context) { - final ChannelHandlerContext ctx = context.getChannelHandlerContext(); - final RequestMessage msg = context.getRequestMessage(); - context.getGremlinExecutor().getScriptEngines().reset(); - context.getChannelHandlerContext().writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SUCCESS).create(), ctx.voidPromise()); - } - - /** - * Pull in maven based dependencies and load Gremlin plugins. - */ - public static void useOp(final Context context) { - final ChannelHandlerContext ctx = context.getChannelHandlerContext(); - final RequestMessage msg = context.getRequestMessage(); - final List<Map<String, String>> usings = (List<Map<String, String>>) msg.getArgs().get(Tokens.ARGS_COORDINATES); - usings.forEach(c -> { - final String group = c.get(Tokens.ARGS_COORDINATES_GROUP); - final String artifact = c.get(Tokens.ARGS_COORDINATES_ARTIFACT); - final String version = c.get(Tokens.ARGS_COORDINATES_VERSION); - logger.info("Loading plugin [group={},artifact={},version={}]", group, artifact, version); - context.getGremlinExecutor().getScriptEngines().use(group, artifact, version); - - final Map<String, String> coords = new HashMap<String, String>() {{ - put("group", group); - put("artifact", artifact); - put("version", version); - }}; - - context.getChannelHandlerContext().writeAndFlush(ResponseMessage.build(msg).code(ResponseStatusCode.SUCCESS).result(coords).create(), ctx.voidPromise()); - }); - } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java index 9b16a3b..62a08cb 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/Session.java @@ -22,7 +22,6 @@ import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor; import org.apache.tinkerpop.gremlin.server.Context; import org.apache.tinkerpop.gremlin.server.GraphManager; import org.apache.tinkerpop.gremlin.server.Settings; -import org.apache.tinkerpop.gremlin.server.util.LifeCycleHook; import org.apache.tinkerpop.gremlin.server.util.ThreadFactoryUtil; import org.apache.tinkerpop.gremlin.structure.Graph; import org.slf4j.Logger; @@ -30,7 +29,6 @@ import org.slf4j.LoggerFactory; import javax.script.Bindings; import javax.script.SimpleBindings; -import java.util.HashSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -222,20 +220,13 @@ public class Session { this.bindings.clear(); this.bindings.putAll(b); }) - .enabledPlugins(new HashSet<>(settings.plugins)) .globalBindings(graphManager.getAsBindings()) .executorService(executor) .scheduledExecutorService(scheduledExecutorService); settings.scriptEngines.forEach((k, v) -> { - // use plugins if they are present and the old approach if not - if (v.plugins.isEmpty()) { - // make sure that server related classes are available at init - ultimately this body of code will be - // deleted when deprecation is removed - v.imports.add(LifeCycleHook.class.getCanonicalName()); - v.imports.add(LifeCycleHook.Context.class.getCanonicalName()); - gremlinExecutorBuilder.addEngineSettings(k, v.imports, v.staticImports, v.scripts, v.config); - } else { + // use plugins if they are present + if (!v.plugins.isEmpty()) { // make sure that server related classes are available at init - new approach. the LifeCycleHook stuff // will be added explicitly via configuration using GremlinServerGremlinModule in the yaml gremlinExecutorBuilder.addPlugins(k, v.plugins); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java index c5a05e4..cefa045 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java @@ -28,7 +28,6 @@ import org.apache.tinkerpop.gremlin.driver.Tokens; import org.apache.tinkerpop.gremlin.driver.message.RequestMessage; import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage; import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode; -import org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines; import org.apache.tinkerpop.gremlin.jsr223.JavaTranslator; import org.apache.tinkerpop.gremlin.process.traversal.Bytecode; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java index 03317d3..b5e46fc 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/GremlinServerInstall.java @@ -18,7 +18,7 @@ */ package org.apache.tinkerpop.gremlin.server.util; -import org.apache.tinkerpop.gremlin.groovy.plugin.Artifact; +import org.apache.tinkerpop.gremlin.groovy.util.Artifact; import org.apache.tinkerpop.gremlin.groovy.util.DependencyGrabber; import groovy.lang.GroovyClassLoader; http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java index b9b7280..116d627 100644 --- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java +++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java @@ -29,7 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -121,20 +120,13 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> { .afterFailure((b, e) -> this.graphManager.rollbackAll()) .beforeEval(b -> this.graphManager.rollbackAll()) .afterTimeout(b -> this.graphManager.rollbackAll()) - .enabledPlugins(new HashSet<>(settings.plugins)) .globalBindings(this.graphManager.getAsBindings()) .executorService(this.gremlinExecutorService) .scheduledExecutorService(this.scheduledExecutorService); settings.scriptEngines.forEach((k, v) -> { - // use plugins if they are present and the old approach if not - if (v.plugins.isEmpty()) { - // make sure that server related classes are available at init - ultimately this body of code will be - // deleted when deprecation is removed - v.imports.add(LifeCycleHook.class.getCanonicalName()); - v.imports.add(LifeCycleHook.Context.class.getCanonicalName()); - gremlinExecutorBuilder.addEngineSettings(k, v.imports, v.staticImports, v.scripts, v.config); - } else { + // use plugins if they are present + if (!v.plugins.isEmpty()) { // make sure that server related classes are available at init - new approach. the LifeCycleHook stuff // will be added explicitly via configuration using GremlinServerGremlinModule in the yaml gremlinExecutorBuilder.addPlugins(k, v.plugins); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/gremlin-server/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.server.OpProcessor ---------------------------------------------------------------------- diff --git a/gremlin-server/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.server.OpProcessor b/gremlin-server/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.server.OpProcessor index 315dd7b..4f1bf10 100644 --- a/gremlin-server/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.server.OpProcessor +++ b/gremlin-server/src/main/resources/META-INF/services/org.apache.tinkerpop.gremlin.server.OpProcessor @@ -1,4 +1,3 @@ org.apache.tinkerpop.gremlin.server.op.standard.StandardOpProcessor -org.apache.tinkerpop.gremlin.server.op.control.ControlOpProcessor org.apache.tinkerpop.gremlin.server.op.session.SessionOpProcessor org.apache.tinkerpop.gremlin.server.op.traversal.TraversalOpProcessor \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGremlinSuite.java ---------------------------------------------------------------------- diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGremlinSuite.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGremlinSuite.java index 3f7009f..2bce560 100644 --- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGremlinSuite.java +++ b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/HadoopGremlinSuite.java @@ -20,7 +20,6 @@ package org.apache.tinkerpop.gremlin.hadoop; import org.apache.tinkerpop.gremlin.AbstractGremlinSuite; -import org.apache.tinkerpop.gremlin.hadoop.jsr223.HadoopGremlinPluginCheck; import org.apache.tinkerpop.gremlin.hadoop.structure.io.FileSystemStorageCheck; import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine; import org.junit.runners.model.InitializationError; @@ -31,6 +30,6 @@ import org.junit.runners.model.RunnerBuilder; */ public class HadoopGremlinSuite extends AbstractGremlinSuite { public HadoopGremlinSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError { - super(klass, builder, new Class<?>[]{HadoopGremlinPluginCheck.class, FileSystemStorageCheck.class}, new Class<?>[]{HadoopGremlinPluginCheck.class, FileSystemStorageCheck.class}, true, TraversalEngine.Type.COMPUTER); + super(klass, builder, new Class<?>[]{FileSystemStorageCheck.class}, new Class<?>[]{FileSystemStorageCheck.class}, true, TraversalEngine.Type.COMPUTER); } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPluginCheck.java ---------------------------------------------------------------------- diff --git a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPluginCheck.java b/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPluginCheck.java deleted file mode 100644 index baa96da..0000000 --- a/hadoop-gremlin/src/test/java/org/apache/tinkerpop/gremlin/hadoop/jsr223/HadoopGremlinPluginCheck.java +++ /dev/null @@ -1,397 +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.hadoop.jsr223; - -import org.apache.tinkerpop.gremlin.AbstractGremlinTest; -import org.apache.tinkerpop.gremlin.LoadGraphWith; -import org.apache.tinkerpop.gremlin.TestHelper; -import org.apache.tinkerpop.gremlin.groovy.loaders.GremlinLoader; -import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin; -import org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor; -import org.apache.tinkerpop.gremlin.groovy.plugin.RemoteAcceptor; -import org.apache.tinkerpop.gremlin.hadoop.Constants; -import org.apache.tinkerpop.gremlin.hadoop.HadoopGremlinSuite; -import org.apache.tinkerpop.gremlin.process.traversal.Traversal; -import org.apache.tinkerpop.gremlin.util.Gremlin; -import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; -import org.codehaus.groovy.tools.shell.Groovysh; -import org.codehaus.groovy.tools.shell.IO; -import org.junit.Before; -import org.junit.Test; - -import javax.script.ScriptException; -import javax.tools.JavaCompiler; -import javax.tools.SimpleJavaFileObject; -import javax.tools.ToolProvider; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.URI; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.jar.Attributes; -import java.util.jar.JarEntry; -import java.util.jar.JarOutputStream; -import java.util.jar.Manifest; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -/** - * This is an test that is mean to be used in the context of the {@link HadoopGremlinSuite} and shouldn't be - * executed on its own. - * - * @author Marko A. Rodriguez (http://markorodriguez.com) - */ -public class HadoopGremlinPluginCheck extends AbstractGremlinTest { - // *********************** - // This test will be removed as the old "plugin" infrastructure was deprecated in 3.2.4. need to rework the - // tests a bi for this to see what the model is for validating the jsr223 plugins. note that the code from - // gremlin-groovy-test, specifically TestableConsolePluginAcceptor, has been copied to the bottom of this - // file for reference - // *********************** - @Test - public void nothing() { - // this is just to stop junit failures until this test gets figured out - } - - /** - @Before - public void setupTest() { - try { - this.console = new TestableConsolePluginAcceptor(); - final HadoopGremlinPlugin plugin = new HadoopGremlinPlugin(); - plugin.pluginTo(this.console); - this.remote = (HadoopRemoteAcceptor) plugin.remoteAcceptor().get(); - } catch (final Exception e) { - throw new IllegalStateException(e.getMessage(), e); - } - } - - /////////////////// - - private HadoopRemoteAcceptor remote; - private TestableConsolePluginAcceptor console; - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldSupportRemoteTraversal() throws Exception { - this.console.addBinding("graph", this.graph); - this.console.addBinding("g", this.g); - this.remote.connect(Arrays.asList("graph", "g")); - // - Traversal<?, ?> traversal = (Traversal<?, ?>) this.remote.submit(Arrays.asList("g.V().count()")); - assertEquals(6L, traversal.next()); - assertFalse(traversal.hasNext()); - assertNotNull(this.console.getBindings().get(RemoteAcceptor.RESULT)); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldSupportRemoteSugarTraversal() throws Exception { - SugarTestHelper.clearRegistry(this.graphProvider); - this.console.addBinding("graph", this.graph); - this.console.addBinding("g", this.g); - // - this.remote.connect(Arrays.asList("graph", "g")); - try { - this.remote.submit(Arrays.asList("g.V.name.map{it.length()}.sum")); - fail("Should not allow sugar usage"); - } catch (final Exception e) { - // this is good - } - // - this.remote.configure(Arrays.asList("useSugar", "true")); - this.remote.connect(Arrays.asList("graph", "g")); - Traversal<?, ?> traversal = (Traversal<?, ?>) this.remote.submit(Arrays.asList("g.V.name.map{it.length()}.sum")); - assertEquals(28l, traversal.next()); - assertFalse(traversal.hasNext()); - assertNotNull(this.console.getBindings().get(RemoteAcceptor.RESULT)); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldSupportRemoteGroupTraversal() throws Exception { - SugarTestHelper.clearRegistry(this.graphProvider); - GremlinLoader.load(); - this.console.addBinding("graph", this.graph); - this.console.addBinding("g", this.g); - this.remote.connect(Arrays.asList("graph")); - // - this.remote.connect(Arrays.asList("graph", "g")); - Traversal<?, Map<String, List<String>>> traversal = (Traversal<?, Map<String, List<String>>>) this.remote.submit(Arrays.asList("g.V().out().group().by{it.value('name')[1]}.by('name')")); - Map<String, List<String>> map = traversal.next(); - assertEquals(3, map.size()); - assertEquals(1, map.get("a").size()); - assertEquals("vadas", map.get("a").get(0)); - assertEquals(1, map.get("i").size()); - assertEquals("ripple", map.get("i").get(0)); - assertEquals(4, map.get("o").size()); - assertTrue(map.get("o").contains("josh")); - assertTrue(map.get("o").contains("lop")); - assertNotNull(this.console.getBindings().get(RemoteAcceptor.RESULT)); - // - traversal = (Traversal<?, Map<String, List<String>>>) this.remote.submit(Arrays.asList("g.V().out().group().by(label).by{it.value('name')[1]}")); - map = traversal.next(); - assertEquals(2, map.size()); - assertEquals(4, map.get("software").size()); - assertTrue(map.get("software").contains("o")); - assertTrue(map.get("software").contains("i")); - assertEquals(2, map.get("person").size()); - assertTrue(map.get("person").contains("o")); - assertTrue(map.get("person").contains("a")); - assertNotNull(this.console.getBindings().get(RemoteAcceptor.RESULT)); - } - - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldSupportHDFSMethods() throws Exception { - List<String> ls = (List<String>) this.console.eval("hdfs.ls()"); - for (final String line : ls) { - assertTrue(line.startsWith("-") || line.startsWith("r") || line.startsWith("w") || line.startsWith("x")); - assertEquals(" ", line.substring(9, 10)); - } - ls = (List<String>) this.console.eval("fs.ls()"); - for (final String line : ls) { - assertTrue(line.startsWith("-") || line.startsWith("r") || line.startsWith("w") || line.startsWith("x")); - assertEquals(" ", line.substring(9, 10)); - } - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldGracefullyHandleBadGremlinHadoopLibs() throws Exception { - System.setProperty(Constants.HADOOP_GREMLIN_LIBS, TestHelper.makeTestDataDirectory(HadoopGremlinPluginCheck.class, "shouldGracefullyHandleBadGremlinHadoopLibs")); - this.graph.configuration().setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, true); - this.console.addBinding("graph", this.graph); - this.console.addBinding("g", this.g); - this.remote.connect(Arrays.asList("graph", "g")); - Traversal<?, ?> traversal = (Traversal<?, ?>) this.remote.submit(Arrays.asList("g.V()")); - assertEquals(6, IteratorUtils.count(traversal)); - assertNotNull(this.console.getBindings().get(RemoteAcceptor.RESULT)); - } - - @Test - @LoadGraphWith(LoadGraphWith.GraphData.MODERN) - public void shouldSupportVariousFileSystemsInGremlinHadoopLibs() throws Exception { - - // The whole point of this test is to verify that HADOOP_GREMLIN_LIBS may contain paths with or without - // a file system scheme prefix and that either path is properly handled. If all jar files, that were specified - // in HADOOP_GREMLIN_LIBS, are found in the GraphComputers temporary directory after using the GraphComputer - // (by submitting a traversal), the test is considered to be successful. - // - // The traversal will likely never fail, since both - Spark and Giraph - run in the same JVM during tests. This - // is unfortunate as it doesn't allow us to verify that GraphComputers load jars properly in a distributed - // environment. The test would fail in a distributed environment, IF loading the jars specified in - // HADOOP_GREMLIN_LIBS wouldn't work. That is because we generate new jar files on the fly that are definitely - // not part of any existing directory or the current classpath. - - final String testDataDirectory = TestHelper.makeTestDataDirectory(HadoopGremlinPluginCheck.class, "shouldHandleLocalGremlinHadoopLibs"); - final File jarFile1 = createJarFile(testDataDirectory + File.separator + "1", "Greeter1"); - final File jarFile2 = createJarFile(testDataDirectory + File.separator + "2", "Greeter2"); - final String graphComputerJarTargetBasePath = System.getProperty("java.io.tmpdir") + File.separator + - "hadoop-gremlin-" + Gremlin.version() + "-libs" + File.separator; - final File graphComputerJarTargetPath1 = new File(graphComputerJarTargetBasePath + "1" + File.separator + "Greeter1.jar"); - final File graphComputerJarTargetPath2 = new File(graphComputerJarTargetBasePath + "2" + File.separator + "Greeter2.jar"); - - for (final boolean withScheme : Arrays.asList(false, true)) { - - Stream<String> hadoopGremlinLibs = Arrays.asList(jarFile1, jarFile2).stream().map(f -> f.getParentFile().getAbsolutePath()); - if (withScheme) { - hadoopGremlinLibs = hadoopGremlinLibs.map(path -> "file://" + path); - } - System.setProperty(Constants.HADOOP_GREMLIN_LIBS, String.join(File.pathSeparator, hadoopGremlinLibs.collect(Collectors.toList()))); - - this.graph.configuration().setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, true); - this.console.addBinding("graph", this.graph); - this.console.addBinding("g", this.g); - this.remote.connect(Arrays.asList("graph", "g")); - - Traversal<?, ?> traversal = (Traversal<?, ?>) this.remote.submit(Arrays.asList( - "ClassLoader.getSystemClassLoader().addURL('" + jarFile1.toURI().toURL() + "'.toURL());", - "ClassLoader.getSystemClassLoader().addURL('" + jarFile2.toURI().toURL() + "'.toURL());", - "g.V().choose(hasLabel('person'), " + - "values('name').map {Class.forName('Greeter1').hello(it.get())}, " + - "values('name').map {Class.forName('Greeter2').hello(it.get())})")); - - final List<String> expectedMessages = Arrays.asList("marko", "josh", "peter", "vadas").stream(). - map(name -> "Greeter1 says: Hello " + name + "!").collect(Collectors.toList()); - - expectedMessages.addAll(Arrays.asList("lop", "ripple").stream(). - map(name -> "Greeter2 says: Hello " + name + "!").collect(Collectors.toList())); - - while (traversal.hasNext()) { - final String message = (String) traversal.next(); - assertTrue(expectedMessages.remove(message)); - } - - assertEquals(0, expectedMessages.size()); - } - - assertTrue(graphComputerJarTargetPath1.exists()); - assertTrue(graphComputerJarTargetPath2.exists()); - - assert graphComputerJarTargetPath1.delete(); - assert graphComputerJarTargetPath2.delete(); - } - - private File createJarFile(final String directory, final String className) throws IOException { - - new File(directory).mkdirs(); - - final File classFile = new File(directory + File.separator + className + ".class"); - final File jarFile = new File(directory + File.separator + className + ".jar"); - - jarFile.deleteOnExit(); - - final JavaStringObject source = new JavaStringObject(className, - "public class " + className + " {\n" + - " public static String hello(final String name) {\n" + - " return \"" + className + " says: Hello \" + name + \"!\";\n" + - " }\n" + - "}"); - - final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); - final List<String> options = Arrays.asList( - "-d", classFile.getParentFile().getAbsolutePath() - ); - assert compiler.getTask(null, null, null, options, null, Collections.singletonList(source)).call(); - - final Manifest manifest = new Manifest(); - manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); - - try (final JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest)) { - final JarEntry entry = new JarEntry(classFile.getName()); - entry.setTime(classFile.lastModified()); - target.putNextEntry(entry); - try (final FileInputStream fis = new FileInputStream(classFile); - final BufferedInputStream in = new BufferedInputStream(fis)) { - final byte buffer[] = new byte[1024]; - while (true) { - final int count = in.read(buffer); - if (count < 0) break; - target.write(buffer, 0, count); - } - } - target.closeEntry(); - } - - assert classFile.delete(); - - return jarFile; - } - - private static class JavaStringObject extends SimpleJavaFileObject { - - private final String code; - - JavaStringObject(final String className, final String code) { - super(URI.create("string:///" + className.replace(".", "/") + Kind.SOURCE.extension), Kind.SOURCE); - this.code = code; - } - - @Override - public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { - return code; - } - } - **/ - - - ///////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////////////// - - -//package org.apache.tinkerpop.gremlin.groovy.util; -// -//import org.apache.tinkerpop.gremlin.groovy.plugin.GremlinPlugin; -//import org.apache.tinkerpop.gremlin.groovy.plugin.PluginAcceptor; -//import org.codehaus.groovy.tools.shell.Groovysh; -//import org.codehaus.groovy.tools.shell.IO; -// -//import javax.script.ScriptException; -//import java.io.IOException; -//import java.io.OutputStream; -//import java.util.Collections; -//import java.util.HashMap; -//import java.util.Map; -//import java.util.Set; -// -// /** -// * @author Marko A. Rodriguez (http://markorodriguez.com) -// */ -// public class TestableConsolePluginAcceptor implements PluginAcceptor { -// -// public static final String ENVIRONMENT_NAME = "console"; -// public static final String ENVIRONMENT_SHELL = "ConsolePluginAcceptor.shell"; -// public static final String ENVIRONMENT_IO = "ConsolePluginAcceptor.io"; -// -// private Groovysh shell = new Groovysh(new IO(System.in, new OutputStream() { -// @Override -// public void write(int b) throws IOException { -// -// } -// }, System.err)); -// -// @Override -// public void addImports(final Set<String> importStatements) { -// importStatements.forEach(this.shell::execute); -// } -// -// @Override -// public void addBinding(final String key, final Object val) { -// this.shell.getInterp().getContext().setVariable(key, val); -// } -// -// @Override -// public Map<String, Object> getBindings() { -// return Collections.unmodifiableMap(this.shell.getInterp().getContext().getVariables()); -// } -// -// @Override -// public Object eval(final String script) throws ScriptException { -// return this.shell.execute(script); -// } -// -// @Override -// public Map<String, Object> environment() { -// final Map<String, Object> env = new HashMap<>(); -// env.put(GremlinPlugin.ENVIRONMENT, ENVIRONMENT_NAME); -// env.put(ENVIRONMENT_IO, this.shell.getIo()); -// env.put(ENVIRONMENT_SHELL, this.shell); -// return env; -// } -// -// } -} http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/da909d1e/spark-gremlin/src/test/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkHadoopGraphProvider.java ---------------------------------------------------------------------- diff --git a/spark-gremlin/src/test/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkHadoopGraphProvider.java b/spark-gremlin/src/test/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkHadoopGraphProvider.java index 74e1207..bed2ace 100644 --- a/spark-gremlin/src/test/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkHadoopGraphProvider.java +++ b/spark-gremlin/src/test/java/org/apache/tinkerpop/gremlin/spark/process/computer/SparkHadoopGraphProvider.java @@ -24,7 +24,6 @@ import org.apache.tinkerpop.gremlin.GraphProvider; import org.apache.tinkerpop.gremlin.LoadGraphWith; import org.apache.tinkerpop.gremlin.hadoop.Constants; import org.apache.tinkerpop.gremlin.hadoop.HadoopGraphProvider; -import org.apache.tinkerpop.gremlin.hadoop.jsr223.HadoopGremlinPluginCheck; import org.apache.tinkerpop.gremlin.hadoop.structure.io.FileSystemStorageCheck; import org.apache.tinkerpop.gremlin.hadoop.structure.io.HadoopPools; import org.apache.tinkerpop.gremlin.process.computer.Computer; @@ -82,14 +81,6 @@ public class SparkHadoopGraphProvider extends HadoopGraphProvider { config.put(RANDOM.nextBoolean() ? Constants.GREMLIN_SPARK_GRAPH_OUTPUT_RDD : Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName()); } - // sugar plugin causes meta-method issues with a persisted context - if (test.equals(HadoopGremlinPluginCheck.class)) { - Spark.close(); - HadoopPools.close(); - KryoShimServiceLoader.close(); - SugarTestHelper.clearRegistry(); - } - config.put(Constants.GREMLIN_HADOOP_DEFAULT_GRAPH_COMPUTER, SparkGraphComputer.class.getCanonicalName()); config.put(SparkLauncher.SPARK_MASTER, "local[4]"); config.put(Constants.SPARK_SERIALIZER, KryoSerializer.class.getCanonicalName());
