From 9b5a6543d5bcca85176ac19d1c5fca80911fbb2e Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Thu, 23 May 2013 08:10:24 +0000
Subject: [PATCH] CR-1720 OPENDJ-835 Upgrade should add HTTP Connection Handler to config.ldif OPENDJ-914 Upgrade should add Based HTTP Access Logger to config.ldif - HTTP connection handler and the based HTTP access logger are now added to upgrade. - The http-config.json is added to the config file during upgrade. - Simplified UpgradeTasks.java - Added new messages. - Fixed javadoc for unit test.
---
opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java | 199 ++++++++-------------------------
opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java | 85 ++++++++++++++
opends/src/messages/messages/tools.properties | 5
opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java | 5
opends/tests/unit-tests-testng/src/server/org/opends/server/tools/UpgradeTestCase.java | 4
opends/src/server/org/opends/server/tools/upgrade/Upgrade.java | 51 ++++++++
6 files changed, 195 insertions(+), 154 deletions(-)
diff --git a/opends/src/messages/messages/tools.properties b/opends/src/messages/messages/tools.properties
index 77563f2..4423a26 100644
--- a/opends/src/messages/messages/tools.properties
+++ b/opends/src/messages/messages/tools.properties
@@ -2681,6 +2681,9 @@
INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS_1850=See '%s' for a detailed log of this operation
INFO_UPGRADE_TASK_REPLACE_SCHEMA_FILE_1851=Replacing schema file '%s'
INFO_UPGRADE_TASK_REFRESH_UPGRADE_DIRECTORY_1852=Archiving concatenated schema
+INFO_UPGRADE_TASK_ADD_CONFIG_FILE_1853=Adding '%s' configuration file
+SEVERE_ERR_UPGRADE_ADD_CONFIG_FILE_FAILS_1854=An error occurred while adding \
+configuration file '%s': %s
# Upgrade tasks
INFO_UPGRADE_TASK_6869_SUMMARY_10000=Fixing de-DE collation matching rule OID
@@ -2699,3 +2702,5 @@
INFO_UPGRADE_TASK_8387_SUMMARY_10011=Updating dictionary password validator configuration
INFO_UPGRADE_TASK_8389_SUMMARY_10012=Updating attribute value password validator configuration
INFO_UPGRADE_TASK_8487_SUMMARY_10013=Adding PBKDF2 password storage scheme configuration
+INFO_UPGRADE_TASK_8613_SUMMARY_10014=Adding HTTP connection handler configuration
+INFO_UPGRADE_TASK_8832_SUMMARY_10015=Adding file-based HTTP access logger
diff --git a/opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java b/opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java
new file mode 100644
index 0000000..465b839
--- /dev/null
+++ b/opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java
@@ -0,0 +1,85 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Copyright 2013 ForgeRock AS
+ */
+package org.opends.server.tools.upgrade;
+
+import javax.security.auth.callback.CallbackHandler;
+
+import org.opends.server.tools.ClientException;
+
+/**
+ * Abstract upgrade task implementation.
+ */
+public abstract class AbstractUpgradeTask implements UpgradeTask
+{
+ /**
+ * Creates a new abstract upgrade task.
+ */
+ protected AbstractUpgradeTask()
+ {
+ // No implementation required.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void end(UpgradeContext context, CallbackHandler handler)
+ throws ClientException
+ {
+ // Nothing to do.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void interact(UpgradeContext context, CallbackHandler handler)
+ throws ClientException
+ {
+ // Nothing to do.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void start(UpgradeContext context, CallbackHandler handler)
+ throws ClientException
+ {
+ // Nothing to do.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void verify(UpgradeContext context, CallbackHandler handler)
+ throws ClientException
+ {
+ // Nothing to do.
+ }
+}
diff --git a/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java b/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
index 9b4413c..dd67572 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
@@ -225,6 +225,55 @@
+ "PBKDF2PasswordStorageScheme",
"ds-cfg-enabled: true"));
+ register("2.5.0.8613",
+ addConfigFile("http-config.json"),
+ addConfigEntry(INFO_UPGRADE_TASK_8613_SUMMARY.get(),
+ "dn: cn=HTTP Connection Handler,cn=Connection Handlers,cn=config",
+ "changetype: add",
+ "objectClass: ds-cfg-http-connection-handler",
+ "objectClass: ds-cfg-connection-handler",
+ "objectClass: top",
+ "ds-cfg-listen-port: 8080",
+ "cn: HTTP Connection Handler",
+ "ds-cfg-max-blocked-write-time-limit: 2 minutes",
+ "ds-cfg-ssl-client-auth-policy: optional",
+ "ds-cfg-use-tcp-keep-alive: true",
+ "ds-cfg-max-request-size: 5 megabytes",
+ "ds-cfg-use-tcp-no-delay: true",
+ "ds-cfg-allow-tcp-reuse-address: true",
+ "ds-cfg-accept-backlog: 128",
+ "ds-cfg-authentication-required: true",
+ "ds-cfg-buffer-size: 4096 bytes",
+ "ds-cfg-config-file: config/http-config.json",
+ "ds-cfg-listen-address: 0.0.0.0",
+ "ds-cfg-java-class: " +
+ "org.opends.server.protocols.http.HTTPConnectionHandler",
+ "ds-cfg-keep-stats: true",
+ "ds-cfg-ssl-cert-nickname: server-cert",
+ "ds-cfg-use-ssl: false",
+ "ds-cfg-enabled: false"));
+
+ register("2.5.0.8832", addConfigEntry(INFO_UPGRADE_TASK_8832_SUMMARY.get(),
+ "dn: cn=File-Based HTTP Access Logger,cn=Loggers,cn=config",
+ "changetype: add",
+ "objectClass: ds-cfg-file-based-http-access-log-publisher",
+ "objectClass: top",
+ "objectClass: ds-cfg-http-access-log-publisher",
+ "objectClass: ds-cfg-log-publisher",
+ "cn: File-Based HTTP Access Logger",
+ "ds-cfg-java-class: " +
+ "org.opends.server.loggers.TextHTTPAccessLogPublisher",
+ "ds-cfg-asynchronous: true",
+ "ds-cfg-log-file: logs/http-access",
+ "ds-cfg-rotation-policy: " +
+ "cn=24 Hours Time Limit Rotation Policy," +
+ "cn=Log Rotation Policies,cn=config",
+ "ds-cfg-rotation-policy: " +
+ "cn=Size Limit Rotation Policy,cn=Log Rotation Policies,cn=config",
+ "ds-cfg-retention-policy: " +
+ "cn=File Count Retention Policy,cn=Log Retention Policies,cn=config",
+ "ds-cfg-log-file-permissions: 640",
+ "ds-cfg-enabled: false"));
/*
* All upgrades will refresh the server configuration schema and generate
* a new upgrade folder.
@@ -237,8 +286,6 @@
/*register("2.5.0.8657",
rebuildAllIndexes(Message.raw("This is fake Rebuild Task")));*/
- // FIXME: HTTP connection handler and access logger when complete.
-
// @formatter:on
}
diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
index 57151a3..fd55162 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -120,27 +120,8 @@
*/
public static UpgradeTask copySchemaFile(final String fileName)
{
- return new UpgradeTask()
+ return new AbstractUpgradeTask()
{
-
- @Override
- public void end(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void interact(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
@Override
public void perform(final UpgradeContext context,
final CallbackHandler handler) throws ClientException
@@ -170,27 +151,54 @@
e.getMessage()), pnc);
}
}
-
-
-
- @Override
- public void start(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void verify(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
};
}
+ /**
+ * This task copies the file placed in parameter within the config
+ * folder. If the file already exists, it's overwritten.
+ *
+ * @param fileName
+ * The name of the file which need to be copied.
+ * @return A task which copy the the file placed in parameter within the
+ * config folder. If the file already exists, it's
+ * overwritten.
+ */
+ public static UpgradeTask addConfigFile(final String fileName)
+ {
+ return new AbstractUpgradeTask()
+ {
+ @Override
+ public void perform(final UpgradeContext context,
+ final CallbackHandler handler) throws ClientException
+ {
+ final Message msg = INFO_UPGRADE_TASK_ADD_CONFIG_FILE.get(fileName);
+ LOG.log(Level.INFO, msg.toString());
+
+ final ProgressNotificationCallback pnc =
+ new ProgressNotificationCallback(0, msg, 0);
+
+ final File configFile = new File(templateConfigDirectory,
+ fileName);
+
+ try
+ {
+ context.notifyProgress(handler, pnc.changeProgress(20));
+
+ copy(configFile, configDirectory, true);
+ context.notifyProgress(handler, pnc.changeProgress(100));
+ }
+ catch (final IOException e)
+ {
+ manageTaskException(
+ context,
+ handler,
+ ERR_UPGRADE_ADD_CONFIG_FILE_FAILS.get(configFile.getName(),
+ e.getMessage()), pnc);
+ }
+ }
+ };
+ }
/**
@@ -266,27 +274,9 @@
public static UpgradeTask newAttributeTypes(final Message summary,
final String fileName, final String... names)
{
- return new UpgradeTask()
+ return new AbstractUpgradeTask()
{
@Override
- public void end(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void interact(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
public void perform(final UpgradeContext context,
final CallbackHandler handler) throws ClientException
{
@@ -316,24 +306,6 @@
e.getMessage()), pnc);
}
}
-
-
-
- @Override
- public void start(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void verify(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
};
}
@@ -358,27 +330,9 @@
public static UpgradeTask newObjectClasses(final Message summary,
final String fileName, final String... names)
{
- return new UpgradeTask()
+ return new AbstractUpgradeTask()
{
@Override
- public void end(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void interact(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
public void perform(final UpgradeContext context,
final CallbackHandler handler) throws ClientException
{
@@ -411,24 +365,6 @@
schemaFileTemplate.getName(), e.getMessage()), pnc);
}
}
-
-
-
- @Override
- public void start(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void verify(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
};
}
@@ -514,27 +450,8 @@
*/
public static UpgradeTask updateConfigUpgradeFolder()
{
- return new UpgradeTask()
+ return new AbstractUpgradeTask()
{
-
- @Override
- public void end(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void interact(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
@Override
public void perform(final UpgradeContext context,
final CallbackHandler handler) throws ClientException
@@ -560,24 +477,6 @@
pnc);
}
}
-
-
-
- @Override
- public void start(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
-
-
-
- @Override
- public void verify(final UpgradeContext context,
- final CallbackHandler handler) throws ClientException
- {
- // Nothing to do.
- }
};
}
diff --git a/opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java b/opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java
index 696fc18..b1d5994 100644
--- a/opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java
+++ b/opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java
@@ -100,6 +100,11 @@
+ File.separator + Installation.CONFIG_PATH_RELATIVE + File.separator
+ Installation.SCHEMA_PATH_RELATIVE);
+ /** The template/config folder of the current installation. */
+ static final File templateConfigDirectory = new File(
+ getInstallationPath(), Installation.TEMPLATE_RELATIVE_PATH
+ + File.separator + Installation.CONFIG_PATH_RELATIVE);
+
/**
* Returns the path of the installation of the directory server. Note that
* this method assumes that this code is being run locally.
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/UpgradeTestCase.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/UpgradeTestCase.java
index 483f77e..b07510c 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/UpgradeTestCase.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/UpgradeTestCase.java
@@ -97,10 +97,10 @@
}
/**
- * Tests the Upgrade tool with a running server throws an error.
+ * Tests the upgrade with an offline server and empty args fails.
*/
@Test()
- public void testUpgradeServerOffline() throws InitializationException,
+ public void testUpgradeServerOfflineEmptyArgs() throws InitializationException,
ConfigException, DirectoryException, IOException
{
String[] args = { "" };
--
Gitblit v1.10.0