| | |
| | | |
| | | package org.opends.quicksetup; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | |
| | | import org.opends.admin.ads.ADSContext; |
| | | import org.opends.admin.ads.ServerDescriptor; |
| | | import org.opends.admin.ads.TopologyCacheException; |
| | |
| | | import org.opends.quicksetup.event.ProgressNotifier; |
| | | import org.opends.quicksetup.event.ProgressUpdateListener; |
| | | import org.opends.quicksetup.util.ServerController; |
| | | import org.opends.quicksetup.util.Utils; |
| | | import org.opends.quicksetup.util.ProgressMessageFormatter; |
| | | import org.opends.quicksetup.i18n.ResourceProvider; |
| | | import org.opends.quicksetup.ui.GuiApplication; |
| | | |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | import static org.opends.quicksetup.util.Utils.*; |
| | | |
| | | import java.io.PrintStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | |
| | | public void notifyListenersDone(Integer ratioWhenCompleted) { |
| | | notifyListeners(ratioWhenCompleted, |
| | | getSummary(getCurrentProgressStep()), |
| | | formatter.getFormattedDone() + formatter.getLineBreak()); |
| | | getFormattedDoneWithLineBreak()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param newLogDetail the new log messages that we have for the |
| | | * installation in formatted form. |
| | | */ |
| | | public void notifyListeners(Integer ratio, String currentPhaseSummary, |
| | | String newLogDetail) |
| | | public void notifyListeners(Integer ratio, Message currentPhaseSummary, |
| | | Message newLogDetail) |
| | | { |
| | | listenerDelegate.notifyListeners(getCurrentProgressStep(), |
| | | ratio, currentPhaseSummary, newLogDetail); |
| | |
| | | * @param currentPhaseSummary the localized summary message for the |
| | | * current installation progress in formatted form. |
| | | */ |
| | | public void notifyListeners(Integer ratio, String currentPhaseSummary) { |
| | | public void notifyListeners(Integer ratio, Message currentPhaseSummary) { |
| | | notifyListeners(ratio, getSummary(getCurrentProgressStep()), |
| | | formatter.getFormattedWithPoints(currentPhaseSummary)); |
| | | } |
| | | |
| | | /** |
| | | * Returns a localized message for a key value. In the properties file we |
| | | * have something of type: |
| | | * key=value |
| | | * |
| | | * @see org.opends.quicksetup.i18n.ResourceProvider#getMsg(String) |
| | | * @param key the key in the properties file. |
| | | * @return the value associated to the key in the properties file. |
| | | * properties file. |
| | | */ |
| | | public String getMsg(String key) |
| | | { |
| | | return getI18n().getMsg(key); |
| | | } |
| | | |
| | | /** |
| | | * Returns a localized message for a key value. In the properties file we |
| | | * have something of type: |
| | | * key=value |
| | | * |
| | | * For instance if we pass as key "mykey" and as arguments {"value1"} and |
| | | * in the properties file we have: |
| | | * mykey=value with argument {0}. |
| | | * |
| | | * This method will return "value with argument value1". |
| | | * @see org.opends.quicksetup.i18n.ResourceProvider#getMsg(String, String[]) |
| | | * @param key the key in the properties file. |
| | | * @param args the arguments to be passed to generate the resulting value. |
| | | * @return the value associated to the key in the properties file. |
| | | */ |
| | | public String getMsg(String key, String... args) |
| | | { |
| | | return getI18n().getMsg(key, args); |
| | | } |
| | | |
| | | /** |
| | | * Returns a ResourceProvider instance. |
| | | * @return a ResourceProvider instance. |
| | | */ |
| | | public ResourceProvider getI18n() |
| | | { |
| | | return ResourceProvider.getInstance(); |
| | | } |
| | | |
| | | /** |
| | | * Returns a localized message for a given properties key and throwable. |
| | | * @param key the key of the message in the properties file. |
| | | * @param t the throwable for which we want to get a message. |
| | | * @return a localized message for a given properties key and throwable. |
| | | */ |
| | | public String getThrowableMsg(String key, Throwable t) |
| | | { |
| | | return getThrowableMsg(key, null, t); |
| | | } |
| | | |
| | | /** |
| | | * Returns a localized message for a given properties key and throwable. |
| | | * @param key the key of the message in the properties file. |
| | | * @param args the arguments of the message in the properties file. |
| | | * @param t the throwable for which we want to get a message. |
| | | * |
| | | * @return a localized message for a given properties key and throwable. |
| | | */ |
| | | protected String getThrowableMsg(String key, String[] args, Throwable t) |
| | | { |
| | | return Utils.getThrowableMsg(getI18n(), key, args, t); |
| | | } |
| | | |
| | | /** |
| | | * Sets the formatter this instance should use to used |
| | | * to format progress messages. |
| | | * @param formatter ProgressMessageFormatter for formatting |
| | |
| | | * representation |
| | | * @return the formatted representation of an error for the given text. |
| | | */ |
| | | protected String getFormattedSummary(String text) |
| | | protected Message getFormattedSummary(Message text) |
| | | { |
| | | return formatter.getFormattedSummary(text); |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | * @return the formatted representation of an error for the given text. |
| | | */ |
| | | protected String getFormattedError(String text) |
| | | protected Message getFormattedError(Message text) |
| | | { |
| | | return formatter.getFormattedError(text, false); |
| | | } |
| | | |
| | | /** |
| | | * 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 |
| | | * @return the formatted representation of an warning for the given text. |
| | | */ |
| | | public String getFormattedWarning(String text) |
| | | public Message getFormattedWarning(Message text) |
| | | { |
| | | return formatter.getFormattedWarning(text, false); |
| | | } |
| | |
| | | * @return the formatted representation of an success message for the given |
| | | * text. |
| | | */ |
| | | protected String getFormattedSuccess(String text) |
| | | protected Message getFormattedSuccess(Message text) |
| | | { |
| | | return formatter.getFormattedSuccess(text); |
| | | } |
| | |
| | | * @return the formatted representation of a log error message for the given |
| | | * text. |
| | | */ |
| | | public String getFormattedLogError(String text) |
| | | public Message getFormattedLogError(Message text) |
| | | { |
| | | return formatter.getFormattedLogError(text); |
| | | } |
| | |
| | | * representation |
| | | * @return the formatted representation of a log message for the given text. |
| | | */ |
| | | public String getFormattedLog(String text) |
| | | public Message getFormattedLog(Message text) |
| | | { |
| | | return formatter.getFormattedLog(text); |
| | | } |
| | |
| | | * Returns the formatted representation of the 'Done' text string. |
| | | * @return the formatted representation of the 'Done' text string. |
| | | */ |
| | | public String getFormattedDone() |
| | | public Message getFormattedDone() |
| | | { |
| | | return formatter.getFormattedDone(); |
| | | return Message.raw(formatter.getFormattedDone()); |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of the 'Done' text string |
| | | * with a line break at the end. |
| | | * @return the formatted representation of the 'Done' text string. |
| | | */ |
| | | public Message getFormattedDoneWithLineBreak() { |
| | | return new MessageBuilder(formatter.getFormattedDone()) |
| | | .append(formatter.getLineBreak()).toMessage(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param text the String to which add points. |
| | | * @return the formatted representation of the '.....' text string. |
| | | */ |
| | | public String getFormattedWithPoints(String text) |
| | | public Message getFormattedWithPoints(Message text) |
| | | { |
| | | return formatter.getFormattedWithPoints(text); |
| | | } |
| | |
| | | * @return the formatted representation of a progress message for the given |
| | | * text. |
| | | */ |
| | | public String getFormattedProgress(String text) |
| | | public Message getFormattedProgress(Message text) |
| | | { |
| | | return formatter.getFormattedProgress(text); |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of a progress message for a given |
| | | * text with a line break. |
| | | * @param text the source text from which we want to get the formatted |
| | | * representation |
| | | * @return the formatted representation of a progress message for the given |
| | | * text. |
| | | */ |
| | | public Message getFormattedProgressWithLineBreak(Message text) |
| | | { |
| | | return new MessageBuilder(formatter.getFormattedProgress(text)) |
| | | .append(getLineBreak()).toMessage(); |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of an error message for a given |
| | | * exception. |
| | | * This method applies a margin if the applyMargin parameter is |
| | |
| | | * @return the formatted representation of an error message for the given |
| | | * exception. |
| | | */ |
| | | protected String getFormattedError(Throwable t, boolean applyMargin) |
| | | protected Message getFormattedError(Throwable t, boolean applyMargin) |
| | | { |
| | | return formatter.getFormattedError(t, applyMargin); |
| | | } |
| | | |
| | | /** |
| | | * 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. |
| | | */ |
| | | public String getLineBreak() |
| | | public Message getLineBreak() |
| | | { |
| | | return formatter.getLineBreak(); |
| | | } |
| | |
| | | * Returns the task separator formatted. |
| | | * @return the task separator formatted. |
| | | */ |
| | | protected String getTaskSeparator() |
| | | protected Message getTaskSeparator() |
| | | { |
| | | return formatter.getTaskSeparator(); |
| | | } |
| | |
| | | * notify the ProgressUpdateListeners of this fact. |
| | | * @param newLogDetail the new log detail. |
| | | */ |
| | | public void notifyListeners(String newLogDetail) |
| | | public void notifyListeners(Message newLogDetail) |
| | | { |
| | | Integer ratio = getRatio(getCurrentProgressStep()); |
| | | String currentPhaseSummary = getSummary(getCurrentProgressStep()); |
| | | Message currentPhaseSummary = getSummary(getCurrentProgressStep()); |
| | | notifyListeners(ratio, currentPhaseSummary, newLogDetail); |
| | | } |
| | | |
| | |
| | | * @param step ProgressStop for which a summary is needed |
| | | * @return String representing the summary |
| | | */ |
| | | public abstract String getSummary(ProgressStep step); |
| | | public abstract Message getSummary(ProgressStep step); |
| | | |
| | | /** |
| | | * Sets the current install status for this application. |
| | |
| | | protected void notifyListenersOfLog() { |
| | | File logFile = QuickSetupLog.getLogFile(); |
| | | if (logFile != null) { |
| | | notifyListeners( |
| | | getFormattedProgress(getMsg("general-see-for-details", |
| | | logFile.getPath())) + |
| | | formatter.getLineBreak()); |
| | | MessageBuilder mb = new MessageBuilder(); |
| | | mb.append(INFO_GENERAL_SEE_FOR_DETAILS.get(logFile.getPath())); |
| | | mb.append(formatter.getLineBreak()); |
| | | notifyListeners(mb.toMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | HistoricalRecord.Status.STARTED, |
| | | "log file '" + QuickSetupLog.getLogFile().getPath() + "'"); |
| | | } catch (IOException e) { |
| | | String msg = getMsg("error-logging-operation"); |
| | | Message msg = INFO_ERROR_LOGGING_OPERATION.get(); |
| | | throw ApplicationException.createFileSystemException( |
| | | msg, e); |
| | | } |
| | |
| | | new HistoricalLog(getInstallation().getHistoryLogFile()); |
| | | log.append(id, from, to, status, note); |
| | | } catch (IOException e) { |
| | | String msg = getMsg("error-logging-operation"); |
| | | Message msg = INFO_ERROR_LOGGING_OPERATION.get(); |
| | | throw ApplicationException.createFileSystemException(msg, e); |
| | | } |
| | | } |
| | |
| | | */ |
| | | protected String getStringRepresentation(TopologyCacheException e) |
| | | { |
| | | StringBuilder buf = new StringBuilder(); |
| | | MessageBuilder buf = new MessageBuilder(); |
| | | |
| | | String ldapUrl = e.getLdapUrl(); |
| | | if (ldapUrl != null) |
| | | { |
| | | String hostName = ldapUrl.substring(ldapUrl.indexOf("://") + 3); |
| | | buf.append(getMsg("server-error", hostName) + " "); |
| | | buf.append(INFO_SERVER_ERROR.get(hostName)); |
| | | buf.append(" "); |
| | | } |
| | | if (e.getCause() instanceof NamingException) |
| | | { |
| | | buf.append(getThrowableMsg("bug-msg", null, e.getCause())); |
| | | buf.append(getThrowableMsg(INFO_BUG_MSG.get(), e.getCause())); |
| | | } |
| | | else |
| | | { |
| | | // This is unexpected. |
| | | buf.append(getThrowableMsg("bug-msg", null, e.getCause())); |
| | | buf.append(getThrowableMsg(INFO_BUG_MSG.get(), e.getCause())); |
| | | } |
| | | return buf.toString(); |
| | | } |
| | |
| | | } |
| | | catch (NamingException ne) |
| | | { |
| | | String errorMessage = getMsg("cannot-connect-to-remote-generic", |
| | | Message errorMessage = INFO_CANNOT_CONNECT_TO_REMOTE_GENERIC.get( |
| | | server.getHostPort(true), ne.toString(true)); |
| | | throw new ApplicationException( |
| | | ApplicationReturnCode.ReturnCode.CONFIGURATION_ERROR, errorMessage, |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void println(String msg) |
| | | public void println(Message msg) |
| | | { |
| | | MessageBuilder mb = new MessageBuilder(); |
| | | if (isFirstLine) |
| | | { |
| | | notifyListeners(getFormattedLogError(msg)); |
| | | mb.append(getFormattedLogError(msg)); |
| | | } else |
| | | { |
| | | notifyListeners(formatter.getLineBreak() + getFormattedLogError(msg)); |
| | | mb.append(formatter.getLineBreak()); |
| | | mb.append(getFormattedLogError(msg)); |
| | | } |
| | | notifyListeners(mb.toMessage()); |
| | | isFirstLine = false; |
| | | } |
| | | |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public void println(String msg) |
| | | public void println(Message msg) |
| | | { |
| | | MessageBuilder mb = new MessageBuilder(); |
| | | if (isFirstLine) |
| | | { |
| | | notifyListeners(getFormattedLog(msg)); |
| | | mb.append(getFormattedLog(Message.raw(msg))); |
| | | } else |
| | | { |
| | | notifyListeners(formatter.getLineBreak() + getFormattedLog(msg)); |
| | | mb.append(formatter.getLineBreak()); |
| | | mb.append(getFormattedLog(Message.raw(msg))); |
| | | } |
| | | notifyListeners(mb.toMessage()); |
| | | isFirstLine = false; |
| | | } |
| | | |