Skip to content

Commit f6f2e5f

Browse files
committed
added role awareness
1 parent 38185aa commit f6f2e5f

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

src/main/java/com/arangodb/ArangoDB.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import javax.net.ssl.SSLContext;
3232

3333
import com.arangodb.entity.ArangoDBVersion;
34+
import com.arangodb.entity.ArangoDBRole;
3435
import com.arangodb.entity.LogEntity;
3536
import com.arangodb.entity.LogLevelEntity;
3637
import com.arangodb.entity.UserEntity;
@@ -453,6 +454,18 @@ public ArangoDBVersion getVersion() throws ArangoDBException {
453454
return db().getVersion();
454455
}
455456

457+
/**
458+
* Returns the server role.
459+
*
460+
* @see <a href="https://docs.arangodb.com/current/HTTP/MiscellaneousFunctions/index.html#return-server-version">API
461+
* Documentation</a>
462+
* @return the server role
463+
* @throws ArangoDBException
464+
*/
465+
public ArangoDBRole getRole() throws ArangoDBException {
466+
return db().getRole();
467+
}
468+
456469
/**
457470
* Create a new user. This user will not have access to any database. You need permission to the _system database in
458471
* order to execute this call.

src/main/java/com/arangodb/ArangoDatabase.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.arangodb.entity.AqlFunctionEntity;
2828
import com.arangodb.entity.AqlParseEntity;
2929
import com.arangodb.entity.ArangoDBVersion;
30+
import com.arangodb.entity.ArangoDBRole;
3031
import com.arangodb.entity.CollectionEntity;
3132
import com.arangodb.entity.CursorEntity;
3233
import com.arangodb.entity.DatabaseEntity;
@@ -87,6 +88,18 @@ public ArangoDBVersion getVersion() throws ArangoDBException {
8788
return executor.execute(getVersionRequest(), ArangoDBVersion.class);
8889
}
8990

91+
/**
92+
* Returns the server name and version number.
93+
*
94+
* @see <a href="https://docs.arangodb.com/current/HTTP/MiscellaneousFunctions/index.html#return-server-version">API
95+
* Documentation</a>
96+
* @return the server version, number
97+
* @throws ArangoDBException
98+
*/
99+
public ArangoDBRole getRole() throws ArangoDBException {
100+
return executor.execute(getRoleRequest(), ArangoDBRole.class);
101+
}
102+
90103
/**
91104
* Retrieves a list of all databases the current user can access
92105
*

src/main/java/com/arangodb/internal/ArangoDBConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class ArangoDBConstants {
6161
public static final String PATH_API_ADMIN_LOG_LEVEL = "/_admin/log/level";
6262
public static final String PATH_API_ADMIN_ROUTING_RELOAD = "/_admin/routing/reload";
6363
public static final String PATH_API_IMPORT = "/_api/import";
64+
public static final String PATH_API_ROLE = "_admin/server/role";
6465

6566
public static final String ENCRYPTION_PLAIN = "plain";
6667

src/main/java/com/arangodb/internal/InternalArangoDatabase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ protected Request getVersionRequest() {
9292
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_VERSION);
9393
}
9494

95+
protected Request getRoleRequest() {
96+
return new Request(name, RequestType.GET, ArangoDBConstants.PATH_API_ROLE);
97+
}
98+
9599
protected Request createCollectionRequest(final String name, final CollectionCreateOptions options) {
96100
return new Request(name(), RequestType.POST, ArangoDBConstants.PATH_API_COLLECTION).setBody(
97101
executor.serialize(OptionsBuilder.build(options != null ? options : new CollectionCreateOptions(), name)));

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.arangodb.entity.AqlParseEntity;
5050
import com.arangodb.entity.AqlParseEntity.AstNode;
5151
import com.arangodb.entity.ArangoDBVersion;
52+
import com.arangodb.entity.ArangoDBRole;
5253
import com.arangodb.entity.BaseDocument;
5354
import com.arangodb.entity.BaseEdgeDocument;
5455
import com.arangodb.entity.CollectionEntity;
@@ -124,6 +125,9 @@ public void deleteCollection() {
124125

125126
@Test
126127
public void deleteSystemCollection() {
128+
if (db.getRole().getRole() == "COORDINATOR") {
129+
return;
130+
}
127131
final String name = "_system_test";
128132
db.createCollection(name, new CollectionCreateOptions().isSystem(true));
129133
db.collection(name).drop(true);
@@ -136,6 +140,9 @@ public void deleteSystemCollection() {
136140

137141
@Test
138142
public void deleteSystemCollectionFail() {
143+
if (db.getRole().getRole() == "COORDINATOR") {
144+
return;
145+
}
139146
final String name = "_system_test";
140147
db.createCollection(name, new CollectionCreateOptions().isSystem(true));
141148
try {

0 commit comments

Comments
 (0)