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.couchbase;
017
018import com.couchbase.client.core.message.internal.DiagnosticsReport;
019import com.couchbase.client.java.Cluster;
020import reactor.core.publisher.Mono;
021
022import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator;
023import org.springframework.boot.actuate.health.Health;
024import org.springframework.boot.actuate.health.ReactiveHealthIndicator;
025
026/**
027 * A {@link ReactiveHealthIndicator} for Couchbase.
028 *
029 * @author Mikalai Lushchytski
030 * @author Stephane Nicoll
031 * @since 2.1.0
032 */
033public class CouchbaseReactiveHealthIndicator extends AbstractReactiveHealthIndicator {
034
035        private final Cluster cluster;
036
037        /**
038         * Create a new {@link CouchbaseReactiveHealthIndicator} instance.
039         * @param cluster the Couchbase cluster
040         */
041        public CouchbaseReactiveHealthIndicator(Cluster cluster) {
042                this.cluster = cluster;
043        }
044
045        @Override
046        protected Mono<Health> doHealthCheck(Health.Builder builder) {
047                DiagnosticsReport diagnostics = this.cluster.diagnostics();
048                new CouchbaseHealth(diagnostics).applyTo(builder);
049                return Mono.just(builder.build());
050        }
051
052}