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

Ludovic Poitou
30.02.2013 833ef2eb5fc04139d6b41b4bb96dc4db84e828d5
More code cleanup and use of interfaces in dsreplication and ADS.
6 files modified
130 ■■■■■ changed files
opends/src/ads/org/opends/admin/ads/TopologyCache.java 24 ●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/TopologyCacheException.java 4 ●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/util/PreferredConnection.java 13 ●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/util/ServerLoader.java 19 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java 62 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsreplication/ReplicationUserData.java 8 ●●●●● patch | view | raw | blame | history
opends/src/ads/org/opends/admin/ads/TopologyCache.java
@@ -23,7 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2011-2012 ForgeRock AS
 *      Portions copyright 2011-2013 ForgeRock AS
 */
package org.opends.admin.ads;
@@ -77,10 +77,9 @@
      new HashSet<ServerDescriptor>();
  private final Set<SuffixDescriptor> suffixes =
      new HashSet<SuffixDescriptor>();
  private final LinkedHashSet<PreferredConnection> preferredConnections =
  private final Set<PreferredConnection> preferredConnections =
      new LinkedHashSet<PreferredConnection>();
  private final TopologyCacheFilter filter = new TopologyCacheFilter();
  private final boolean isMultiThreaded = true;
  private final static int MULTITHREAD_TIMEOUT = 90 * 1000;
  private static final Logger LOG =
      Logger.getLogger(TopologyCache.class.getName());
@@ -125,20 +124,10 @@
      for (Map<ServerProperty, Object> serverProperties : adsServers)
      {
        ServerLoader t = getServerLoader(serverProperties);
        if (isMultiThreaded)
        {
          t.start();
          threadSet.add(t);
        }
        else
        {
          t.run();
        }
      }
      if (isMultiThreaded)
      {
        joinThreadSet(threadSet);
      }
      /*
       * Try to consolidate things (even if the data is not complete).
       */
@@ -229,9 +218,6 @@
  /**
   * Reads the replication monitoring.
   *
   * @throws NamingException if an error occurs reading the replication
   * monitoring.
   */
  private void readReplicationMonitoring()
  {
@@ -300,7 +286,7 @@
   *
   * @param cnx the list of preferred connections.
   */
  public void setPreferredConnections(LinkedHashSet<PreferredConnection> cnx)
  public void setPreferredConnections(Set<PreferredConnection> cnx)
  {
    preferredConnections.clear();
    preferredConnections.addAll(cnx);
@@ -421,12 +407,12 @@
   *
   * @return a set of error messages encountered in the TopologyCache.
   */
  public LinkedHashSet<Message> getErrorMessages()
  public Set<Message> getErrorMessages()
  {
    Set<TopologyCacheException> exceptions =
        new HashSet<TopologyCacheException>();
    Set<ServerDescriptor> theServers = getServers();
    LinkedHashSet<Message> exceptionMsgs = new LinkedHashSet<Message>();
    Set<Message> exceptionMsgs = new LinkedHashSet<Message>();
    for (ServerDescriptor server : theServers)
    {
      TopologyCacheException e = server.getLastException();
opends/src/ads/org/opends/admin/ads/TopologyCacheException.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS.
 */
package org.opends.admin.ads;
@@ -149,8 +150,7 @@
  public String getHostPort()
  {
    int index = ldapUrl.indexOf("//");
    String hostPort = ldapUrl.substring(index + 2);
    return hostPort;
    return ldapUrl.substring(index + 2);
  }
  /**
opends/src/ads/org/opends/admin/ads/util/PreferredConnection.java
@@ -23,11 +23,13 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS.
 */
package org.opends.admin.ads.util;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.naming.ldap.InitialLdapContext;
@@ -123,7 +125,7 @@
  /**
   * Commodity method that returns a PreferredConnection object with the
   * information on a given InitialLdapContext.
   * @param ctx the connection we retrieve the inforamtion from.
   * @param ctx the connection we retrieve the information from.
   * @return a preferred connection object.
   */
  public static PreferredConnection getPreferredConnection(
@@ -143,8 +145,7 @@
    {
      type = PreferredConnection.Type.LDAP;
    }
    PreferredConnection cnx = new PreferredConnection(ldapUrl, type);
    return cnx;
    return new PreferredConnection(ldapUrl, type);
  }
@@ -152,14 +153,14 @@
  /**
   * Commodity method that generates a list of preferred connection (of just
   * one) with the information on a given InitialLdapContext.
   * @param ctx the connection we retrieve the inforamtion from.
   * @param ctx the connection we retrieve the information from.
   * @return a list containing the preferred connection object.
   */
  public static LinkedHashSet<PreferredConnection> getPreferredConnections(
  public static Set<PreferredConnection> getPreferredConnections(
      InitialLdapContext ctx)
  {
    PreferredConnection cnx = PreferredConnection.getPreferredConnection(ctx);
    LinkedHashSet<PreferredConnection> returnValue =
    Set<PreferredConnection> returnValue =
      new LinkedHashSet<PreferredConnection>();
    returnValue.add(cnx);
    return returnValue;
opends/src/ads/org/opends/admin/ads/util/ServerLoader.java
@@ -23,12 +23,14 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS.
 */
package org.opends.admin.ads.util;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -45,6 +47,8 @@
import org.opends.admin.ads.TopologyCacheFilter;
import org.opends.admin.ads.ADSContext.ServerProperty;
import static org.opends.server.util.StaticUtils.close;
/**
 * Class used to load the configuration of a server.  Basically the code
 * uses some provided properties and authentication information to connect
@@ -63,7 +67,7 @@
  private int timeout;
  private String dn;
  private String pwd;
  private LinkedHashSet<PreferredConnection> preferredLDAPURLs;
  private final LinkedHashSet<PreferredConnection> preferredLDAPURLs;
  private TopologyCacheFilter filter;
  private static final Logger LOG =
@@ -88,7 +92,7 @@
  public ServerLoader(Map<ServerProperty,Object> serverProperties,
      String dn, String pwd, ApplicationTrustManager trustManager,
      int timeout,
      LinkedHashSet<PreferredConnection> preferredLDAPURLs,
      Set<PreferredConnection> preferredLDAPURLs,
      TopologyCacheFilter filter)
  {
    this.serverProperties = serverProperties;
@@ -235,16 +239,7 @@
    finally
    {
      isOver = true;
      try
      {
        if (ctx != null)
        {
          ctx.close();
        }
      }
      catch (Throwable t)
      {
      }
      close(ctx);
    }
  }
opends/src/server/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -846,7 +846,7 @@
      PurgeHistoricalUserData uData)
  {
    ReplicationCliReturnCode returnValue;
    LinkedList<String> baseDNs = uData.getBaseDNs();
    List<String> baseDNs = uData.getBaseDNs();
    checkSuffixesForLocalPurgeHistorical(baseDNs, false);
    if (!baseDNs.isEmpty())
    {
@@ -1001,7 +1001,7 @@
    if (ctx != null)
    {
      LinkedList<String> baseDNs = uData.getBaseDNs();
      List<String> baseDNs = uData.getBaseDNs();
      checkSuffixesForPurgeHistorical(baseDNs, ctx, false);
      if (!baseDNs.isEmpty())
      {
@@ -1663,7 +1663,7 @@
    String bindDn1 = argParser.getBindDn1();
    String pwd1 = argParser.getBindPassword1();
    String pwd = null;
    LinkedHashMap<String, String> pwdFile = null;
    Map<String, String> pwdFile = null;
    if (argParser.bindPassword1Arg.isPresent())
    {
      pwd = argParser.bindPassword1Arg.getValue();
@@ -2929,7 +2929,7 @@
    String hostSource = argParser.getHostNameSource();
    int portSource = argParser.getPortSource();
    LinkedHashMap<String, String> pwdFile = null;
    Map<String, String> pwdFile = null;
    if (argParser.getSecureArgsList().bindPasswordFileArg.isPresent())
    {
@@ -4118,7 +4118,7 @@
    if (errorMessages.isEmpty())
    {
      LinkedList<String> suffixes = uData.getBaseDNs();
      List<String> suffixes = uData.getBaseDNs();
      checkSuffixesForEnableReplication(suffixes, ctx1, ctx2, false, uData);
      if (!suffixes.isEmpty())
      {
@@ -4250,7 +4250,7 @@
      // This done is for the message informing that we are connecting.
      printProgress(formatter.getFormattedDone());
      printlnProgress();
      LinkedList<String> suffixes = uData.getBaseDNs();
      List<String> suffixes = uData.getBaseDNs();
      checkSuffixesForDisableReplication(suffixes, ctx, false,
          !uData.disableReplicationServer(), !uData.disableReplicationServer());
      if (!suffixes.isEmpty() || uData.disableReplicationServer() ||
@@ -4414,7 +4414,7 @@
    if ((ctxSource != null) && (ctxDestination != null))
    {
      LinkedList<String> baseDNs = uData.getBaseDNs();
      List<String> baseDNs = uData.getBaseDNs();
      checkSuffixesForInitializeReplication(baseDNs, ctxSource, ctxDestination,
          false);
      if (!baseDNs.isEmpty())
@@ -4531,7 +4531,7 @@
    }
    if (ctx != null)
    {
      LinkedList<String> baseDNs = uData.getBaseDNs();
      List<String> baseDNs = uData.getBaseDNs();
      checkSuffixesForInitializeReplication(baseDNs, ctx, false);
      if (!baseDNs.isEmpty())
      {
@@ -4618,7 +4618,7 @@
    }
    if (ctx != null)
    {
      LinkedList<String> baseDNs = uData.getBaseDNs();
      List<String> baseDNs = uData.getBaseDNs();
      checkSuffixesForInitializeReplication(baseDNs, ctx, false);
      if (!baseDNs.isEmpty())
      {
@@ -4707,7 +4707,7 @@
    }
    if (ctx != null)
    {
      LinkedList<String> baseDNs = uData.getBaseDNs();
      List<String> baseDNs = uData.getBaseDNs();
      checkSuffixesForInitializeReplication(baseDNs, ctx, false);
      if (!baseDNs.isEmpty())
      {
@@ -5509,12 +5509,12 @@
      InitialLdapContext ctx2, EnableReplicationUserData uData)
  throws ReplicationCliException
  {
    LinkedHashSet<String> twoReplServers = new LinkedHashSet<String>();
    LinkedHashSet<String> allRepServers = new LinkedHashSet<String>();
    HashMap<String, LinkedHashSet<String>> hmRepServers =
      new HashMap<String, LinkedHashSet<String>>();
    Set<Integer> usedReplicationServerIds = new HashSet<Integer>();
    HashMap<String, Set<Integer>> hmUsedReplicationDomainIds =
    final Set<String> twoReplServers = new LinkedHashSet<String>();
    final Set<String> allRepServers = new LinkedHashSet<String>();
    final Map<String, Set<String>> hmRepServers =
        new HashMap<String, Set<String>>();
    final Set<Integer> usedReplicationServerIds = new HashSet<Integer>();
    final Map<String, Set<Integer>> hmUsedReplicationDomainIds =
      new HashMap<String, Set<Integer>>();
    ServerDescriptor server1;
@@ -5555,10 +5555,10 @@
    {
      // Inform the user of the potential errors that we found in the already
      // registered servers.
      LinkedHashSet<Message> messages = new LinkedHashSet<Message>();
      final Set<Message> messages = new LinkedHashSet<Message>();
      try
      {
        LinkedHashSet<PreferredConnection> cnx =
        final Set<PreferredConnection> cnx =
          new LinkedHashSet<PreferredConnection>();
        cnx.addAll(PreferredConnection.getPreferredConnections(ctx1));
        cnx.addAll(PreferredConnection.getPreferredConnections(ctx2));
@@ -5898,7 +5898,7 @@
      printProgress(formatter.getFormattedDone());
      printlnProgress();
    }
    LinkedList<String> baseDNs = uData.getBaseDNs();
    List<String> baseDNs = uData.getBaseDNs();
    if (!adsAlreadyReplicated)
    {
      boolean found = false;
@@ -5928,7 +5928,7 @@
    try
    {
      LinkedHashSet<PreferredConnection> cnx =
      Set<PreferredConnection> cnx =
        new LinkedHashSet<PreferredConnection>();
      cnx.addAll(PreferredConnection.getPreferredConnections(ctx1));
      cnx.addAll(PreferredConnection.getPreferredConnections(ctx2));
@@ -5996,7 +5996,7 @@
    for (String baseDN : uData.getBaseDNs())
    {
      LinkedHashSet<String> repServersForBaseDN = new LinkedHashSet<String>();
      Set<String> repServersForBaseDN = new LinkedHashSet<String>();
      repServersForBaseDN.addAll(getReplicationServers(baseDN, cache1,
          server1));
      repServersForBaseDN.addAll(getReplicationServers(baseDN, cache2,
@@ -6327,7 +6327,7 @@
    if (!argParser.isInteractive())
    {
      // Inform the user of the potential errors that we found.
      LinkedHashSet<Message> messages = new LinkedHashSet<Message>();
      Set<Message> messages = new LinkedHashSet<Message>();
      if (cache != null)
      {
        messages.addAll(cache.getErrorMessages());
@@ -6400,7 +6400,7 @@
      // Inform the user
      if (beforeLastRepServer.size() > 0)
      {
        LinkedHashSet<String> baseDNs = new LinkedHashSet<String>();
        Set<String> baseDNs = new LinkedHashSet<String>();
        for (SuffixDescriptor suffix : beforeLastRepServer)
        {
          if (!Utils.areDnsEqual(suffix.getDN(),
@@ -6446,7 +6446,7 @@
      {
        // Check that there are other replicas and that this message, really
        // makes sense to be displayed.
        LinkedHashSet<String> suffixArg = new LinkedHashSet<String>();
        Set<String> suffixArg = new LinkedHashSet<String>();
        for (SuffixDescriptor suffix : lastRepServer)
        {
          boolean baseDNSpecified = false;
@@ -6832,7 +6832,7 @@
    if (!argParser.isInteractive())
    {
      // Inform the user of the potential errors that we found.
      LinkedHashSet<Message> messages = new LinkedHashSet<Message>();
      Set<Message> messages = new LinkedHashSet<Message>();
      messages.addAll(cache.getErrorMessages());
      if (!messages.isEmpty())
      {
@@ -7018,7 +7018,7 @@
   */
  private void displayStatus(
      List<Set<ReplicaDescriptor>> orderedReplicaLists,
      boolean scriptFriendly, LinkedHashSet<PreferredConnection> cnx,
      boolean scriptFriendly, Set<PreferredConnection> cnx,
      Set<ServerDescriptor> servers,
      Set<ReplicaDescriptor> replicasWithNoReplicationServer,
      Set<ServerDescriptor> serversWithNoReplica)
@@ -7309,7 +7309,7 @@
   * @param scriptFriendly wheter to display it on script-friendly mode or not.
   */
  private void displayStatus(Set<ServerDescriptor> servers,
      boolean scriptFriendly, LinkedHashSet<PreferredConnection> cnx)
      boolean scriptFriendly, Set<PreferredConnection> cnx)
  {
    TableBuilder tableBuilder = new TableBuilder();
    tableBuilder.appendHeading(INFO_REPLICATION_STATUS_HEADER_SERVERPORT.get());
@@ -7546,7 +7546,7 @@
   */
  private void configureAsReplicationServer(InitialLdapContext ctx,
      int replicationPort, boolean useSecureReplication,
      LinkedHashSet<String> replicationServers,
      Set<String> replicationServers,
      Set<Integer> usedReplicationServerIds) throws OpenDsException
  {
    printProgress(formatter.getFormattedWithPoints(
@@ -8592,7 +8592,7 @@
  private void removeReferencesInServer(ServerDescriptor server,
      String replicationServer, String bindDn, String pwd,
      Collection<String> baseDNs, boolean updateReplicationServers,
      LinkedHashSet<PreferredConnection> cnx)
      Set<PreferredConnection> cnx)
  throws ReplicationCliException
  {
    TopologyCacheFilter filter = new TopologyCacheFilter();
@@ -9570,7 +9570,7 @@
      ReplicationUserData uData)
  throws ArgumentException
  {
    LinkedList<String> baseDNs = uData.getBaseDNs();
    List<String> baseDNs = uData.getBaseDNs();
    StringArgument baseDNsArg = new StringArgument("baseDNs",
        OPTION_SHORT_BASEDN,
        OPTION_LONG_BASEDN, false, true, true, INFO_BASEDN_PLACEHOLDER.get(),
@@ -10570,7 +10570,7 @@
    PointAdder pointAdder = new PointAdder(this);
    try
    {
      LinkedHashSet<PreferredConnection> cnx =
      Set<PreferredConnection> cnx =
        new LinkedHashSet<PreferredConnection>();
      cnx.addAll(PreferredConnection.getPreferredConnections(
          adsCtx1.getDirContext()));
opends/src/server/org/opends/server/tools/dsreplication/ReplicationUserData.java
@@ -23,11 +23,13 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions Copyright 2013 ForgeRock AS.
 */
package org.opends.server.tools.dsreplication;
import java.util.LinkedList;
import java.util.List;
/**
 * This class is used to store the information provided by the user in the
@@ -37,7 +39,7 @@
 */
public abstract class ReplicationUserData
{
  private LinkedList<String> baseDNs = new LinkedList<String>();
  private final LinkedList<String> baseDNs = new LinkedList<String>();
  private String adminUid;
  private String adminPwd;
@@ -81,7 +83,7 @@
   * Returns the Base DNs to replicate.
   * @return the Base DNs to replicate.
   */
  public LinkedList<String> getBaseDNs()
  public List<String> getBaseDNs()
  {
    return new LinkedList<String>(baseDNs);
  }
@@ -90,7 +92,7 @@
   * Sets the Base DNs to replicate.
   * @param baseDNs the Base DNs to replicate.
   */
  public void setBaseDNs(LinkedList<String> baseDNs)
  public void setBaseDNs(List<String> baseDNs)
  {
    this.baseDNs.clear();
    this.baseDNs.addAll(baseDNs);