| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | |
| | | import org.opends.admin.ads.util.ApplicationTrustManager; |
| | | import org.opends.guitools.i18n.ResourceProvider; |
| | | import org.opends.guitools.statuspanel.event.ServerStatusChangeEvent; |
| | | import org.opends.guitools.statuspanel.event.ServerStatusChangeListener; |
| | | import org.opends.guitools.statuspanel.event.StatusPanelButtonListener; |
| | |
| | | import org.opends.quicksetup.util.HtmlProgressMessageFormatter; |
| | | import org.opends.quicksetup.util.Utils; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.opends.messages.MessageDescriptor; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | |
| | | /** |
| | | * This is the main class of the status panel. |
| | |
| | | |
| | | private ServerStatusDescriptor desc; |
| | | |
| | | private String lastDetail; |
| | | private String lastSummary; |
| | | private Message lastDetail; |
| | | private Message lastSummary; |
| | | |
| | | private Thread progressUpdater; |
| | | |
| | |
| | | isStarting = true; |
| | | lastDetail = null; |
| | | getProgressDialog().setSummary( |
| | | getFormattedSummary(getMsg("summary-starting"))); |
| | | getProgressDialog().setDetails(""); |
| | | getFormattedSummary(INFO_SUMMARY_STARTING.get())); |
| | | getProgressDialog().setDetails(Message.EMPTY); |
| | | serverStatusPooler.beginServerStart(); |
| | | getProgressDialog().setCloseButtonEnabled(false); |
| | | getStatusPanelDialog().setStartButtonEnabled(false); |
| | |
| | | isStopping = true; |
| | | lastDetail = null; |
| | | getProgressDialog().setSummary( |
| | | getFormattedSummary(getMsg("summary-stopping"))); |
| | | getProgressDialog().setDetails(""); |
| | | getFormattedSummary(INFO_SUMMARY_STOPPING.get())); |
| | | getProgressDialog().setDetails(Message.EMPTY); |
| | | serverStatusPooler.beginServerStop(); |
| | | getProgressDialog().setCloseButtonEnabled(false); |
| | | getStatusPanelDialog().setStartButtonEnabled(false); |
| | |
| | | isRestarting = true; |
| | | lastDetail = null; |
| | | getProgressDialog().setSummary( |
| | | getFormattedSummary(getMsg("summary-stopping"))); |
| | | getProgressDialog().setDetails(""); |
| | | getFormattedSummary(INFO_SUMMARY_STOPPING.get())); |
| | | getProgressDialog().setDetails(Message.EMPTY); |
| | | serverStatusPooler.beginServerStop(); |
| | | getProgressDialog().setCloseButtonEnabled(false); |
| | | getStatusPanelDialog().setStartButtonEnabled(false); |
| | |
| | | } |
| | | catch (ConfigException ce) |
| | | { |
| | | Utilities.displayError(getLoginDialog(), ce.getMessage(), |
| | | getMsg("error-title")); |
| | | Utilities.displayError(getLoginDialog(), ce.getMessageObject(), |
| | | INFO_ERROR_TITLE.get()); |
| | | getLoginDialog().toFront(); |
| | | } |
| | | } |
| | |
| | | if (isRestarting) |
| | | { |
| | | updateProgress( |
| | | getFormattedSummary(getMsg("summary-starting")), |
| | | getTaskSeparator()); |
| | | getFormattedSummary(INFO_SUMMARY_STARTING.get()), |
| | | getTaskSeparator()); |
| | | } |
| | | updateProgress( |
| | | getFormattedSummary(getMsg("summary-starting")), |
| | | getFormattedProgress(getMsg("progress-starting")) + getLineBreak()); |
| | | getFormattedSummary(INFO_SUMMARY_STARTING.get()), |
| | | getFormattedProgressWithLineBreak(INFO_PROGRESS_STARTING.get())); |
| | | |
| | | ArrayList<String> argList = new ArrayList<String>(); |
| | | Installation installation = |
| | |
| | | } |
| | | if (!running) |
| | | { |
| | | updateProgress(getFormattedError(getMsg("summary-start-error")), |
| | | getFormattedError(getMsg("error-starting-server-generic"), |
| | | updateProgress(getFormattedError(INFO_SUMMARY_START_ERROR.get()), |
| | | getFormattedError(INFO_ERROR_STARTING_SERVER_GENERIC.get(), |
| | | true)); |
| | | } |
| | | else |
| | | { |
| | | updateProgress( |
| | | getFormattedSuccess(getMsg("summary-start-success")), |
| | | ""); |
| | | getFormattedSuccess(INFO_SUMMARY_START_SUCCESS.get()), |
| | | Message.EMPTY); |
| | | started = true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | String[] arg = {String.valueOf(returnValue)}; |
| | | String msg = getMsg("error-starting-server-code", arg); |
| | | Message msg = INFO_ERROR_STARTING_SERVER_CODE |
| | | .get(String.valueOf(returnValue)); |
| | | |
| | | /* |
| | | * The return code is not the one expected, assume the server could |
| | | * not be started. |
| | | */ |
| | | updateProgress( |
| | | getFormattedError(getMsg("summary-start-error")), |
| | | getFormattedError(INFO_SUMMARY_START_ERROR.get()), |
| | | msg); |
| | | } |
| | | |
| | | } catch (IOException ioe) |
| | | { |
| | | String msg = getThrowableMsg("error-starting-server", ioe); |
| | | Message msg = |
| | | Utils.getThrowableMsg(INFO_ERROR_STARTING_SERVER.get(), ioe); |
| | | updateProgress( |
| | | getFormattedError(getMsg("summary-start-error")), |
| | | getFormattedError(INFO_SUMMARY_START_ERROR.get()), |
| | | msg); |
| | | } |
| | | catch (InterruptedException ie) |
| | | { |
| | | String msg = getThrowableMsg("error-starting-server", ie); |
| | | Message msg = Utils.getThrowableMsg(INFO_ERROR_STARTING_SERVER.get(), ie); |
| | | updateProgress( |
| | | getFormattedError(getMsg("summary-start-error")), |
| | | getFormattedError(INFO_SUMMARY_START_ERROR.get()), |
| | | msg); |
| | | } |
| | | |
| | |
| | | { |
| | | boolean stopped = false; |
| | | updateProgress( |
| | | getFormattedSummary(getMsg("summary-stopping")), |
| | | getFormattedProgress(getMsg("progress-stopping")) + getLineBreak()); |
| | | getFormattedSummary(INFO_SUMMARY_STOPPING.get()), |
| | | getFormattedProgressWithLineBreak(INFO_PROGRESS_STOPPING.get())); |
| | | |
| | | ArrayList<String> argList = new ArrayList<String>(); |
| | | Installation installation = |
| | |
| | | .isServerRunning(); |
| | | if (!stopped) |
| | | { |
| | | String msg = |
| | | getFormattedLog(getMsg("progress-server-waiting-to-stop"))+ |
| | | getLineBreak(); |
| | | Message msg = new MessageBuilder( |
| | | getFormattedLog(INFO_PROGRESS_SERVER_WAITING_TO_STOP.get())) |
| | | .append(getLineBreak()).toMessage(); |
| | | updateProgress( |
| | | getFormattedSummary(getMsg("summary-stopping")), |
| | | getFormattedSummary(INFO_SUMMARY_STOPPING.get()), |
| | | msg); |
| | | try |
| | | { |
| | |
| | | |
| | | if (returnValue == clientSideError) |
| | | { |
| | | String msg = getLineBreak() + |
| | | getFormattedLog(getMsg("progress-server-already-stopped"))+ |
| | | getLineBreak(); |
| | | Message msg = new MessageBuilder(getLineBreak()).append( |
| | | getFormattedLog(INFO_PROGRESS_SERVER_ALREADY_STOPPED.get())).append( |
| | | getLineBreak()).toMessage(); |
| | | if (!isRestarting) |
| | | { |
| | | updateProgress( |
| | | getFormattedSuccess(getMsg("summary-stop-success")), |
| | | getFormattedSuccess(INFO_SUMMARY_STOP_SUCCESS.get()), |
| | | msg); |
| | | } |
| | | else |
| | | { |
| | | updateProgress( |
| | | getFormattedSummary(getMsg("summary-stop-success")), |
| | | getFormattedSummary(INFO_SUMMARY_STOP_SUCCESS.get()), |
| | | msg); |
| | | } |
| | | stopped = true; |
| | | } |
| | | else if (returnValue != 0) |
| | | { |
| | | String[] arg = {String.valueOf(returnValue)}; |
| | | String msg = getMsg("error-stopping-server-code", arg); |
| | | Message msg = INFO_ERROR_STOPPING_SERVER_CODE |
| | | .get(String.valueOf(returnValue)); |
| | | |
| | | /* |
| | | * The return code is not the one expected, assume the server could |
| | | * not be stopped. |
| | | */ |
| | | updateProgress( |
| | | getFormattedError(getMsg("summary-stop-error")), |
| | | getFormattedError(INFO_SUMMARY_STOP_ERROR.get()), |
| | | msg); |
| | | } |
| | | else |
| | | { |
| | | String msg = getFormattedLog(getMsg("progress-server-stopped")); |
| | | Message msg = getFormattedLog(INFO_PROGRESS_SERVER_STOPPED.get()); |
| | | if (!isRestarting) |
| | | { |
| | | updateProgress( |
| | | getFormattedSuccess(getMsg("summary-stop-success")), |
| | | getFormattedSuccess(INFO_SUMMARY_STOP_SUCCESS.get()), |
| | | msg); |
| | | } |
| | | else |
| | | { |
| | | updateProgress( |
| | | getFormattedSummary(getMsg("summary-stop-success")), |
| | | getFormattedSummary(INFO_SUMMARY_STOP_SUCCESS.get()), |
| | | msg); |
| | | } |
| | | stopped = true; |
| | |
| | | |
| | | } catch (IOException ioe) |
| | | { |
| | | String msg = getThrowableMsg("error-stopping-server", ioe); |
| | | Message msg = Utils.getThrowableMsg( |
| | | INFO_ERROR_STOPPING_SERVER.get(), ioe); |
| | | updateProgress( |
| | | getFormattedError(getMsg("summary-stop-error")), |
| | | getFormattedError(INFO_SUMMARY_STOP_ERROR.get()), |
| | | msg); |
| | | } |
| | | catch (InterruptedException ie) |
| | | { |
| | | String msg = getThrowableMsg("error-stopping-server", ie); |
| | | Message msg = Utils.getThrowableMsg(INFO_ERROR_STOPPING_SERVER.get(), ie); |
| | | updateProgress( |
| | | getFormattedError(getMsg("summary-stop-error")), |
| | | getFormattedError(INFO_SUMMARY_STOP_ERROR.get()), |
| | | msg); |
| | | } |
| | | return stopped; |
| | |
| | | * @param summary the summary for the start/stop/restart operation. |
| | | * @param newDetail the new detail for the start/stop/restart operation. |
| | | */ |
| | | private synchronized void updateProgress(final String summary, |
| | | final String newDetail) |
| | | private synchronized void updateProgress(final Message summary, |
| | | final Message newDetail) |
| | | { |
| | | if (lastDetail == null) |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | lastDetail += newDetail; |
| | | lastDetail = new MessageBuilder(lastDetail) |
| | | .append(newDetail).toMessage(); |
| | | } |
| | | lastSummary = summary; |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | String lastDisplayedSummary = null; |
| | | String lastDisplayedDetail = null; |
| | | Message lastDisplayedSummary = null; |
| | | Message lastDisplayedDetail = null; |
| | | while (true) |
| | | { |
| | | if (lastSummary != null) |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns a localized message for a key value. In the properties file we |
| | | * have something of type: |
| | | * key=value |
| | | * |
| | | * @see ResourceProvider#getMsg(String) |
| | | * @param key the key in the properties file. |
| | | * @return the value associated to the key in the properties file. |
| | | * properties file. |
| | | */ |
| | | private 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 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. |
| | | */ |
| | | private String getMsg(String key, String[] args) |
| | | { |
| | | return getI18n().getMsg(key, args); |
| | | } |
| | | |
| | | /** |
| | | * Returns a ResourceProvider instance. |
| | | * @return a ResourceProvider instance. |
| | | */ |
| | | private ResourceProvider getI18n() |
| | | { |
| | | return ResourceProvider.getInstance(); |
| | | } |
| | | |
| | | /** |
| | | * Returns the formatted representation of the text that is the summary of the |
| | | * installation process (the one that goes in the UI next to the progress |
| | | * bar). |
| | |
| | | * representation |
| | | * @return the formatted representation of an error for the given text. |
| | | */ |
| | | private String getFormattedSummary(String text) |
| | | private Message getFormattedSummary(Message text) |
| | | { |
| | | return formatter.getFormattedSummary(text); |
| | | } |
| | |
| | | * @return the formatted representation of an success message for the given |
| | | * text. |
| | | */ |
| | | private String getFormattedSuccess(String text) |
| | | private Message getFormattedSuccess(Message text) |
| | | { |
| | | return formatter.getFormattedSuccess(text); |
| | | } |
| | |
| | | * representation |
| | | * @return the formatted representation of an error for the given text. |
| | | */ |
| | | private String getFormattedError(String text) |
| | | private Message getFormattedError(Message text) |
| | | { |
| | | return formatter.getFormattedError(text, false); |
| | | } |
| | |
| | | * representation |
| | | * @return the formatted representation of an error for the given text. |
| | | */ |
| | | private String getFormattedError(String text, boolean applyMargin) |
| | | private Message getFormattedError(Message text, boolean applyMargin) |
| | | { |
| | | return formatter.getFormattedError(text, applyMargin); |
| | | } |
| | |
| | | * @return the formatted representation of a log error message for the given |
| | | * text. |
| | | */ |
| | | private String getFormattedLogError(String text) |
| | | private Message getFormattedLogError(Message text) |
| | | { |
| | | return formatter.getFormattedLogError(text); |
| | | } |
| | |
| | | * representation |
| | | * @return the formatted representation of a log message for the given text. |
| | | */ |
| | | private String getFormattedLog(String text) |
| | | private Message getFormattedLog(Message text) |
| | | { |
| | | return formatter.getFormattedLog(text); |
| | | } |
| | |
| | | * Returns the line break formatted. |
| | | * @return the line break formatted. |
| | | */ |
| | | private String getLineBreak() |
| | | private Message getLineBreak() |
| | | { |
| | | return formatter.getLineBreak(); |
| | | } |
| | |
| | | * Returns the task separator formatted. |
| | | * @return the task separator formatted. |
| | | */ |
| | | private String getTaskSeparator() |
| | | private Message getTaskSeparator() |
| | | { |
| | | return formatter.getTaskSeparator(); |
| | | } |
| | |
| | | * @return the formatted representation of a progress message for the given |
| | | * text. |
| | | */ |
| | | private String getFormattedProgress(String text) |
| | | private Message getFormattedProgress(Message text) |
| | | { |
| | | return formatter.getFormattedProgress(text); |
| | | } |
| | | |
| | | /** |
| | | * 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. |
| | | * Returns the formatted representation of a progress message for a given |
| | | * text with a line feed at the end. |
| | | * @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. |
| | | */ |
| | | private 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. |
| | | */ |
| | | private String getThrowableMsg(String key, String[] args, Throwable t) |
| | | { |
| | | return Utils.getThrowableMsg(getI18n(), key, args, t); |
| | | private Message getFormattedProgressWithLineBreak(Message text) { |
| | | return new MessageBuilder(text).append(getLineBreak()).toMessage(); |
| | | } |
| | | |
| | | /** |
| | |
| | | private class ProgressReader |
| | | { |
| | | private boolean isFirstLine; |
| | | private String errorMsg; |
| | | private Message errorMsg; |
| | | |
| | | /** |
| | | * The protected constructor. |
| | |
| | | public ProgressReader(final BufferedReader reader, final boolean isError, |
| | | final boolean isStart) |
| | | { |
| | | final String errorTag = |
| | | isError ? "error-reading-erroroutput" : "error-reading-output"; |
| | | final MessageDescriptor.Arg0 errorTag = |
| | | isError ? INFO_ERROR_READING_ERROROUTPUT : |
| | | INFO_ERROR_READING_OUTPUT; |
| | | |
| | | isFirstLine = true; |
| | | |
| | |
| | | String line = reader.readLine(); |
| | | while (line != null) |
| | | { |
| | | StringBuilder buf = new StringBuilder(); |
| | | MessageBuilder buf = new MessageBuilder(); |
| | | if (!isFirstLine) |
| | | { |
| | | buf.append(formatter.getLineBreak()); |
| | | } |
| | | if (isError) |
| | | { |
| | | buf.append(getFormattedLogError(line)); |
| | | buf.append(getFormattedLogError(Message.raw(line))); |
| | | } else |
| | | { |
| | | buf.append(getFormattedLog(line)); |
| | | buf.append(getFormattedLog(Message.raw(line))); |
| | | } |
| | | String summary = isStart? |
| | | getFormattedSummary(getMsg("summary-starting")): |
| | | getFormattedSummary(getMsg("summary-stopping")); |
| | | updateProgress(summary, buf.toString()); |
| | | Message summary = isStart? |
| | | getFormattedSummary(INFO_SUMMARY_STARTING.get()): |
| | | getFormattedSummary(INFO_SUMMARY_STOPPING.get()); |
| | | updateProgress(summary, buf.toMessage()); |
| | | isFirstLine = false; |
| | | |
| | | line = reader.readLine(); |
| | | } |
| | | } catch (IOException ioe) |
| | | { |
| | | errorMsg = getThrowableMsg(errorTag, ioe); |
| | | errorMsg = Utils.getThrowableMsg(errorTag.get(), ioe); |
| | | |
| | | } catch (Throwable t) |
| | | { |
| | | errorMsg = getThrowableMsg(errorTag, t); |
| | | errorMsg = Utils.getThrowableMsg(errorTag.get(), t); |
| | | } |
| | | } |
| | | }); |
| | | t.start(); |
| | | } |
| | | |
| | | public String getErrorMessage() |
| | | public Message getErrorMessage() |
| | | { |
| | | return errorMsg; |
| | | } |
| | |
| | | private boolean confirmStop() |
| | | { |
| | | return Utilities.displayConfirmation(getStatusPanelDialog(), |
| | | getMsg("confirm-stop-message"), getMsg("confirm-stop-title")); |
| | | INFO_CONFIRM_STOP_MESSAGE.get(), |
| | | INFO_CONFIRM_STOP_TITLE.get()); |
| | | } |
| | | |
| | | /** |
| | |
| | | private boolean confirmRestart() |
| | | { |
| | | return Utilities.displayConfirmation(getStatusPanelDialog(), |
| | | getMsg("confirm-restart-message"), getMsg("confirm-restart-title")); |
| | | INFO_CONFIRM_RESTART_MESSAGE.get(), |
| | | INFO_CONFIRM_RESTART_TITLE.get()); |
| | | } |
| | | |
| | | /** |