summaryrefslogtreecommitdiffstats
path: root/pki
diff options
context:
space:
mode:
authorvakwetu <vakwetu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2011-08-04 18:46:19 +0000
committervakwetu <vakwetu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2011-08-04 18:46:19 +0000
commit2bb285a8a42f978fa36ea44206d57fe0d9ae22aa (patch)
tree6cbefafadac7e1060f40c8c32395228ac20378ff /pki
parentc449610f779afb2242180d68180cfa4a9a9a641d (diff)
downloadpki-2bb285a8a42f978fa36ea44206d57fe0d9ae22aa.tar.gz
pki-2bb285a8a42f978fa36ea44206d57fe0d9ae22aa.tar.xz
pki-2bb285a8a42f978fa36ea44206d57fe0d9ae22aa.zip
Resolves #726785 - If replication fails while setting up a clone it will wait forever
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@2107 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki')
-rw-r--r--pki/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java108
1 files changed, 73 insertions, 35 deletions
diff --git a/pki/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java b/pki/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java
index feb16a490..bdd0b0d08 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/csadmin/DatabasePanel.java
@@ -1156,9 +1156,17 @@ public class DatabasePanel extends WizardPanelBase {
// 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 @@ public class DatabasePanel extends WizardPanelBase {
}
}
- 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 @@ public class DatabasePanel extends WizardPanelBase {
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 {