| | |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.INFO_ERROR_READING_SERVER_CONFIGURATION; |
| | | import static org.opends.messages.QuickSetupMessages.INFO_NOT_AVAILABLE_LABEL; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | | import java.net.URI; |
| | |
| | | private boolean displayMustStartLegend; |
| | | |
| | | /** Prefix for log files. */ |
| | | public static final String LOG_FILE_PREFIX = "opendj-status-"; |
| | | private static final String LOG_FILE_PREFIX = "opendj-status-"; |
| | | /** Suffix for log files. */ |
| | | public static final String LOG_FILE_SUFFIX = ".log"; |
| | | private static final String LOG_FILE_SUFFIX = ".log"; |
| | | |
| | | private ApplicationTrustManager interactiveTrustManager; |
| | | private boolean useInteractiveTrustManager; |
| | |
| | | * The print stream to use for standard output. |
| | | * @param err |
| | | * The print stream to use for standard error. |
| | | * @param in |
| | | * The input stream to use for standard input. |
| | | */ |
| | | public StatusCli(PrintStream out, PrintStream err, InputStream in) |
| | | private StatusCli(PrintStream out, PrintStream err) |
| | | { |
| | | super(out, err); |
| | | } |
| | |
| | | */ |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = mainCLI(args, true, System.out, System.err, System.in); |
| | | int retCode = mainCLI(args, System.out, System.err); |
| | | if(retCode != 0) |
| | | { |
| | | System.exit(retCode); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that information to |
| | | * run the status tool. |
| | | * |
| | | * @param args the command-line arguments provided to this program. |
| | | * |
| | | * @return The return code. |
| | | */ |
| | | |
| | | public static int mainCLI(String[] args) |
| | | { |
| | | return mainCLI(args, true, System.out, System.err, System.in); |
| | | } |
| | | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that information to run |
| | | * the status tool. |
| | | * |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | * @param initializeServer |
| | | * Indicates whether to initialize the server. |
| | | * @param outStream |
| | | * The output stream to use for standard output, or {@code null} |
| | | * if standard output is not needed. |
| | | * @param errStream |
| | | * The output stream to use for standard error, or {@code null} |
| | | * if standard error is not needed. |
| | | * @param inStream |
| | | * The input stream to use for standard input. |
| | | * @return The return code. |
| | | */ |
| | | public static int mainCLI(String[] args, boolean initializeServer, |
| | | OutputStream outStream, OutputStream errStream, InputStream inStream) |
| | | public static int mainCLI(String[] args, OutputStream outStream, OutputStream errStream) |
| | | { |
| | | PrintStream out = NullOutputStream.wrapOrNullStream(outStream); |
| | | PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | |
| | | t.printStackTrace(); |
| | | } |
| | | |
| | | final StatusCli statusCli = new StatusCli(out, err, inStream); |
| | | final StatusCli statusCli = new StatusCli(out, err); |
| | | int retCode = statusCli.execute(args); |
| | | if (retCode == 0) |
| | | { |
| | |
| | | * The command-line arguments provided to this program. |
| | | * @return The return code of the process. |
| | | */ |
| | | public int execute(String[] args) { |
| | | private int execute(String[] args) { |
| | | argParser = new StatusCliArgumentParser(StatusCli.class.getName()); |
| | | try { |
| | | argParser.initializeGlobalArguments(getOutputStream()); |
| | |
| | | String bindDn = null; |
| | | String bindPwd = null; |
| | | |
| | | ManagementContext mContext = null; |
| | | |
| | | // This is done because we do not need to ask the user about these |
| | | // parameters. We force their presence in the |
| | | // LDAPConnectionConsoleInteraction, this done, it will not prompt |
| | |
| | | argParser.displayMessageAndUsageReference(getErrStream(), e.getMessageObject()); |
| | | return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get(); |
| | | } |
| | | |
| | | boolean managementContextOpened = false; |
| | | try |
| | | { |
| | | if (argParser.isInteractive()) |
| | |
| | | } |
| | | if (bindPwd != null && !bindPwd.isEmpty()) |
| | | { |
| | | mContext = getManagementContextFromConnection(ci); |
| | | interactiveTrustManager = ci.getTrustManager(); |
| | | controlInfo.setTrustManager(interactiveTrustManager); |
| | | useInteractiveTrustManager = true; |
| | | try (ManagementContext mContext = getManagementContextFromConnection(ci)) |
| | | { |
| | | managementContextOpened = true; |
| | | interactiveTrustManager = ci.getTrustManager(); |
| | | controlInfo.setTrustManager(interactiveTrustManager); |
| | | useInteractiveTrustManager = true; |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | logger.traceException(e); |
| | | } |
| | | } |
| | | } catch (ClientException e) { |
| | | println(e.getMessageObject()); |
| | | return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get(); |
| | | } finally { |
| | | closeSilently(mContext); |
| | | } |
| | | |
| | | if (mContext != null) |
| | | if (managementContextOpened) |
| | | { |
| | | try (ConnectionWrapper conn = Utilities.getAdminDirContext(controlInfo, bindDn, bindPwd)) |
| | | { |