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

Jean-Noël Rouvignac
08.26.2016 2f0a3726faaca307036b55cb0306590140996014
Partial OPENDJ-2625 Convert all code that uses JNDI to use the SDK instead

Convert dsreplication
3 files modified
437 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java 277 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java 41 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java 119 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -20,6 +20,8 @@
import static com.forgerock.opendj.cli.Utils.*;
import static com.forgerock.opendj.util.OperatingSystem.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.forgerock.util.Utils.*;
import static org.opends.admin.ads.ServerDescriptor.*;
import static org.opends.admin.ads.ServerDescriptor.ServerProperty.*;
@@ -51,17 +53,8 @@
import java.util.Map;
import java.util.Set;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NamingSecurityException;
import javax.naming.directory.Attribute;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.Rdn;
import javax.swing.JPanel;
@@ -71,6 +64,12 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.ManagedObjectDefinition;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.EntryNotFoundException;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.SearchRequest;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.server.config.client.BackendCfgClient;
import org.forgerock.opendj.server.config.server.BackendCfg;
import org.opends.admin.ads.ADSContext;
@@ -4169,47 +4168,46 @@
    boolean taskCreated = false;
    int i = 1;
    boolean isOver = false;
    String dn = null;
    BasicAttributes attrs = new BasicAttributes();
    Attribute oc = new BasicAttribute("objectclass");
    oc.add("top");
    oc.add("ds-task");
    oc.add("ds-task-initialize-from-remote-replica");
    attrs.put(oc);
    attrs.put("ds-task-class-name", "org.opends.server.tasks.InitializeTask");
    attrs.put("ds-task-initialize-domain-dn", suffixDn);
    attrs.put("ds-task-initialize-replica-server-id", String.valueOf(replicaId));
    String dn = "";
    AddRequest addRequest = newAddRequest(dn)
        .addAttribute("objectclass", "top", "ds-task", "ds-task-initialize-from-remote-replica")
        .addAttribute("ds-task-class-name", "org.opends.server.tasks.InitializeTask")
        .addAttribute("ds-task-initialize-domain-dn", suffixDn)
        .addAttribute("ds-task-initialize-replica-server-id", String.valueOf(replicaId));
    while (!taskCreated)
    {
      checkAbort();
      String id = "quicksetup-initialize" + i;
      dn = "ds-task-id=" + id + ",cn=Scheduled Tasks,cn=Tasks";
      attrs.put("ds-task-id", id);
      addRequest
          .setName(dn)
          .replaceAttribute("ds-task-id", id);
      try
      {
        DirContext dirCtx = conn.getLdapContext().createSubcontext(dn, attrs);
        conn.getConnection().add(addRequest);
        taskCreated = true;
        logger.info(LocalizableMessage.raw("created task entry: " + attrs));
        dirCtx.close();
        logger.info(LocalizableMessage.raw("created task entry: " + addRequest));
      }
      catch (NameAlreadyBoundException x)
      catch (LdapException e)
      {
        logger.warn(LocalizableMessage.raw("A task with dn: " + dn + " already existed."));
      }
      catch (NamingException ne)
      {
        logger.error(LocalizableMessage.raw("Error creating task " + attrs, ne));
        throw new ApplicationException(ReturnCode.APPLICATION_ERROR, getThrowableMsg(
            INFO_ERROR_LAUNCHING_INITIALIZATION.get(sourceServerDisplay), ne), ne);
        if (e.getResult().getResultCode() == ResultCode.ENTRY_ALREADY_EXISTS)
        {
          logger.warn(LocalizableMessage.raw("A task with dn: " + dn + " already existed."));
        }
        else
        {
          logger.error(LocalizableMessage.raw("Error creating task " + addRequest, e));
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, getThrowableMsg(
              INFO_ERROR_LAUNCHING_INITIALIZATION.get(sourceServerDisplay), e), e);
        }
      }
      i++;
    }
    // Wait until it is over
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
    String filter = "objectclass=*";
    searchControls.setReturningAttributes(new String[] { "ds-task-unprocessed-entry-count",
      "ds-task-processed-entry-count", "ds-task-log-message", "ds-task-state" });
    SearchRequest searchRequest =
        newSearchRequest(dn, BASE_OBJECT, "(objectclass=*)", "ds-task-unprocessed-entry-count",
            "ds-task-processed-entry-count", "ds-task-log-message", "ds-task-state");
    LocalizableMessage lastDisplayedMsg = null;
    String lastLogMsg = null;
    long lastTimeMsgDisplayed = -1;
@@ -4232,85 +4230,22 @@
        // server will receive a connect error.
        checkAbort();
      }
      try
      {
        NamingEnumeration<SearchResult> res = conn.getLdapContext().search(dn, filter, searchControls);
        SearchResult sr = null;
        try
        {
          while (res.hasMore())
          {
            sr = res.next();
          }
        }
        finally
        {
          res.close();
        }
        SearchResultEntry sr = conn.getConnection().searchSingleEntry(searchRequest);
        // Get the number of entries that have been handled and
        // a percentage...
        LocalizableMessage msg;
        String sProcessed = getFirstValue(sr, "ds-task-processed-entry-count");
        String sUnprocessed = getFirstValue(sr, "ds-task-unprocessed-entry-count");
        long processed = -1;
        long unprocessed = -1;
        if (sProcessed != null)
        {
          processed = Integer.parseInt(sProcessed);
        }
        if (sUnprocessed != null)
        {
          unprocessed = Integer.parseInt(sUnprocessed);
        }
        long processed = asInteger(sr, "ds-task-processed-entry-count");
        long unprocessed = asInteger(sr, "ds-task-unprocessed-entry-count");
        totalEntries = Math.max(totalEntries, processed + unprocessed);
        if (processed != -1 && unprocessed != -1)
        {
          if (processed + unprocessed > 0)
          {
            long perc = (100 * processed) / (processed + unprocessed);
            msg = INFO_INITIALIZE_PROGRESS_WITH_PERCENTAGE.get(sProcessed, perc);
          }
          else
          {
            //msg = INFO_NO_ENTRIES_TO_INITIALIZE.get();
            msg = null;
          }
        }
        else if (processed != -1)
        {
          msg = INFO_INITIALIZE_PROGRESS_WITH_PROCESSED.get(sProcessed);
        }
        else if (unprocessed != -1)
        {
          msg = INFO_INITIALIZE_PROGRESS_WITH_UNPROCESSED.get(sUnprocessed);
        }
        else
        {
          msg = lastDisplayedMsg;
        }
        LocalizableMessage msg = getLocalizedMessage(lastDisplayedMsg, processed, unprocessed);
        // TODO JNR extract method
        if (msg != null)
        {
          long currentTime = System.currentTimeMillis();
          /* Refresh period: to avoid having too many lines in the log */
          long minRefreshPeriod;
          if (totalEntries < 100)
          {
            minRefreshPeriod = 0;
          }
          else if (totalEntries < 1000)
          {
            minRefreshPeriod = 1000;
          }
          else if (totalEntries < 10000)
          {
            minRefreshPeriod = 5000;
          }
          else
          {
            minRefreshPeriod = 10000;
          }
          long minRefreshPeriod = getMinRefreshPeriodInMillis(totalEntries);
          if (currentTime - minRefreshPeriod > lastTimeMsgLogged)
          {
            lastTimeMsgLogged = currentTime;
@@ -4325,14 +4260,14 @@
          }
        }
        String logMsg = getFirstValue(sr, "ds-task-log-message");
        String logMsg = firstValueAsString(sr, "ds-task-log-message");
        if (logMsg != null && !logMsg.equals(lastLogMsg))
        {
          logger.info(LocalizableMessage.raw(logMsg));
          lastLogMsg = logMsg;
        }
        InstallerHelper helper = new InstallerHelper();
        String state = getFirstValue(sr, "ds-task-state");
        String state = firstValueAsString(sr, "ds-task-state");
        TaskState taskState = TaskState.fromString(state);
        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
@@ -4388,7 +4323,7 @@
          }
        }
      }
      catch (NameNotFoundException x)
      catch (EntryNotFoundException x)
      {
        isOver = true;
        logger.info(LocalizableMessage.raw("Initialization entry not found."));
@@ -4398,15 +4333,65 @@
          notifyListeners(getLineBreak());
        }
      }
      catch (NamingException ne)
      catch (LdapException e)
      {
        throw new ApplicationException(ReturnCode.APPLICATION_ERROR, getThrowableMsg(INFO_ERROR_POOLING_INITIALIZATION
            .get(sourceServerDisplay), ne), ne);
            .get(sourceServerDisplay), e), e);
      }
    }
    resetGenerationId(conn, suffixDn, sourceServerDisplay);
  }
  private LocalizableMessage getLocalizedMessage(LocalizableMessage lastDisplayedMsg, long processed, long unprocessed)
  {
    if (processed != -1 && unprocessed != -1)
    {
      if (processed + unprocessed > 0)
      {
        long perc = (100 * processed) / (processed + unprocessed);
        return INFO_INITIALIZE_PROGRESS_WITH_PERCENTAGE.get(processed, perc);
      }
      else
      {
        // return INFO_NO_ENTRIES_TO_INITIALIZE.get();
        return null;
      }
    }
    else if (processed != -1)
    {
      return INFO_INITIALIZE_PROGRESS_WITH_PROCESSED.get(processed);
    }
    else if (unprocessed != -1)
    {
      return INFO_INITIALIZE_PROGRESS_WITH_UNPROCESSED.get(unprocessed);
    }
    else
    {
      return lastDisplayedMsg;
    }
  }
  /** Refresh period: to avoid having too many lines in the log */
  private long getMinRefreshPeriodInMillis(long totalEntries)
  {
    if (totalEntries < 100)
    {
      return 0;
    }
    else if (totalEntries < 1000)
    {
      return 1000;
    }
    else if (totalEntries < 10000)
    {
      return 5000;
    }
    else
    {
      return 10000;
    }
  }
  /**
   * Returns the configuration file path to be used when invoking the
   * command-lines.
@@ -4430,71 +4415,57 @@
    boolean taskCreated = false;
    int i = 1;
    boolean isOver = false;
    String dn = null;
    BasicAttributes attrs = new BasicAttributes();
    Attribute oc = new BasicAttribute("objectclass");
    oc.add("top");
    oc.add("ds-task");
    oc.add("ds-task-reset-generation-id");
    attrs.put(oc);
    attrs.put("ds-task-class-name", "org.opends.server.tasks.SetGenerationIdTask");
    attrs.put("ds-task-reset-generation-id-domain-base-dn", suffixDn);
    String dn = "";
    AddRequest addRequest = newAddRequest(dn)
        .addAttribute("objectclass", "top", "ds-task", "ds-task-reset-generation-id")
        .addAttribute("ds-task-class-name", "org.opends.server.tasks.SetGenerationIdTask")
        .addAttribute("ds-task-reset-generation-id-domain-base-dn", suffixDn);
    while (!taskCreated)
    {
      checkAbort();
      String id = "quicksetup-reset-generation-id-" + i;
      dn = "ds-task-id=" + id + ",cn=Scheduled Tasks,cn=Tasks";
      attrs.put("ds-task-id", id);
      addRequest
          .setName(dn)
          .replaceAttribute("ds-task-id", id);
      try
      {
        DirContext dirCtx = conn.getLdapContext().createSubcontext(dn, attrs);
        conn.getConnection().add(addRequest);
        taskCreated = true;
        logger.info(LocalizableMessage.raw("created task entry: " + attrs));
        dirCtx.close();
        logger.info(LocalizableMessage.raw("created task entry: " + addRequest));
      }
      catch (NameAlreadyBoundException x)
      catch (LdapException e)
      {
      }
      catch (NamingException ne)
      {
        logger.error(LocalizableMessage.raw("Error creating task " + attrs, ne));
        throw new ApplicationException(ReturnCode.APPLICATION_ERROR, getThrowableMsg(
            INFO_ERROR_LAUNCHING_INITIALIZATION.get(sourceServerDisplay), ne), ne);
        if (e.getResult().getResultCode() != ResultCode.ENTRY_ALREADY_EXISTS)
        {
          logger.error(LocalizableMessage.raw("Error creating task " + addRequest, e));
          throw new ApplicationException(ReturnCode.APPLICATION_ERROR, getThrowableMsg(
              INFO_ERROR_LAUNCHING_INITIALIZATION.get(sourceServerDisplay), e), e);
        }
      }
      i++;
    }
    // Wait until it is over
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
    String filter = "objectclass=*";
    searchControls.setReturningAttributes(new String[] { "ds-task-log-message", "ds-task-state" });
    String lastLogMsg = null;
    while (!isOver)
    {
      StaticUtils.sleep(500);
      try
      {
        NamingEnumeration<SearchResult> res = conn.getLdapContext().search(dn, filter, searchControls);
        SearchResult sr = null;
        try
        {
          while (res.hasMore())
          {
            sr = res.next();
          }
        }
        finally
        {
          res.close();
        }
        String logMsg = getFirstValue(sr, "ds-task-log-message");
        SearchRequest searchRequest =
            newSearchRequest(dn, BASE_OBJECT, "(objectclass=*)", "ds-task-log-message", "ds-task-state");
        SearchResultEntry sr = conn.getConnection().searchSingleEntry(searchRequest);
        String logMsg = firstValueAsString(sr, "ds-task-log-message");
        if (logMsg != null && !logMsg.equals(lastLogMsg))
        {
          logger.info(LocalizableMessage.raw(logMsg));
          lastLogMsg = logMsg;
        }
        String state = getFirstValue(sr, "ds-task-state");
        String state = firstValueAsString(sr, "ds-task-state");
        TaskState taskState = TaskState.fromString(state);
        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
        {
@@ -4515,14 +4486,14 @@
          }
        }
      }
      catch (NameNotFoundException x)
      catch (EntryNotFoundException x)
      {
        isOver = true;
      }
      catch (NamingException ne)
      catch (LdapException e)
      {
        throw new ApplicationException(ReturnCode.APPLICATION_ERROR,
            getThrowableMsg(INFO_ERROR_POOLING_INITIALIZATION.get(sourceServerDisplay), ne), ne);
            getThrowableMsg(INFO_ERROR_POOLING_INITIALIZATION.get(sourceServerDisplay), e), e);
      }
    }
  }
opendj-server-legacy/src/main/java/org/opends/quicksetup/util/Utils.java
@@ -19,6 +19,8 @@
import static com.forgerock.opendj.cli.Utils.*;
import static com.forgerock.opendj.util.OperatingSystem.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.forgerock.util.Utils.*;
import static org.opends.admin.ads.util.ConnectionUtils.*;
import static org.opends.messages.QuickSetupMessages.*;
@@ -52,12 +54,9 @@
import javax.naming.AuthenticationException;
import javax.naming.CommunicationException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NamingSecurityException;
import javax.naming.NoPermissionException;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.ldap.LdapName;
import org.forgerock.i18n.LocalizableMessage;
@@ -66,6 +65,8 @@
import org.forgerock.opendj.config.ManagedObjectDefinition;
import org.forgerock.opendj.ldap.AuthorizationException;
import org.forgerock.opendj.ldap.ConnectionException;
import org.forgerock.opendj.ldap.requests.SearchRequest;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.server.config.client.BackendCfgClient;
import org.forgerock.opendj.server.config.server.BackendCfg;
import org.opends.admin.ads.ADSContext;
@@ -955,43 +956,23 @@
   */
  public static long getServerClock(ConnectionWrapper conn)
  {
    long time = -1;
    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.OBJECT_SCOPE);
    ctls.setReturningAttributes(new String[] { "currentTime" });
    String filter = "(objectclass=*)";
    SearchRequest request = newSearchRequest("cn=monitor", BASE_OBJECT, "(objectclass=*)", "currentTime");
    try
    {
      LdapName jndiName = new LdapName("cn=monitor");
      NamingEnumeration<?> listeners = conn.getLdapContext().search(jndiName, filter, ctls);
      SearchResultEntry sr = conn.getConnection().searchSingleEntry(request);
      try
      {
        while (listeners.hasMore())
        {
          SearchResult sr = (SearchResult) listeners.next();
      String v = firstValueAsString(sr, "currentTime");
          String v = getFirstValue(sr, "currentTime");
      SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
      formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
          TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
          SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss'Z'");
          formatter.setTimeZone(utcTimeZone);
          time = formatter.parse(v).getTime();
        }
      }
      finally
      {
        listeners.close();
      }
      return formatter.parse(v).getTime();
    }
    catch (Throwable t)
    {
      logger.warn(LocalizableMessage.raw("Error retrieving server current time: " + t, t));
      return -1;
    }
    return time;
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -23,6 +23,8 @@
import static com.forgerock.opendj.util.OperatingSystem.*;
import static java.util.Collections.*;
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.forgerock.util.Utils.*;
import static org.opends.admin.ads.ServerDescriptor.*;
import static org.opends.admin.ads.util.ConnectionUtils.*;
@@ -62,7 +64,6 @@
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicReference;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
@@ -90,7 +91,13 @@
import org.forgerock.opendj.config.PropertyException;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.EntryNotFoundException;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.SearchRequest;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldif.ConnectionEntryReader;
import org.forgerock.opendj.server.config.client.CryptoManagerCfgClient;
import org.forgerock.opendj.server.config.client.ReplicationDomainCfgClient;
import org.forgerock.opendj.server.config.client.ReplicationServerCfgClient;
@@ -1399,7 +1406,7 @@
      waitUntilResetChangeNumberTaskEnds(connDest, taskDN);
      return SUCCESSFUL;
    }
    catch (ReplicationCliException | NamingException | NullPointerException e)
    catch (ReplicationCliException | NamingException | LdapException | NullPointerException e)
    {
      errPrintln(ERROR_RESET_CHANGE_NUMBER_EXCEPTION.get(e.getLocalizedMessage()));
      return ERROR_RESET_CHANGE_NUMBER_PROBLEM;
@@ -1435,15 +1442,15 @@
      sleepCatchInterrupt(500);
      try
      {
        SearchResult sr = getLastSearchResult(conn, taskDN, "ds-task-log-message", "ds-task-state");
        String logMsg = getFirstValue(sr, "ds-task-log-message");
        SearchResultEntry sr = getLastSearchResult(conn, taskDN, "ds-task-log-message", "ds-task-state");
        String logMsg = firstValueAsString(sr, "ds-task-log-message");
        if (logMsg != null && !logMsg.equals(lastLogMsg))
        {
          logger.info(LocalizableMessage.raw(logMsg));
          lastLogMsg = logMsg;
        }
        String state = getFirstValue(sr, "ds-task-state");
        String state = firstValueAsString(sr, "ds-task-state");
        TaskState taskState = TaskState.fromString(state);
        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
        {
@@ -1466,11 +1473,11 @@
          return;
        }
      }
      catch (NameNotFoundException x)
      catch (EntryNotFoundException x)
      {
        return;
      }
      catch (NamingException e)
      catch (IOException e)
      {
        throw new ReplicationCliException(getThrowableMsg(ERR_READING_SERVER_TASK_PROGRESS.get(), e),
            ERROR_CONNECTING, e);
@@ -7120,7 +7127,7 @@
          "dsreplication-reset-generation-id",
          attrMap);
    }
    catch (NamingException ne)
    catch (LdapException e)
    {
      LocalizableMessage msg = isPre ?
          ERR_LAUNCHING_PRE_EXTERNAL_INITIALIZATION.get():
@@ -7128,7 +7135,7 @@
      ReplicationCliReturnCode code = isPre?
          ERROR_LAUNCHING_PRE_EXTERNAL_INITIALIZATION:
          ERROR_LAUNCHING_POST_EXTERNAL_INITIALIZATION;
      throw new ReplicationCliException(getThrowableMsg(msg, ne), code, ne);
      throw new ReplicationCliException(getThrowableMsg(msg, e), code, e);
    }
    String lastLogMsg = null;
@@ -7137,14 +7144,14 @@
      sleepCatchInterrupt(500);
      try
      {
        SearchResult sr = getLastSearchResult(conn, dn, "ds-task-log-message", "ds-task-state");
        String logMsg = getFirstValue(sr, "ds-task-log-message");
        SearchResultEntry sr = getLastSearchResult(conn, dn, "ds-task-log-message", "ds-task-state");
        String logMsg = firstValueAsString(sr, "ds-task-log-message");
        if (logMsg != null && !logMsg.equals(lastLogMsg))
        {
          logger.info(LocalizableMessage.raw(logMsg));
          lastLogMsg = logMsg;
        }
        String state = getFirstValue(sr, "ds-task-state");
        String state = firstValueAsString(sr, "ds-task-state");
        TaskState taskState = TaskState.fromString(state);
        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
@@ -7167,11 +7174,11 @@
          }
        }
      }
      catch (NameNotFoundException x)
      catch (EntryNotFoundException x)
      {
        isOver = true;
      }
      catch (NamingException ne)
      catch (IOException ne)
      {
        throw new ReplicationCliException(getThrowableMsg(ERR_READING_SERVER_TASK_PROGRESS.get(), ne),
            ERROR_CONNECTING, ne);
@@ -7228,10 +7235,10 @@
          "dsreplication-initialize",
          attrsMap);
    }
    catch (NamingException ne)
    catch (LdapException e)
    {
      throw new ClientException(ReturnCode.APPLICATION_ERROR,
              getThrowableMsg(INFO_ERROR_LAUNCHING_INITIALIZATION.get(hostPort), ne), ne);
          getThrowableMsg(INFO_ERROR_LAUNCHING_INITIALIZATION.get(hostPort), e), e);
    }
    LocalizableMessage lastDisplayedMsg = null;
@@ -7244,22 +7251,12 @@
      sleepCatchInterrupt(500);
      try
      {
        SearchResult sr = getLastSearchResult(conn, dn, "ds-task-unprocessed-entry-count",
        SearchResultEntry sr = getLastSearchResult(conn, dn, "ds-task-unprocessed-entry-count",
            "ds-task-processed-entry-count", "ds-task-log-message", "ds-task-state" );
        // Get the number of entries that have been handled and a percentage...
        String sProcessed = getFirstValue(sr, "ds-task-processed-entry-count");
        String sUnprocessed = getFirstValue(sr, "ds-task-unprocessed-entry-count");
        long processed = -1;
        long unprocessed = -1;
        if (sProcessed != null)
        {
          processed = Integer.parseInt(sProcessed);
        }
        if (sUnprocessed != null)
        {
          unprocessed = Integer.parseInt(sUnprocessed);
        }
        long processed = asInteger(sr, "ds-task-processed-entry-count");
        long unprocessed = asInteger(sr, "ds-task-unprocessed-entry-count");
        totalEntries = Math.max(totalEntries, processed+unprocessed);
        LocalizableMessage msg = getMsg(lastDisplayedMsg, processed, unprocessed);
@@ -7284,14 +7281,14 @@
          }
        }
        String logMsg = getFirstValue(sr, "ds-task-log-message");
        String logMsg = firstValueAsString(sr, "ds-task-log-message");
        if (logMsg != null && !logMsg.equals(lastLogMsg))
        {
          logger.info(LocalizableMessage.raw(logMsg));
          lastLogMsg = logMsg;
        }
        InstallerHelper helper = new InstallerHelper();
        String state = getFirstValue(sr, "ds-task-state");
        String state = firstValueAsString(sr, "ds-task-state");
        TaskState taskState = TaskState.fromString(state);
        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
@@ -7346,7 +7343,7 @@
          }
        }
      }
      catch (NameNotFoundException x)
      catch (EntryNotFoundException x)
      {
        isOver = true;
        logger.info(LocalizableMessage.raw("Initialization entry not found."));
@@ -7356,69 +7353,65 @@
          println();
        }
      }
      catch (NamingException ne)
      catch (IOException e)
      {
        throw new ClientException(
            ReturnCode.APPLICATION_ERROR,
                getThrowableMsg(INFO_ERROR_POOLING_INITIALIZATION.get(hostPort), ne), ne);
            getThrowableMsg(INFO_ERROR_POOLING_INITIALIZATION.get(hostPort), e), e);
      }
    }
  }
  private SearchResult getLastSearchResult(ConnectionWrapper conn, String dn, String... returnedAttributes)
      throws NamingException
  private SearchResultEntry getLastSearchResult(ConnectionWrapper conn, String dn, String... returnedAttributes)
      throws IOException
  {
    SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);
    searchControls.setReturningAttributes(returnedAttributes);
    NamingEnumeration<SearchResult> res = conn.getLdapContext().search(dn, "objectclass=*", searchControls);
    try
    SearchRequest request = newSearchRequest(dn, BASE_OBJECT, "(objectclass=*)", returnedAttributes);
    try (ConnectionEntryReader entryReader = conn.getConnection().search(request))
    {
      SearchResult sr = null;
      while (res.hasMore())
      SearchResultEntry sr = null;
      while (entryReader.hasNext())
      {
        sr = res.next();
        sr = entryReader.readEntry();
      }
      return sr;
    }
    finally
    {
      res.close();
    }
  }
  private String createServerTask(ConnectionWrapper conn, String taskObjectclass,
      String taskJavaClass, String taskID, Map<String, String> taskAttrs) throws NamingException
      String taskJavaClass, String taskID, Map<String, String> taskAttrs) throws LdapException
  {
    int i = 1;
    String dn = "";
    BasicAttributes attrs = new BasicAttributes();
    attrs.put("objectclass", taskObjectclass);
    attrs.put("ds-task-class-name", taskJavaClass);
    AddRequest request = newAddRequest(dn)
        .addAttribute("objectclass", taskObjectclass)
        .addAttribute("ds-task-class-name", taskJavaClass);
    for (Map.Entry<String, String> attr : taskAttrs.entrySet())
    {
      attrs.put(attr.getKey(), attr.getValue());
      request.addAttribute(attr.getKey(), attr.getValue());
    }
    while (true)
    {
      String id = taskID + "-" + i;
      dn = "ds-task-id=" + id + ",cn=Scheduled Tasks,cn=Tasks";
      request.setName(dn);
      try
      {
        DirContext dirCtx = conn.getLdapContext().createSubcontext(dn, attrs);
        logger.info(LocalizableMessage.raw("created task entry: " + attrs));
        dirCtx.close();
        conn.getConnection().add(request);
        logger.info(LocalizableMessage.raw("created task entry: " + request));
        return dn;
      }
      catch (NameAlreadyBoundException x)
      catch (LdapException e)
      {
        logger.warn(LocalizableMessage.raw("A task with dn: " + dn + " already existed."));
      }
      catch (NamingException ne)
      {
        logger.error(LocalizableMessage.raw("Error creating task " + attrs, ne));
        throw ne;
        if (e.getResult().getResultCode() == ResultCode.ENTRY_ALREADY_EXISTS)
        {
          logger.warn(LocalizableMessage.raw("A task with dn: " + dn + " already existed."));
        }
        else
        {
          logger.error(LocalizableMessage.raw("Error creating task " + request, e));
          throw e;
        }
      }
      i++;
    }