Visitar URL original
fix and improve plugin managements · ArcadeData/arcadedb@b0e7a67 · GitHub
Skip to content

Commit b0e7a67

Browse files
committed
fix and improve plugin managements
1 parent 8400f61 commit b0e7a67

12 files changed

Lines changed: 214 additions & 157 deletions

File tree

‎engine/pom.xml‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@
157157
<artifactId>antlr4-runtime</artifactId>
158158
<version>${antlr4.version}</version>
159159
</dependency>
160-
<dependency>
161-
<groupId>org.slf4j</groupId>
162-
<artifactId>slf4j-jdk14</artifactId>
163-
<version>${slf4j.version}</version>
164-
</dependency>
165160
<dependency>
166161
<groupId>org.graalvm.sdk</groupId>
167162
<artifactId>graal-sdk</artifactId>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.arcadedb.metrics.prometheus.PrometheusMetricsPlugin

‎metrics/src/test/java/com/arcadedb/metrics/prometheus/PrometheusMetricsPluginNotAuthenticatedTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PrometheusMetricsPluginNotAuthenticatedTest extends BaseGraphServerTest {
3737
public void setTestConfiguration() {
3838
super.setTestConfiguration();
3939
System.setProperty("arcadedb.serverMetrics.prometheus.requireAuthentication", "false");
40-
GlobalConfiguration.SERVER_PLUGINS.setValue("Prometheus:com.arcadedb.metrics.prometheus.PrometheusMetricsPlugin");
40+
GlobalConfiguration.SERVER_PLUGINS.setValue("PrometheusMetricsPlugin");
4141
}
4242

4343
@AfterEach

‎package/src/main/assembly/full.xml‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,23 @@
109109
<exclude>com.arcadedb:arcadedb-mongodbw</exclude>
110110
<exclude>com.arcadedb:arcadedb-redisw</exclude>
111111
<exclude>com.arcadedb:arcadedb-grpcw</exclude>
112+
<exclude>com.arcadedb:arcadedb-graphql</exclude>
113+
<exclude>com.arcadedb:arcadedb-studio</exclude>
114+
<exclude>com.arcadedb:arcadedb-metrics</exclude>
112115
</excludes>
113116
</dependencySet>
114117
<!-- Plugin modules in separate directory -->
115118
<dependencySet>
116119
<outputDirectory>lib/plugins</outputDirectory>
117120
<includes>
118-
<include>com.arcadedb:arcadedb-gremlin</include>
119-
<include>com.arcadedb:arcadedb-postgresw</include>
120-
<include>com.arcadedb:arcadedb-mongodbw</include>
121-
<include>com.arcadedb:arcadedb-redisw</include>
122-
<include>com.arcadedb:arcadedb-grpcw</include>
121+
<exclude>com.arcadedb:arcadedb-gremlin</exclude>
122+
<exclude>com.arcadedb:arcadedb-postgresw</exclude>
123+
<exclude>com.arcadedb:arcadedb-mongodbw</exclude>
124+
<exclude>com.arcadedb:arcadedb-redisw</exclude>
125+
<exclude>com.arcadedb:arcadedb-grpcw</exclude>
126+
<exclude>com.arcadedb:arcadedb-graphql</exclude>
127+
<exclude>com.arcadedb:arcadedb-studio</exclude>
128+
<exclude>com.arcadedb:arcadedb-metrics</exclude>
123129
</includes>
124130
<useTransitiveDependencies>false</useTransitiveDependencies>
125131
</dependencySet>

‎package/src/main/assembly/headless.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<exclude>com.arcadedb:arcadedb-grpcw</exclude>
111111
<exclude>com.arcadedb:arcadedb-graphql</exclude>
112112
<exclude>com.arcadedb:arcadedb-studio</exclude>
113+
<exclude>com.arcadedb:arcadedb-metrics</exclude>
113114
</excludes>
114115
</dependencySet>
115116
<!-- Plugin modules in separate directory -->

‎package/src/main/assembly/minimal.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<exclude>com.arcadedb:arcadedb-redisw</exclude>
110110
<exclude>com.arcadedb:arcadedb-grpcw</exclude>
111111
<exclude>com.arcadedb:arcadedb-graphql</exclude>
112+
<exclude>com.arcadedb:arcadedb-metrics</exclude>
112113
</excludes>
113114
</dependencySet>
114115
<!-- Plugin modules in separate directory -->

‎pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@
411411
</build>
412412

413413
<dependencies>
414+
<dependency>
415+
<groupId>org.slf4j</groupId>
416+
<artifactId>slf4j-jdk14</artifactId>
417+
<version>${slf4j.version}</version>
418+
</dependency>
414419
<dependency>
415420
<groupId>org.junit.jupiter</groupId>
416421
<artifactId>junit-jupiter</artifactId>

‎server/src/main/java/com/arcadedb/server/ArcadeDBServer.java‎

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
import com.arcadedb.server.ha.HAServer;
4040
import com.arcadedb.server.ha.ReplicatedDatabase;
4141
import com.arcadedb.server.http.HttpServer;
42+
import com.arcadedb.server.plugin.PluginManager;
4243
import com.arcadedb.server.security.ServerSecurity;
4344
import com.arcadedb.server.security.ServerSecurityException;
4445
import com.arcadedb.server.security.ServerSecurityUser;
45-
import com.arcadedb.server.plugin.PluginManager;
4646
import com.arcadedb.utility.CodeUtils;
4747
import com.arcadedb.utility.FileUtils;
4848
import com.arcadedb.utility.ServerPathUtils;
@@ -59,7 +59,15 @@
5959
import java.io.IOException;
6060
import java.io.InputStream;
6161
import java.lang.reflect.InvocationTargetException;
62-
import java.util.*;
62+
import java.util.ArrayList;
63+
import java.util.Collection;
64+
import java.util.Collections;
65+
import java.util.LinkedHashMap;
66+
import java.util.LinkedHashSet;
67+
import java.util.List;
68+
import java.util.Locale;
69+
import java.util.Map;
70+
import java.util.Set;
6371
import java.util.concurrent.ConcurrentHashMap;
6472
import java.util.concurrent.ConcurrentMap;
6573
import java.util.logging.Level;
@@ -77,15 +85,13 @@ public enum STATUS {OFFLINE, STARTING, ONLINE, SHUTTING_DOWN}
7785
private String hostAddress;
7886
private final boolean replicationLifecycleEventsEnabled;
7987
private FileServerEventLog eventLog;
80-
private final Map<String, ServerPlugin> plugins =
81-
new LinkedHashMap<>();
88+
private final Map<String, ServerPlugin> plugins = new LinkedHashMap<>();
8289
private PluginManager pluginManager;
8390
private String serverRootPath;
8491
private HAServer haServer;
8592
private ServerSecurity security;
8693
private HttpServer httpServer;
87-
private final ConcurrentMap<String, ServerDatabase> databases =
88-
new ConcurrentHashMap<>();
94+
private final ConcurrentMap<String, ServerDatabase> databases = new ConcurrentHashMap<>();
8995
private final List<ReplicationCallback> testEventListeners = new ArrayList<>();
9096
private volatile STATUS status = STATUS.OFFLINE;
9197
// private ServerMonitor serverMonitor;
@@ -175,8 +181,8 @@ public synchronized void start() {
175181
// START HTTP SERVER IMMEDIATELY. THE HTTP ADDRESS WILL BE USED BY HA
176182
httpServer = new HttpServer(this);
177183

178-
registerPlugins(ServerPlugin.INSTALLATION_PRIORITY.BEFORE_HTTP_ON);
179-
pluginManager.startPlugins(ServerPlugin.INSTALLATION_PRIORITY.BEFORE_HTTP_ON);
184+
// registerPlugins(ServerPlugin.PluginInstallationPriority.BEFORE_HTTP_ON);
185+
pluginManager.startPlugins(ServerPlugin.PluginInstallationPriority.BEFORE_HTTP_ON);
180186

181187
httpServer.startService();
182188

@@ -185,16 +191,16 @@ public synchronized void start() {
185191
haServer.startService();
186192
}
187193

188-
registerPlugins(ServerPlugin.INSTALLATION_PRIORITY.AFTER_HTTP_ON);
189-
pluginManager.startPlugins(ServerPlugin.INSTALLATION_PRIORITY.AFTER_HTTP_ON);
194+
// registerPlugins(ServerPlugin.PluginInstallationPriority.AFTER_HTTP_ON);
195+
pluginManager.startPlugins(ServerPlugin.PluginInstallationPriority.AFTER_HTTP_ON);
190196

191197
loadDefaultDatabases();
192198

193199
// RELOAD DATABASE IF A PLUGIN REGISTERED A NEW DATABASE (LIKE THE GREMLIN SERVER)
194200
loadDatabases();
195201

196-
registerPlugins(ServerPlugin.INSTALLATION_PRIORITY.AFTER_DATABASES_OPEN);
197-
pluginManager.startPlugins(ServerPlugin.INSTALLATION_PRIORITY.AFTER_DATABASES_OPEN);
202+
// registerPlugins(ServerPlugin.PluginInstallationPriority.AFTER_DATABASES_OPEN);
203+
pluginManager.startPlugins(ServerPlugin.PluginInstallationPriority.AFTER_DATABASES_OPEN);
198204

199205
status = STATUS.ONLINE;
200206

@@ -293,7 +299,7 @@ private Set<String> getAllPluginNames() {
293299
return result;
294300
}
295301

296-
private void registerPlugins(final ServerPlugin.INSTALLATION_PRIORITY installationPriority) {
302+
private void registerPlugins(final ServerPlugin.PluginInstallationPriority installationPriority) {
297303
final String registeredPlugins = configuration.getValueAsString(GlobalConfiguration.SERVER_PLUGINS);
298304
if (registeredPlugins != null && !registeredPlugins.isEmpty()) {
299305
final String[] pluginEntries = registeredPlugins.split(",");
@@ -495,7 +501,7 @@ public String toString() {
495501
}
496502

497503
public ServerDatabase getDatabase(final String databaseName, final boolean createIfNotExists,
498-
final boolean allowLoad) {
504+
final boolean allowLoad) {
499505
if (databaseName == null || databaseName.trim().isEmpty())
500506
throw new IllegalArgumentException("Invalid database name " + databaseName);
501507

@@ -516,7 +522,7 @@ public ServerDatabase getDatabase(final String databaseName, final boolean creat
516522

517523
ComponentFile.MODE defaultDbMode =
518524
configuration.getValueAsEnum(GlobalConfiguration.SERVER_DEFAULT_DATABASE_MODE,
519-
ComponentFile.MODE.class);
525+
ComponentFile.MODE.class);
520526
if (defaultDbMode == null)
521527
defaultDbMode = READ_WRITE;
522528

@@ -613,46 +619,46 @@ private void loadDefaultDatabases() {
613619
final String commandParams = command.substring(commandSeparator + 1);
614620

615621
switch (commandType) {
616-
case "restore":
617-
// DROP THE DATABASE BECAUSE THE RESTORE OPERATION WILL TAKE CARE OF CREATING A NEW DATABASE
618-
if (database != null) {
619-
((DatabaseInternal) database).getEmbedded().drop();
620-
databases.remove(dbName);
621-
}
622-
final String dbPath =
623-
configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + File.separator + dbName;
622+
case "restore":
623+
// DROP THE DATABASE BECAUSE THE RESTORE OPERATION WILL TAKE CARE OF CREATING A NEW DATABASE
624+
if (database != null) {
625+
((DatabaseInternal) database).getEmbedded().drop();
626+
databases.remove(dbName);
627+
}
628+
final String dbPath =
629+
configuration.getValueAsString(GlobalConfiguration.SERVER_DATABASE_DIRECTORY) + File.separator + dbName;
624630
// new Restore(commandParams, dbPath).restoreDatabase();
625631

626-
try {
627-
final Class<?> clazz = Class.forName("com.arcadedb.integration.restore.Restore");
628-
final Object restorer = clazz.getConstructor(String.class, String.class).newInstance(commandParams,
629-
dbPath);
632+
try {
633+
final Class<?> clazz = Class.forName("com.arcadedb.integration.restore.Restore");
634+
final Object restorer = clazz.getConstructor(String.class, String.class).newInstance(commandParams,
635+
dbPath);
630636

631-
clazz.getMethod("restoreDatabase").invoke(restorer);
637+
clazz.getMethod("restoreDatabase").invoke(restorer);
632638

633-
} catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
634-
InstantiationException e) {
635-
throw new CommandExecutionException("Error on restoring database, restore libs not found in " +
636-
"classpath", e);
637-
} catch (final InvocationTargetException e) {
638-
throw new CommandExecutionException("Error on restoring database", e.getTargetException());
639-
}
639+
} catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
640+
InstantiationException e) {
641+
throw new CommandExecutionException("Error on restoring database, restore libs not found in " +
642+
"classpath", e);
643+
} catch (final InvocationTargetException e) {
644+
throw new CommandExecutionException("Error on restoring database", e.getTargetException());
645+
}
640646

641-
getDatabase(dbName);
642-
break;
647+
getDatabase(dbName);
648+
break;
643649

644-
case "import":
645-
if (database == null) {
646-
// CREATE THE DATABASE
647-
LogManager.instance().log(this, Level.INFO, "Creating default database '%s'...", null, dbName);
648-
database = createDatabase(dbName, defaultDbMode);
649-
}
650-
database.command("sql", "import database " + commandParams);
651-
break;
650+
case "import":
651+
if (database == null) {
652+
// CREATE THE DATABASE
653+
LogManager.instance().log(this, Level.INFO, "Creating default database '%s'...", null, dbName);
654+
database = createDatabase(dbName, defaultDbMode);
655+
}
656+
database.command("sql", "import database " + commandParams);
657+
break;
652658

653-
default:
654-
LogManager.instance().log(this, Level.SEVERE, "Unsupported command %s in startup command: '%s'", null
655-
, commandType);
659+
default:
660+
LogManager.instance().log(this, Level.SEVERE, "Unsupported command %s in startup command: '%s'", null
661+
, commandType);
656662
}
657663
}
658664
} else {
@@ -693,7 +699,7 @@ private void parseCredentials(final String dbName, final String credentials) {
693699
user = security.authenticate(userName, userPassword, dbName);
694700

695701
// UPDATE DB LIST + GROUP
696-
user.addDatabase(dbName, new String[]{userGroup});
702+
user.addDatabase(dbName, new String[] { userGroup });
697703
security.saveUsers();
698704

699705
} catch (final ServerSecurityException e) {
@@ -704,7 +710,7 @@ private void parseCredentials(final String dbName, final String credentials) {
704710
}
705711
} else {
706712
// UPDATE DB LIST
707-
user.addDatabase(dbName, new String[]{userGroup});
713+
user.addDatabase(dbName, new String[] { userGroup });
708714
security.saveUsers();
709715
}
710716
} else {
@@ -715,7 +721,7 @@ private void parseCredentials(final String dbName, final String credentials) {
715721

716722
// UPDATE DB LIST + GROUP
717723
ServerSecurityUser user = security.getUser(userName);
718-
user.addDatabase(dbName, new String[]{userGroup});
724+
user.addDatabase(dbName, new String[] { userGroup });
719725
security.saveUsers();
720726
}
721727
}

‎server/src/main/java/com/arcadedb/server/ServerPlugin.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
import com.arcadedb.server.http.HttpServer;
2323
import io.undertow.server.handlers.PathHandler;
2424

25-
import static com.arcadedb.server.ServerPlugin.INSTALLATION_PRIORITY.BEFORE_HTTP_ON;
25+
import static com.arcadedb.server.ServerPlugin.PluginInstallationPriority.BEFORE_HTTP_ON;
2626

2727
public interface ServerPlugin {
28-
enum INSTALLATION_PRIORITY {BEFORE_HTTP_ON, AFTER_HTTP_ON, AFTER_DATABASES_OPEN}
28+
enum PluginInstallationPriority {BEFORE_HTTP_ON, AFTER_HTTP_ON, AFTER_DATABASES_OPEN}
29+
30+
default String getName() {
31+
return this.getClass().getSimpleName();
32+
}
2933

3034
default void configure(ArcadeDBServer arcadeDBServer, ContextConfiguration configuration) {
3135
// DEFAULT IMPLEMENTATION
@@ -41,7 +45,7 @@ default void registerAPI(final HttpServer httpServer, final PathHandler routes)
4145
// DEFAULT IMPLEMENTATION
4246
}
4347

44-
default INSTALLATION_PRIORITY getInstallationPriority() {
48+
default PluginInstallationPriority getInstallationPriority() {
4549
return BEFORE_HTTP_ON;
4650
}
4751
}

‎server/src/main/java/com/arcadedb/server/plugin/PluginDescriptor.java‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.arcadedb.server.ServerPlugin;
2222

23-
import java.io.File;
2423
import java.util.Objects;
2524

2625
/**
@@ -30,15 +29,13 @@
3029
* @author Luca Garulli (l.garulli@arcadedata.com)
3130
*/
3231
public class PluginDescriptor {
33-
private final String pluginName;
34-
private final File pluginJarFile;
35-
private final ClassLoader classLoader;
36-
private ServerPlugin pluginInstance;
37-
private boolean started;
32+
private final String pluginName;
33+
private final ClassLoader classLoader;
34+
private ServerPlugin pluginInstance;
35+
private boolean started;
3836

39-
public PluginDescriptor(final String pluginName, final File pluginJarFile, final ClassLoader classLoader) {
37+
public PluginDescriptor(final String pluginName, final ClassLoader classLoader) {
4038
this.pluginName = Objects.requireNonNull(pluginName, "Plugin name cannot be null");
41-
this.pluginJarFile = Objects.requireNonNull(pluginJarFile, "Plugin JAR file cannot be null");
4239
this.classLoader = Objects.requireNonNull(classLoader, "Class loader cannot be null");
4340
this.started = false;
4441
}
@@ -47,10 +44,6 @@ public String getPluginName() {
4744
return pluginName;
4845
}
4946

50-
public File getPluginJarFile() {
51-
return pluginJarFile;
52-
}
53-
5447
public ClassLoader getClassLoader() {
5548
return classLoader;
5649
}
@@ -75,7 +68,6 @@ public void setStarted(final boolean started) {
7568
public String toString() {
7669
return "PluginDescriptor{" +
7770
"pluginName='" + pluginName + '\'' +
78-
", pluginJarFile=" + pluginJarFile +
7971
", started=" + started +
8072
'}';
8173
}

0 commit comments

Comments
 (0)