| | |
| | | import java.security.cert.CertificateException; |
| | | import java.security.cert.X509Certificate; |
| | | import java.util.HashSet; |
| | | import java.util.Iterator; |
| | | import java.util.Set; |
| | | import java.util.TreeSet; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | */ |
| | | class StatusCli extends ConsoleApplication |
| | | { |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private boolean displayMustAuthenticateLegend; |
| | | private boolean displayMustStartLegend; |
| | | |
| | | /** Prefix for log files. */ |
| | | public static final String LOG_FILE_PREFIX = "opendj-status-"; |
| | | |
| | | /** Suffix for log files. */ |
| | | public static final String LOG_FILE_SUFFIX = ".log"; |
| | | |
| | | private ApplicationTrustManager interactiveTrustManager; |
| | | |
| | | private boolean useInteractiveTrustManager; |
| | | |
| | | /** The Logger. */ |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** The argument parser. */ |
| | | private StatusCliArgumentParser argParser; |
| | | |
| | |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainCLI(args, true, System.out, System.err, System.in); |
| | | |
| | | if(retCode != 0) |
| | | { |
| | | System.exit(retCode); |
| | |
| | | } |
| | | |
| | | final StatusCli statusCli = new StatusCli(out, err, inStream); |
| | | |
| | | return statusCli.execute(args, initializeServer); |
| | | return statusCli.execute(args); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | * @param initializeServer |
| | | * Indicates whether to initialize the server. |
| | | * @return The return code of the process. |
| | | */ |
| | | public int execute(String[] args, boolean initializeServer) { |
| | | public int execute(String[] args) { |
| | | argParser = new StatusCliArgumentParser(StatusCli.class.getName()); |
| | | try { |
| | | argParser.initializeGlobalArguments(getOutputStream()); |
| | |
| | | println(e.getMessageObject()); |
| | | return 1; |
| | | } |
| | | int v = argParser.validateGlobalOptions(getErrorStream()); |
| | | |
| | | int v = argParser.validateGlobalOptions(getErrorStream()); |
| | | if (v != ReturnCode.SUCCESS.get()) { |
| | | println(LocalizableMessage.raw(argParser.getUsage())); |
| | | return v; |
| | | } else { |
| | | } |
| | | |
| | | final ControlPanelInfo controlInfo = ControlPanelInfo.getInstance(); |
| | | controlInfo.setTrustManager(getTrustManager()); |
| | | controlInfo.setConnectTimeout(argParser.getConnectTimeout()); |
| | |
| | | // parameters. We force their presence in the |
| | | // LDAPConnectionConsoleInteraction, this done, it will not prompt |
| | | // the user for them. |
| | | final SecureConnectionCliArgs secureArgsList = |
| | | argParser.getSecureArgsList(); |
| | | final SecureConnectionCliArgs secureArgsList = argParser.getSecureArgsList(); |
| | | controlInfo.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN); |
| | | int port = CliConstants.DEFAULT_ADMINISTRATION_CONNECTOR_PORT; |
| | | controlInfo.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN); |
| | |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | logger.error(LocalizableMessage |
| | | .raw("Error parsing url: " + ldapUrl)); |
| | | logger.error(LocalizableMessage.raw("Error parsing url: " + ldapUrl)); |
| | | } |
| | | secureArgsList.hostNameArg.setPresent(true); |
| | | secureArgsList.portArg.setPresent(true); |
| | | secureArgsList.hostNameArg.addValue(secureArgsList.hostNameArg |
| | | .getDefaultValue()); |
| | | secureArgsList.hostNameArg.addValue(secureArgsList.hostNameArg.getDefaultValue()); |
| | | secureArgsList.portArg.addValue(Integer.toString(port)); |
| | | try |
| | | { |
| | |
| | | // and if none of them can be used we will just not ask for the |
| | | // protocol to be used. |
| | | final LDAPConnectionConsoleInteraction ci = |
| | | new LDAPConnectionConsoleInteraction(this, argParser |
| | | .getSecureArgsList()); |
| | | new LDAPConnectionConsoleInteraction(this, argParser.getSecureArgsList()); |
| | | |
| | | ci.run(false); |
| | | if (argParser.isInteractive()) |
| | |
| | | } else { |
| | | writeStatus(controlInfo); |
| | | } |
| | | } |
| | | |
| | | return ReturnCode.SUCCESS.get(); |
| | | } |
| | |
| | | |
| | | if (timeToSleep > 0) |
| | | { |
| | | try |
| | | { |
| | | Thread.sleep(timeToSleep); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | StaticUtils.sleep(timeToSleep); |
| | | } |
| | | println(); |
| | | println(LocalizableMessage.raw( |
| | | " ---------------------")); |
| | | println(LocalizableMessage.raw(" ---------------------")); |
| | | println(); |
| | | writeStatus(controlInfo.getServerDescriptor()); |
| | | first = false; |
| | |
| | | * @param desc |
| | | * The ServerStatusDescriptor object. |
| | | */ |
| | | private void writeStatusContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeStatusContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | LocalizableMessage status; |
| | | writeLabelValue(INFO_SERVER_STATUS_LABEL.get(), getStatus(desc), maxLabelWidth); |
| | | } |
| | | |
| | | private LocalizableMessage getStatus(ServerDescriptor desc) |
| | | { |
| | | switch (desc.getStatus()) |
| | | { |
| | | case STARTED: |
| | | status = INFO_SERVER_STARTED_LABEL.get(); |
| | | break; |
| | | |
| | | return INFO_SERVER_STARTED_LABEL.get(); |
| | | case STOPPED: |
| | | status = INFO_SERVER_STOPPED_LABEL.get(); |
| | | break; |
| | | |
| | | return INFO_SERVER_STOPPED_LABEL.get(); |
| | | case STARTING: |
| | | status = INFO_SERVER_STARTING_LABEL.get(); |
| | | break; |
| | | |
| | | return INFO_SERVER_STARTING_LABEL.get(); |
| | | case STOPPING: |
| | | status = INFO_SERVER_STOPPING_LABEL.get(); |
| | | break; |
| | | |
| | | return INFO_SERVER_STOPPING_LABEL.get(); |
| | | case NOT_CONNECTED_TO_REMOTE: |
| | | status = INFO_SERVER_NOT_CONNECTED_TO_REMOTE_STATUS_LABEL.get(); |
| | | break; |
| | | |
| | | return INFO_SERVER_NOT_CONNECTED_TO_REMOTE_STATUS_LABEL.get(); |
| | | case UNKNOWN: |
| | | status = INFO_SERVER_UNKNOWN_STATUS_LABEL.get(); |
| | | break; |
| | | |
| | | return INFO_SERVER_UNKNOWN_STATUS_LABEL.get(); |
| | | default: |
| | | throw new IllegalStateException("Unknown status: "+desc.getStatus()); |
| | | } |
| | | writeLabelValue(INFO_SERVER_STATUS_LABEL.get(), status, |
| | | maxLabelWidth); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param desc |
| | | * The ServerDescriptor object. |
| | | */ |
| | | private void writeCurrentConnectionContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeCurrentConnectionContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | LocalizableMessage text; |
| | | if (desc.getStatus() == ServerDescriptor.ServerStatus.STARTED) |
| | | { |
| | | int nConn = desc.getOpenConnections(); |
| | | if (nConn >= 0) |
| | | { |
| | | text = LocalizableMessage.raw(String.valueOf(nConn)); |
| | | } |
| | | else |
| | | { |
| | | if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | text = getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else |
| | | { |
| | | text = getNotAvailableText(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | text = getNotAvailableBecauseServerIsDownText(); |
| | | writeLabelValue(INFO_CONNECTIONS_LABEL.get(), getNbConnection(desc), maxLabelWidth); |
| | | } |
| | | |
| | | writeLabelValue(INFO_CONNECTIONS_LABEL.get(), text, maxLabelWidth); |
| | | private LocalizableMessage getNbConnection(ServerDescriptor desc) |
| | | { |
| | | if (desc.getStatus() == ServerDescriptor.ServerStatus.STARTED) |
| | | { |
| | | final int nConn = desc.getOpenConnections(); |
| | | if (nConn >= 0) |
| | | { |
| | | return LocalizableMessage.raw(String.valueOf(nConn)); |
| | | } |
| | | else if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | return getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else |
| | | { |
| | | return getNotAvailableText(); |
| | | } |
| | | } |
| | | return getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param maxLabelWidth |
| | | * The maximum label width of the left label. |
| | | */ |
| | | private void writeHostnameContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeHostnameContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | writeLabelValue(INFO_HOSTNAME_LABEL.get(), LocalizableMessage.raw(desc |
| | | .getHostname()), maxLabelWidth); |
| | | LocalizableMessage text = LocalizableMessage.raw(desc.getHostname()); |
| | | writeLabelValue(INFO_HOSTNAME_LABEL.get(), text, maxLabelWidth); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param maxLabelWidth |
| | | * The maximum label width of the left label. |
| | | */ |
| | | private void writeAdministrativeUserContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeAdministrativeUserContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | Set<DN> administrators = desc.getAdministrativeUsers(); |
| | | LocalizableMessage text; |
| | | if (administrators.size() > 0) |
| | | { |
| | | TreeSet<DN> ordered = new TreeSet<DN>(); |
| | | ordered.addAll(administrators); |
| | | TreeSet<DN> ordered = new TreeSet<DN>(administrators); |
| | | for (DN dn : ordered) |
| | | { |
| | | writeLabelValue(INFO_ADMINISTRATIVE_USERS_LABEL.get(), LocalizableMessage.raw(dn.toString()), maxLabelWidth); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | writeLabelValue(INFO_ADMINISTRATIVE_USERS_LABEL.get(), getErrorText(desc), maxLabelWidth); |
| | | } |
| | | } |
| | | |
| | | DN first = ordered.iterator().next(); |
| | | writeLabelValue( |
| | | INFO_ADMINISTRATIVE_USERS_LABEL.get(), |
| | | LocalizableMessage.raw(first.toString()), |
| | | maxLabelWidth); |
| | | |
| | | Iterator<DN> it = ordered.iterator(); |
| | | // First one already printed |
| | | it.next(); |
| | | while (it.hasNext()) |
| | | private LocalizableMessage getErrorText(ServerDescriptor desc) |
| | | { |
| | | writeLabelValue( |
| | | INFO_ADMINISTRATIVE_USERS_LABEL.get(), |
| | | LocalizableMessage.raw(it.next().toString()), |
| | | maxLabelWidth); |
| | | } |
| | | } |
| | | else |
| | | if (desc.getStatus() == ServerDescriptor.ServerStatus.STARTED |
| | | && (!desc.isAuthenticated() || !desc.getExceptions().isEmpty())) |
| | | { |
| | | if (desc.getStatus() == ServerDescriptor.ServerStatus.STARTED) |
| | | { |
| | | if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | text = getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | return getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else |
| | | { |
| | | text = getNotAvailableText(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | text = getNotAvailableText(); |
| | | } |
| | | writeLabelValue(INFO_ADMINISTRATIVE_USERS_LABEL.get(), text, |
| | | maxLabelWidth); |
| | | } |
| | | return getNotAvailableText(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param maxLabelWidth |
| | | * The maximum label width of the left label. |
| | | */ |
| | | private void writeInstallPathContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeInstallPathContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | writeLabelValue(INFO_INSTALLATION_PATH_LABEL.get(), |
| | | LocalizableMessage.raw(desc.getInstallPath()), |
| | |
| | | * @param maxLabelWidth |
| | | * The maximum label width of the left label. |
| | | */ |
| | | private void writeInstancePathContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeInstancePathContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | writeLabelValue(INFO_CTRL_PANEL_INSTANCE_PATH_LABEL.get(), |
| | | LocalizableMessage.raw(desc.getInstancePath()), |
| | |
| | | * @param desc |
| | | * The ServerDescriptor object. |
| | | */ |
| | | private void writeVersionContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeVersionContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | String openDSVersion = desc.getOpenDSVersion(); |
| | | writeLabelValue(INFO_OPENDS_VERSION_LABEL.get(), |
| | |
| | | * @param maxLabelWidth |
| | | * The maximum label width of the left label. |
| | | */ |
| | | private void writeJavaVersionContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeJavaVersionContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | LocalizableMessage text; |
| | | writeLabelValue(INFO_JAVA_VERSION_LABEL.get(), getJavaVersion(desc), maxLabelWidth); |
| | | } |
| | | |
| | | private LocalizableMessage getJavaVersion(ServerDescriptor desc) |
| | | { |
| | | if (desc.getStatus() == ServerDescriptor.ServerStatus.STARTED) |
| | | { |
| | | if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | text = getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | return getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else |
| | | { |
| | | text = LocalizableMessage.raw(desc.getJavaVersion()); |
| | | return LocalizableMessage.raw(desc.getJavaVersion()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | text = getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | writeLabelValue(INFO_JAVA_VERSION_LABEL.get(), text, maxLabelWidth); |
| | | return getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param maxLabelWidth |
| | | * The maximum label width of the left label. |
| | | */ |
| | | private void writeAdminConnectorContents(ServerDescriptor desc, |
| | | int maxLabelWidth) |
| | | private void writeAdminConnectorContents(ServerDescriptor desc, int maxLabelWidth) |
| | | { |
| | | ConnectionHandlerDescriptor adminConnector = desc.getAdminConnector(); |
| | | if (adminConnector != null) |
| | | { |
| | | LocalizableMessage text = INFO_CTRL_PANEL_ADMIN_CONNECTOR_DESCRIPTION.get( |
| | | adminConnector.getPort()); |
| | | writeLabelValue(INFO_CTRL_PANEL_ADMIN_CONNECTOR_LABEL.get(), text, |
| | | maxLabelWidth); |
| | | LocalizableMessage text = INFO_CTRL_PANEL_ADMIN_CONNECTOR_DESCRIPTION.get(adminConnector.getPort()); |
| | | writeLabelValue(INFO_CTRL_PANEL_ADMIN_CONNECTOR_LABEL.get(), text, maxLabelWidth); |
| | | } |
| | | else |
| | | { |
| | |
| | | { |
| | | if (!desc.isAuthenticated()) |
| | | { |
| | | println( |
| | | INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LABEL.get()); |
| | | println(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LABEL.get()); |
| | | } |
| | | else |
| | | { |
| | |
| | | else |
| | | { |
| | | BaseDNTableModel baseDNTableModel = new BaseDNTableModel(true, false); |
| | | baseDNTableModel.setData(replicas, desc.getStatus(), |
| | | desc.isAuthenticated()); |
| | | baseDNTableModel.setData(replicas, desc.getStatus(), desc.isAuthenticated()); |
| | | |
| | | writeBaseDNTableModel(baseDNTableModel, desc); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private String[] getHostNames(ConnectionHandlerTableModel tableModel, |
| | | int row) |
| | | private String[] getHostNames(ConnectionHandlerTableModel tableModel, int row) |
| | | { |
| | | String v = (String)tableModel.getValueAt(row, 0); |
| | | String htmlTag = "<html>"; |
| | |
| | | |
| | | private LocalizableMessage getCellValue(Object v, ServerDescriptor desc) |
| | | { |
| | | LocalizableMessage s = null; |
| | | if (v != null) |
| | | { |
| | | if (v instanceof String) |
| | | { |
| | | s = LocalizableMessage.raw((String)v); |
| | | return LocalizableMessage.raw((String) v); |
| | | } |
| | | else if (v instanceof Integer) |
| | | { |
| | | int nEntries = ((Integer)v).intValue(); |
| | | if (nEntries >= 0) |
| | | { |
| | | s = LocalizableMessage.raw(String.valueOf(nEntries)); |
| | | return LocalizableMessage.raw(String.valueOf(nEntries)); |
| | | } |
| | | else if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | return getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else |
| | | { |
| | | if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | s = getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else |
| | | { |
| | | s = getNotAvailableText(); |
| | | } |
| | | return getNotAvailableText(); |
| | | } |
| | | } |
| | | else |
| | |
| | | throw new IllegalStateException("Unknown object type: "+v); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | s = getNotAvailableText(); |
| | | } |
| | | return s; |
| | | return getNotAvailableText(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param desc |
| | | * The Server Status descriptor. |
| | | */ |
| | | private void writeBaseDNTableModel(BaseDNTableModel tableModel, |
| | | ServerDescriptor desc) |
| | | private void writeBaseDNTableModel(BaseDNTableModel tableModel, ServerDescriptor desc) |
| | | { |
| | | boolean isRunning = |
| | | desc.getStatus() == ServerDescriptor.ServerStatus.STARTED; |
| | | boolean isRunning = desc.getStatus() == ServerDescriptor.ServerStatus.STARTED; |
| | | |
| | | int labelWidth = 0; |
| | | int labelWidthWithoutReplicated = 0; |
| | |
| | | } |
| | | for (int j=0; j<tableModel.getColumnCount(); j++) |
| | | { |
| | | LocalizableMessage value; |
| | | Object v = tableModel.getValueAt(i, j); |
| | | if (v != null) |
| | | { |
| | | if (v == BaseDNTableModel.NOT_AVAILABLE_SERVER_DOWN) |
| | | { |
| | | value = getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | else if (v == BaseDNTableModel.NOT_AVAILABLE_AUTHENTICATION_REQUIRED) |
| | | { |
| | | value = getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else if (v == BaseDNTableModel.NOT_AVAILABLE) |
| | | { |
| | | value = getNotAvailableText(); |
| | | } |
| | | else if (v instanceof String) |
| | | { |
| | | value = LocalizableMessage.raw((String)v); |
| | | } |
| | | else if (v instanceof LocalizableMessage) |
| | | { |
| | | value = (LocalizableMessage)v; |
| | | } |
| | | else if (v instanceof Integer) |
| | | { |
| | | int nEntries = ((Integer)v).intValue(); |
| | | if (nEntries >= 0) |
| | | { |
| | | value = LocalizableMessage.raw(String.valueOf(nEntries)); |
| | | } |
| | | else |
| | | { |
| | | if (!isRunning) |
| | | { |
| | | value = getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | value = getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else |
| | | { |
| | | value = getNotAvailableText(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | throw new IllegalStateException("Unknown object type: "+v); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | value = LocalizableMessage.EMPTY; |
| | | } |
| | | |
| | | if (value.equals(getNotAvailableText())) |
| | | { |
| | | if (!isRunning) |
| | | { |
| | | value = getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | value = getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | } |
| | | LocalizableMessage value = getValue(desc, isRunning, v); |
| | | |
| | | boolean doWrite = true; |
| | | boolean isReplicated = |
| | |
| | | String.valueOf(tableModel.getValueAt(i, 3))); |
| | | if (j == 4 || j == 5) |
| | | { |
| | | // If the suffix is not replicated we do not have to display these |
| | | // lines. |
| | | // If the suffix is not replicated we do not have to display these lines |
| | | doWrite = isReplicated; |
| | | } |
| | | if (doWrite) |
| | |
| | | } |
| | | } |
| | | |
| | | private LocalizableMessage getValue(ServerDescriptor desc, boolean isRunning, Object v) |
| | | { |
| | | if (v != null) |
| | | { |
| | | if (v == BaseDNTableModel.NOT_AVAILABLE_SERVER_DOWN) |
| | | { |
| | | return getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | else if (v == BaseDNTableModel.NOT_AVAILABLE_AUTHENTICATION_REQUIRED) |
| | | { |
| | | return getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | else if (v == BaseDNTableModel.NOT_AVAILABLE) |
| | | { |
| | | return getNotAvailableText(desc, isRunning); |
| | | } |
| | | else if (v instanceof String) |
| | | { |
| | | return LocalizableMessage.raw((String) v); |
| | | } |
| | | else if (v instanceof LocalizableMessage) |
| | | { |
| | | return (LocalizableMessage) v; |
| | | } |
| | | else if (v instanceof Integer) |
| | | { |
| | | final int nEntries = ((Integer) v).intValue(); |
| | | if (nEntries >= 0) |
| | | { |
| | | return LocalizableMessage.raw(String.valueOf(nEntries)); |
| | | } |
| | | return getNotAvailableText(desc, isRunning); |
| | | } |
| | | else |
| | | { |
| | | throw new IllegalStateException("Unknown object type: " + v); |
| | | } |
| | | } |
| | | return LocalizableMessage.EMPTY; |
| | | } |
| | | |
| | | private LocalizableMessage getNotAvailableText(ServerDescriptor desc, boolean isRunning) |
| | | { |
| | | if (!isRunning) |
| | | { |
| | | return getNotAvailableBecauseServerIsDownText(); |
| | | } |
| | | if (!desc.isAuthenticated() || !desc.getExceptions().isEmpty()) |
| | | { |
| | | return getNotAvailableBecauseAuthenticationIsRequiredText(); |
| | | } |
| | | return getNotAvailableText(); |
| | | } |
| | | |
| | | private void writeLabelValue(final LocalizableMessage label, |
| | | final LocalizableMessage value, final int maxLabelWidth) |
| | | { |
| | |
| | | { |
| | | buf.append(" "); |
| | | } |
| | | buf.append(" ").append(String.valueOf(value)); |
| | | buf.append(" ").append(value); |
| | | println(buf.toMessage()); |
| | | } |
| | | |
| | |
| | | return argParser.isInteractive(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isMenuDrivenMode() { |
| | | return true; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isQuiet() { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return argParser.isScriptFriendly(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return true; |
| | | } |
| | | |
| | | // FIXME Common code with DSConfigand tools*. This method needs to be moved. |
| | | /** FIXME Common code with DSConfigand tools*. This method needs to be moved. */ |
| | | private ManagementContext getManagementContextFromConnection( |
| | | final LDAPConnectionConsoleInteraction ci) throws ClientException |
| | | { |
| | |
| | | try |
| | | { |
| | | final SSLContextBuilder sslBuilder = new SSLContextBuilder(); |
| | | sslBuilder.setTrustManager((trustManager == null ? TrustManagers |
| | | .trustAll() : trustManager)); |
| | | sslBuilder.setTrustManager(trustManager == null ? TrustManagers.trustAll() : trustManager); |
| | | sslBuilder.setKeyManager(keyManager); |
| | | options.setUseStartTLS(ci.useStartTLS()); |
| | | options.setSSLContext(sslBuilder.getSSLContext()); |
| | |
| | | } |
| | | } |
| | | |
| | | return LDAPManagementContext.newManagementContext(connection, LDAPProfile |
| | | .getInstance()); |
| | | return LDAPManagementContext.newManagementContext(connection, LDAPProfile.getInstance()); |
| | | } |
| | | } |