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 */
016package org.springframework.boot.actuate.autoconfigure.couchbase;
017
018import java.util.Map;
019
020import com.couchbase.client.java.Cluster;
021
022import org.springframework.boot.actuate.autoconfigure.health.CompositeHealthIndicatorConfiguration;
023import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
024import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
025import org.springframework.boot.actuate.couchbase.CouchbaseHealthIndicator;
026import org.springframework.boot.actuate.health.HealthIndicator;
027import org.springframework.boot.autoconfigure.AutoConfigureAfter;
028import org.springframework.boot.autoconfigure.AutoConfigureBefore;
029import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
030import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
031import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
032import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
033import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration;
034import org.springframework.context.annotation.Bean;
035import org.springframework.context.annotation.Configuration;
036
037/**
038 * {@link EnableAutoConfiguration Auto-configuration} for
039 * {@link CouchbaseHealthIndicator}.
040 *
041 * @author EddĂș MelĂ©ndez
042 * @author Stephane Nicoll
043 * @author Andy Wilkinson Nicoll
044 * @since 2.0.0
045 */
046@Configuration
047@ConditionalOnClass(Cluster.class)
048@ConditionalOnBean(Cluster.class)
049@ConditionalOnEnabledHealthIndicator("couchbase")
050@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class)
051@AutoConfigureAfter(CouchbaseAutoConfiguration.class)
052public class CouchbaseHealthIndicatorAutoConfiguration
053                extends CompositeHealthIndicatorConfiguration<CouchbaseHealthIndicator, Cluster> {
054
055        private final Map<String, Cluster> clusters;
056
057        public CouchbaseHealthIndicatorAutoConfiguration(Map<String, Cluster> clusters) {
058                this.clusters = clusters;
059        }
060
061        @Bean
062        @ConditionalOnMissingBean(name = "couchbaseHealthIndicator")
063        public HealthIndicator couchbaseHealthIndicator() {
064                return createHealthIndicator(this.clusters);
065        }
066
067        @Override
068        protected CouchbaseHealthIndicator createHealthIndicator(Cluster cluster) {
069                return new CouchbaseHealthIndicator(cluster);
070        }
071
072}