001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.boot.actuate.autoconfigure.elasticsearch; 018 019import java.util.Map; 020 021import org.elasticsearch.client.RestClient; 022 023import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration; 024import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; 025import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; 026import org.springframework.boot.actuate.elasticsearch.ElasticsearchRestHealthIndicator; 027import org.springframework.boot.actuate.health.HealthIndicator; 028import org.springframework.boot.autoconfigure.AutoConfigureAfter; 029import org.springframework.boot.autoconfigure.AutoConfigureBefore; 030import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 031import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; 032import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 033import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 034import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration; 035import org.springframework.context.annotation.Bean; 036import org.springframework.context.annotation.Configuration; 037 038/** 039 * {@link EnableAutoConfiguration Auto-configuration} for 040 * {@link ElasticsearchRestHealthIndicator} using the {@link RestClient}. 041 * 042 * @author Artsiom Yudovin 043 * @since 2.1.1 044 */ 045 046@Configuration 047@ConditionalOnClass(RestClient.class) 048@ConditionalOnBean(RestClient.class) 049@ConditionalOnEnabledHealthIndicator("elasticsearch") 050@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class) 051@AutoConfigureAfter({ RestClientAutoConfiguration.class, 052 ElasticSearchClientHealthIndicatorAutoConfiguration.class }) 053public class ElasticSearchRestHealthIndicatorAutoConfiguration extends 054 CompositeHealthIndicatorConfiguration<ElasticsearchRestHealthIndicator, RestClient> { 055 056 private final Map<String, RestClient> clients; 057 058 public ElasticSearchRestHealthIndicatorAutoConfiguration( 059 Map<String, RestClient> clients) { 060 this.clients = clients; 061 } 062 063 @Bean 064 @ConditionalOnMissingBean(name = "elasticsearchRestHealthIndicator") 065 public HealthIndicator elasticsearchRestHealthIndicator() { 066 return createHealthIndicator(this.clients); 067 } 068 069 @Override 070 protected ElasticsearchRestHealthIndicator createHealthIndicator(RestClient client) { 071 return new ElasticsearchRestHealthIndicator(client); 072 } 073 074}