mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
21 hours ago 0bc642c94610ed0cdd162533dd086fbd45a415bc
Send dsreplication diagnostics to stderr (#1330)

## Summary

- Send standalone `dsreplication` diagnostics to stderr so they are
visible in the CI job log.
- Remove the success message that points to a temporary log deleted at
exit.

## Verification

- Maven `verify -Pprecommit` with `ReplicationCliMainTest` passed both
tests.
- A two-server smoke test verified replication of 100 users and checked
stderr for diagnostics from both a successful initialization and an
unreachable source.
4 files modified
110 ■■■■■ changed files
opendj-doc-generated-ref/src/main/asciidoc/admin-guide/chap-mv-servers.adoc 4 ●●●●● patch | view | raw | blame | history
opendj-doc-generated-ref/src/main/asciidoc/admin-guide/chap-replication.adoc 41 ●●●●● patch | view | raw | blame | history
opendj-doc-generated-ref/src/main/asciidoc/man-pages/_dsreplication-examples.adoc 12 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java 53 ●●●●● patch | view | raw | blame | history
opendj-doc-generated-ref/src/main/asciidoc/admin-guide/chap-mv-servers.adoc
@@ -104,10 +104,6 @@
Disabling replication port 8989 of server opendj2.example.com:4444 ..... Done.
Removing registration information ..... Done.
Removing truststore information ..... Done.
See
/var/.../opends-replication-3173475478874782719.log
for a detailed log of this operation.
----
. With the server no longer receiving traffic or accepting updates from clients, and no longer replicating to other servers, you can shut it down in preparation for the move:
opendj-doc-generated-ref/src/main/asciidoc/admin-guide/chap-replication.adoc
@@ -227,6 +227,8 @@
This section shows how to configure replication with command-line tools, such as the `dsreplication` command, described in xref:../reference/admin-tools-ref.adoc#dsreplication-1[dsreplication(1)] in the __Reference__.
The `dsreplication` examples show standard output. Diagnostic messages go to standard error (`stderr`).
[#enable-repl]
==== Enabling Replication
@@ -276,10 +278,6 @@
Replication has been successfully enabled.  Note that for replication to
 work you must initialize the contents of the base DN's that are being
  replicated (use dsreplication initialize to do so).
See
/var/.../opends-replication-7958637258600693490.log
for a detailed log of this operation.
----
To enable secure connections for replication use the `--secureReplication1` and `--secureReplication2` options, which are equivalent to selecting Configure as Secure in the replication topology options screen of the setup wizard.
@@ -334,10 +332,6 @@
Initializing base DN dc=example,dc=com with the contents from
 opendj.example.com:4444: 160 entries processed (100 % complete).
Base DN initialized successfully.
See
/var/.../opends-replication-5020375834904394170.log
for a detailed log of this operation.
----
====
@@ -431,10 +425,6 @@
Replication has been successfully enabled.  Note that for replication to
 work you must initialize the contents of the base DN's that are being
 replicated (use dsreplication initialize to do so).
See
/var/.../opends-replication-1672058070147419978.log
for a detailed log of this operation.
----
+
Contrary to the message from the command, you do not need to use the `dsreplication initialize` command at this point.
@@ -619,10 +609,6 @@
 opendj2.example.com:4444 ..... Done.
Removing registration information ..... Done.
Removing truststore information ..... Done.
See
/var/.../opends-replication-125248191132797765.log
for a detailed log of this operation.
----
+
The `dsreplication disable` as shown completely removes the replication configuration information from the server.
@@ -709,10 +695,6 @@
 you must initialize the contents of the base DN's that are being
 replicated (use dsreplication initialize to do so).
See
/var/.../opends-replication-1720959352638609971.log
for a detailed log of this operation.
$ dsreplication \
 enable \
 --adminUID admin \
@@ -760,10 +742,6 @@
Replication has been successfully enabled.  Note that for replication to work
 you must initialize the contents of the base DN's that are being
 replicated (use dsreplication initialize to do so).
See
/var/folders/.../opends-replication-5893037538856033562.log
for a detailed log of this operation.
----
. Initialize replication from one of the directory servers:
@@ -784,10 +762,6 @@
Initializing base DN dc=example,dc=com with the contents from
 opendj.example.com:4444: 160 entries processed (100 % complete).
Base DN initialized successfully.
See
/var/.../opends-replication-7677303986403997574.log
for a detailed log of this operation.
----
====
@@ -863,10 +837,6 @@
Replication has been successfully enabled.  Note that for replication to work
 you must initialize the contents of the base DNs that are being replicated
 (use dsreplication initialize to do so).
See
/var/.../opendj-replication-859181866587327450.log
for a detailed log of this operation.
----
+
Here the existing server is both directory server and replication server. If the existing server is a standalone replication server, then also use the appropriate `--onlyReplicationServer` option.
@@ -893,10 +863,6 @@
0 entries processed (0 % complete).
176 entries processed (100 % complete).
Base DN initialized successfully.
See
/var/.../opendj-replication-4326340645155418876.log
for a detailed log of this operation.
----
. If you want to make the directory server replica read-only for client application traffic, see xref:#read-only-repl["Read-Only Replicas"].
@@ -2005,9 +1971,6 @@
 --no-prompt
Change-log change number reset task has finished successfully.
See /path/to/opendj-replication-....log
for a detailed log of this operation.
----
+
At this point, the new replica's change log starts with the last change number from the existing replica. Earlier change numbers are no longer present in the new replica's change log.
opendj-doc-generated-ref/src/main/asciidoc/man-pages/_dsreplication-examples.adoc
@@ -13,7 +13,7 @@
  information: "Portions Copyright [year] [name of copyright owner]".
  Copyright 2015-2016 ForgeRock AS.
  Portions Copyright 2024 3A Systems LLC.
  Portions Copyright 2024-2026 3A Systems, LLC.
////
@@ -21,6 +21,8 @@
The following example enables and then initializes replication for a new replica
on `opendj2.example.com` from an existing replica on `opendj.example.com`.
The example shows standard output. `dsreplication` writes diagnostics to standard error (`stderr`).
[source, console]
----
$ dsreplication enable -I admin -w password -X -n -b dc=example,dc=com \
@@ -54,18 +56,10 @@
 work you must initialize the contents of the base DN's that are being
  replicated (use dsreplication initialize to do so).
See
/var/.../opends-replication-7958637258600693490.log
for a detailed log of this operation.
$ dsreplication initialize-all -I admin -w password -X -n -b dc=example,dc=com \
 -h opendj.example.com -p 4444
Initializing base DN dc=example,dc=com with the contents from
 opendj.example.com:4444: 160 entries processed (100 % complete).
Base DN initialized successfully.
See
/var/.../opends-replication-5020375834904394170.log
for a detailed log of this operation.
----
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -138,7 +138,11 @@
import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
import org.opends.server.backends.task.TaskState;
import org.opends.server.core.DirectoryServer;
import org.opends.server.loggers.ErrorLogPublisher;
import org.opends.server.loggers.ErrorLogger;
import org.opends.server.loggers.JDKLogging;
import org.opends.server.loggers.TextErrorLogPublisher;
import org.opends.server.loggers.TextWriter;
import org.opends.server.tasks.PurgeConflictsHistoricalTask;
import org.opends.server.tools.dsreplication.EnableReplicationUserData.EnableReplicationServerData;
import org.opends.server.tools.dsreplication.ReplicationCliArgumentParser.ServerArgs;
@@ -326,8 +330,13 @@
  public static void main(String[] args)
  {
    int retCode = mainCLI(args, true, System.out, System.err);
    System.exit(retCode);
    JDKLogging.enableLoggingForOpenDJTool(System.err);
    final ErrorLogPublisher errorLogPublisher =
        TextErrorLogPublisher.getToolStartupTextErrorPublisher(new TextWriter.STREAM(System.err));
    ErrorLogger.getInstance().addLogPublisher(errorLogPublisher);
    ReplicationCliMain replicationCli = new ReplicationCliMain(System.out, System.err);
    System.exit(replicationCli.execute(args, true).getReturnCode());
  }
  /**
@@ -484,15 +493,12 @@
    sourceServerCI = new LDAPConnectionConsoleInteraction(this, argParser.getSecureArgsList());
    sourceServerCI.setDisplayLdapIfSecureParameters(false);
    ReplicationCliReturnCode returnValue = SUCCESSFUL_NOP;
    String subCommand = null;
    final SubcommandChoice subcommandChoice = getSubcommandChoice(argParser.getSubCommand());
    if (subcommandChoice != null)
    {
      subCommand = subcommandChoice.getName();
      returnValue = execute(subcommandChoice);
      return execute(subcommandChoice);
    }
    else if (argParser.isInteractive())
    if (argParser.isInteractive())
    {
      final SubcommandChoice subCommandChoice = promptForSubcommand();
      if (subCommandChoice == null || SubcommandChoice.CANCEL.equals(subCommandChoice))
@@ -500,7 +506,7 @@
        return USER_CANCELLED;
      }
      subCommand = subCommandChoice.getName();
      final String subCommand = subCommandChoice.getName();
      if (subCommand != null)
      {
        String[] newArgs = new String[args.length + 1];
@@ -509,28 +515,12 @@
        // The server (if requested) has already been initialized.
        return execute(newArgs, false);
      }
    }
    else
    {
      errPrintln(ERR_REPLICATION_VALID_SUBCOMMAND_NOT_FOUND.get("--" + OPTION_LONG_NO_PROMPT));
      errPrintln(LocalizableMessage.raw(argParser.getUsage()));
      return ERROR_USER_DATA;
      return SUCCESSFUL_NOP;
    }
    // Display the log file only if the operation is successful (when there
    // is a critical error this is already displayed).
    if (returnValue == SUCCESSFUL && displayLogFileAtEnd(subCommand))
    {
      File logFile = ControlPanelLog.getLogFile();
      if (logFile != null)
      {
        println();
        println(INFO_GENERAL_SEE_FOR_DETAILS.get(logFile.getPath()));
        println();
      }
    }
    return returnValue;
    errPrintln(ERR_REPLICATION_VALID_SUBCOMMAND_NOT_FOUND.get("--" + OPTION_LONG_NO_PROMPT));
    errPrintln(LocalizableMessage.raw(argParser.getUsage()));
    return ERROR_USER_DATA;
  }
  private SubcommandChoice getSubcommandChoice(SubCommand subCommand)
@@ -9023,13 +9013,6 @@
    return results;
  }
  private boolean displayLogFileAtEnd(String subCommand)
  {
    final List<String> subCommands = Arrays.asList(ENABLE_REPLICATION_SUBCMD_NAME, DISABLE_REPLICATION_SUBCMD_NAME,
        INITIALIZE_ALL_REPLICATION_SUBCMD_NAME, INITIALIZE_REPLICATION_SUBCMD_NAME, RESET_CHANGE_NUMBER_SUBCMD_NAME);
    return subCommands.contains(subCommand);
  }
  /**
   * Returns the timeout to be used to connect in milliseconds.  The method
   * must be called after parsing the arguments.