| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | * Portions copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup; |
| | |
| | | import org.opends.admin.ads.util.ServerLoader; |
| | | import org.opends.quicksetup.event.ProgressNotifier; |
| | | import org.opends.quicksetup.event.ProgressUpdateListener; |
| | | import org.opends.quicksetup.util.ServerController; |
| | | import org.opends.quicksetup.util.ProgressMessageFormatter; |
| | | import org.opends.quicksetup.util.UIKeyStore; |
| | | import org.opends.quicksetup.ui.GuiApplication; |
| | |
| | | import java.io.PrintStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | |
| | | |
| | | /** |
| | | * This class represents an application that can be run in the context of |
| | | * QuickSetup. Examples of applications might be 'installer', 'uninstaller' |
| | | * and 'upgrader'. |
| | | * QuickSetup. Examples of applications might be 'installer' and 'uninstaller'. |
| | | */ |
| | | public abstract class Application implements ProgressNotifier, Runnable { |
| | | |
| | |
| | | |
| | | private Installation installation; |
| | | |
| | | private ServerController serverController; |
| | | |
| | | private ApplicationTrustManager trustManager; |
| | | |
| | | private boolean notifyListeners = true; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Gets the OpenDS installation associated with the execution of this |
| | | * Gets the OpenDJ installation associated with the execution of this |
| | | * command. |
| | | * @return Installation object representing the current OpenDS installation |
| | | */ |
| | |
| | | this.installation = installation; |
| | | } |
| | | |
| | | /** |
| | | * Gets a server controller for use by this application. |
| | | * @return ServerController that can be used to start and stop the server. |
| | | */ |
| | | public ServerController getServerController() { |
| | | if (serverController == null) { |
| | | serverController = new ServerController(this); |
| | | } |
| | | return serverController; |
| | | } |
| | | |
| | | /** |
| | | * Returns the UserData object representing the parameters provided by |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted text string 'Error' with a line break at the end. |
| | | * @return formatted 'Error' |
| | | */ |
| | | protected Message getFormattedErrorWithLineBreak() { |
| | | return new MessageBuilder(formatter.getFormattedError()) |
| | | .append(formatter.getLineBreak()).toMessage(); |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of an error for a given text. |
| | | * @param text the source text from which we want to get the formatted |
| | | * representation |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of an error message for a given |
| | | * exception. |
| | | * This method applies a margin if the applyMargin parameter is |
| | | * <CODE>true</CODE>. |
| | | * @param m the exception. |
| | | * @param b specifies whether we apply a margin or not to the |
| | | * resulting formatted text. |
| | | * @return the formatted representation of an error message for the given |
| | | * exception. |
| | | */ |
| | | protected Message getFormattedErrorWithLineBreak(Message m, boolean b) { |
| | | return new MessageBuilder(formatter.getFormattedError(m,b)) |
| | | .append(formatter.getLineBreak()).toMessage(); |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of an error message for a given |
| | | * exception. |
| | | * This method applies a margin if the applyMargin parameter is |
| | | * <CODE>true</CODE>. |
| | | * @param t the exception. |
| | | * @param b specifies whether we apply a margin or not to the |
| | | * resulting formatted text. |
| | | * @return the formatted representation of an error message for the given |
| | | * exception. |
| | | */ |
| | | protected Message getFormattedErrorWithLineBreak(Throwable t, boolean b) { |
| | | return new MessageBuilder(formatter.getFormattedError(t,b)) |
| | | .append(formatter.getLineBreak()).toMessage(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns the formatted representation of an warning for a given text. |
| | | * @param text the source text from which we want to get the formatted |
| | | * representation |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of an error message for a given |
| | | * exception. |
| | | * This method applies a margin if the applyMargin parameter is |
| | | * <CODE>true</CODE>. |
| | | * @param m the message. |
| | | * @param applyMargin specifies whether we apply a margin or not to the |
| | | * resulting formatted text. |
| | | * @return the formatted representation of an error message for the given |
| | | * exception. |
| | | */ |
| | | protected Message getFormattedError(Message m, boolean applyMargin) |
| | | { |
| | | return formatter.getFormattedError(m, applyMargin); |
| | | } |
| | | |
| | | /** |
| | | * Returns the line break formatted. |
| | | * @return the line break formatted. |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Makes available a <code>UserInteraction</code> class that can be used |
| | | * by the application to interact with the user. If the user has requested |
| | | * a quiet session this method returns null. |
| | | * @return UserInteraction object |
| | | */ |
| | | public UserInteraction userInteraction() { |
| | | // Note: overridden in GuiApplication |
| | | return new CliUserInteraction(getUserData()); |
| | | } |
| | | |
| | | /** |
| | | * Conditionally notifies listeners of the log file if it |
| | | * has been initialized. |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Writes an initial record in the installation's historical |
| | | * log describing moving from one version to another. |
| | | * @param fromVersion from with install will be migrated |
| | | * @param toVersion to which install will be migrated |
| | | * @return Long ID for this session |
| | | * @throws ApplicationException if something goes wrong |
| | | */ |
| | | protected Long writeInitialHistoricalRecord( |
| | | BuildInformation fromVersion, |
| | | BuildInformation toVersion) |
| | | throws ApplicationException { |
| | | Long id; |
| | | try { |
| | | HistoricalLog log = |
| | | new HistoricalLog(getInstallation().getHistoryLogFile()); |
| | | id = log.append(fromVersion, toVersion, |
| | | HistoricalRecord.Status.STARTED, |
| | | "log file '" + QuickSetupLog.getLogFile().getPath() + "'"); |
| | | } catch (IOException e) { |
| | | Message msg = INFO_ERROR_LOGGING_OPERATION.get(); |
| | | throw ApplicationException.createFileSystemException( |
| | | msg, e); |
| | | } |
| | | return id; |
| | | } |
| | | |
| | | /** |
| | | * Writes a record into this installation's historical log. |
| | | * @param id obtained from calling <code>writeInitialHistoricalRecord</code> |
| | | * @param from version from with install will be migrated |
| | | * @param to version to which install will be migrated |
| | | * @param status of the operation |
| | | * @param note string with additional information |
| | | * @throws ApplicationException if something goes wrong |
| | | */ |
| | | protected void writeHistoricalRecord( |
| | | Long id, |
| | | BuildInformation from, |
| | | BuildInformation to, |
| | | HistoricalRecord.Status status, |
| | | String note) |
| | | throws ApplicationException { |
| | | try { |
| | | HistoricalLog log = |
| | | new HistoricalLog(getInstallation().getHistoryLogFile()); |
| | | log.append(id, from, to, status, note); |
| | | } catch (IOException e) { |
| | | Message msg = INFO_ERROR_LOGGING_OPERATION.get(); |
| | | throw ApplicationException.createFileSystemException(msg, e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Returns a localized representation of a TopologyCacheException object. |
| | | * @param e the exception we want to obtain the representation from. |
| | | * @return a localized representation of a TopologyCacheException object. |
| | |
| | | ServerLoader loader = new ServerLoader(adsProperties, dn, pwd, |
| | | trustManager, timeout, cnx, filter); |
| | | |
| | | InitialLdapContext ctx = null; |
| | | InitialLdapContext ctx; |
| | | try |
| | | { |
| | | ctx = loader.createContext(); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Notifies the progress update listeners of the application of the message |
| | | * we received. |
| | | * @return <CODE>true</CODE> if we must notify the application listeners |
| | | * of the message and <CODE>false</CODE> otherwise. |
| | | */ |
| | | public boolean isNotifyListeners() |
| | | { |
| | | return notifyListeners; |
| | | } |
| | | |
| | | /** |
| | | * Tells whether we must notify the listeners or not of the message |
| | | * received. |
| | |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | // do nothing |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | // do nothing |
| | | } |
| | | } |
| | | pointAdderStopped = true; |