Search in sources :

Example 1 with ConditionalOnEnabledHealthIndicator

use of org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator in project cas by apereo.

the class CasCoreMonitorConfiguration method sessionHealthIndicator.

@ConditionalOnMissingBean(name = "sessionHealthIndicator")
@Bean
@ConditionalOnEnabledHealthIndicator("sessionHealthIndicator")
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public HealthIndicator sessionHealthIndicator(@Qualifier(TicketRegistry.BEAN_NAME) final TicketRegistry ticketRegistry, final CasConfigurationProperties casProperties) {
    val warnSt = casProperties.getMonitor().getSt().getWarn();
    val warnTgt = casProperties.getMonitor().getTgt().getWarn();
    if (warnSt.getThreshold() > 0 && warnTgt.getThreshold() > 0) {
        LOGGER.debug("Configured session monitor with service ticket threshold [{}] and session threshold [{}]", warnSt.getThreshold(), warnTgt.getThreshold());
        return new TicketRegistryHealthIndicator(ticketRegistry, warnSt.getThreshold(), warnTgt.getThreshold());
    }
    return () -> Health.up().build();
}
Also used : lombok.val(lombok.val) TicketRegistryHealthIndicator(org.apereo.cas.monitor.TicketRegistryHealthIndicator) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ConditionalOnEnabledHealthIndicator

use of org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator in project cas by apereo.

the class MongoDbMonitoringConfiguration method mongoHealthIndicator.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnEnabledHealthIndicator("mongoHealthIndicator")
@ConditionalOnMissingBean(name = "mongoHealthIndicator")
public HealthIndicator mongoHealthIndicator(final CasConfigurationProperties casProperties, @Qualifier("mongoHealthIndicatorTemplate") final BeanContainer<CasMongoOperations> mongoHealthIndicatorTemplate) {
    val warn = casProperties.getMonitor().getWarn();
    val results = mongoHealthIndicatorTemplate.toList().stream().map(template -> new MongoDbHealthIndicator(template, warn.getEvictionThreshold(), warn.getThreshold())).collect(Collectors.toList());
    return new CompositeHealthIndicator(results);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) MongoDbHealthIndicator(org.apereo.cas.monitor.MongoDbHealthIndicator) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) CasMongoOperations(org.apereo.cas.mongo.CasMongoOperations) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) Collectors(java.util.stream.Collectors) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Configuration(org.springframework.context.annotation.Configuration) BeanContainer(org.apereo.cas.util.spring.beans.BeanContainer) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) CasSSLContext(org.apereo.cas.authentication.CasSSLContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CompositeHealthIndicator(org.apereo.cas.monitor.CompositeHealthIndicator) Bean(org.springframework.context.annotation.Bean) CompositeHealthIndicator(org.apereo.cas.monitor.CompositeHealthIndicator) MongoDbHealthIndicator(org.apereo.cas.monitor.MongoDbHealthIndicator) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with ConditionalOnEnabledHealthIndicator

use of org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator in project cas by apereo.

the class LdapMonitorConfiguration method pooledLdapConnectionFactoryHealthIndicator.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnEnabledHealthIndicator("pooledLdapConnectionFactoryHealthIndicator")
public CompositeHealthContributor pooledLdapConnectionFactoryHealthIndicator(final CasConfigurationProperties casProperties, @Qualifier("pooledLdapConnectionFactoryHealthIndicatorListFactoryBean") final ListFactoryBean factoryBean) throws Exception {
    val ldaps = casProperties.getMonitor().getLdap();
    val connectionFactoryList = Objects.requireNonNull(factoryBean.getObject());
    val contributors = new LinkedHashMap<>();
    ldaps.stream().filter(LdapMonitorProperties::isEnabled).map(Unchecked.function(ldap -> {
        val executor = Beans.newThreadPoolExecutorFactoryBean(ldap.getPool());
        val connectionFactory = LdapUtils.newLdaptivePooledConnectionFactory(ldap);
        connectionFactoryList.add(connectionFactory);
        val healthIndicator = new PooledLdapConnectionFactoryHealthIndicator(Beans.newDuration(ldap.getMaxWait()).toMillis(), connectionFactory, executor.getObject(), new SearchConnectionValidator());
        val name = StringUtils.defaultIfBlank(ldap.getName(), UUID.randomUUID().toString());
        return Pair.of(name, healthIndicator);
    })).forEach(it -> contributors.put(it.getKey(), it.getValue()));
    return CompositeHealthContributor.fromMap((Map) contributors);
}
Also used : lombok.val(lombok.val) SearchConnectionValidator(org.ldaptive.SearchConnectionValidator) LdapMonitorProperties(org.apereo.cas.configuration.model.core.monitor.LdapMonitorProperties) PooledLdapConnectionFactoryHealthIndicator(org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator) LinkedHashMap(java.util.LinkedHashMap) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ListFactoryBean(org.springframework.beans.factory.config.ListFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

lombok.val (lombok.val)3 ConditionalOnEnabledHealthIndicator (org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator)3 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)3 Bean (org.springframework.context.annotation.Bean)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 LinkedHashMap (java.util.LinkedHashMap)1 Collectors (java.util.stream.Collectors)1 CasSSLContext (org.apereo.cas.authentication.CasSSLContext)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 LdapMonitorProperties (org.apereo.cas.configuration.model.core.monitor.LdapMonitorProperties)1 CasMongoOperations (org.apereo.cas.mongo.CasMongoOperations)1 MongoDbConnectionFactory (org.apereo.cas.mongo.MongoDbConnectionFactory)1 CompositeHealthIndicator (org.apereo.cas.monitor.CompositeHealthIndicator)1 MongoDbHealthIndicator (org.apereo.cas.monitor.MongoDbHealthIndicator)1 PooledLdapConnectionFactoryHealthIndicator (org.apereo.cas.monitor.PooledLdapConnectionFactoryHealthIndicator)1 TicketRegistryHealthIndicator (org.apereo.cas.monitor.TicketRegistryHealthIndicator)1 BeanContainer (org.apereo.cas.util.spring.beans.BeanContainer)1 SearchConnectionValidator (org.ldaptive.SearchConnectionValidator)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 ListFactoryBean (org.springframework.beans.factory.config.ListFactoryBean)1