From 412d236404aa0ef9aebec658a1aeca80ab968fcd Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> Date: Tue, 13 Aug 2024 14:13:25 +0200 Subject: Make echo liveness probe available under /actuator/health for resources - implement spring's HealthIndicator interface to provide health probe based on AaiGraphChecker - conditionally enable the probe when aai.actuator.echo.enabled=true - increase snapshot version to 1.15.6-SNAPSHOT Issue-ID: AAI-3959 Change-Id: Ie2b49ad1f3145285be844bb11aa8119a16fb68c9 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> --- .../onap/aai/rest/util/EchoHealthIndicator.java | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 aai-resources/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java (limited to 'aai-resources/src/main/java/org') diff --git a/aai-resources/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java b/aai-resources/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java new file mode 100644 index 00000000..fd5dbcf8 --- /dev/null +++ b/aai-resources/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java @@ -0,0 +1,50 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2024 Deutsche Telekom. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.aai.rest.util; + +import org.onap.aai.tasks.AaiGraphChecker; +import org.onap.aai.tasks.AaiGraphChecker.CheckerType; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.stereotype.Component; + +import lombok.RequiredArgsConstructor; + +@Component +@RequiredArgsConstructor +@ConditionalOnProperty(name = "aai.actuator.echo.enabled", havingValue = "true") +public class EchoHealthIndicator implements HealthIndicator { + + private final AaiGraphChecker aaiGraphChecker; + + @Override + public Health health() { + return healthy() + ? Health.up().build() + : Health.down().build(); + } + + private boolean healthy() { + return aaiGraphChecker.isAaiGraphDbAvailable(CheckerType.ACTUAL); + } + +} -- cgit