/*
* 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 legal-notices/CDDLv1_0.txt
* 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 legal-notices/CDDLv1_0.txt.
* 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-2014 ForgeRock AS
*/
/**
* Factory methods for create new upgrade tasks.
*/
public final class UpgradeTasks
{
/**
* An errors counter in case of ignore errors mode.
*/
/**
* Logger for the upgrade.
*/
/**
* The indexes list to rebuild are united here.
*/
/**
* A flag to avoid rebuild single indexes if 'rebuild all' is selected.
*/
static boolean isRebuildAllIndexesIsPresent = false;
/**
* A flag for marking 'rebuild all' task accepted by user.
*/
static boolean isRebuildAllIndexesTaskAccepted = false;
/**
* Returns a new upgrade task which adds a config entry to the underlying
* config file.
*
* @param summary
* The summary of this upgrade task.
* @param ldif
* The LDIF record which will be applied to matching entries.
* @return A new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*/
{
}
/**
* Returns a new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*
* @param summary
* The summary of this upgrade task.
* @param description
* The detailed description of this upgrade task.
* @param ldif
* The LDIF record which will be applied to matching entries.
* @return A new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*/
{
}
/**
* This task copies the file placed in parameter within the config / schema
* 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 / schema folder. If the file already exists, it's
* overwritten.
*/
{
return new AbstractUpgradeTask()
{
{
final ProgressNotificationCallback pnc =
final File schemaFileTemplate =
try
{
{
throw new IOException(ERR_UPGRADE_CORRUPTED_TEMPLATE
}
}
catch (final IOException e)
{
}
}
};
}
/**
* 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.
*/
{
return new AbstractUpgradeTask()
{
{
final ProgressNotificationCallback pnc =
try
{
}
catch (final IOException e)
{
}
}
};
}
/**
* Returns a new upgrade task which deletes a config entry from the underlying
* config file.
*
* @param summary
* The summary of this upgrade task.
* @param dnInLDIF
* The dn to delete in the form of LDIF.
* @return A new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*/
{
return new AbstractUpgradeTask()
{
{
}
};
}
/**
* Returns a new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*
* @param summary
* The summary of this upgrade task.
* @param filter
* The LDAP filter which configuration entries must match.
* @param ldif
* The LDIF record which will be applied to matching entries.
* @return A new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*/
{
}
/**
* Returns a new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*
* @param summary
* The summary of this upgrade task.
* @param description
* The detailed description of this upgrade task.
* @param filter
* The LDAP filter which configuration entries must match.
* @param ldif
* The LDIF record which will be applied to matching entries.
* @return A new upgrade task which applies an LDIF record to all
* configuration entries matching the provided filter.
*/
{
}
/**
* This task adds a new attribute type (must exists in the original file) to
* the specified file placed in parameter. The destination must be a file
* attribute type named 'etag' in the 00.core.ldif. The 'etag' attribute
* already exists in the 00-core.ldif template schema file.
*
* <pre>
* register("2.5.0.7192",
* newAttributeTypes(Message.raw("New attribute etag"),
* false, "00-core.ldif",
* "1.3.6.1.4.1.36733.2.1.1.59"));
* </pre>
*
* @param summary
* The summary of the task.
* @param fileName
* The file where to add the new attribute types. This file must be
* contained in the configuration/schema folder.
* @param attributeOids
* The OIDs of the new attributes to add to.
* @return An upgrade task which adds new attribute types, defined previously
* in the configuration template files, reads the definition
* and adds it onto the specified file in parameter.
*/
{
return new AbstractUpgradeTask()
{
{
final ProgressNotificationCallback pnc =
final File schemaFileTemplate =
try
{
final int changeCount =
}
catch (final IOException e)
{
}
catch (final IllegalStateException e)
{
}
}
};
}
/**
* This task adds a new object class (must exists in the original file) to the
* specified file placed in parameter. The destination must be a file
*
* @param summary
* The summary of the task.
* @param fileName
* The file where to add the new object classes. This file must be
* contained in the configuration/schema folder.
* @param objectClassesOids
* The OIDs of the new object classes to add to.
* @return An upgrade task which adds new object classes, defined previously
* in the configuration template files,
* reads the definition and adds it onto the specified file in
* parameter.
*/
{
return new AbstractUpgradeTask()
{
{
final ProgressNotificationCallback pnc =
final File schemaFileTemplate =
try
{
final int changeCount =
}
catch (final IOException e)
{
}
catch (final IllegalStateException e)
{
}
}
};
}
/**
* Creates a group of tasks which will only be invoked if the current version
* is more recent than the provided version. This may be useful in cases where
* a regression was introduced in version X and resolved in a later version Y.
* In this case, the provided upgrade tasks will only be invoked if the
* current version is between X (inclusive) and Y (exclusive).
*
* @param versionString
* The lower bound version. The upgrade tasks will not be applied if
* the current version is older than this version.
* @param tasks
* The group of tasks to invoke if the current version is equal to or
* more recent than {@code versionString}.
* @return An upgrade task which will only be invoked if the current version
* is more recent than the provided version.
*/
final UpgradeTask... tasks)
{
return new AbstractUpgradeTask()
{
{
{
{
}
}
}
{
{
{
}
}
}
{
{
{
}
}
}
{
{
boolean isOk = true;
{
if (isOk)
{
try
{
}
catch (ClientException e)
{
isOk = false;
}
}
else
{
}
}
}
}
private boolean currentVersionEqualToOrMoreRecentThan(
{
}
};
}
/**
* Creates a rebuild all indexes task.
*
* @param summary
* The summary of this upgrade task.
* @return An Upgrade task which rebuild all the indexes.
*/
{
return new AbstractUpgradeTask()
{
private boolean isATaskToPerform = false;
{
Upgrade.setHasPostUpgradeTask(true);
// Requires answer from the user.
isRebuildAllIndexesIsPresent = true;
}
throws ClientException
{
if (!isATaskToPerform)
{
}
}
throws ClientException
{
}
};
}
/**
* Creates a rebuild index task for a given single index. As this task is
* possibly lengthy, it's considered as a post upgrade task. This task is not
* mandatory; e.g not require user interaction, but could be required to get a
* fully functional server. <br />
* The post upgrade task just register the task. The rebuild indexes tasks are
* completed at the end of the upgrade process.
*
* @param summary
* A message describing why the index needs to be rebuilt and asking
* them whether or not they wish to perform this task after the
* upgrade.
* @param index
* The index to rebuild.
* @return The rebuild index task.
*/
{
return new AbstractUpgradeTask()
{
private boolean isATaskToPerform = false;
{
Upgrade.setHasPostUpgradeTask(true);
// Requires answer from the user.
}
throws ClientException
{
if (isATaskToPerform)
{
}
else
{
}
}
throws ClientException
{
{
}
}
};
}
/**
* This task is processed at the end of the upgrade, rebuilding indexes. If a
* rebuild all indexes has been registered before, it takes the flag
* relatively to single rebuild index.
*
* @return The post upgrade rebuild indexes task.
*/
{
return new AbstractUpgradeTask()
{
throws ClientException
{
{
}
else if (!indexesListToRebuild.isEmpty()
{
message =
// Adding all requested indexes.
{
}
}
else
{
return;
}
// Startup message.
// Sets the arguments like the rebuild index command line.
"-f",
.getAbsolutePath()));
/*
* Index(es) could be contained in several backends or none, If none,
* the post upgrade tasks succeed and a message is printed in the
* upgrade log file.
*/
{
{
}
final String[] commandLineArgs =
// Displays info about command line args for log only.
/*
* The rebuild-index process just display a status ok / fails. The
* logger stream contains all the log linked to this process. The
* complete process is not displayed in the upgrade console.
*/
final int result =
new RebuildIndex().rebuildIndexesWithinMultipleBackends(true,
if (result == 0)
{
.toString());
}
else
{
}
}
else
{
}
}
};
}
/**
* Creates a file object representing config/upgrade/schema.ldif.current which
* the server creates the first time it starts if there are schema
* customizations.
*
* new schema.ldif.rev which is needed after schema customization for
* starting correctly the server.
*/
{
return new AbstractUpgradeTask()
{
{
final ProgressNotificationCallback pnc =
try
{
}
{
}
}
};
}
/**
* Renames the SNMP security config file if it exists. Since 2.5.0.7466 this
* file has been renamed.
*
* @param summary
* The summary of this upgrade task.
* @return An upgrade task which renames the old SNMP security config file if
* it exists.
*/
{
return new AbstractUpgradeTask()
{
{
/*
* Snmp config file contains old name in old version(like 2.4.5), in
* order to make sure the process will still work after upgrade, we need
* to rename it - only if it exists.
*/
{
try
{
final File oldSnmpConfig =
"opends-snmp.security");
if (oldSnmpConfig.exists())
{
final File snmpConfig =
"opendj-snmp.security");
}
}
{
.getMessage()), pnc);
}
}
}
};
}
{
return new AbstractUpgradeTask()
{
private boolean userConfirmation = true;
{
{
// Process needs to have user's response to perform the current
// modification.
final int answer =
// The user refuses to perform this task.
{
userConfirmation = false;
}
}
}
{
if (userConfirmation)
{
}
}
};
}
final int changeCount)
{
if (changeCount != 0)
{
}
else
{
}
}
{
{
}
{
}
}
throws ClientException
{
countErrors++;
if (!context.isIgnoreErrorsMode())
{
}
}
{
return new AbstractUpgradeTask()
{
private boolean userConfirmation = true;
{
{
// Process needs to have user's response to perform the current
// modification.
final int answer =
// The user refuses to perform this task.
{
userConfirmation = false;
}
}
}
{
if (userConfirmation)
{
}
}
};
}
throws ClientException
{
final ProgressNotificationCallback pnc =
try
{
final File configFile =
final int changeCount =
}
catch (final Exception e)
{
}
}
// Prevent instantiation.
private UpgradeTasks()
{
// Do nothing.
}
}