Created
September 12, 2018 15:05
-
-
Save ghenzler/ea6cd808243a79eec320760e49475226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.sling.hc.api.HealthCheck | |
//------------------------------------- | |
// Hostile Health Check | |
//------------------------------------- | |
// !!! Be careful, this creates a long-running health check blocking one | |
// thread of the HC thread pool. Unregister the hostile health check by | |
// creating a file "hc-unregister" in the current working dir (usually the | |
// dir next to crx-quickstart folder) and running the HC one more time | |
import org.apache.sling.hc.api.Result | |
import org.apache.sling.hc.util.FormattingResultLog | |
File currentWorkingDir = new File(System.getProperty('user.dir')) | |
dynamicHealthCheck = new HealthCheck() { | |
def serviceRegistration | |
def repository | |
Result execute() { | |
FormattingResultLog log = new FormattingResultLog() | |
log.info("Groovy Health Check") | |
for(int i=1; i<10;i++) { | |
def hcSession = null | |
try { | |
hcSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray())); | |
hcSession.getNode("/").recurse { node -> | |
log.debug("node: "+node.getPath()) | |
} | |
} finally { | |
if(hcSession!=null) { | |
hcSession.logout() | |
} | |
} | |
} | |
def markerFile = new File(currentWorkingDir, "hc-unregister") | |
if(markerFile.exists()) { | |
markerFile.renameTo(new File(currentWorkingDir, "hc-unregister-done")) | |
serviceRegistration.unregister() | |
} | |
return new Result(log) | |
} | |
} | |
resourceChangeListenerReg = bundleContext.registerService( | |
"org.apache.sling.hc.api.HealthCheck", | |
dynamicHealthCheck, | |
new Hashtable([(HealthCheck.NAME): "Hostile Health Check", (HealthCheck.TAGS): ["groovy","dashboard"]])) | |
dynamicHealthCheck.serviceRegistration = resourceChangeListenerReg | |
dynamicHealthCheck.repository = session.getRepository() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment