Index: base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java =================================================================== --- base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java (revision 2105) +++ base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java (revision 2106) @@ -1156,9 +1156,17 @@ // initialize consumer initializeConsumer(replicadn, conn1, masterAgreementName); + while (! replicationDone(replicadn, conn1, masterAgreementName)) { + CMS.debug("DatabasePanel setupReplication: Waiting for replication to complete"); + Thread.sleep(1000); + } - // compare entries - compareAndWaitEntries(conn1, conn2, basedn); + String status = replicationStatus(replicadn, conn1, masterAgreementName); + if (!status.startsWith("0 ")) { + CMS.debug("DatabasePanel setupReplication: consumer initialization failed. " + + status); + throw new IOException("consumer initialization failed. " + status); + } } catch (Exception e) { CMS.debug("DatabasePanel setupReplication: "+e.toString()); @@ -1166,39 +1174,6 @@ } } - private void compareAndWaitEntries(LDAPConnection conn1, - LDAPConnection conn2, String basedn) - { - try { - LDAPSearchResults res = conn1.search(basedn, - LDAPConnection.SCOPE_ONE, "(objectclass=*)", null, true); - while (res.hasMoreElements()) { - LDAPEntry source = res.next(); - // check if this entry is present in conn2 - LDAPEntry dest = null; - do { - CMS.debug("DatabasePanel comparetAndWaitEntries checking " + - source.getDN()); - try { - dest = conn2.read(source.getDN(), (String[])null); - } catch (Exception e1) { - CMS.debug("DatabasePanel comparetAndWaitEntries " + - source.getDN() + " not found, let's wait!"); - try { - Thread.sleep(5000); - } catch (Exception e2) { - } - } - } while (dest == null); - - // check children of this entry - compareAndWaitEntries(conn1, conn2, source.getDN()); - } // while - } catch (Exception ex) { - CMS.debug("DatabasePanel comparetAndWaitEntries " + ex); - } - } - /** * If validiate() returns false, this method will be called. */ @@ -1432,6 +1407,69 @@ CMS.debug("DatabasePanel initializeConsumer: Successfully initialize consumer"); } + private boolean replicationDone(String replicadn, LDAPConnection conn, String name) + throws IOException { + String dn = "cn="+name+","+replicadn; + String filter = "(objectclass=*)"; + String[] attrs = {"nsds5beginreplicarefresh"}; + + CMS.debug("DatabasePanel replicationDone: dn: "+dn); + try { + LDAPSearchResults results = conn.search(dn, LDAPConnection.SCOPE_BASE, filter, + attrs, true); + + int count = results.getCount(); + if (count < 1) { + throw new IOException("Replication entry not found"); + } + + LDAPEntry entry = results.next(); + LDAPAttribute refresh = entry.getAttribute("nsds5beginreplicarefresh"); + if (refresh == null) { + return true; + } + return false; + } catch (Exception e) { + CMS.debug("DatabasePanel replicationDone: exception " + e); + throw new IOException("Exception in replicationDone: " + e); + } + } + + private String replicationStatus(String replicadn, LDAPConnection conn, String name) + throws IOException { + String dn = "cn="+name+","+replicadn; + String filter = "(objectclass=*)"; + String[] attrs = {"nsds5replicalastinitstatus"}; + String status = null; + + CMS.debug("DatabasePanel replicationStatus: dn: "+dn); + try { + LDAPSearchResults results = conn.search(dn, LDAPConnection.SCOPE_BASE, filter, + attrs, false); + + int count = results.getCount(); + if (count < 1) { + throw new IOException("Replication entry not found"); + } + + LDAPEntry entry = results.next(); + LDAPAttribute attr = entry.getAttribute("nsds5replicalastinitstatus"); + if (attr != null) { + Enumeration valsInAttr = attr.getStringValues(); + if (valsInAttr.hasMoreElements()) { + return (String)valsInAttr.nextElement(); + } else { + throw new IOException("No value returned for nsds5replicalastinitstatus"); + } + } else { + throw new IOException("nsDS5ReplicaLastInitStatus is null."); + } + } catch (Exception e) { + CMS.debug("DatabasePanel replicationStatus: exception " + e); + throw new IOException("Exception in replicationStatus: " + e); + } + } + private String getInstanceDir(LDAPConnection conn) { String instancedir=""; try {