--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 OpenInfra Foundation Europe. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.config.health;
+
+import org.onap.policy.common.message.bus.event.TopicEndpoint;
+import org.onap.policy.common.message.bus.event.TopicEndpointManager;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.boot.actuate.health.HealthIndicator;
+import org.springframework.stereotype.Component;
+
+@Component
+public class KafkaHealthIndicator implements HealthIndicator {
+
+ private final TopicEndpoint topicEndpoint = TopicEndpointManager.getManager();
+
+ @Override
+ public Health getHealth(boolean includeDetails) {
+ return HealthIndicator.super.getHealth(includeDetails);
+ }
+
+ @Override
+ public Health health() {
+ var healthBuilder = new Health.Builder();
+ if (topicEndpoint.isAlive()) {
+ healthBuilder.withDetail("topicEndpoint", topicEndpoint);
+ healthBuilder.up();
+ } else {
+ healthBuilder.down();
+ }
+ return healthBuilder.build();
+ }
+}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2025 Nordix Foundation.
+ * Copyright (C) 2021-2025 OpenInfra Foundation Europe. 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.
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.onap.policy.common.message.bus.event.TopicEndpoint;
+import org.onap.policy.common.message.bus.event.TopicEndpointManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
@Test
void testGetHealth() {
webClient.get().uri("/health").accept(APPLICATION_JSON)
- .exchange().expectStatus().isOk();
+ .exchange().expectStatus().isOk()
+ .expectBody().jsonPath("$.status.code").isEqualTo("UP");
+
+ TopicEndpoint topicEndpoint = TopicEndpointManager.getManager();
+ topicEndpoint.stop();
+
+ webClient.get().uri("/health").accept(APPLICATION_JSON)
+ .exchange().expectStatus().is5xxServerError()
+ .expectBody().jsonPath("$.status.code").isEqualTo("DOWN");
+
+ topicEndpoint.start();
}
@Test