systemStatusDAO.save(systemStatus);
}
private void doPatch() {
SystemInfo systemInfo = systemStatusDAO.getLatest();
// the current patch version application is running
Integer currentPatchLevel = systemInfo.getPatchLevel();
// if it's not set in the db... should only ever happen once (unless you dropped your db)
if (currentPatchLevel == null) {
currentPatchLevel = 0;
}
// from the properties, this is what we should apply
Integer latestPatchAvailable = new Integer(latestPatch);
logger.info("[BOOTSTRAP] db is at patch level " + currentPatchLevel);
logger.info("[BOOTSTRAP] available patch number is " + latestPatchAvailable);
// See if there is anything to do
if (!isPatchRequired()) {
logger.info("[BOOTSTRAP] nothing to do, exiting doPatch()");
return;
}
// check to see if this host is the PatchMaster, all others are blocked until completion
try {
String hostname = java.net.InetAddress.getLocalHost().getHostName();
if (!hostname.equals(patchMaster)) {
// sleep, waking periodically to see if the patch is done.
while (isPatchRequired()) {
logger.info("[BOOTSTRAP]" + hostname + " sleeping while db is locked and patches are applied.");
Thread.sleep(3000); // 3 second nap
}
logger.info("[BOOTSTRAP]" + hostname + " waking from sleep and booting, patch master is done.");
// done, continue the boot process
return;
}
} catch (Exception e) {
logger.error("[BOOTSTRAP] patch failure: " + e.getMessage());
throw new RuntimeException("[BOOTSTRAP] patch failure, terminating." + e.getMessage());
}
// apply patches if you are the patch master
while (currentPatchLevel < latestPatchAvailable) {
try {
currentPatchLevel = currentPatchLevel + 1;
Patch patch = (Patch) applicationContext.getBean("patch" + currentPatchLevel);
if (patch == null) {
logger.info("[BOOTSTRAP] class not found for patch" + currentPatchLevel);
logger.info("[BOOTSTRAP] patch " + currentPatchLevel + " not applied, exiting patch process");
break;
}
patch.applyPatch(applicationManager, applicationContext);
// if it fails do no set this.. there is no "continue" here.
systemInfo.setPatchLevel(currentPatchLevel);
systemStatusDAO.save(systemInfo);
} catch (PatchException e) {
logger.info("[BOOTSTRAP] " + e.getMessage() + " patch " + currentPatchLevel + " not applied, exiting patch process");
break;