From 77977ff9093de337fb8a791b4980aac766a34fb4 Mon Sep 17 00:00:00 2001 From: Michele Rastelli Date: Tue, 25 Apr 2023 14:25:36 +0200 Subject: [PATCH] serverId query parameter for /_admin/log/level --- src/main/java/com/arangodb/ArangoDB.java | 22 ++++++++++--- .../com/arangodb/async/ArangoDBAsync.java | 32 ++++++++++++++++--- .../async/internal/ArangoDBAsyncImpl.java | 24 ++++++++++---- .../com/arangodb/internal/ArangoDBImpl.java | 19 +++++++---- .../arangodb/internal/InternalArangoDB.java | 8 +++-- .../com/arangodb/model/LogLevelOptions.java | 14 ++++++++ src/test/java/com/arangodb/ArangoDBTest.java | 19 +++++++++++ .../java/com/arangodb/async/ArangoDBTest.java | 18 +++++++++++ 8 files changed, 133 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/arangodb/model/LogLevelOptions.java diff --git a/src/main/java/com/arangodb/ArangoDB.java b/src/main/java/com/arangodb/ArangoDB.java index 746a4f23f..0b069a630 100644 --- a/src/main/java/com/arangodb/ArangoDB.java +++ b/src/main/java/com/arangodb/ArangoDB.java @@ -38,10 +38,7 @@ import com.arangodb.internal.util.DefaultArangoSerialization; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; -import com.arangodb.model.DBCreateOptions; -import com.arangodb.model.LogOptions; -import com.arangodb.model.UserCreateOptions; -import com.arangodb.model.UserUpdateOptions; +import com.arangodb.model.*; import com.arangodb.util.*; import com.arangodb.velocypack.VPack; import com.arangodb.velocypack.VPackAnnotationFieldFilter; @@ -1036,6 +1033,14 @@ default Boolean createDatabase(String name) throws ArangoDBException { */ LogLevelEntity getLogLevel() throws ArangoDBException; + /** + * Returns the server's current loglevel settings. + * + * @return the server's current loglevel settings + * @since ArangoDB 3.10 + */ + LogLevelEntity getLogLevel(LogLevelOptions options) throws ArangoDBException; + /** * Modifies and returns the server's current loglevel settings. * @@ -1046,6 +1051,15 @@ default Boolean createDatabase(String name) throws ArangoDBException { */ LogLevelEntity setLogLevel(LogLevelEntity entity) throws ArangoDBException; + /** + * Modifies and returns the server's current loglevel settings. + * + * @param entity loglevel settings + * @return the server's current loglevel settings + * @since ArangoDB 3.10 + */ + LogLevelEntity setLogLevel(LogLevelEntity entity, LogLevelOptions options) throws ArangoDBException; + /** * @return the list of available rules and their respective flags * @throws ArangoDBException diff --git a/src/main/java/com/arangodb/async/ArangoDBAsync.java b/src/main/java/com/arangodb/async/ArangoDBAsync.java index 544131762..287cf1a22 100644 --- a/src/main/java/com/arangodb/async/ArangoDBAsync.java +++ b/src/main/java/com/arangodb/async/ArangoDBAsync.java @@ -37,10 +37,7 @@ import com.arangodb.internal.util.DefaultArangoSerialization; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstConnectionFactorySync; -import com.arangodb.model.DBCreateOptions; -import com.arangodb.model.LogOptions; -import com.arangodb.model.UserCreateOptions; -import com.arangodb.model.UserUpdateOptions; +import com.arangodb.model.*; import com.arangodb.util.ArangoDeserializer; import com.arangodb.util.ArangoSerialization; import com.arangodb.util.ArangoSerializer; @@ -197,6 +194,16 @@ default CompletableFuture createDatabase(final String name) { */ CompletableFuture getRole(); + /** + * Returns the id of a server in a cluster. + * + * @return the server id + * @throws ArangoDBException + * @see API + * Documentation + */ + CompletableFuture getServerId() throws ArangoDBException; + /** * Create a new user. This user will not have access to any database. You need permission to the _system database in * order to execute this call. @@ -331,6 +338,14 @@ default CompletableFuture createDatabase(final String name) { */ CompletableFuture getLogLevel(); + /** + * Returns the server's current loglevel settings. + * + * @return the server's current loglevel settings + * @since ArangoDB 3.10 + */ + CompletableFuture getLogLevel(final LogLevelOptions options); + /** * Modifies and returns the server's current loglevel settings. * @@ -339,6 +354,15 @@ default CompletableFuture createDatabase(final String name) { */ CompletableFuture setLogLevel(final LogLevelEntity entity); + /** + * Modifies and returns the server's current loglevel settings. + * + * @param entity loglevel settings + * @return the server's current loglevel settings + * @since ArangoDB 3.10 + */ + CompletableFuture setLogLevel(final LogLevelEntity entity, final LogLevelOptions options); + /** * @return the list of available rules and their respective flags * @since ArangoDB 3.10 diff --git a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java index 86775bbcf..cbda81c28 100644 --- a/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java +++ b/src/main/java/com/arangodb/async/internal/ArangoDBAsyncImpl.java @@ -37,10 +37,7 @@ import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; import com.arangodb.internal.velocystream.internal.VstConnectionSync; -import com.arangodb.model.DBCreateOptions; -import com.arangodb.model.LogOptions; -import com.arangodb.model.UserCreateOptions; -import com.arangodb.model.UserUpdateOptions; +import com.arangodb.model.*; import com.arangodb.velocypack.Type; import com.arangodb.velocystream.Request; import com.arangodb.velocystream.Response; @@ -168,6 +165,11 @@ public CompletableFuture getRole() { return executor.execute(getRoleRequest(), getRoleResponseDeserializer()); } + @Override + public CompletableFuture getServerId() { + return executor.execute(getServerIdRequest(), getServerIdResponseDeserializer()); + } + @Override public CompletableFuture createUser(final String user, final String passwd) { return executor.execute(createUserRequest(db().dbName(), user, passwd, new UserCreateOptions()), @@ -234,12 +236,22 @@ public CompletableFuture getLogEntries(final LogOptions option @Override public CompletableFuture getLogLevel() { - return executor.execute(getLogLevelRequest(), LogLevelEntity.class); + return getLogLevel(new LogLevelOptions()); + } + + @Override + public CompletableFuture getLogLevel(final LogLevelOptions options) { + return executor.execute(getLogLevelRequest(options), LogLevelEntity.class); } @Override public CompletableFuture setLogLevel(final LogLevelEntity entity) { - return executor.execute(setLogLevelRequest(entity), LogLevelEntity.class); + return setLogLevel(entity, new LogLevelOptions()); + } + + @Override + public CompletableFuture setLogLevel(final LogLevelEntity entity, final LogLevelOptions options) { + return executor.execute(setLogLevelRequest(entity, options), LogLevelEntity.class); } @Override diff --git a/src/main/java/com/arangodb/internal/ArangoDBImpl.java b/src/main/java/com/arangodb/internal/ArangoDBImpl.java index 1c00cc6d2..c51ee93d4 100644 --- a/src/main/java/com/arangodb/internal/ArangoDBImpl.java +++ b/src/main/java/com/arangodb/internal/ArangoDBImpl.java @@ -32,10 +32,7 @@ import com.arangodb.internal.util.ArangoSerializationFactory.Serializer; import com.arangodb.internal.velocystream.VstCommunicationSync; import com.arangodb.internal.velocystream.VstProtocol; -import com.arangodb.model.DBCreateOptions; -import com.arangodb.model.LogOptions; -import com.arangodb.model.UserCreateOptions; -import com.arangodb.model.UserUpdateOptions; +import com.arangodb.model.*; import com.arangodb.util.ArangoCursorInitializer; import com.arangodb.util.ArangoSerialization; import com.arangodb.velocypack.Type; @@ -262,12 +259,22 @@ public LogEntriesEntity getLogEntries(final LogOptions options) throws ArangoDBE @Override public LogLevelEntity getLogLevel() throws ArangoDBException { - return executor.execute(getLogLevelRequest(), LogLevelEntity.class); + return getLogLevel(new LogLevelOptions()); + } + + @Override + public LogLevelEntity getLogLevel(final LogLevelOptions options) throws ArangoDBException { + return executor.execute(getLogLevelRequest(options), LogLevelEntity.class); } @Override public LogLevelEntity setLogLevel(final LogLevelEntity entity) throws ArangoDBException { - return executor.execute(setLogLevelRequest(entity), LogLevelEntity.class); + return setLogLevel(entity, new LogLevelOptions()); + } + + @Override + public LogLevelEntity setLogLevel(final LogLevelEntity entity, final LogLevelOptions options) { + return executor.execute(setLogLevelRequest(entity, options), LogLevelEntity.class); } @Override diff --git a/src/main/java/com/arangodb/internal/InternalArangoDB.java b/src/main/java/com/arangodb/internal/InternalArangoDB.java index c88c823a1..f97323648 100644 --- a/src/main/java/com/arangodb/internal/InternalArangoDB.java +++ b/src/main/java/com/arangodb/internal/InternalArangoDB.java @@ -189,12 +189,14 @@ protected Request getLogEntriesRequest(final LogOptions options) { .putQueryParam(LogOptions.PROPERTY_SORT, params.getSort()); } - protected Request getLogLevelRequest() { - return request(DbName.SYSTEM, RequestType.GET, PATH_API_ADMIN_LOG_LEVEL); + protected Request getLogLevelRequest(final LogLevelOptions options) { + return request(DbName.SYSTEM, RequestType.GET, PATH_API_ADMIN_LOG_LEVEL) + .putQueryParam("serverId", options.getServerId()); } - protected Request setLogLevelRequest(final LogLevelEntity entity) { + protected Request setLogLevelRequest(final LogLevelEntity entity, final LogLevelOptions options) { return request(DbName.SYSTEM, RequestType.PUT, PATH_API_ADMIN_LOG_LEVEL) + .putQueryParam("serverId", options.getServerId()) .setBody(util().serialize(entity)); } diff --git a/src/main/java/com/arangodb/model/LogLevelOptions.java b/src/main/java/com/arangodb/model/LogLevelOptions.java new file mode 100644 index 000000000..9ce6ca52e --- /dev/null +++ b/src/main/java/com/arangodb/model/LogLevelOptions.java @@ -0,0 +1,14 @@ +package com.arangodb.model; + +public class LogLevelOptions { + private String serverId; + + public String getServerId() { + return serverId; + } + + public LogLevelOptions serverId(final String serverId) { + this.serverId = serverId; + return this; + } +} diff --git a/src/test/java/com/arangodb/ArangoDBTest.java b/src/test/java/com/arangodb/ArangoDBTest.java index 0a1feb228..040f2dc5a 100644 --- a/src/test/java/com/arangodb/ArangoDBTest.java +++ b/src/test/java/com/arangodb/ArangoDBTest.java @@ -644,6 +644,25 @@ void setAllLogLevel(ArangoDB arangoDB) { } } + @ParameterizedTest(name = "{index}") + @MethodSource("arangos") + void logLevelWithServerId(ArangoDB arangoDB) { + assumeTrue(isAtLeastVersion(3, 10)); + assumeTrue(isCluster()); + String serverId = arangoDB.getServerId(); + LogLevelOptions options = new LogLevelOptions().serverId(serverId); + final LogLevelEntity entity = new LogLevelEntity(); + try { + entity.setGraphs(LogLevelEntity.LogLevel.ERROR); + final LogLevelEntity logLevel = arangoDB.setLogLevel(entity, options); + assertThat(logLevel.getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR); + assertThat(arangoDB.getLogLevel(options).getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR); + } finally { + entity.setGraphs(LogLevelEntity.LogLevel.INFO); + arangoDB.setLogLevel(entity); + } + } + @ParameterizedTest(name = "{index}") @MethodSource("arangos") void getQueryOptimizerRules(ArangoDB arangoDB) { diff --git a/src/test/java/com/arangodb/async/ArangoDBTest.java b/src/test/java/com/arangodb/async/ArangoDBTest.java index 2ba37dc57..52c94af39 100644 --- a/src/test/java/com/arangodb/async/ArangoDBTest.java +++ b/src/test/java/com/arangodb/async/ArangoDBTest.java @@ -636,6 +636,24 @@ void setLogLevel() throws InterruptedException, ExecutionException { } } + @Test + void logLevelWithServerId() throws InterruptedException, ExecutionException { + assumeTrue(isAtLeastVersion(3, 10)); + assumeTrue(isCluster()); + String serverId = arangoDB.getServerId().get(); + LogLevelOptions options = new LogLevelOptions().serverId(serverId); + final LogLevelEntity entity = new LogLevelEntity(); + try { + entity.setGraphs(LogLevelEntity.LogLevel.ERROR); + final LogLevelEntity logLevel = arangoDB.setLogLevel(entity, options).get(); + assertThat(logLevel.getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR); + assertThat(arangoDB.getLogLevel(options).get().getGraphs()).isEqualTo(LogLevelEntity.LogLevel.ERROR); + } finally { + entity.setGraphs(LogLevelEntity.LogLevel.INFO); + arangoDB.setLogLevel(entity); + } + } + @Test void queueTime() throws InterruptedException, ExecutionException { List>> reqs = IntStream.range(0, 80)