InstallerHelper.java revision d0d27dbc1cd64b2ef276a3b280b21d9d6e1081db
/*
* 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 is the only class that uses classes in org.opends.server (excluding the
* case of DynamicConstants, SetupUtils and CertificateManager
* which are already included in quicksetup.jar).
*
* Important note: do not include references to this class until OpenDS.jar has
* been loaded. These classes must be loaded during Runtime.
* The code is written in a way that when we execute the code that uses these
* classes the required jar files are already loaded. However these jar files
* are not necessarily loaded when we create this class.
*/
public class InstallerHelper {
/**
* Invokes the method ConfigureDS.configMain with the provided parameters.
* @param args the arguments to be passed to ConfigureDS.configMain.
* @return the return code of the ConfigureDS.configMain method.
* @throws ApplicationException if something goes wrong.
* @see org.opends.server.tools.ConfigureDS#configMain(String[],
* java.io.OutputStream, java.io.OutputStream)
*/
}
/**
* Invokes the import-ldif command-line with the provided parameters.
*
* @param application
* the application that is launching this.
* @param args
* the arguments to be passed to import-ldif.
* @return the return code of the import-ldif call.
* @throws IOException
* if the process could not be launched.
* @throws InterruptedException
* if the process was interrupted.
*/
public int invokeImportLDIF(final Application application, String[] args) throws IOException, InterruptedException
{
final File binPath = new File(installPath, isWindows() ? Installation.WINDOWS_BINARIES_PATH_RELATIVE
final ProcessBuilder processBuilder = new ProcessBuilder(argList.toArray(new String[argList.size()]));
try
{
new OutputReader(err)
{
{
}
};
new OutputReader(out)
{
{
}
};
}
finally
{
{
}
}
}
{
try
{
}
catch (Throwable t)
{
}
}
/**
* Returns the LocalizableMessage ID that corresponds to a successfully started server.
* @return the LocalizableMessage ID that corresponds to a successfully started server.
*/
public String getStartedId()
{
}
/**
* This methods enables this server as a Windows service.
* @throws ApplicationException if something goes wrong.
*/
public void enableWindowsService() throws ApplicationException {
switch (code) {
case
break;
case
break;
default:
throw new ApplicationException(
errorMessage, null);
}
}
/**
* This method disables this server as a Windows service.
* @throws ApplicationException if something goes worong.
*/
public void disableWindowsService() throws ApplicationException
{
throw new ApplicationException(
// TODO: fix this message's format string
}
}
/**
* Creates a template LDIF file with an entry that has as dn the provided
* baseDn.
* @param baseDn the dn of the entry that will be created in the LDIF file.
* @return the File object pointing to the created temporary file.
* @throws ApplicationException if something goes wrong.
*/
throws ApplicationException {
try
{
} catch (IOException ioe)
{
throw new ApplicationException(
}
try
{
throw new ApplicationException(
} catch (Throwable t) {
throw new ApplicationException(
INFO_BUG_MSG.get(), t), t);
}
return ldifFile;
}
/**
* Deletes a backend on the server.
* @param ctx the connection to the server.
* @param backendName the name of the backend to be deleted.
* @param serverDisplay the server display.
* @throws ApplicationException if something goes wrong.
*/
throws ApplicationException
{
try
{
}
catch (Throwable t)
{
throw new ApplicationException(
t);
}
}
/**
* Deletes a backend on the server. It assumes the server is stopped.
* @param backendName the name of the backend to be deleted.
* @throws ApplicationException if something goes wrong.
*/
throws ApplicationException
{
try
{
// Read the configuration file.
backendName)+",cn=Backends,cn=config";
}
{
throw new ApplicationException(
}
}
/**
* Creates a local database backend on the server.
*
* @param ctx
* the connection to the server.
* @param backendName
* the name of the backend to be created.
* @param baseDNs
* the list of base DNs to be defined on the server.
* @param serverDisplay
* the server display.
* @throws ApplicationException
* if something goes wrong.
*/
public void createLocalDBBackend(DirContext ctx, String backendName, Set<String> baseDNs, String serverDisplay)
throws ApplicationException
{
try
{
LocalDBBackendCfgClient backend = root.createBackend(LocalDBBackendCfgDefn.getInstance(), backendName, null);
backend.setEnabled(true);
{
}
}
catch (Throwable t)
{
throw new ApplicationException(
}
}
/**
* Sets the base DNs on a given backend.
* @param ctx the connection to the server.
* @param backendName the name of the backend where the base Dns must be
* defined.
* @param baseDNs the list of base DNs to be defined on the server.
* @param serverDisplay the server display.
* @throws ApplicationException if something goes wrong.
*/
throws ApplicationException
{
try
{
{
}
}
catch (Throwable t)
{
throw new ApplicationException(
t);
}
}
/**
* Configures the replication on a given server.
* @param remoteCtx the connection to the server where we want to configure
* the replication.
* @param replicationServers a Map where the key value is the base dn and
* the value is the list of replication servers for that base dn (or domain).
* @param replicationPort the replicationPort of the server that is being
* configured (it might not exist and the user specified it in the setup).
* @param useSecureReplication whether to encrypt connections with the
* replication port or not.
* @param serverDisplay the server display.
* @param usedReplicationServerIds the list of replication server ids that
* are already used.
* @param usedServerIds the list of server ids (domain ids) that
* are already used.
* @throws ApplicationException if something goes wrong.
* @return a ConfiguredReplication object describing what has been configured.
*/
throws ApplicationException
{
boolean synchProviderCreated;
boolean synchProviderEnabled;
boolean replicationServerCreated;
boolean secureReplicationEnabled;
try
{
/*
* Configure Synchronization plugin.
*/
try
{
}
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
}
{
"Multimaster Synchronization",
new ArrayList<PropertyException>());
getName());
synchProviderCreated = true;
synchProviderEnabled = false;
}
else
{
synchProviderCreated = false;
{
synchProviderEnabled = true;
}
else
{
synchProviderEnabled = false;
}
}
/*
* Configure the replication server.
*/
if (!sync.hasReplicationServer())
{
if (useSecureReplication)
{
if (!crypto.isSSLEncryption())
{
crypto.setSSLEncryption(true);
secureReplicationEnabled = true;
}
else
{
// Only mark as true if we actually change the configuration
secureReplicationEnabled = false;
}
}
else
{
secureReplicationEnabled = false;
}
new ArrayList<PropertyException>());
replicationServerCreated = true;
}
else
{
secureReplicationEnabled = false;
replicationServerCreated = false;
}
{
}
{
}
/*
* Create the domains
*/
if (domainNames == null)
{
domainNames = new String[]{};
}
{
}
{
boolean isCreated;
{
if (areDnsEqual(dn,
{
domainName = domainNames[i];
}
}
{
new ArrayList<PropertyException>());
isCreated = true;
}
else
{
isCreated = false;
}
if (oldServers == null)
{
}
}
return new ConfiguredReplication(synchProviderCreated,
}
catch (Throwable t)
{
throw new ApplicationException(
t);
}
}
{
return result;
}
/**
* Configures the replication on a given server.
*
* @param remoteCtx
* the connection to the server where we want to configure the
* replication.
* @param replConf
* the object describing what was configured.
* @param serverDisplay
* the server display.
* @throws ApplicationException
* if something goes wrong.
*/
public void unconfigureReplication(InitialLdapContext remoteCtx, ConfiguredReplication replConf, String serverDisplay)
throws ApplicationException
{
try
{
ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(remoteCtx));
// Unconfigure Synchronization plugin.
if (replConf.isSynchProviderCreated())
{
try
{
}
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
}
}
else
{
try
{
if (replConf.isSynchProviderEnabled())
{
}
{
}
else if (sync.hasReplicationServer())
{
if (replServers != null)
{
}
}
{
{
}
else
{
try
{
if (replServers != null)
{
d.commit();
}
}
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
}
}
}
}
catch (ManagedObjectNotFoundException monfe)
{
// It does not exist.
}
}
{
if (crypto.isSSLEncryption())
{
crypto.setSSLEncryption(false);
}
}
}
catch (Throwable t)
{
throw new ApplicationException(ReturnCode.CONFIGURATION_ERROR, INFO_ERROR_CONFIGURING_REMOTE_GENERIC.get(
serverDisplay, t), t);
}
}
/**
* For the given state provided by a Task tells if the task is done or not.
*
* @param sState
* the String representing the task state.
* @return <CODE>true</CODE> if the task is done and <CODE>false</CODE>
* otherwise.
*/
{
}
/**
* For the given state provided by a Task tells if the task is successful or
* not.
*
* @param sState
* the String representing the task state.
* @return <CODE>true</CODE> if the task is successful and <CODE>false</CODE>
* otherwise.
*/
{
}
/**
* For the given state provided by a Task tells if the task is complete with
* errors or not.
*
* @param sState
* the String representing the task state.
* @return <CODE>true</CODE> if the task is complete with errors and
* <CODE>false</CODE> otherwise.
*/
{
}
/**
* For the given state provided by a Task tells if the task is stopped by
* error or not.
*
* @param sState
* the String representing the task state.
* @return <CODE>true</CODE> if the task is stopped by error and
* <CODE>false</CODE> otherwise.
*/
{
}
/**
* Tells whether the provided log message corresponds to a peers not found
* error during the initialization of a replica or not.
*
* @param logMsg
* the log message.
* @return <CODE>true</CODE> if the log message corresponds to a peers not
* found error during initialization and <CODE>false</CODE> otherwise.
*/
{
}
/**
* Returns the ID to be used for a new replication server or domain.
* @param usedIds the list of already used ids.
* @return the ID to be used for a new replication server or domain.
*/
{
int id = 0;
{
}
return id;
}
/**
* Returns the name to be used for a new replication domain.
* @param existingDomains the existing domains names.
* @param newDomainId the new domain replication id.
* @param baseDN the base DN of the domain.
* @return the name to be used for a new replication domain.
*/
{
boolean nameExists = true;
int j = 0;
while (nameExists)
{
boolean found = false;
{
}
if (found)
{
}
else
{
nameExists = false;
}
j++;
}
return domainName;
}
/**
* Writes the set-java-home file that is used by the scripts to set the java
* home and the java arguments.
*
* @param uData
* the data provided by the user.
* @param installPath
* where the server is installed.
* @throws IOException
* if an error occurred writing the file.
*/
{
{
}
// Try to transform things if necessary. The following map has as key
// the original JavaArgument object and as value the 'transformed' JavaArgument.
{
{
{
// The argument works, so just use it.
}
else
{
// We have to fix it somehow: test separately memory and other
// arguments to see if something works.
JavaArguments transformedArguments = getBestEffortArguments(origJavaArguments, javaHome, installPath);
}
}
// else, support is already checked.
}
{
// Apply the following policy: overwrite the values in the file only
// if the values provided by the user are not the default ones.
{
}
else
{
}
}
{
}
}
private void putBooleanPropertyFrom(
{
if (propertyValue == null || !("true".equalsIgnoreCase(propertyValue) || "false".equalsIgnoreCase(propertyValue)))
{
}
else
{
}
}
/**
* Tries to figure out a new JavaArguments object that works, based on the
* provided JavaArguments. It is more efficient to call this method if we are
* sure that the provided JavaArguments object does not work.
*
* @param origJavaArguments
* the java arguments that does not work.
* @param javaHome
* the java home to be used to test the java arguments.
* @param installPath
* the install path.
* @return a working JavaArguments object.
*/
private JavaArguments getBestEffortArguments(JavaArguments origJavaArguments, String javaHome, String installPath)
{
boolean supportsMemory = false;
if (m.length() > 0)
{
}
boolean supportsAdditional = false;
if (a.length() > 0)
{
}
if (supportsMemory)
{
}
else
{
// Try to figure out a smaller amount of memory.
if (maxMemory != -1)
{
{
}
{
// Supports this option.
}
}
}
if (supportsAdditional)
{
}
return javaArgs;
}
{
{
{
}
else
{
break;
}
}
return commentLines;
}
{
try
{
}
catch (Throwable t)
{ /* do nothing */
}
finally
{
}
return fileProperties;
}
{
}
/**
* Writes the set-java-home file that is used by the scripts to set the java
* home and the java arguments. Since the set-java-home file is created and
* may be changed, it's created under the instancePath.
*
* @param installPath
* the install path of the server.
* @param javaHome
* the java home to be used.
* @param arguments
* a Map containing as key the name of the script and as value, the
* java arguments to be set for the script.
* @param otherProperties
* other properties that must be set in the file.
* @throws IOException
* if an error occurred writing the file.
*/
private void writeSetOpenDSJavaHome(String installPath, String javaHome, Map<String, JavaArguments> arguments,
{
{
}
{
}
{
}
// Create directory if it doesn't exist yet
{
}
final String destinationFile = Utils.getPath(libDir, isWindows() ? Installation.SET_JAVA_PROPERTIES_FILE_WINDOWS
// Launch the script
{
"--propertiesFile", propertiesFile,
"--destinationFile", destinationFile,
"--quiet"
};
{
logger.warn(LocalizableMessage.raw("Error creating java home scripts, error code: " + returnValue));
}
}
/**
* Returns the java argument property for a given script.
*
* @param scriptName
* the script name.
* @return the java argument property for a given script.
*/
{
return scriptName + ".java-args";
}
/**
* If the log message is of type "[03/Apr/2008:21:25:43 +0200] category=JEB
* severity=NOTICE msgID=8847454 Processed 1 entries, imported 0, skipped 1,
* rejected 0 and migrated 0 in 1 seconds (average rate 0.0/sec)" returns the
* message part. Returns <CODE>null</CODE> otherwise.
*
* @param msg
* the message to be parsed.
* @return the parsed import message.
*/
{
{
if (index != -1)
{
}
}
return null;
}
}