Installation.java revision 5e5acc733bf20faa22d4e9be582f555bbda0867b
/*
* 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 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* This class represents the physical state of an OpenDJ installation. All the
* operations are dependent upon the root directory that is specified in the
* constructor.
*/
public final class Installation
{
/** Relative path to bootstrap OpenDJ jar file. */
/** Relative path to bootstrap-client OpenDJ jar file. */
/** The relative path where all the Windows binaries (batch files) are. */
/** The relative path where all the UNIX binaries (scripts) are. */
/** The relative path where all the MacOS X Applications are. */
/** The relative path where all the libraries (jar files) are. */
/** The relative path where the resources directory (to customize the product) is. */
/** The relative path where customer classes are. */
/** The relative path where the database files are. */
/** The relative path where the log files are. */
/** The relative path where the LDIF files are. */
/** The relative path where the backup files are. */
/** The relative path where the config files are. */
/** The relative path where the config files are. */
/** Relative path to the locks directory. */
/** Relative path to the locks directory. */
/** The relative path to the current Configuration LDIF file. */
/** The relative path to the current Configuration LDIF file. */
/** The relative path to the instance.loc file. */
/** The path to the instance.loc file. */
/** The relative path to tmpl_instance. */
/** The relative path to buildinfo file. */
/** The UNIX setup script file name. */
/** The Windows setup batch file name. */
/** The UNIX uninstall script file name. */
/** The Windows uninstall batch file name. */
/** The UNIX upgrade script file name. */
/** The UNIX start script file name. */
/** The Windows start batch file name. */
/** The UNIX stop script file name. */
/** The Windows stop batch file name. */
/** The UNIX control panel script file name. */
/** The Windows control panel batch file name. */
/** The MacOS X Java application stub name. */
/** The MacOS X control panel application bundle name. */
/** The UNIX status command line script file name. */
/** The Windows status command line batch file name. */
/** The UNIX import LDIF script file name. */
/** The Windows import LDIF batch file name. */
/**
* Name of the file kept in the history directory containing logs of upgrade
* and reversions.
*/
/** The default java properties file. */
/** The default java properties file relative path. */
public static final String RELATIVE_JAVA_PROPERTIES_FILE =
/** The set java home and arguments properties file for Windows. */
/** Script utils file for UNIX systems. */
/** Script utils file for Windows. */
/** The set java home and arguments properties file for UNIX systems. */
/** Directories required to be present for this installation to be considered valid. */
/** The default base DN prompted to user in setup interactive mode. */
/**
* Performs validation on the specified file to make sure that it is an actual
* OpenDJ installation.
*
* @param rootDirectory
* File directory candidate
* @throws IllegalArgumentException
* if root directory does not appear to be an OpenDJ installation
* root. The thrown exception contains a localized message
* indicating the reason why <code>rootDirectory</code> is not a
* valid OpenDJ install root.
*/
throws IllegalArgumentException
{
if (rootDirectory == null)
{
}
else if (!rootDirectory.exists())
{
.getPath(rootDirectory));
}
else if (!rootDirectory.isDirectory())
{
.getPath(rootDirectory));
}
else
{
{
{
{
}
}
}
else
{
.getPath(rootDirectory));
}
}
if (failureReason != null)
{
}
}
private static Installation local;
/**
* Obtains the installation by reading the classpath of the running JVM to
* determine the location of the jars and determine the installation root.
*
* @return Installation obtained by reading the classpath
*/
public static Installation getLocal()
{
{
// This allows testing of configuration components when the OpenDJ.jar
// in the classpath does not necessarily point to the server's
.getProperty("org.opends.quicksetup.instance");
if (installRoot == null)
{
}
if (instanceRoot == null)
{
}
}
return local;
}
private File rootDirectory;
private File instanceDirectory;
private Configuration configuration;
private Configuration baseConfiguration;
private BuildInformation buildInformation;
private BuildInformation instanceInformation;
/**
* Creates a new instance from a root directory specified as a string.
*
* @param rootDirectory
* of this installation
* @param instanceRootDirectory
* The instance root directory
*/
{
}
/**
* Creates a new instance from a root directory specified as a File.
*
* @param rootDirectory
* of this installation
* @param instanceDirectory
* of the instance
*/
{
}
/**
* Gets the top level directory of an OpenDJ installation.
*
* @return File object representing the top level directory of and OpenDJ
* installation
*/
public File getRootDirectory()
{
return this.rootDirectory;
}
/**
* Gets the top level directory of an OpenDJ instance.
*
* @return File object representing the top level directory of and OpenDK
* installation
*/
public File getInstanceDirectory()
{
return this.instanceDirectory;
}
/**
* Sets the root directory of this installation.
*
* @param rootDirectory
* File of this installation
*/
{
// Hold off on doing validation of rootDirectory since
// some applications (like the Installer) create an Installation
// before the actual bits have been laid down on the file system.
this.rootDirectory = rootDirectory;
// Obtaining build information is a fairly time consuming operation.
// Try to get a head start if possible.
if (isValid(rootDirectory))
{
try
{
+ bi));
}
catch (ApplicationException e)
{
}
}
}
/**
* Sets the root directory of this instance.
*
* @param instanceDirectory
* File of this instance
*/
{
// Hold off on doing validation of rootDirectory since
// some applications (like the Installer) create an Installation
// before the actual bits have been laid down on the filesystem.
this.instanceDirectory = instanceDirectory;
// Obtaining build information is a fairly time consuming operation.
// Try to get a head start if possible.
if (isValid(instanceDirectory))
{
try
{
+ ": " + bi));
}
catch (ApplicationException e)
{
}
}
}
/**
* Indicates whether or not this installation appears to be an actual OpenDJ
* installation.
*
* @param file
* The root directory
* @return boolean where true indicates that this does indeed appear to be a
* valid OpenDJ installation; false otherwise
*/
{
try
{
return true;
}
catch (IllegalArgumentException e)
{
return false;
}
}
/**
* Creates a string explaining why this is not a legitimate OpenDJ
* installation. Null if this is in fact a valid installation.
*
* @return localized message indicating the reason this is not an OpenDJ
* installation
*/
public String getInvalidityReason()
{
try
{
return null;
}
catch (IllegalArgumentException e)
{
return e.getLocalizedMessage();
}
}
/**
* Gets the Configuration object representing this file. The current
* configuration is stored in config/config.ldif.
*
* @return Configuration representing the current configuration.
*/
public Configuration getCurrentConfiguration()
{
if (configuration == null)
{
}
return configuration;
}
/**
* Gets the Configuration object representing this file. The base
* configuration is stored in config/upgrade/config.ldif.[svn rev].
*
* @return Configuration object representing the base configuration.
* @throws ApplicationException
* if there was a problem determining the svn rev number.
*/
{
if (baseConfiguration == null)
{
}
return baseConfiguration;
}
/**
* Gets the current status of this installation.
*
* @return Status object representing the state of this installation.
*/
{
{
}
return status;
}
/**
* Returns the path to the libraries.
*
* @return the path to the libraries.
*/
public File getLibrariesDirectory()
{
}
/**
* Returns the path to the resources directory.
*
* @return the path to the resources directory.
*/
public File getResourcesDirectory()
{
}
/**
* Returns the path to the classes directory.
*
* @return the path to the classes directory.
*/
public File getClassesDirectory()
{
}
/**
* Creates a File object representing config/upgrade/schema.ldif.current which
* the server creates the first time it starts if there are schema
* customizations.
*
* @return File object with no
*/
public File getSchemaConcatFile()
{
}
/**
* Creates a File object representing config/upgrade/schema.ldif.current which
* the server creates the first time it starts if there are schema
* customizations.
*
* @return File object with no
* @throws ApplicationException
* if there was a problem determining the svn revision number
*/
{
}
/**
* Creates a File object representing config/upgrade/schema.ldif.current which
* the server creates the first time it starts if there are schema
* customizations.
*
* @return File object with no
* @throws ApplicationException
* if there was a problem determining the svn revision number
*/
{
return new File(getConfigurationUpgradeDirectory(), BASE_CONFIG_FILE_PREFIX + getInstanceVCSRevision());
}
/**
* Gets the VCS revision of the build.
*
* @return String representing the VCS revision
* @throws ApplicationException
* if for some reason the number could not be determined
*/
{
return getBuildInformation().getRevision();
}
/**
* Gets the VCS revision of the instance.
*
* @return Integer representing the svn number
* @throws ApplicationException
* if for some reason the number could not be determined
*/
{
return getInstanceBuildInformation().getRevision();
}
/**
* Returns the path to the configuration file of the directory server. Note
* that this method assumes that this code is being run locally.
*
* @return the path of the configuration file of the directory server.
*/
public File getCurrentConfigurationFile()
{
}
/**
* of the Open DS installation. The path is relative to the installation path.
*
* of the Open DS installation.
*/
public File getBinariesDirectory()
{
}
/**
* Returns the path to the database files under the install path.
*
* @return the path to the database files under the install path.
*/
public File getDatabasesDirectory()
{
}
/**
* Returns the path to the backup files under the install path.
*
* @return the path to the backup files under the install path.
*/
public File getBackupDirectory()
{
}
/**
* Returns the path to the config files under the install path.
*
* @return the path to the config files under the install path.
*/
public File getConfigurationDirectory()
{
}
/**
* Returns the path to the log files under the install path.
*
* @return the path to the log files under the install path.
*/
public File getLogsDirectory()
{
}
/**
* Returns the directory where the lock files are stored.
*
* @return the path to the lock files.
*/
public File getLocksDirectory()
{
}
/**
* Gets the directory used to store the template configuration.
*
* @return The directory used to store the template configuration.
*/
public File getTemplateDirectory()
{
}
/**
* Gets the directory used to store files temporarily.
*
* @return File temporary directory
*/
public File getTemporaryDirectory()
{
}
/**
* Returns the directory where the lock files are stored.
*
* @return the path to the lock files.
*/
public File getHistoryDirectory()
{
}
/**
* Creates a new directory in the history directory appropriate for backing up
* an installation during an upgrade.
*
* @return File representing a new backup directory. The directory can be
* assumed to exist if this method returns cleanly.
* @throws IOException
* if an error occurred creating the directory.
*/
{
.currentTimeMillis()));
if (backupDirectory.exists())
{
}
if (!backupDirectory.mkdirs())
{
throw new IOException("failed to create history backup directory");
}
return backupDirectory;
}
/**
* Gets the log file where the history of upgrades and reversions is kept.
*
*/
public File getHistoryLogFile()
{
}
/**
*
*/
public File getConfigurationUpgradeDirectory()
{
}
/**
* Gets the directory where the upgrader stores files temporarily.
*
* @return File representing the upgrader's temporary directory
*/
public File getTemporaryUpgradeDirectory()
{
}
/**
* Gets the file for invoking a particular command appropriate for the current
* operating system.
*
* @param command
* name of the command
* @return File representing the command
*/
{
}
/**
* Gets the file responsible for stopping the server appropriate for the
* current operating system.
*
* @return File representing the stop command
*/
public File getServerStartCommandFile()
{
}
/**
* Gets the file responsible for stopping the server appropriate for the
* current operating system.
*
* @return File representing the stop command
*/
public File getServerStopCommandFile()
{
}
/**
* Returns the 'ldif' directory.
*
* @return the 'ldif' directory.
*/
public File getLdifDirectory()
{
}
/**
* Returns the path to the quicksetup jar file.
*
* @return the path to the quicksetup jar file.
*/
public File getQuicksetupJarFile()
{
}
/**
* Returns the path to the opends jar file.
*
* @return the path to the opends jar file.
*/
public File getOpenDSJarFile()
{
}
/**
* Returns the path to the uninstall.bat file.
*
* @return the path to the uninstall.bat file.
*/
public File getUninstallBatFile()
{
}
/**
* Gets the control panel command file appropriate for the current operating
* system.
*
* @return File object representing the control panel command
*/
public File getControlPanelCommandFile()
{
if (isWindows())
{
}
else if (isMacOS())
{
}
else
{
}
}
/**
* Gets information about the build that was used to produce the bits for this
* installation.
*
* @return BuildInformation object describing this installation
* @throws ApplicationException
* if there is a problem obtaining the build information
*/
{
return getBuildInformation(true);
}
/**
* Gets information about the build that was used to produce the bits for this
* installation.
*
* @param useCachedVersion
* where true indicates that a potentially cached version of the
* build information is acceptable for use; false indicates the the
* build information will be created from scratch which is
* potentially time consuming
* @return BuildInformation object describing this installation
* @throws ApplicationException
* if there is a problem obtaining the build information
*/
throws ApplicationException
{
{
new Callable<BuildInformation>()
{
{
}
});
try
{
}
catch (InterruptedException e)
{
}
catch (ExecutionException e)
{
throw (ApplicationException) e.getCause();
}
}
return buildInformation;
}
/**
* Gets information about the build that was used to produce the instance.
*
* @return BuildInformation object describing this instance
*/
{
return getInstanceBuildInformation(true);
}
/**
* Gets information about the build that was used to produce the instance.
*
* @param useCachedVersion
* where true indicates that a potentially cached version of the
* build information is acceptable for use; false indicates the build
* information will be created from scratch which is potentially time
* consuming
* @return BuildInformation object describing this instance
*/
{
{
try
{
{
// Read the first line and close the file.
{
}
}
else
{
return getBuildInformation();
}
}
catch (Exception e)
{
}
}
return instanceInformation;
}
}