/*
* 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 2008-2009 Sun Microsystems, Inc.
* Portions Copyright 2011-2013 ForgeRock AS
*/
/**
* The class used to define a number of common methods and mechanisms for the
* tasks that are run in the Control Panel.
*
*/
public abstract class Task
{
/**
* The different task types.
*
*/
public enum Type
{
/**
* New Base DN creation.
*/
/**
* New index creation.
*/
/**
* Modification of indexes.
*/
/**
* Deletion of indexes.
*/
/**
* Creation of VLV indexes.
*/
/**
* Modification of VLV indexes.
*/
/**
* Deletion of VLV indexes.
*/
/**
* Import of an LDIF file.
*/
/**
* Export of an LDIF file.
*/
/**
* Backup.
*/
/**
* Restore.
*/
/**
* Verification of indexes.
*/
/**
* Rebuild of indexes.
*/
/**
* Enabling of Windows Service.
*/
/**
* Disabling of Windows Service.
*/
/**
* Starting the server.
*/
/**
* Stopping the server.
*/
/**
* Updating the java settings for the different command-lines.
*/
/**
* Creating a new element in the schema.
*/
/**
* Deleting an schema element.
*/
/**
* Modify an schema element.
*/
/**
* Modifying an entry.
*/
/**
* Creating an entry.
*/
/**
* Deleting an entry.
*/
/**
* Deleting a base DN.
*/
/**
* Deleting a backend.
*/
/**
* Other task.
*/
}
/**
* The state on which the task can be.
*/
public enum State
{
/**
* The task is not started.
*/
/**
* The task is running.
*/
/**
* The task finished successfully.
*/
/**
* The task finished with error.
*/
}
/**
* Returns the names of the backends that are affected by the task.
* @return the names of the backends that are affected by the task.
*/
/**
* The current state of the task.
*/
/**
* The return code of the task.
*/
/**
* The last exception encountered during the task execution.
*/
/**
* The progress logs of the task. Note that the user of StringBuffer is not
* a bug, because of the way the contents of logs is updated, using
* StringBuffer instead of StringBuilder is required.
*/
/**
* The error logs of the task.
*/
/**
* The standard output logs of the task.
*/
/**
* The print stream for the error logs.
*/
new ApplicationPrintStream();
/**
* The print stream for the standard output logs.
*/
new ApplicationPrintStream();
/**
* The process (if any) that the task launched. For instance if this is a
* start server task, the process generated executing the start-ds
* command-line.
*/
/**
* Constructor of the task.
* @param info the control panel information.
* @param progressDialog the progress dialog where the task progress will be
* displayed.
*/
{
this.progressDialog = progressDialog;
{
/**
* Add a new line to the logs.
* @param msg the new line.
*/
{
}
});
{
/**
* Add a new line to the error logs.
* @param msg the new line.
*/
{
}
});
}
/**
* Returns the ControlPanelInfo object.
* @return the ControlPanelInfo object.
*/
{
return info;
}
/**
* Returns the logs of the task.
* @return the logs of the task.
*/
{
}
/**
* Returns the error logs of the task.
* @return the error logs of the task.
*/
{
}
/**
* Returns the output logs of the task.
* @return the output logs of the task.
*/
{
return outputLogs.toString();
}
/**
* Returns the state of the task.
* @return the state of the task.
*/
{
return state;
}
/**
* Returns last exception encountered during the task execution.
* Returns <CODE>null</CODE> if no exception was found.
* @return last exception encountered during the task execution.
*/
{
return lastException;
}
/**
* Returns the return code (this makes sense when the task launches a
* command-line, it will return the error code returned by the command-line).
* @return the return code.
*/
{
return returnCode;
}
/**
* Returns the process that the task launched.
* Returns <CODE>null</CODE> if not process was launched.
* @return the process that the task launched.
*/
{
return process;
}
/**
* Returns the progress dialog.
* @return the progress dialog.
*/
{
return progressDialog;
}
/**
* Tells whether a new server descriptor should be regenerated when the task
* is over. If the task has an influence in the configuration or state of
* the server (for instance the creation of a base DN) this method should
* return <CODE>true</CODE> so that the configuration will be re-read and
* all the ConfigChangeListeners will receive a notification with the new
* configuration.
* @return <CODE>true</CODE> if a new server descriptor must be regenerated
* when the task is over and <CODE>false</CODE> otherwise.
*/
public boolean regenerateDescriptor()
{
return true;
}
/**
* Method that is called when everything is finished after updating the
* progress dialog. It is called from the event thread.
*/
public void postOperation()
{
}
/**
* The description of the task. It is used in both the incompatibility
* messages and in the warning message displayed when the user wants to
* quit and there are tasks running.
* @return the description of the task.
*/
/**
* Adds a configuration element created listener.
* @param listener the listener.
*/
public void addConfigurationElementCreatedListener(
{
}
/**
* Removes a configuration element created listener.
* @param listener the listener.
*/
public void removeConfigurationElementCreatedListener(
{
}
/**
* Notifies the configuration element created listener that a new object has
* been created.
* @param configObject the created object.
*/
{
{
new ConfigurationElementCreatedEvent(this, configObject));
}
}
/**
* Returns a String representation of a value. In general this is called
* to display the command-line equivalent when we do a modification in an
* entry. But since some attributes must be obfuscated (like the user
* password) we pass through this method.
* @param attrName the attribute name.
* @param o the attribute value.
* @return the obfuscated String representing the attribute value to be
* displayed in the logs of the user.
*/
{
{
return Utilities.OBFUSCATED_VALUE;
}
else
{
if (o instanceof byte[])
{
byte[] bytes = (byte[])o;
if (displayBase64(attrName))
{
{
}
else
{
}
}
else
{
{
}
else
{
// Get the String value
return v.toString();
}
}
}
else
{
}
}
}
/**
* Obfuscates (if required) the attribute value in an LDIF line.
* @param line the line of the LDIF file that must be treated.
* @return the line obfuscated.
*/
{
if (index != -1)
{
{
}
else
{
returnValue = line;
}
}
else
{
returnValue = line;
}
return returnValue;
}
/**
* Executes a command-line synchronously.
* @param commandLineName the command line full path.
* @param args the arguments for the command-line.
* @return the error code returned by the command-line.
*/
{
returnCode = -1;
{
}
// Use the java args in the script.
//env.put(SetupUtils.OPENDJ_JAVA_ARGS, "");
try {
} catch (Throwable t)
{
lastException = t;
}
finally
{
{
}
{
}
}
return returnCode;
}
/**
* Informs of whether the task to be launched can be launched or not. Every
* task must implement this method so that we avoid launching in paralel two
* tasks that are not compatible. Note that in general if the current task
* is not running this method will return <CODE>true</CODE>.
*
* @param taskToBeLaunched the Task that we are trying to launch.
* @param incompatibilityReasons the list of incompatibility reasons that
* must be updated.
* @return <CODE>true</CODE> if the task that we are trying to launch can be
* launched in paralel with this task and <CODE>false</CODE> otherwise.
*/
/**
* Execute the task. This method is synchronous.
*
*/
public abstract void runTask();
/**
* Returns the type of the task.
* @return the type of the task.
*/
/**
*/
{
{
try
{
binDir = f.getCanonicalPath();
}
catch (Throwable t)
{
binDir = f.getAbsolutePath();
}
{
}
}
return binDir;
}
/**
* Check whether the provided task and this task run on the same server.
* @param task the task the task to be analyzed.
* @return <CODE>true</CODE> if both tasks run on the same server and
* <CODE>false</CODE> otherwise.
*/
{
boolean runningOnSameServer = false;
{
runningOnSameServer = true;
}
else
{
// Compare the host name and the instance path. This is safer than
// comparing ports: we might be running locally on a stopped instance with
// the same configuration as a "remote" (though located on the same
// machine) server.
{
}
else
{
}
if (runningOnSameServer)
{
{
}
else
{
}
}
}
return runningOnSameServer;
}
/**
* Returns the server descriptor on which the task was launched.
* @return the server descriptor on which the task was launched.
*/
{
return server;
}
/**
* Returns the full path of the command-line associated with this task or
* <CODE>null</CODE> if there is not a command-line (or a single command-line)
* associated with the task.
* @return the full path of the command-line associated with this task.
*/
/**
* Returns the full path of the command-line for a given script name.
* @param scriptBasicName the script basic name (with no extension).
* @return the full path of the command-line for a given script name.
*/
{
{
}
else
{
}
return cmdLineName;
}
/**
* Returns the list of command-line arguments.
* @return the list of command-line arguments.
*/
/**
* Returns the list of obfuscated command-line arguments. This is called
* basically to display the equivalent command-line to the user.
* @param clearArgs the arguments in clear.
* @return the list of obfuscated command-line arguments.
*/
{
"--newPassword"};
{
{
{
break;
}
}
}
return args;
}
/**
* Returns the command-line arguments that correspond to the configuration.
* This method is called to remove them when we display the equivalent
* command-line. In some cases we run the methods of the command-line
* directly (on this JVM) instead of launching the script in another process.
* When we call this methods we must add these arguments, but they are not
* to be included as arguments of the command-line (when is launched as a
* script).
* @return the command-line arguments that correspond to the configuration.
*/
{
return args;
}
/**
* Returns the list of arguments related to the connection (host, port, bind
* DN, etc.).
* @return the list of arguments related to the connection.
*/
{
return getConnectionCommandLineArguments(true, false);
}
/**
* Returns the list of arguments related to the connection (host, port, bind
* DN, etc.).
* @param useAdminConnector use the administration connector to generate
* the command line.
* @param addConnectionTypeParameters add the connection type parameters
* (--useSSL or --useStartTLS parameters: for ldapadd, ldapdelete, etc.).
* @return the list of arguments related to the connection.
*/
boolean useAdminConnector, boolean addConnectionTypeParameters)
{
if (useAdminConnector)
{
}
else
{
}
{
{
}
if (isSSL || isStartTLS)
{
}
if (isSSL && addConnectionTypeParameters)
{
}
else if (isStartTLS && addConnectionTypeParameters)
{
}
}
return args;
}
/**
* Returns the noPropertiesFile argument.
* @return the noPropertiesFile argument.
*/
{
return "--noPropertiesFile";
}
/**
* Returns the command-line to be displayed (when we display the equivalent
* command-line).
* @return the command-line to be displayed.
*/
{
if (cmdLineName != null)
{
}
else
{
return null;
}
}
/**
* Commodity method to know if the server is running or not.
* @return <CODE>true</CODE> if the server is running and <CODE>false</CODE>
* otherwise.
*/
protected boolean isServerRunning()
{
}
/**
*
* Returns the print stream for the error logs.
* @return the print stream for the error logs.
*/
{
return errorPrintStream;
}
/**
*
* Returns the print stream for the output logs.
* @return the print stream for the output logs.
*/
{
return outPrintStream;
}
/**
* Prints the equivalent modify command line in the progress dialog.
* @param dn the dn of the modified entry.
* @param mods the modifications.
* @param useAdminCtx use the administration connector.
*/
{
}
/**
* Prints the equivalent modify command line in the progress dialog.
* @param dn the dn of the modified entry.
* @param mods the modifications.
* @param useAdminCtx use the administration connector.
*/
{
getConnectionCommandLineArguments(useAdminCtx, true)));
args);
boolean firstChangeType = true;
{
if (firstChangeType)
{
}
else
{
}
firstChangeType = false;
{
}
{
}
else
{
}
{
try
{
// We are systematically adding the values in binary mode.
// Use the attribute names to figure out the value to be displayed.
{
}
else
{
}
}
catch (NamingException ne)
{
// Bug
throw new RuntimeException(
}
}
}
}
/**
* The separator used to link the lines of the resulting command-lines.
*/
/**
* Returns the equivalent command line in HTML without font properties.
* @param cmdName the command name.
* @param args the arguments for the command line.
* @return the equivalent command-line in HTML.
*/
{
{
{
}
else
{
}
}
}
/**
* Prints the equivalent command line.
* @param cmdName the command name.
* @param args the arguments for the command line.
* @param msg the message associated with the command line.
*/
{
}
/**
* Tells whether the provided attribute's values must be displayed using
* base 64 when displaying the equivalent command-line or not.
* @param attrName the attribute name.
* @return <CODE>true</CODE> if the attribute must be displayed using base 64
* and <CODE>false</CODE> otherwise.
*/
{
{
}
}
/**
* Prints the equivalent rename command line in the progress dialog.
* @param oldDN the old DN of the entry.
* @param newDN the new DN of the entry.
* @param useAdminCtx use the administration connector.
*/
boolean useAdminCtx)
{
getConnectionCommandLineArguments(useAdminCtx, true)));
args);
}
/**
* Returns the incompatible message between two tasks.
* @param taskRunning the task that is running.
* @param taskToBeLaunched the task that we are trying to launch.
* @return the incompatible message between two tasks.
*/
{
}
}