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 2019/05/20 13:12:42 UTC
[tinkerpop] branch master updated: TINKERPOP-2216 add status
attribute for warnings
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/master by this push:
new 848a0fe TINKERPOP-2216 add status attribute for warnings
new 62f69ce Merge pull request #1113 from dalaro/TINKERPOP-2216
848a0fe is described below
commit 848a0fef5240974dd3e43e15d67decec8e16bd8d
Author: Dan LaRocque <da...@hopcount.org>
AuthorDate: Tue May 14 16:26:21 2019 -0500
TINKERPOP-2216 add status attribute for warnings
---
.../apache/tinkerpop/gremlin/console/PluggedIn.groovy | 5 +++++
.../gremlin/console/jsr223/DriverRemoteAcceptor.java | 18 +++++++++++++++++-
.../jsr223/MockGroovyGremlinShellEnvironment.java | 8 ++++++++
.../jsr223/console/GremlinShellEnvironment.java | 4 ++++
.../org/apache/tinkerpop/gremlin/driver/Tokens.java | 15 +++++++++++++++
5 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/PluggedIn.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/PluggedIn.groovy
index e8a3b8a..06b88fd 100644
--- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/PluggedIn.groovy
+++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/PluggedIn.groovy
@@ -100,6 +100,11 @@ class PluggedIn {
}
@Override
+ void errPrintln(final String line) {
+ io.err.println("[warn] " + line);
+ }
+
+ @Override
def <T> T execute(final String line) {
return (T) shell.execute(line)
}
diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
index dd0db46..b56835a 100644
--- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
+++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/jsr223/DriverRemoteAcceptor.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.RequestOptions;
import org.apache.tinkerpop.gremlin.driver.Result;
import org.apache.tinkerpop.gremlin.driver.ResultSet;
+import org.apache.tinkerpop.gremlin.driver.Tokens;
import org.apache.tinkerpop.gremlin.driver.exception.ResponseException;
import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
import org.apache.tinkerpop.gremlin.jsr223.console.GremlinShellEnvironment;
@@ -213,7 +214,22 @@ public class DriverRemoteAcceptor implements RemoteAcceptor {
if (timeout > NO_TIMEOUT)
options.timeout(timeout);
- return this.currentClient.submit(gremlin, options.create()).all().get();
+ ResultSet rs = this.currentClient.submit(gremlin, options.create());
+ List<Result> results = rs.all().get();
+ Map<String, Object> statusAttributes = rs.statusAttributes().getNow(null);
+
+ // Check for and print warnings
+ if (null != statusAttributes && statusAttributes.containsKey(Tokens.STATUS_ATTRIBUTE_WARNINGS)) {
+ Object warningAttributeObject = statusAttributes.get(Tokens.STATUS_ATTRIBUTE_WARNINGS);
+ if (warningAttributeObject instanceof List) {
+ for (Object warningListItem : (List<?>)warningAttributeObject)
+ shellEnvironment.errPrintln(String.valueOf(warningListItem));
+ } else {
+ shellEnvironment.errPrintln(String.valueOf(warningAttributeObject));
+ }
+ }
+
+ return results;
} catch (Exception e) {
// handle security error as-is and unwrapped
final Optional<Throwable> throwable = Stream.of(ExceptionUtils.getThrowables(e)).filter(t -> t instanceof SaslException).findFirst();
diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/MockGroovyGremlinShellEnvironment.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/MockGroovyGremlinShellEnvironment.java
index 6184b54..e24b77c 100644
--- a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/MockGroovyGremlinShellEnvironment.java
+++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/jsr223/MockGroovyGremlinShellEnvironment.java
@@ -58,6 +58,14 @@ public class MockGroovyGremlinShellEnvironment implements GremlinShellEnvironmen
}
@Override
+ public void errPrintln(final String line) {
+ if (null == io)
+ groovysh.getIo().err.println("[warn]" + line);
+ else
+ io.err.println("[warn]" + line);
+ }
+
+ @Override
public <T> T execute(final String line) {
return (T) groovysh.execute(line);
}
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java
index 6fc1363..8763d42 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/console/GremlinShellEnvironment.java
@@ -33,5 +33,9 @@ public interface GremlinShellEnvironment {
public void println(final String line);
+ public default void errPrintln(final String line) {
+ println(line);
+ }
+
public <T> T execute(final String line);
}
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
index 0a8b4d0..df84de0 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Tokens.java
@@ -60,4 +60,19 @@ public final class Tokens {
public static final String STATUS_ATTRIBUTE_EXCEPTIONS = "exceptions";
public static final String STATUS_ATTRIBUTE_STACK_TRACE = "stackTrace";
+ /**
+ * A {@link ResultSet#statusAttributes()} key for user-facing warnings.
+ * <p>
+ * Implementations that set this key should consider using one of
+ * these two recommended value types:
+ * <ul>
+ * <li>A {@link java.util.List} implementation containing
+ * references for which {@link String#valueOf(Object)} produces
+ * a meaningful return value. For example, a list of strings.</li>
+ * <li>Otherwise, any single non-list object for which
+ * {@link String#valueOf(Object)} produces a meaningful return value.
+ * For example, a string.</li>
+ * </ul>
+ */
+ public static final String STATUS_ATTRIBUTE_WARNINGS = "warnings";
}