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.couchbase; 018 019import com.couchbase.client.core.message.internal.DiagnosticsReport; 020import com.couchbase.client.java.Cluster; 021 022import org.springframework.boot.actuate.health.AbstractHealthIndicator; 023import org.springframework.boot.actuate.health.Health; 024import org.springframework.boot.actuate.health.HealthIndicator; 025import org.springframework.util.Assert; 026 027/** 028 * {@link HealthIndicator} for Couchbase. 029 * 030 * @author EddĂș MelĂ©ndez 031 * @author Stephane Nicoll 032 * @since 2.0.0 033 */ 034public class CouchbaseHealthIndicator extends AbstractHealthIndicator { 035 036 private final Cluster cluster; 037 038 /** 039 * Create an indicator with the specified {@link Cluster}. 040 * @param cluster the Couchbase Cluster 041 * @since 2.0.6 042 */ 043 public CouchbaseHealthIndicator(Cluster cluster) { 044 super("Couchbase health check failed"); 045 Assert.notNull(cluster, "Cluster must not be null"); 046 this.cluster = cluster; 047 } 048 049 @Override 050 protected void doHealthCheck(Health.Builder builder) throws Exception { 051 DiagnosticsReport diagnostics = this.cluster.diagnostics(); 052 new CouchbaseHealth(diagnostics).applyTo(builder); 053 } 054 055}