UninstallCliHelper.java revision a6d6ee0e88ee402c8e27e300f9e8d488811bb84e
/*
* 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
* 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
*
*
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
/**
* The class used to provide some CLI interface in the uninstall.
*
* This class basically is in charge of parsing the data provided by the user
* in the command line and displaying messages asking the user for information.
*
* Once the user has provided all the required information it calls Uninstaller
* and launches it.
*
*/
class UninstallCliHelper extends CliApplicationHelper {
private UninstallerArgumentParser parser;
/**
* Default constructor.
*/
public UninstallCliHelper()
{
}
/**
* Creates a UserData based in the arguments provided. It asks
* user for additional information if what is provided in the arguments is not
* enough.
* @param args the ArgumentParser with the allowed arguments of the command
* line.
* @param rawArguments the arguments provided in the command line.
* @return the UserData object with what the user wants to uninstall
* and null if the user cancels the uninstallation.
* @throws UserDataException if there is an error parsing the data
* in the arguments.
*/
throws UserDataException
{
boolean isInteractive;
boolean isQuiet;
boolean isCancelled = false;
/* Step 1: analyze the arguments.
*/
try
{
}
catch (ArgumentException ae)
{
}
/* Step 2: check that the provided parameters are compatible.
*/
{
}
/* Step 3: If this is an interactive uninstall ask for confirmation to
* delete the different parts of the installation if the user did not
* specify anything to delete. If we are not in interactive mode
* check that the user specified something to be deleted.
*/
try {
} catch (IOException ioe) {
}
try {
} catch (IOException ioe) {
}
boolean somethingSpecifiedToDelete =
args.removeBackupFiles() ||
args.removeDatabases() ||
args.removeLDIFFiles() ||
args.removeLogFiles() ||
{
}
else
{
if (!isInteractive)
{
throw new UserDataException(null,
}
else
{
}
}
{
}
{
try
{
}
catch (Throwable t)
{
}
}
/*
* Step 4: check if server is running. Depending if it is running and the
* OS we are running, ask for authentication information.
*/
if (!isCancelled)
{
}
{
}
{
}
return userData;
}
/**
* Commodity method used to ask the user to confirm the deletion of certain
* parts of the server. It updates the provided UserData object
* accordingly. Returns <CODE>true</CODE> if the user cancels and <CODE>
* false</CODE> otherwise.
* @param userData the UserData object to be updated.
* @param outsideDbs the set of relative paths of databases located outside
* the installation path of the server.
* @param outsideLogs the set of relative paths of log files located outside
* the installation path of the server.
* @return <CODE>true</CODE> if the user cancels and <CODE>false</CODE>
* otherwise.
*/
{
boolean cancelled = false;
};
{
cancelled = true;
}
{
userData.setRemoveBackups(true);
userData.setRemoveDatabases(true);
userData.setRemoveLDIFs(true);
userData.setRemoveLogs(true);
}
else
{
boolean somethingSelected = false;
while (!somethingSelected)
{
// Ask for confirmation for the different items
)
};
Message[] validValues = {
};
{
if (!ignore)
{
}
else
{
answers[i] = false;
}
}
{
switch (i)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
if (answers[i])
{
}
break;
case 7:
if (answers[i])
{
}
break;
}
}
!userData.getRemoveDatabases() &&
!userData.getRemoveBackups() &&
!userData.getRemoveLDIFs() &&
{
somethingSelected = false;
}
else
{
somethingSelected = true;
}
}
}
return cancelled;
}
/**
* Commodity method used to ask the user (when necessary) if the server must
* be stopped or not. It also prompts (if required) for authentication.
* @param userData the UserData object to be updated with the
* authentication of the user.
* @return <CODE>true</CODE> if the user wants to continue with uninstall and
* <CODE>false</CODE> otherwise.
* @throws UserDataException if there is a problem with the data
* provided by the user (in the particular case where we are on quiet
* uninstall and some data is missing or not valid).
*/
throws UserDataException
{
boolean cancelled = false;
try
{
}
catch (Throwable t)
{
}
{
if (conf.isServerRunning())
{
if (interactive)
{
if (confirmToUpdateRemote())
{
if (cancelled)
{
/* Ask for confirmation to stop server */
cancelled = !confirmToStopServer();
}
else
{
if (cancelled)
{
/* Ask for confirmation to stop server */
cancelled = !confirmToStopServer();
}
}
}
else
{
/* Ask for confirmation to stop server */
cancelled = !confirmToStopServer();
}
}
else
{
}
}
else
{
if (interactive)
{
{
// Ask for authentication if needed, etc.
if (startWorked)
{
if (cancelled)
{
/* Ask for confirmation to stop server */
cancelled = !confirmToStopServer();
}
else
{
if (cancelled)
{
/* Ask for confirmation to stop server */
cancelled = !confirmToStopServer();
}
}
}
else
{
userData.setStopServer(false);
/* Ask for confirmation to delete files */
cancelled = !confirmDeleteFiles();
}
}
else
{
/* Ask for confirmation to delete files */
cancelled = !confirmDeleteFiles();
}
}
else
{
// Ask for authentication if needed, etc.
if (startWorked)
{
userData.setStopServer(true);
}
else
{
userData.setStopServer(false);
}
}
}
{
/* During all the confirmations, the server might be stopped. */
}
}
else
{
if (conf.isServerRunning())
{
if (interactive)
{
/* Ask for confirmation to stop server */
cancelled = !confirmToStopServer();
}
if (!cancelled)
{
/* During all the confirmations, the server might be stopped. */
}
}
else
{
userData.setStopServer(false);
if (interactive)
{
/* Ask for confirmation to delete files */
cancelled = !confirmDeleteFiles();
}
}
}
return cancelled;
}
/**
* Ask for confirmation to stop server.
* @return <CODE>true</CODE> if the user wants to continue and stop the
* server. <CODE>false</CODE> otherwise.
*/
private boolean confirmToStopServer()
{
}
/**
* Ask for confirmation to delete files.
* @return <CODE>true</CODE> if the user wants to continue and delete the
* files. <CODE>false</CODE> otherwise.
*/
private boolean confirmDeleteFiles()
{
}
/**
* Ask for confirmation to update configuration on remote servers.
* @return <CODE>true</CODE> if the user wants to continue and stop the
* server. <CODE>false</CODE> otherwise.
*/
private boolean confirmToUpdateRemote()
{
}
/**
* Ask for confirmation to update configuration on remote servers.
* @return <CODE>true</CODE> if the user wants to continue and stop the
* server. <CODE>false</CODE> otherwise.
*/
private boolean confirmToUpdateRemoteAndStart()
{
}
/**
* Ask for confirmation to provide again authentication.
* @return <CODE>true</CODE> if the user wants to provide authentication
* againr. <CODE>false</CODE> otherwise.
*/
private boolean promptToProvideAuthenticationAgain()
{
}
/**
* Ask for data required to update configuration on remote servers. If
* all the data is provided and validated, we assume that the user wants
* to update the remote servers.
* @return <CODE>true</CODE> if the user wants to continue and update the
* remote servers. <CODE>false</CODE> otherwise.
*/
{
boolean accepted = true;
int port = 389;
boolean couldConnect = false;
while (!couldConnect && accepted)
{
boolean prompted = false;
{
prompted = true;
}
{
if (!prompted)
{
}
}
try
{
try
{
}
catch (Throwable t)
{
}
couldConnect = true;
}
catch (NamingException ne)
{
{
}
else
{
}
}
catch (ConfigException ce)
{
useSSL = false;
useStartTLS = false;
if (!useSSL)
{
}
}
catch (Throwable t)
{
}
finally
{
{
try
{
}
catch (Throwable t)
{
}
}
}
}
if (accepted)
{
while (referencedHostName == null)
{
}
try
{
}
catch (Throwable t)
{
}
}
return accepted;
}
{
}
private boolean startServer(boolean supressOutput)
{
boolean serverStarted = false;
{
/**
* {@inheritDoc}
*/
public String getInstallationPath()
{
}
/**
* {@inheritDoc}
*/
public ProgressStep getCurrentProgressStep()
{
return UninstallProgressStep.NOT_STARTED;
}
/**
* {@inheritDoc}
*/
{
return 0;
}
/**
* {@inheritDoc}
*/
{
return null;
}
/**
* {@inheritDoc}
*/
public boolean isFinished()
{
return false;
}
/**
* {@inheritDoc}
*/
public boolean isCancellable()
{
return false;
}
/**
* {@inheritDoc}
*/
public void cancel()
{
}
/**
* {@inheritDoc}
*/
public void run()
{
}
};
if (!supressOutput)
{
new ProgressUpdateListener() {
}
});
}
Installation.getLocal());
try
{
if (!supressOutput)
{
}
if (!supressOutput)
{
}
}
catch (ApplicationException ae)
{
if (!supressOutput)
{
}
}
return serverStarted;
}
/**
* Updates the contents of the UninstallUserData while trying to connect
* to the remote servers. It returns <CODE>true</CODE> if we could connect
* to the remote servers and all the presented certificates were accepted and
* <CODE>false</CODE> otherwise.
* continue if
* @param userData the user data to be updated.
* @return <CODE>true</CODE> if we could connect
* to the remote servers and all the presented certificates were accepted and
* <CODE>false</CODE> otherwise.
*/
private boolean updateUserUninstallDataWithRemoteServers(
{
boolean accepted = false;
boolean exceptionOccurred = true;
try
{
int port = 389;
try
{
}
catch (Throwable t)
{
}
exceptionOccurred = false;
}
catch (ConfigException ce)
{
}
catch (NamingException ne)
{
{
ne.getMessage()));
}
else
{
}
} catch (TopologyCacheException te)
{
} catch (Throwable t)
{
}
finally
{
{
try
{
}
catch (Throwable t)
{
}
}
}
if (exceptionOccurred)
{
if (!interactive)
{
if (forceOnError)
{
}
else
{
}
}
else
{
}
}
return accepted;
}
/**
* Method that interacts with the user depending on what errors where
* encountered in the TopologyCache object. This method assumes that the
* TopologyCache has been reloaded.
* Returns <CODE>true</CODE> if the user accepts all the problems encountered
* and <CODE>false</CODE> otherwise.
* @param userData the user data.
*/
{
boolean returnValue;
boolean stopProcessing = false;
boolean reloadTopologyCache = false;
new HashSet<TopologyCacheException>();
/* Analyze if we had any exception while loading servers. For the moment
* only throw the exception found if the user did not provide the
* Administrator DN and this caused a problem authenticating in one server
* or if there is a certificate problem.
*/
{
if (e != null)
{
exceptions.add(e);
}
}
/* Check the exceptions and see if we throw them or not. */
for (TopologyCacheException e : exceptions)
{
if (stopProcessing)
{
break;
}
switch (e.getType())
{
case NOT_GLOBAL_ADMINISTRATOR:
stopProcessing = true;
break;
{
if (interactive)
{
if (promptForCertificateConfirmation(e.getCause(),
e.getTrustManager(), e.getLdapUrl(),
{
stopProcessing = true;
reloadTopologyCache = true;
}
else
{
stopProcessing = true;
}
}
else
{
stopProcessing = true;
}
}
else
{
}
break;
default:
}
}
if (interactive)
{
{
}
else if (reloadTopologyCache)
{
}
else
{
}
}
else
{
{
returnValue = false;
}
else
{
returnValue = true;
}
}
return returnValue;
}
}