From 1c50a85548b529e2b397a2d3b19c473d9b89bb62 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 12 Nov 2015 09:27:22 +0000
Subject: [PATCH] OPENDJ-1742 Implement 2.x -> 3.0 changelog migration task
---
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java | 69 ++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
index c815b5d..9bcf691 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -1095,6 +1095,75 @@
}
}
+ static UpgradeTask clearReplicationDbDirectory()
+ {
+ return new AbstractUpgradeTask()
+ {
+ private File replicationDbDir;
+
+ @Override
+ public void prepare(final UpgradeContext context) throws ClientException
+ {
+ String replDbDir = readReplicationDbDirFromConfig();
+ if (replDbDir != null
+ && context.confirmYN(INFO_UPGRADE_TASK_MIGRATE_CHANGELOG_DESCRIPTION.get(), NO) == YES)
+ {
+ replicationDbDir = new File(getInstancePath(), replDbDir).getAbsoluteFile();
+ }
+ // if replDbDir == null, then this is not an RS, there is no changelog DB to clear
+ }
+
+ private String readReplicationDbDirFromConfig() throws ClientException
+ {
+ final SearchRequest sr = Requests.newSearchRequest(
+ DN.valueOf("cn=replication server,cn=Multimaster Synchronization,cn=Synchronization Providers,cn=config"),
+ SearchScope.BASE_OBJECT, Filter.alwaysTrue());
+ try (final EntryReader entryReader = searchConfigFile(sr))
+ {
+ if (entryReader.hasNext())
+ {
+ final Entry replServerCfg = entryReader.readEntry();
+ return replServerCfg.parseAttribute("ds-cfg-replication-db-directory").asString();
+ }
+ return null;
+ }
+ catch (IOException e)
+ {
+ LocalizableMessage msg = INFO_UPGRADE_TASK_MIGRATE_CONFIG_READ_FAIL.get();
+ throw new ClientException(ReturnCode.APPLICATION_ERROR, msg, e);
+ }
+ }
+
+ @Override
+ public void perform(final UpgradeContext context) throws ClientException
+ {
+ if (replicationDbDir == null)
+ {
+ // there is no changelog DB to clear
+ return;
+ }
+
+ LocalizableMessage msg = INFO_UPGRADE_TASK_DELETE_CHANGELOG_SUMMARY.get(replicationDbDir);
+ ProgressNotificationCallback pnc =
+ new ProgressNotificationCallback(0, msg, 0);
+ context.notifyProgress(pnc);
+ try
+ {
+ FileManager.deleteRecursively(replicationDbDir);
+ context.notifyProgress(pnc.setProgress(100));
+ }
+ catch (ClientException e)
+ {
+ manageTaskException(context, e.getMessageObject(), pnc);
+ }
+ catch (Exception e)
+ {
+ manageTaskException(context, LocalizableMessage.raw(e.getLocalizedMessage()), pnc);
+ }
+ }
+ };
+ }
+
/** Prevent instantiation. */
private UpgradeTasks()
{
--
Gitblit v1.10.0