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 2017/05/03 13:56:26 UTC
[33/50] [abbrv] tinkerpop git commit: TINKERPOP-1010 Remove
deprecated methods around Gremlin Server
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/IteratorHandler.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/IteratorHandler.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/IteratorHandler.java
deleted file mode 100644
index 527aa37..0000000
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/IteratorHandler.java
+++ /dev/null
@@ -1,124 +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.handler;
-
-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.Settings;
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelOutboundHandlerAdapter;
-import io.netty.channel.ChannelPromise;
-import io.netty.util.ReferenceCountUtil;
-import io.netty.util.concurrent.EventExecutorGroup;
-import io.netty.util.concurrent.Future;
-import org.apache.commons.lang.time.StopWatch;
-import org.javatuples.Pair;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.TimeoutException;
-
-/**
- * This handler helps in scenarios where iteration is not being already handled later in the Netty pipeline. It is
- * important that if this handler is used at all, that it not block, thus ensure that if {@link Iterator} instances
- * are passed to it, they do not contain large result sets or iterates over objects that require network calls.
- *
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @deprecated As of release 3.1.1-incubating, not directly replaced.
- */
-@Deprecated
-@ChannelHandler.Sharable
-public class IteratorHandler extends ChannelOutboundHandlerAdapter {
- private static final Logger logger = LoggerFactory.getLogger(IteratorHandler.class);
-
- private final Settings settings;
-
- public IteratorHandler(final Settings settings) {
- this.settings = settings;
- }
-
- @Override
- public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception {
- if (msg instanceof Pair) {
- try {
- final Pair pair = (Pair) msg;
- final Iterator itty = (Iterator) pair.getValue1();
- final RequestMessage requestMessage = (RequestMessage) pair.getValue0();
-
- // the batch size can be overriden by the request
- final int resultIterationBatchSize = (Integer) requestMessage.optionalArgs(Tokens.ARGS_BATCH_SIZE).orElse(settings.resultIterationBatchSize);
-
- // timer for the total serialization time
- final StopWatch stopWatch = new StopWatch();
-
- final EventExecutorGroup executorService = ctx.executor();
- final Future<?> iteration = executorService.submit((Callable<Void>) () -> {
- logger.debug("Preparing to iterate results from - {} - in thread [{}]", requestMessage, Thread.currentThread().getName());
-
- stopWatch.start();
-
- List<Object> aggregate = new ArrayList<>(resultIterationBatchSize);
- while (itty.hasNext()) {
- aggregate.add(itty.next());
-
- // send back a page of results if batch size is met or if it's the end of the results being
- // iterated
- if (aggregate.size() == resultIterationBatchSize || !itty.hasNext()) {
- final ResponseStatusCode code = itty.hasNext() ? ResponseStatusCode.PARTIAL_CONTENT : ResponseStatusCode.SUCCESS;
- ctx.writeAndFlush(ResponseMessage.build(requestMessage)
- .code(code)
- .result(aggregate).create());
- aggregate = new ArrayList<>(resultIterationBatchSize);
- }
-
- stopWatch.split();
- if (stopWatch.getSplitTime() > settings.serializedResponseTimeout)
- throw new TimeoutException("Serialization of the entire response exceeded the serializeResponseTimeout setting");
-
- stopWatch.unsplit();
- }
-
- return null;
- });
-
- iteration.addListener(f -> {
- stopWatch.stop();
-
- if (!f.isSuccess()) {
- final String errorMessage = String.format("Response iteration and serialization exceeded the configured threshold for request [%s] - %s", msg, f.cause().getMessage());
- logger.warn(errorMessage);
- ctx.writeAndFlush(ResponseMessage.build(requestMessage).code(ResponseStatusCode.SERVER_ERROR_TIMEOUT).statusMessage(errorMessage).create());
- }
- });
- } finally {
- ReferenceCountUtil.release(msg);
- }
-
- } else {
- ctx.write(msg, promise);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/NioGremlinResponseEncoder.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/NioGremlinResponseEncoder.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/NioGremlinResponseEncoder.java
deleted file mode 100644
index 6a98b8b..0000000
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/NioGremlinResponseEncoder.java
+++ /dev/null
@@ -1,93 +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.handler;
-
-import com.codahale.metrics.Meter;
-import io.netty.util.CharsetUtil;
-import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
-import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
-import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
-import org.apache.tinkerpop.gremlin.driver.ser.MessageTextSerializer;
-import org.apache.tinkerpop.gremlin.server.GremlinServer;
-import org.apache.tinkerpop.gremlin.server.util.MetricManager;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToByteEncoder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static com.codahale.metrics.MetricRegistry.name;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @deprecated As of release 3.1.1-incubating, replaced by {@link NioGremlinResponseFrameEncoder} and
- * {@link GremlinResponseFrameEncoder}
- * @see <a href="https://issues.apache.org/jira/browse/TINKERPOP-1035">TINKERPOP-1035</a>
- */
-@Deprecated
-@ChannelHandler.Sharable
-public class NioGremlinResponseEncoder extends MessageToByteEncoder<ResponseMessage> {
- private static final Logger logger = LoggerFactory.getLogger(NioGremlinResponseEncoder.class);
- static final Meter errorMeter = MetricManager.INSTANCE.getMeter(name(GremlinServer.class, "errors"));
-
- @Override
- protected void encode(final ChannelHandlerContext ctx, final ResponseMessage responseMessage, final ByteBuf byteBuf) throws Exception {
- final MessageSerializer serializer = ctx.channel().attr(StateKey.SERIALIZER).get();
- final boolean useBinary = ctx.channel().attr(StateKey.USE_BINARY).get();
-
- try {
- if (!responseMessage.getStatus().getCode().isSuccess())
- errorMeter.mark();
-
- if (useBinary) {
- final ByteBuf bytes = serializer.serializeResponseAsBinary(responseMessage, ctx.alloc());
- byteBuf.writeInt(bytes.capacity());
- byteBuf.writeBytes(bytes);
- bytes.release();
- } else {
- // the expectation is that the GremlinTextRequestDecoder will have placed a MessageTextSerializer
- // instance on the channel.
- final MessageTextSerializer textSerializer = (MessageTextSerializer) serializer;
- final byte [] bytes = textSerializer.serializeResponseAsString(responseMessage).getBytes(CharsetUtil.UTF_8);
- byteBuf.writeInt(bytes.length);
- byteBuf.writeBytes(bytes);
- }
- } catch (Exception ex) {
- errorMeter.mark();
- logger.warn("The result [{}] in the request {} could not be serialized and returned.", responseMessage.getResult(), responseMessage.getRequestId(), ex);
- final String errorMessage = String.format("Error during serialization: %s",
- ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
- final ResponseMessage error = ResponseMessage.build(responseMessage.getRequestId())
- .statusMessage(errorMessage)
- .code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION).create();
- if (useBinary) {
- final ByteBuf bytes = serializer.serializeResponseAsBinary(error, ctx.alloc());
- byteBuf.writeInt(bytes.capacity());
- byteBuf.writeBytes(bytes);
- bytes.release();
- } else {
- final MessageTextSerializer textSerializer = (MessageTextSerializer) serializer;
- final byte [] bytes = textSerializer.serializeResponseAsString(error).getBytes(CharsetUtil.UTF_8);
- byteBuf.writeInt(bytes.length);
- byteBuf.writeBytes(bytes);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/OpSelectorHandler.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/OpSelectorHandler.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/OpSelectorHandler.java
index 432cecd..cd51c32 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/OpSelectorHandler.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/OpSelectorHandler.java
@@ -18,19 +18,16 @@
*/
package org.apache.tinkerpop.gremlin.server.handler;
-import com.codahale.metrics.Meter;
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.server.Context;
import org.apache.tinkerpop.gremlin.server.GraphManager;
-import org.apache.tinkerpop.gremlin.server.GremlinServer;
import org.apache.tinkerpop.gremlin.server.OpProcessor;
import org.apache.tinkerpop.gremlin.server.Settings;
import org.apache.tinkerpop.gremlin.server.op.OpLoader;
import org.apache.tinkerpop.gremlin.server.op.OpProcessorException;
-import org.apache.tinkerpop.gremlin.server.util.MetricManager;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
@@ -42,8 +39,6 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
-import static com.codahale.metrics.MetricRegistry.name;
-
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
@@ -51,16 +46,6 @@ import static com.codahale.metrics.MetricRegistry.name;
public class OpSelectorHandler extends MessageToMessageDecoder<RequestMessage> {
private static final Logger logger = LoggerFactory.getLogger(OpSelectorHandler.class);
- /**
- * Captures the "error" count as a reportable metric for Gremlin Server.
- *
- * @deprecated As of release 3.1.1-incubating, not replaced. Direct usage is discouraged with sub-classes as
- * error counts are captured more globally for error messages written down the pipeline to
- * {@link GremlinResponseFrameEncoder}.
- */
- @Deprecated
- static final Meter errorMeter = MetricManager.INSTANCE.getMeter(name(GremlinServer.class, "errors"));
-
private final Settings settings;
private final GraphManager graphManager;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/WsGremlinResponseEncoder.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/WsGremlinResponseEncoder.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/WsGremlinResponseEncoder.java
deleted file mode 100644
index 80565f1..0000000
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/handler/WsGremlinResponseEncoder.java
+++ /dev/null
@@ -1,105 +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.handler;
-
-import com.codahale.metrics.Meter;
-import org.apache.tinkerpop.gremlin.driver.MessageSerializer;
-import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
-import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
-import org.apache.tinkerpop.gremlin.driver.ser.MessageTextSerializer;
-import org.apache.tinkerpop.gremlin.server.GremlinServer;
-import org.apache.tinkerpop.gremlin.server.op.session.Session;
-import org.apache.tinkerpop.gremlin.server.util.MetricManager;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToMessageEncoder;
-import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-
-import static com.codahale.metrics.MetricRegistry.name;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @deprecated As of release 3.1.1-incubating, replaced by {@link WsGremlinResponseFrameEncoder} and
- * {@link GremlinResponseFrameEncoder}
- * @see <a href="https://issues.apache.org/jira/browse/TINKERPOP-1035">TINKERPOP-1035</a>
- */
-@Deprecated
-@ChannelHandler.Sharable
-public class WsGremlinResponseEncoder extends MessageToMessageEncoder<ResponseMessage> {
- private static final Logger logger = LoggerFactory.getLogger(WsGremlinResponseEncoder.class);
- static final Meter errorMeter = MetricManager.INSTANCE.getMeter(name(GremlinServer.class, "errors"));
-
- @Override
- protected void encode(final ChannelHandlerContext ctx, final ResponseMessage o, final List<Object> objects) throws Exception {
- final MessageSerializer serializer = ctx.channel().attr(StateKey.SERIALIZER).get();
- final boolean useBinary = ctx.channel().attr(StateKey.USE_BINARY).get();
- final Session session = ctx.channel().attr(StateKey.SESSION).get();
-
- try {
- if (!o.getStatus().getCode().isSuccess())
- errorMeter.mark();
-
- if (useBinary) {
- final ByteBuf serialized;
-
- // if the request came in on a session then the serialization must occur in that same thread.
- if (null == session)
- serialized = serializer.serializeResponseAsBinary(o, ctx.alloc());
- else
- serialized = session.getExecutor().submit(() -> serializer.serializeResponseAsBinary(o, ctx.alloc())).get();
-
- objects.add(new BinaryWebSocketFrame(serialized));
- } else {
- // the expectation is that the GremlinTextRequestDecoder will have placed a MessageTextSerializer
- // instance on the channel.
- final MessageTextSerializer textSerializer = (MessageTextSerializer) serializer;
-
- final String serialized;
-
- // if the request came in on a session then the serialization must occur in that same thread.
- if (null == session)
- serialized = textSerializer.serializeResponseAsString(o);
- else
- serialized = session.getExecutor().submit(() -> textSerializer.serializeResponseAsString(o)).get();
-
- objects.add(new TextWebSocketFrame(true, 0, serialized));
- }
- } catch (Exception ex) {
- errorMeter.mark();
- logger.warn("The result [{}] in the request {} could not be serialized and returned.", o.getResult(), o.getRequestId(), ex);
- final String errorMessage = String.format("Error during serialization: %s",
- ex.getCause() != null ? ex.getCause().getMessage() : ex.getMessage());
- final ResponseMessage error = ResponseMessage.build(o.getRequestId())
- .statusMessage(errorMessage)
- .code(ResponseStatusCode.SERVER_ERROR_SERIALIZATION).create();
- if (useBinary) {
- objects.add(new BinaryWebSocketFrame(serializer.serializeResponseAsBinary(error, ctx.alloc())));
- } else {
- final MessageTextSerializer textSerializer = (MessageTextSerializer) serializer;
- objects.add(new TextWebSocketFrame(textSerializer.serializeResponseAsString(error)));
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/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 13e5968..c6e2ab1 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
@@ -18,7 +18,6 @@
*/
package org.apache.tinkerpop.gremlin.server.op;
-import com.codahale.metrics.Meter;
import com.codahale.metrics.Timer;
import org.apache.tinkerpop.gremlin.driver.Tokens;
import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
@@ -31,7 +30,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.server.OpProcessor;
-import org.apache.tinkerpop.gremlin.server.handler.GremlinResponseFrameEncoder;
import org.apache.tinkerpop.gremlin.structure.Column;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.server.Context;
@@ -41,15 +39,12 @@ import org.apache.tinkerpop.gremlin.server.util.MetricManager;
import org.apache.tinkerpop.gremlin.util.function.ThrowingConsumer;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import io.netty.channel.ChannelHandlerContext;
-import org.codehaus.groovy.control.ErrorCollector;
import org.codehaus.groovy.control.MultipleCompilationErrorsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.script.Bindings;
-import javax.script.ScriptException;
import javax.script.SimpleBindings;
-import java.net.SocketAddress;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
@@ -75,26 +70,6 @@ public abstract class AbstractEvalOpProcessor extends AbstractOpProcessor {
public static final Timer evalOpTimer = MetricManager.INSTANCE.getTimer(name(GremlinServer.class, "op", "eval"));
/**
- * Captures the "error" count as a reportable metric for Gremlin Server.
- *
- * @deprecated As of release 3.1.1-incubating, not replaced. Direct usage is discouraged with sub-classes as
- * error counts are captured more globally for error messages written down the pipeline to
- * {@link GremlinResponseFrameEncoder}.
- */
- @Deprecated
- static final Meter errorMeter = MetricManager.INSTANCE.getMeter(name(GremlinServer.class, "errors"));
-
- /**
- * Regex for validating that binding variables.
- *
- * @deprecated As of release 3.1.2-incubating, not replaced. This {@code Pattern} is not used internally.
- * Deprecated rather than just removing as it's possible that someone else might be using it when developing
- * custom {@link OpProcessor} implementations.
- */
- @Deprecated
- protected static final Pattern validBindingName = Pattern.compile("[a-zA-Z$_][a-zA-Z0-9$_]*");
-
- /**
* This may or may not be the full set of invalid binding keys. It is dependent on the static imports made to
* Gremlin Server. This should get rid of the worst offenders though and provide a good message back to the
* calling client.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/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 3a3c836..fe308e3 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
@@ -18,14 +18,11 @@
*/
package org.apache.tinkerpop.gremlin.server.op.session;
-import com.codahale.metrics.Metric;
-import com.codahale.metrics.MetricFilter;
import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
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.MetricManager;
import org.apache.tinkerpop.gremlin.server.util.ThreadFactoryUtil;
import org.apache.tinkerpop.gremlin.structure.Graph;
@@ -34,8 +31,6 @@ import org.slf4j.LoggerFactory;
import javax.script.Bindings;
import javax.script.SimpleBindings;
-import java.util.Collections;
-import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -47,6 +42,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
/**
+ * Defines a "session" for the {@link SessionOpProcessor} which preserves state between requests made to Gremlin
+ * Server. Since transactions are bound to a single thread the "session" maintains its own thread to process Gremlin
+ * statements so that each request can be executed within it to preserve the transaction state from one request to
+ * the next.
+ *
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
public class Session {
@@ -130,7 +130,7 @@ public class Session {
return this.scheduledExecutorService.schedule(() -> {
logger.info("Session {} has been idle for more than {} milliseconds - preparing to close",
this.session, this.configuredSessionTimeout);
- kill();
+ kill(false);
}, this.configuredSessionTimeout, TimeUnit.MILLISECONDS);
}
@@ -139,20 +139,9 @@ public class Session {
}
/**
- * Stops the session with call to {@link #kill()} but also stops the session expiration call which ensures that
- * the session is only killed once. Calls {@link #manualKill(boolean)} with {@code false}.
- *
- * @deprecated As of release 3.2.4, replaced by {@link #manualKill(boolean)}.
- */
- @Deprecated
- public void manualKill() {
- manualKill(false);
- }
-
- /**
- * Stops the session with call to {@link #kill()} but also stops the session expiration call which ensures that
- * the session is only killed once. See {@link #kill(boolean)} for information on how what "forcing" the session
- * kill will mean.
+ * Stops the session with call to {@link #kill(boolean)} but also stops the session expiration call which ensures
+ * that the session is only killed once. See {@link #kill(boolean)} for information on how what "forcing" the
+ * session kill will mean.
*/
public void manualKill(final boolean force) {
kill.get().cancel(true);
@@ -160,17 +149,6 @@ public class Session {
}
/**
- * Kills the session and rollback any uncommitted changes on transactional graphs. Same as calling
- * {@link #kill(boolean)} with {@code false}.
- *
- * @deprecated As of release 3.2.4, replaced by {@link #kill(boolean)}.
- */
- @Deprecated
- public synchronized void kill() {
- kill(false);
- }
-
- /**
* Kills the session and rollback any uncommitted changes on transactional graphs. When "force" closed, the
* session won't bother to try to submit transaction close commands. It will be up to the underlying graph
* implementation to determine how it will clean up orphaned transactions. The force will try to cancel scheduled
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java
index fe3cc85..99f7d28 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/session/SessionOpProcessor.java
@@ -160,7 +160,7 @@ public class SessionOpProcessor extends AbstractEvalOpProcessor {
@Override
public void close() throws Exception {
- sessions.values().forEach(Session::manualKill);
+ sessions.values().forEach(session -> session.manualKill(false));
}
protected void evalOp(final Context context) throws OpProcessorException {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java
deleted file mode 100644
index 3852ca1..0000000
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerAuthOldIntegrateTest.java
+++ /dev/null
@@ -1,243 +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;
-
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.apache.tinkerpop.gremlin.driver.Client;
-import org.apache.tinkerpop.gremlin.driver.Cluster;
-import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
-import org.apache.tinkerpop.gremlin.driver.ser.Serializers;
-import org.apache.tinkerpop.gremlin.server.auth.SimpleAuthenticator;
-import org.ietf.jgss.GSSException;
-import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeoutException;
-
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- * @deprecated As of release 3.1.1-incubating, replaced by {@link GremlinServerAuthIntegrateTest}
- * @see <a href="https://issues.apache.org/jira/browse/TINKERPOP-981">TINKERPOP-981</a>
- */
-@Deprecated
-public class GremlinServerAuthOldIntegrateTest extends AbstractGremlinServerIntegrationTest {
-
- /**
- * Configure specific Gremlin Server settings for specific tests.
- */
- @Override
- public Settings overrideSettings(final Settings settings) {
- final Settings.AuthenticationSettings authSettings = new Settings.AuthenticationSettings();
- authSettings.className = SimpleAuthenticator.class.getName();
-
- // use a credentials graph with one user in it: stephen/password
- final Map<String,Object> authConfig = new HashMap<>();
- authConfig.put(SimpleAuthenticator.CONFIG_CREDENTIALS_DB, "conf/tinkergraph-empty.properties");
- authConfig.put(SimpleAuthenticator.CONFIG_CREDENTIALS_LOCATION, "data/credentials.kryo");
-
- authSettings.config = authConfig;
- settings.authentication = authSettings;
-
- final String nameOfTest = name.getMethodName();
- switch (nameOfTest) {
- case "shouldAuthenticateOverSslWithPlainText":
- case "shouldFailIfSslEnabledOnServerButNotClient":
- final Settings.SslSettings sslConfig = new Settings.SslSettings();
- sslConfig.enabled = true;
- settings.ssl = sslConfig;
- break;
- }
-
- return settings;
- }
-
- @Test
- public void shouldFailIfSslEnabledOnServerButNotClient() throws Exception {
- final Cluster cluster = TestClientFactory.open();
- final Client client = cluster.connect();
-
- try {
- client.submit("1+1").all().get();
- fail("This should not succeed as the client did not enable SSL");
- } catch(Exception ex) {
- final Throwable root = ExceptionUtils.getRootCause(ex);
- assertEquals(TimeoutException.class, root.getClass());
- assertThat(root.getMessage(), startsWith("Timed out while waiting for an available host"));
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldAuthenticateWithPlainText() throws Exception {
- final Cluster cluster = TestClientFactory.build().credentials("stephen", "password").create();
- final Client client = cluster.connect();
-
- try {
- assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
- assertEquals(3, client.submit("1+2").all().get().get(0).getInt());
- assertEquals(4, client.submit("1+3").all().get().get(0).getInt());
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldAuthenticateOverSslWithPlainText() throws Exception {
- final Cluster cluster = TestClientFactory.build()
- .enableSsl(true)
- .credentials("stephen", "password").create();
- final Client client = cluster.connect();
-
- try {
- assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
- assertEquals(3, client.submit("1+2").all().get().get(0).getInt());
- assertEquals(4, client.submit("1+3").all().get().get(0).getInt());
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldFailAuthenticateWithPlainTextNoCredentials() throws Exception {
- final Cluster cluster = TestClientFactory.open();
- final Client client = cluster.connect();
-
- try {
- client.submit("1+1").all().get();
- fail("This should not succeed as the client did not provide credentials");
- } catch(Exception ex) {
- final Throwable root = ExceptionUtils.getRootCause(ex);
- assertTrue(root instanceof ResponseException || root instanceof GSSException);
-
- // removed this assert as the text of the message changes based on kerberos config - stupid kerberos
- // assertThat(root.getMessage(), startsWith("Invalid name provided"));
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldFailAuthenticateWithPlainTextBadPassword() throws Exception {
- final Cluster cluster = TestClientFactory.build().credentials("stephen", "bad").create();
- final Client client = cluster.connect();
-
- try {
- client.submit("1+1").all().get();
- fail("This should not succeed as the client did not provide valid credentials");
- } catch(Exception ex) {
- final Throwable root = ExceptionUtils.getRootCause(ex);
- assertEquals(ResponseException.class, root.getClass());
- assertEquals("Username and/or password are incorrect", root.getMessage());
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldFailAuthenticateWithPlainTextBadUsername() throws Exception {
- final Cluster cluster = TestClientFactory.build().credentials("marko", "password").create();
- final Client client = cluster.connect();
-
- try {
- client.submit("1+1").all().get();
- } catch(Exception ex) {
- final Throwable root = ExceptionUtils.getRootCause(ex);
- assertEquals(ResponseException.class, root.getClass());
- assertEquals("Username and/or password are incorrect", root.getMessage());
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldAuthenticateWithPlainTextOverJSONSerialization() throws Exception {
- final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON)
- .credentials("stephen", "password").create();
- final Client client = cluster.connect();
-
- try {
- assertEquals(3, client.submit("1+2").all().get().get(0).getInt());
- assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
- assertEquals(4, client.submit("1+3").all().get().get(0).getInt());
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldAuthenticateWithPlainTextOverGraphSONSerialization() throws Exception {
- final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V1D0)
- .credentials("stephen", "password").create();
- final Client client = cluster.connect();
-
- try {
- assertEquals(2, client.submit("1+1").all().get().get(0).getInt());
- assertEquals(3, client.submit("1+2").all().get().get(0).getInt());
- assertEquals(4, client.submit("1+3").all().get().get(0).getInt());
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldAuthenticateAndWorkWithVariablesOverJsonSerialization() throws Exception {
- final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON)
- .credentials("stephen", "password").create();
- final Client client = cluster.connect(name.getMethodName());
-
- try {
- final Vertex vertex = (Vertex) client.submit("v=graph.addVertex(\"name\", \"stephen\")").all().get().get(0).getObject();
- assertEquals("stephen", vertex.value("name"));
-
- final Property vpName = (Property)client.submit("v.property('name')").all().get().get(0).getObject();
- assertEquals("stephen", vpName.value());
- } finally {
- cluster.close();
- }
- }
-
- @Test
- public void shouldAuthenticateAndWorkWithVariablesOverGraphSONSerialization() throws Exception {
- final Cluster cluster = TestClientFactory.build().serializer(Serializers.GRAPHSON_V1D0)
- .credentials("stephen", "password").create();
- final Client client = cluster.connect(name.getMethodName());
-
- try {
- final Map vertex = (Map) client.submit("v=graph.addVertex('name', 'stephen')").all().get().get(0).getObject();
- final Map<String, List<Map>> properties = (Map) vertex.get("properties");
- assertEquals("stephen", properties.get("name").get(0).get("value"));
-
- final Map vpName = (Map)client.submit("v.property('name')").all().get().get(0).getObject();
- assertEquals("stephen", vpName.get("value"));
- } finally {
- cluster.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java
index 9cea2ce..2851cd3 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinServerHttpIntegrateTest.java
@@ -112,10 +112,6 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra
case "should200OnPOSTWithAuthorizationHeader":
configureForAuthentication(settings);
break;
- case "should401OnPOSTWithInvalidPasswordAuthorizationHeaderOld":
- case "should200OnPOSTWithAuthorizationHeaderOld":
- configureForAuthenticationOld(settings);
- break;
}
return settings;
}
@@ -132,20 +128,6 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra
settings.authentication = authSettings;
}
- @Deprecated
- private void configureForAuthenticationOld(final Settings settings) {
- final Settings.AuthenticationSettings authSettings = new Settings.AuthenticationSettings();
- authSettings.className = SimpleAuthenticator.class.getName();
-
- // use a credentials graph with one user in it: stephen/password
- final Map<String,Object> authConfig = new HashMap<>();
- authConfig.put(SimpleAuthenticator.CONFIG_CREDENTIALS_DB, "conf/tinkergraph-empty.properties");
- authConfig.put(SimpleAuthenticator.CONFIG_CREDENTIALS_LOCATION, "data/credentials.kryo");
-
- authSettings.config = authConfig;
- settings.authentication = authSettings;
- }
-
@Test
public void should401OnGETWithNoAuthorizationHeader() throws Exception {
final CloseableHttpClient httpclient = HttpClients.createDefault();
@@ -241,20 +223,6 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra
}
@Test
- @Deprecated
- public void should401OnPOSTWithInvalidPasswordAuthorizationHeaderOld() throws Exception {
- final CloseableHttpClient httpclient = HttpClients.createDefault();
- final HttpPost httppost = new HttpPost(TestClientFactory.createURLString());
- httppost.addHeader("Content-Type", "application/json");
- httppost.addHeader("Authorization", "Basic " + encoder.encodeToString("stephen:not-my-password".getBytes()));
- httppost.setEntity(new StringEntity("{\"gremlin\":\"1-1\"}", Consts.UTF_8));
-
- try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
- assertEquals(401, response.getStatusLine().getStatusCode());
- }
- }
-
- @Test
public void should200OnGETWithAuthorizationHeader() throws Exception {
final CloseableHttpClient httpclient = HttpClients.createDefault();
final HttpGet httpget = new HttpGet(TestClientFactory.createURLString("?gremlin=1-1"));
@@ -287,24 +255,6 @@ public class GremlinServerHttpIntegrateTest extends AbstractGremlinServerIntegra
}
@Test
- @Deprecated
- public void should200OnPOSTWithAuthorizationHeaderOld() throws Exception {
- final CloseableHttpClient httpclient = HttpClients.createDefault();
- final HttpPost httppost = new HttpPost(TestClientFactory.createURLString());
- httppost.addHeader("Content-Type", "application/json");
- httppost.addHeader("Authorization", "Basic " + encoder.encodeToString("stephen:password".getBytes()));
- httppost.setEntity(new StringEntity("{\"gremlin\":\"1-1\"}", Consts.UTF_8));
-
- try (final CloseableHttpResponse response = httpclient.execute(httppost)) {
- assertEquals(200, response.getStatusLine().getStatusCode());
- assertEquals("application/json", response.getEntity().getContentType().getValue());
- final String json = EntityUtils.toString(response.getEntity());
- final JsonNode node = mapper.readTree(json);
- assertEquals(0, node.get("result").get("data").get(0).intValue());
- }
- }
-
- @Test
public void should200OnGETWithGremlinQueryStringArgumentWithBindingsAndFunction() throws Exception {
final CloseableHttpClient httpclient = HttpClients.createDefault();
final HttpGet httpget = new HttpGet(TestClientFactory.createURLString("?gremlin=addItUp(Integer.parseInt(x),Integer.parseInt(y))&bindings.x=10&bindings.y=10"));
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e2d1063e/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticatorTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticatorTest.java
index ff8677e..fe197d8 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticatorTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/auth/SimpleAuthenticatorTest.java
@@ -47,8 +47,8 @@ public class SimpleAuthenticatorTest {
@Test
public void shouldCreateNewPlainTextSaslNegotiator() {
- final Authenticator.SaslNegotiator negotiator1 = authenticator.newSaslNegotiator();
- final Authenticator.SaslNegotiator negotiator2 = authenticator.newSaslNegotiator();
+ final Authenticator.SaslNegotiator negotiator1 = authenticator.newSaslNegotiator(null);
+ final Authenticator.SaslNegotiator negotiator2 = authenticator.newSaslNegotiator(null);
assertNotEquals(negotiator1, negotiator2);
assertNotEquals(negotiator2, negotiator1);
@@ -62,11 +62,10 @@ public class SimpleAuthenticatorTest {
@Test
public void shouldUseTinkerGraphForCredentialsStoreAndSucceed() throws Exception {
final Map<String,Object> config = new HashMap<>();
- config.put(SimpleAuthenticator.CONFIG_CREDENTIALS_DB, "conf/tinkergraph-empty.properties");
- config.put(SimpleAuthenticator.CONFIG_CREDENTIALS_LOCATION, "data/credentials.kryo");
+ config.put(SimpleAuthenticator.CONFIG_CREDENTIALS_DB, "conf/tinkergraph-credentials.properties");
authenticator.setup(config);
- final Authenticator.SaslNegotiator negotiator = authenticator.newSaslNegotiator();
+ final Authenticator.SaslNegotiator negotiator = authenticator.newSaslNegotiator(null);
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
final byte[] nul = new byte[] {0};
stream.write(nul);
@@ -82,11 +81,10 @@ public class SimpleAuthenticatorTest {
@Test(expected = AuthenticationException.class)
public void shouldUseTinkerGraphForCredentialsStoreAndFail() throws Exception {
final Map<String,Object> config = new HashMap<>();
- config.put(SimpleAuthenticator.CONFIG_CREDENTIALS_DB, "conf/tinkergraph-empty.properties");
- config.put(SimpleAuthenticator.CONFIG_CREDENTIALS_LOCATION, "data/credentials.kryo");
+ config.put(SimpleAuthenticator.CONFIG_CREDENTIALS_DB, "conf/tinkergraph-credentials.properties");
authenticator.setup(config);
- final Authenticator.SaslNegotiator negotiator = authenticator.newSaslNegotiator();
+ final Authenticator.SaslNegotiator negotiator = authenticator.newSaslNegotiator(null);
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
final byte[] nul = new byte[] {0};
stream.write(nul);