From be7c9be12ddf4717855de61e89b0042fa886503b Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Fri, 09 Sep 2016 09:45:26 +0000
Subject: [PATCH] OPENDJ-3089 OPENDJ-1237 SchemaWriter provides list of offline schema modifications without static call to DirectoryServer
---
opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java | 33 ++++++++++++++++
opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java | 41 --------------------
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java | 3 -
opendj-server-legacy/src/main/java/org/opends/server/types/SchemaWriter.java | 11 +++--
opendj-server-legacy/src/main/java/org/opends/server/core/SynchronizationProviderConfigManager.java | 2
opendj-server-legacy/src/main/java/org/opends/server/api/SynchronizationProvider.java | 5 ++
opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/MultimasterReplication.java | 6 +-
7 files changed, 49 insertions(+), 52 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/api/SynchronizationProvider.java b/opendj-server-legacy/src/main/java/org/opends/server/api/SynchronizationProvider.java
index b4555cd..955b67e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/api/SynchronizationProvider.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/api/SynchronizationProvider.java
@@ -19,10 +19,12 @@
+
import java.util.List;
import org.forgerock.opendj.server.config.server.SynchronizationProviderCfg;
import org.forgerock.opendj.config.server.ConfigException;
+import org.opends.server.core.ServerContext;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
@@ -53,6 +55,7 @@
* Performs any initialization that might be necessary for this
* synchronization provider.
*
+ * @param serverContext The server context.
* @param config The configuration information for this
* synchronization provider.
*
@@ -66,7 +69,7 @@
* is not related to the server
* configuration.
*/
- public abstract void initializeSynchronizationProvider(T config)
+ public abstract void initializeSynchronizationProvider(ServerContext serverContext, T config)
throws ConfigException, InitializationException;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
index ee46065..e51cc70 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -96,7 +96,6 @@
import org.opends.server.types.Modification;
import org.opends.server.types.Privilege;
import org.opends.server.types.RestoreConfig;
-import org.opends.server.types.SchemaWriter;
import org.opends.server.types.SearchFilter;
import org.opends.server.util.BackupManager;
import org.opends.server.util.LDIFException;
@@ -225,8 +224,6 @@
}
}
- new SchemaWriter(serverContext).updateConcatenatedSchema();
-
// Register with the Directory Server as a configurable component.
currentConfig.addSchemaChangeListener(this);
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
index f2aa50f..95d357d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -148,7 +148,6 @@
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.LockManager;
-import org.opends.server.types.Modification;
import org.opends.server.types.Operation;
import org.opends.server.types.Privilege;
import org.opends.server.types.RestoreConfig;
@@ -505,12 +504,6 @@
/** The sets of mail server properties. */
private List<Properties> mailServerPropertySets;
- /**
- * The set of schema changes made by editing the schema configuration files
- * with the server offline.
- */
- private List<Modification> offlineSchemaChanges;
-
/** The log rotation policy config manager for the Directory Server. */
private LogRotationPolicyConfigManager rotationPolicyConfigManager;
@@ -1221,7 +1214,6 @@
directoryServer.identityMappers = new ConcurrentHashMap<>();
directoryServer.extendedOperationHandlers = new ConcurrentHashMap<>();
directoryServer.saslMechanismHandlers = new ConcurrentHashMap<>();
- directoryServer.offlineSchemaChanges = new LinkedList<>();
directoryServer.backupTaskListeners = new CopyOnWriteArrayList<>();
directoryServer.restoreTaskListeners = new CopyOnWriteArrayList<>();
directoryServer.exportTaskListeners = new CopyOnWriteArrayList<>();
@@ -1719,6 +1711,7 @@
public void initializeSchema() throws InitializationException, ConfigException
{
schemaHandler.initialize(serverContext);
+ schemaHandler.detectChangesOnInitialization();
// With server schema in place set compressed schema.
compressedSchema = new DefaultCompressedSchema(serverContext);
@@ -2203,38 +2196,6 @@
}
/**
- * Retrieves a list of modifications detailing any schema changes that may
- * have been made with the server offline (e.g., by directly editing the
- * schema configuration files). Note that this information will not be
- * available until the server backends (and in particular, the schema backend)
- * have been initialized.
- *
- * @return A list of modifications detailing any schema changes that may have
- * been made with the server offline, or an empty list if no offline
- * schema changes have been detected.
- */
- public static List<Modification> getOfflineSchemaChanges()
- {
- return directoryServer.offlineSchemaChanges;
- }
-
- /**
- * Specifies a list of modifications detailing any schema changes that may
- * have been made with the server offline.
- *
- * @param offlineSchemaChanges A list of modifications detailing any schema
- * changes that may have been made with the
- * server offline. It must not be {@code null}.
- */
- public static void setOfflineSchemaChanges(List<Modification>
- offlineSchemaChanges)
- {
- ifNull(offlineSchemaChanges);
-
- directoryServer.offlineSchemaChanges = offlineSchemaChanges;
- }
-
- /**
* Retrieves the set of virtual attribute rules registered with the Directory
* Server.
*
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java
index 05d50e2..285ba9e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/SchemaHandler.java
@@ -15,6 +15,8 @@
*/
package org.opends.server.core;
+import static java.util.Collections.emptyList;
+
import static org.opends.messages.ConfigMessages.ERR_CONFIG_SCHEMA_DIR_NOT_DIRECTORY;
import static org.opends.messages.ConfigMessages.ERR_CONFIG_SCHEMA_NO_SCHEMA_DIR;
import static org.opends.messages.SchemaMessages.NOTE_SCHEMA_IMPORT_FAILED;
@@ -143,6 +145,12 @@
private SchemaWriter schemaWriter;
/**
+ * The list of offline modifications made to the schema.
+ * This list is built when initializing the schema handler.
+ */
+ private List<Modification> offlineSchemaModifications = emptyList();
+
+ /**
* A set of extra attributes that are not used directly by the schema but may
* be used by other component to store information in the schema.
* <p>
@@ -244,6 +252,7 @@
{
throw new ConfigException(e.getMessageObject(), e);
}
+
}
finally
{
@@ -252,6 +261,19 @@
}
/**
+ * Detects offline schema changes by comparing schema files and concatenated schema.
+ * <p>
+ * Updates the concatenated schema if changes are detected.
+ *
+ * @throws InitializationException
+ * If an error occurs while updating the concatenated schema
+ */
+ public void detectChangesOnInitialization() throws InitializationException
+ {
+ offlineSchemaModifications = schemaWriter.updateConcatenatedSchemaIfChangesDetected();
+ }
+
+ /**
* Returns the schema.
*
* @return the schema
@@ -287,6 +309,17 @@
}
/**
+ * Returns the list of offline modifications made to the schema, which is built once when
+ * initializing the schema.
+ *
+ * @return the offline schema modifications list
+ */
+ public List<Modification> getOfflineSchemaModifications()
+ {
+ return Collections.unmodifiableList(offlineSchemaModifications);
+ }
+
+ /**
* Updates the schema using the provided schema updater.
*
* @param updater
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/SynchronizationProviderConfigManager.java b/opendj-server-legacy/src/main/java/org/opends/server/core/SynchronizationProviderConfigManager.java
index bc3ef38..6f37bb7 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/SynchronizationProviderConfigManager.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/SynchronizationProviderConfigManager.java
@@ -314,7 +314,7 @@
try
{
// Initialize the Synchronization Provider.
- provider.initializeSynchronizationProvider(configuration);
+ provider.initializeSynchronizationProvider(serverContext, configuration);
} catch (Exception e)
{
try
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/MultimasterReplication.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/MultimasterReplication.java
index 4f6fba1..c632fb8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/MultimasterReplication.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/MultimasterReplication.java
@@ -51,6 +51,7 @@
import org.opends.server.api.RestoreTaskListener;
import org.opends.server.api.SynchronizationProvider;
import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.ServerContext;
import org.opends.server.replication.service.DSRSShutdownSync;
import org.opends.server.types.BackupConfig;
import org.opends.server.types.Control;
@@ -250,7 +251,7 @@
}
@Override
- public void initializeSynchronizationProvider(
+ public void initializeSynchronizationProvider(ServerContext serverContext,
ReplicationSynchronizationProviderCfg cfg) throws ConfigException
{
domains.clear();
@@ -275,8 +276,7 @@
}
// If any schema changes were made with the server offline, then handle them now.
- List<Modification> offlineSchemaChanges =
- DirectoryServer.getOfflineSchemaChanges();
+ List<Modification> offlineSchemaChanges = serverContext.getSchemaHandler().getOfflineSchemaModifications();
if (offlineSchemaChanges != null && !offlineSchemaChanges.isEmpty())
{
processSchemaChange(offlineSchemaChanges);
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/SchemaWriter.java b/opendj-server-legacy/src/main/java/org/opends/server/types/SchemaWriter.java
index 99f7d41..a798d1a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/SchemaWriter.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/SchemaWriter.java
@@ -40,6 +40,7 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -163,16 +164,18 @@
}
/**
- * Updates the concatenated schema if changes are detected in the current schema files.
+ * Updates the concatenated schema if changes are detected in the current schema files
+ * and return the modifications.
* <p>
* Identify any differences that may exist between the concatenated schema file from the last
* online modification and the current schema files. If there are any differences, then they
* should be from making changes to the schema files with the server offline.
*
+ * @return the list of modifications made offline on the schema.
* @throws InitializationException
* If concatenated schema can't be updated
*/
- public void updateConcatenatedSchema() throws InitializationException
+ public List<Modification> updateConcatenatedSchemaIfChangesDetected() throws InitializationException
{
try
{
@@ -214,12 +217,11 @@
{
// TODO : Raise an alert notification.
- DirectoryServer.setOfflineSchemaChanges(mods);
-
// Write a new concatenated schema file with the most recent information
// so we don't re-find these same changes on the next startup.
writeConcatenatedSchema();
}
+ return mods;
}
catch (InitializationException ie)
{
@@ -230,6 +232,7 @@
logger.traceException(e);
logger.error(ERR_SCHEMA_ERROR_DETERMINING_SCHEMA_CHANGES, getExceptionMessage(e));
+ return Collections.emptyList();
}
}
--
Gitblit v1.10.0