Skip to content

Commit

Permalink
Block startup until initial profile load completed
Browse files Browse the repository at this point in the history
It is possible for the CMS getStatus resource to indicate that CMS
is ready when the initial loading of profiles (which is performed by
another thread) is not complete.  During startup, wait for the
initial loading of profiles to complete before continuing.

Fixes: https://fedorahosted.org/pki/ticket/1702
(cherry picked from commit e8a1d9c)
  • Loading branch information
frasertweedale authored and Matthew Harmsen committed Jan 21, 2016
1 parent 7356d2f commit b169684
Showing 1 changed file with 35 additions and 2 deletions.
Expand Up @@ -19,10 +19,12 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;

import netscape.ldap.LDAPAttribute;
import netscape.ldap.LDAPConnection;
Expand Down Expand Up @@ -68,6 +70,11 @@ public class LDAPProfileSubsystem
/* Set of nsUniqueIds of deleted entries */
private TreeSet<String> deletedNsUniqueIds;

/* Variables to track initial loading of profiles */
private Integer initialNumProfiles = null;
private int numProfilesLoaded = 0;
private CountDownLatch initialLoadDone = new CountDownLatch(1);

/**
* Initializes this subsystem with the given configuration
* store.
Expand Down Expand Up @@ -109,6 +116,13 @@ public void init(ISubsystem owner, IConfigStore config)

monitor = new Thread(this, "profileChangeMonitor");
monitor.start();
try {
initialLoadDone.await();
} catch (InterruptedException e) {
CMS.debug("LDAPProfileSubsystem: caught InterruptedException "
+ "while waiting for initial load of profiles.");
}
CMS.debug("LDAPProfileSubsystem: finished init");
}

/**
Expand Down Expand Up @@ -380,6 +394,12 @@ private String createProfileDN(String id) throws EProfileException {
return "cn=" + id + "," + dn;
}

private void checkInitialLoadDone() {
if (initialNumProfiles != null
&& numProfilesLoaded >= initialNumProfiles)
initialLoadDone.countDown();
}

public void run() {
int op = LDAPPersistSearchControl.ADD
| LDAPPersistSearchControl.MODIFY
Expand All @@ -400,12 +420,23 @@ public void run() {
cons.setServerControls(persistCtrl);
cons.setBatchSize(1);
cons.setServerTimeLimit(0 /* seconds */);
String[] attrs = {"*", "entryUSN", "nsUniqueId"};
String[] attrs = {"*", "entryUSN", "nsUniqueId", "numSubordinates"};
LDAPSearchResults results = conn.search(
dn, LDAPConnection.SCOPE_ONE, "(objectclass=*)",
dn, LDAPConnection.SCOPE_SUB, "(objectclass=*)",
attrs, false, cons);
while (!stopped && results.hasMoreElements()) {
LDAPEntry entry = results.next();

String[] objectClasses =
entry.getAttribute("objectClass").getStringValueArray();
if (Arrays.asList(objectClasses).contains("organizationalUnit")) {
initialNumProfiles = new Integer(
entry.getAttribute("numSubordinates")
.getStringValueArray()[0]);
checkInitialLoadDone();
continue;
}

LDAPEntryChangeControl changeControl = (LDAPEntryChangeControl)
LDAPUtil.getControl(
LDAPEntryChangeControl.class, results.getResponseControls());
Expand Down Expand Up @@ -436,6 +467,8 @@ public void run() {
} else {
CMS.debug("Profile change monitor: immediate result");
readProfile(entry);
numProfilesLoaded += 1;
checkInitialLoadDone();
}
}
} catch (ELdapException e) {
Expand Down

0 comments on commit b169684

Please sign in to comment.