summaryrefslogtreecommitdiffstats
path: root/pki/patches/pki-core-9.0.3-r2106.patch
blob: e99ef3f1431335900174ffd1e17afe7fe006cd84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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 {