summaryrefslogtreecommitdiffstats
path: root/aai-resources
diff options
context:
space:
mode:
Diffstat (limited to 'aai-resources')
-rw-r--r--aai-resources/pom.xml2
-rw-r--r--aai-resources/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java50
-rw-r--r--aai-resources/src/main/resources/application.properties6
-rw-r--r--aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java15
-rw-r--r--aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java70
5 files changed, 142 insertions, 1 deletions
diff --git a/aai-resources/pom.xml b/aai-resources/pom.xml
index 7334d9a..0c615b5 100644
--- a/aai-resources/pom.xml
+++ b/aai-resources/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.onap.aai.resources</groupId>
<artifactId>resources</artifactId>
- <version>1.14.5-SNAPSHOT</version>
+ <version>1.14.6-SNAPSHOT</version>
</parent>
<properties>
<java.version>1.8</java.version>
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 0000000..fd5dbcf
--- /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);
+ }
+
+}
diff --git a/aai-resources/src/main/resources/application.properties b/aai-resources/src/main/resources/application.properties
index 2f33d8a..6487dee 100644
--- a/aai-resources/src/main/resources/application.properties
+++ b/aai-resources/src/main/resources/application.properties
@@ -155,3 +155,9 @@ BOOTSTRAP_SERVERS=localhost:9092
JAAS_CONFIG=""
BUNDLECONFIG_DIR=src/main/resources/
AJSC_HOME=./
+
+# If true, the actuator health check will be overriden
+# to use the AaiGraphChecker check instead
+# this does the same as the /echo endpoint,
+# but doesn't show up in micrometer metrics
+aai.actuator.echo.enabled=false
diff --git a/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java b/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java
index cce0ae7..e412ded 100644
--- a/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java
+++ b/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java
@@ -5,10 +5,12 @@ import java.util.Collections;
import org.onap.aai.setup.SchemaVersions;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
+import org.springframework.context.annotation.Primary;
import org.springframework.http.MediaType;
import org.springframework.test.web.reactive.server.WebTestClient;
@@ -19,6 +21,7 @@ public class WebClientConfiguration {
@Lazy
@Bean
+ @Primary
WebTestClient webTestClient(@LocalServerPort int port) {
return WebTestClient.bindToServer()
.baseUrl("http://localhost:" + port + "/aai/" + schemaVersions.getDefaultVersion())
@@ -31,4 +34,16 @@ public class WebClientConfiguration {
})
.build();
}
+
+ @Lazy
+ @Bean
+ WebTestClient mgmtClient(@Value("${local.management.port}") int port) {
+ return WebTestClient.bindToServer()
+ .baseUrl("http://localhost:" + port)
+ .responseTimeout(Duration.ofSeconds(300))
+ .defaultHeaders(headers -> {
+ headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
+ })
+ .build();
+ }
}
diff --git a/aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java b/aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java
new file mode 100644
index 0000000..f6f7480
--- /dev/null
+++ b/aai-resources/src/test/java/org/onap/aai/rest/util/EchoHealthIndicatorTest.java
@@ -0,0 +1,70 @@
+/**
+ * ============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 static org.mockito.Mockito.when;
+
+import org.junit.jupiter.api.Test;
+import org.onap.aai.config.WebClientConfiguration;
+import org.onap.aai.tasks.AaiGraphChecker;
+import org.onap.aai.tasks.AaiGraphChecker.CheckerType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.context.annotation.Import;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.web.reactive.server.WebTestClient;
+
+@Import(WebClientConfiguration.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@TestPropertySource(properties = "aai.actuator.echo.enabled=true")
+public class EchoHealthIndicatorTest {
+
+ @Autowired
+ @Qualifier("mgmtClient")
+ WebTestClient webClient;
+
+ @MockBean private AaiGraphChecker aaiGraphChecker;
+
+ @Test
+ public void thatActuatorCheckIsHealthy() {
+ when(aaiGraphChecker.isAaiGraphDbAvailable(CheckerType.ACTUAL)).thenReturn(true);
+
+ webClient.get()
+ .uri("/actuator/health")
+ .exchange()
+ .expectStatus()
+ .isOk();
+ }
+
+ @Test
+ public void thatActuatorCheckIsUnhealthy() {
+ when(aaiGraphChecker.isAaiGraphDbAvailable(CheckerType.ACTUAL)).thenReturn(false);
+
+ webClient.get()
+ .uri("/actuator/health")
+ .exchange()
+ .expectStatus()
+ .is5xxServerError();
+ }
+}