Search in sources :

Example 1 with HealthCheck

use of org.eclipse.microprofile.health.HealthCheck in project wildfly-swarm by wildfly-swarm.

the class HealthExtension method afterDeploymentValidation.

/**
 * Instantiates <em>unmanaged instances</em> of HealthCheckProcedure and
 * handle manually their CDI creation lifecycle.
 * Add them to the {@link Monitor}.
 */
private void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
    try {
        for (AnnotatedType delegate : delegates) {
            Unmanaged<HealthCheck> unmanagedHealthCheck = new Unmanaged<HealthCheck>(beanManager, delegate.getJavaClass());
            Unmanaged.UnmanagedInstance<HealthCheck> healthCheckInstance = unmanagedHealthCheck.newInstance();
            HealthCheck healthCheck = healthCheckInstance.produce().inject().postConstruct().get();
            healthChecks.add(healthCheck);
            healthCheckInstances.add(healthCheckInstance);
            monitor.registerHealthBean(healthCheck);
            log.info(">> Added health bean impl " + healthCheck);
        }
        // we don't need the references anymore
        delegates.clear();
    } catch (Exception e) {
        throw new RuntimeException("Failed to register health bean", e);
    }
}
Also used : ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) AnnotatedType(javax.enterprise.inject.spi.AnnotatedType) Unmanaged(javax.enterprise.inject.spi.Unmanaged) HealthCheck(org.eclipse.microprofile.health.HealthCheck) NamingException(javax.naming.NamingException)

Example 2 with HealthCheck

use of org.eclipse.microprofile.health.HealthCheck in project wildfly by wildfly.

the class CDIExtension method addHealthChecks.

private void addHealthChecks(AnnotationLiteral qualifier, BiConsumer<HealthCheck, ClassLoader> healthFunction, List<HealthCheck> healthChecks) {
    for (HealthCheck healthCheck : instance.select(HealthCheck.class, qualifier)) {
        healthFunction.accept(healthCheck, module.getClassLoader());
        healthChecks.add(healthCheck);
    }
}
Also used : HealthCheck(org.eclipse.microprofile.health.HealthCheck)

Example 3 with HealthCheck

use of org.eclipse.microprofile.health.HealthCheck in project wildfly by wildfly.

the class CDIExtension method removeHealthCheck.

private void removeHealthCheck(List<HealthCheck> healthChecks, Consumer<HealthCheck> healthFunction) {
    for (HealthCheck healthCheck : healthChecks) {
        healthFunction.accept(healthCheck);
        instance.destroy(healthCheck);
    }
    healthChecks.clear();
}
Also used : HealthCheck(org.eclipse.microprofile.health.HealthCheck)

Example 4 with HealthCheck

use of org.eclipse.microprofile.health.HealthCheck in project Payara by payara.

the class HealthCDIExtension method registerHealthCheck.

private void registerHealthCheck(Bean<?> bean, BeanManager beanManager) {
    HealthCheck healthCheck = (HealthCheck) beanManager.getReference(bean, HealthCheck.class, beanManager.createCreationalContext(bean));
    healthService.registerHealthCheck(appName, healthCheck, HealthCheckType.fromQualifiers(bean.getQualifiers()));
    healthService.registerClassLoader(appName, healthCheck.getClass().getClassLoader());
    LOGGER.log(Level.INFO, "Registered {0} as a HealthCheck for app: {1}", new Object[] { bean.getBeanClass().getCanonicalName(), appName });
}
Also used : HealthCheck(org.eclipse.microprofile.health.HealthCheck)

Example 5 with HealthCheck

use of org.eclipse.microprofile.health.HealthCheck in project Payara by payara.

the class HealthCheckService method getCollectiveHealthChecks.

private Map<String, Set<HealthCheck>> getCollectiveHealthChecks(HealthCheckType type) {
    final Map<String, Set<HealthCheck>> healthChecks;
    if (type == READINESS) {
        healthChecks = readiness;
    } else if (type == LIVENESS) {
        healthChecks = liveness;
    } else if (type == STARTUP) {
        healthChecks = startup;
    } else {
        // Make sure we do a deep-copy first, otherwise the first map the foreach consumer gets used on will be a
        // shallow copy: the two maps will essentially be the same map (changes to one affecting the other)
        healthChecks = readiness.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> new HashSet(entry.getValue())));
        BiConsumer<? super String, ? super Set<HealthCheck>> mergeHealthCheckMap = (key, value) -> healthChecks.merge(key, value, (oldValue, newValue) -> {
            oldValue.addAll(newValue);
            return oldValue;
        });
        liveness.forEach(mergeHealthCheckMap);
        startup.forEach(mergeHealthCheckMap);
    }
    return healthChecks;
}
Also used : JsonWriterFactory(javax.json.JsonWriterFactory) Events(org.glassfish.api.event.Events) MonitoringWatchCollector(fish.payara.monitoring.collect.MonitoringWatchCollector) Map(java.util.Map) WebApplication(com.sun.enterprise.web.WebApplication) LIVENESS(fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheckServiceEvents(fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents) MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Collections.emptyList(java.util.Collections.emptyList) UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WARNING(java.util.logging.Level.WARNING) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) MonitoringDataSource(fish.payara.monitoring.collect.MonitoringDataSource) List(java.util.List) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) MicroprofileHealthCheckConfiguration(fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration) Optional(java.util.Optional) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) JsonObjectBuilder(javax.json.JsonObjectBuilder) Deployment(org.glassfish.internal.deployment.Deployment) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) READINESS(fish.payara.microprofile.healthcheck.HealthCheckType.READINESS) JsonGenerator(javax.json.stream.JsonGenerator) InvocationManager(org.glassfish.api.invocation.InvocationManager) JsonArrayBuilder(javax.json.JsonArrayBuilder) Globals(org.glassfish.internal.api.Globals) MonitoringData(fish.payara.monitoring.collect.MonitoringData) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InvocationException(org.glassfish.api.invocation.InvocationException) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) BiConsumer(java.util.function.BiConsumer) Json(javax.json.Json) Collections.singletonMap(java.util.Collections.singletonMap) EventListener(org.glassfish.api.event.EventListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) RunLevel(org.glassfish.hk2.runlevel.RunLevel) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebContainer(com.sun.enterprise.web.WebContainer) IOException(java.io.IOException) Checker(fish.payara.nucleus.healthcheck.configuration.Checker) STARTUP(fish.payara.microprofile.healthcheck.HealthCheckType.STARTUP) Status(org.eclipse.microprofile.health.HealthCheckResponse.Status) MonitoringWatchSource(fish.payara.monitoring.collect.MonitoringWatchSource) JsonWriter(javax.json.JsonWriter) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) ConfigListener(org.jvnet.hk2.config.ConfigListener) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) Set(java.util.Set) HashSet(java.util.HashSet) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) HashSet(java.util.HashSet)

Aggregations

HealthCheck (org.eclipse.microprofile.health.HealthCheck)8 ArrayList (java.util.ArrayList)3 HealthCheckResponse (org.eclipse.microprofile.health.HealthCheckResponse)3 WebApplication (com.sun.enterprise.web.WebApplication)2 WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)2 WebContainer (com.sun.enterprise.web.WebContainer)2 LIVENESS (fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS)2 READINESS (fish.payara.microprofile.healthcheck.HealthCheckType.READINESS)2 STARTUP (fish.payara.microprofile.healthcheck.HealthCheckType.STARTUP)2 PayaraHealthCheck (fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck)2 MicroprofileHealthCheckConfiguration (fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration)2 MonitoringData (fish.payara.monitoring.collect.MonitoringData)2 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)2 MonitoringDataSource (fish.payara.monitoring.collect.MonitoringDataSource)2 MonitoringWatchCollector (fish.payara.monitoring.collect.MonitoringWatchCollector)2 MonitoringWatchSource (fish.payara.monitoring.collect.MonitoringWatchSource)2 Checker (fish.payara.nucleus.healthcheck.configuration.Checker)2 PayaraHealthCheckServiceEvents (fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 IOException (java.io.IOException)2