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

jvergara
23.16.2007 6bc9517c206b0b8d7cfec7ea4abb7f9dfad535ac
opends/src/guitools/org/opends/guitools/statuspanel/ConfigFromLDAP.java
@@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TreeSet;
@@ -43,6 +44,7 @@
import javax.naming.ldap.LdapName;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.quicksetup.util.Utils;
import org.opends.messages.Message;
@@ -798,8 +800,8 @@
      type = BaseDNDescriptor.Type.NOT_REPLICATED;
    }
    return new BaseDNDescriptor(type, baseDn, null, ageOfOldestMissingChange,
      missingChanges);
    return new BaseDNDescriptor(type, baseDn, null, -1,
        ageOfOldestMissingChange, missingChanges);
  }
  /**
@@ -932,13 +934,35 @@
      Set<String> baseDns = getValues(entry, "ds-cfg-base-dn");
      TreeSet<BaseDNDescriptor> replicas = new TreeSet<BaseDNDescriptor>();
      int nEntries = getEntryCount(ctx, id);
      Set<String> baseDnEntries = getBaseDNEntryCount(ctx, id);
      DatabaseDescriptor db = new DatabaseDescriptor(id, replicas, nEntries);
      for (String baseDn : baseDns)
      {
        BaseDNDescriptor rep = getBaseDNDescriptor(ctx, baseDn);
        rep.setDatabase(db);
        nEntries = -1;
        for (String s : baseDnEntries)
        {
          int index = s.indexOf(" ");
          if (index != -1)
          {
            String dn = s.substring(index +1);
            if (Utils.areDnsEqual(baseDn, dn))
            {
              try
              {
                nEntries = Integer.parseInt(s.substring(0, index));
              }
              catch (Throwable t)
              {
                /* Ignore */
              }
              break;
            }
          }
        }
        rep.setEntries(nEntries);
        db.getBaseDns().add(rep);
      }
@@ -1019,4 +1043,36 @@
  {
    return ConfigFromFile.isConfigBackend(id);
  }
  /**
   * Returns the values of the ds-base-dn-entry count attributes for the given
   * backend monitor entry using the provided InitialLdapContext.
   * @param ctx the InitialLdapContext to use to update the configuration.
   * @param backendID the id of the backend.
   * @return the values of the ds-base-dn-entry count attribute.
   * @throws NamingException if there was an error.
   */
  private static Set<String> getBaseDNEntryCount(InitialLdapContext ctx,
      String backendID) throws NamingException
  {
    LinkedHashSet<String> v = new LinkedHashSet<String>();
    SearchControls ctls = new SearchControls();
    ctls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
    ctls.setReturningAttributes(
        new String[] {
            "ds-base-dn-entry-count"
        });
    String filter = "(ds-backend-id="+backendID+")";
    LdapName jndiName = new LdapName("cn=monitor");
    NamingEnumeration listeners = ctx.search(jndiName, filter, ctls);
    while(listeners.hasMore())
    {
      SearchResult sr = (SearchResult)listeners.next();
      v.addAll(ConnectionUtils.getValues(sr, "ds-base-dn-entry-count"));
    }
    return v;
  }
}