diff --git a/gremlin/pom.xml b/gremlin/pom.xml index 336c6c48f4..4d5b5e2315 100644 --- a/gremlin/pom.xml +++ b/gremlin/pom.xml @@ -32,11 +32,6 @@ arcadedb-gremlin jar - - 3.5.1 - 5.8.1 - - com.arcadedb @@ -73,7 +68,7 @@ org.junit.vintage junit-vintage-engine - ${junit5.version} + ${junit.jupiter.version} test diff --git a/pom.xml b/pom.xml index 2991a943a3..829b878a67 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ UTF-8 + 3.5.1 1.2.2 3.8.1 0.8.7 diff --git a/server/pom.xml b/server/pom.xml index 4fbd8b9b07..c578941b52 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -86,6 +86,11 @@ ${project.parent.version} compile + + org.apache.tinkerpop + gremlin-server + ${gremlin.version} + io.undertow undertow-core diff --git a/server/src/main/java/com/arcadedb/server/gremlin/GremlinServerPlugin.java b/server/src/main/java/com/arcadedb/server/gremlin/GremlinServerPlugin.java new file mode 100644 index 0000000000..9659f3ca96 --- /dev/null +++ b/server/src/main/java/com/arcadedb/server/gremlin/GremlinServerPlugin.java @@ -0,0 +1,94 @@ +/* + * Copyright © 2021-present Arcade Data Ltd (info@arcadedata.com) + * + * Licensed 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 com.arcadedb.server.gremlin; + +import com.arcadedb.ContextConfiguration; +import com.arcadedb.log.LogManager; +import com.arcadedb.server.ArcadeDBServer; +import com.arcadedb.server.ServerException; +import com.arcadedb.server.ServerPlugin; +import com.arcadedb.server.http.HttpServer; +import io.undertow.server.handlers.PathHandler; +import org.apache.tinkerpop.gremlin.server.GremlinServer; +import org.apache.tinkerpop.gremlin.server.Settings; + +import java.io.*; +import java.lang.reflect.*; +import java.util.logging.*; + +public class GremlinServerPlugin implements ServerPlugin { + private static final String CONFIG_GREMLIN_SERVER_YAML = "/config/gremlin-server.yaml"; + private ArcadeDBServer server; + private ContextConfiguration configuration; + private GremlinServer gremlinServer; + + @Override + public void configure(final ArcadeDBServer arcadeDBServer, final ContextConfiguration configuration) { + this.server = arcadeDBServer; + this.configuration = configuration; + } + + @Override + public void startService() { + Settings settings = null; + final File confFile = new File(server.getRootPath() + CONFIG_GREMLIN_SERVER_YAML); + if (confFile.exists()) { + try (FileInputStream is = new FileInputStream(confFile.getAbsolutePath())) { + settings = Settings.read(is); + } catch (Exception e) { + LogManager.instance() + .log(this, Level.INFO, "Error on loading Gremlin Server configuration file '%s'. Using default configuration", null, CONFIG_GREMLIN_SERVER_YAML); + } + } else + LogManager.instance() + .log(this, Level.INFO, "Cannot find Gremlin Server configuration file '%s'. Using default configuration", null, CONFIG_GREMLIN_SERVER_YAML); + + if (settings == null) + // DEFAULT CONFIGURATION + settings = new Settings(); + + for (String key : configuration.getContextKeys()) { + if (key.startsWith("gremlin.")) { + final Object value = configuration.getValue(key, null); + final String gremlinConfigKey = key.substring("gremlin.".length()); + + try { + final Field field = settings.getClass().getField(gremlinConfigKey); + field.set(settings, value); + } catch (NoSuchFieldException | IllegalAccessException e) { + // IGNORE IT + } + } + } + + gremlinServer = new GremlinServer(settings); + try { + gremlinServer.start(); + } catch (Exception e) { + throw new ServerException("Error on starting GremlinServer plugin", e); + } + } + + @Override + public void stopService() { + if (gremlinServer != null) + gremlinServer.stop(); + } + + @Override + public void registerAPI(HttpServer httpServer, final PathHandler routes) { + } +}