001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.health; 018 019import java.util.Collections; 020import java.util.Map; 021import java.util.Optional; 022 023import org.apache.camel.Ordered; 024import org.apache.camel.spi.HasGroup; 025import org.apache.camel.spi.HasId; 026 027public interface HealthCheck extends HasGroup, HasId, Ordered { 028 enum State { 029 UP, 030 DOWN, 031 UNKNOWN 032 } 033 034 @Override 035 default int getOrder() { 036 return Ordered.LOWEST; 037 } 038 039 /** 040 * Return meta data associated with this {@link HealthCheck}. 041 */ 042 default Map<String, Object> getMetaData() { 043 return Collections.emptyMap(); 044 } 045 046 /** 047 * Return the configuration associated with this {@link HealthCheck}. 048 */ 049 HealthCheckConfiguration getConfiguration(); 050 051 /** 052 * Invoke the check. 053 * 054 * @see {@link #call(Map)} 055 */ 056 default Result call() { 057 return call(Collections.emptyMap()); 058 } 059 060 /** 061 * Invoke the check. The implementation is responsible to eventually perform 062 * the check according to the limitation of the third party system i.e. 063 * it should not be performed too often to avoid rate limiting. The options 064 * argument can be used to pass information specific to the check like 065 * forcing the check to be performed against the the policies. The implementation 066 * is responsible to catch an handle any exception thrown by the underlying 067 * technology, including unchecked ones. 068 */ 069 Result call(Map<String, Object> options); 070 071 /** 072 * Response to an health check invocation. 073 */ 074 interface Result { 075 076 /** 077 * The {@link HealthCheck} associated to this response. 078 */ 079 HealthCheck getCheck(); 080 081 /** 082 * The state of the service. 083 */ 084 State getState(); 085 086 /** 087 * A message associated to the result, used to provide more information 088 * for unhealthy services. 089 */ 090 Optional<String> getMessage(); 091 092 /** 093 * An error associated to the result, used to provide the error associated 094 * to unhealthy services. 095 */ 096 Optional<Throwable> getError(); 097 098 /** 099 * An key/value combination of details. 100 * 101 * @return a non null details map 102 */ 103 Map<String, Object> getDetails(); 104 } 105}