- 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>
<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>
--- /dev/null
+/**
+ * ============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);
+ }
+
+}
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
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;
@Lazy
@Bean
+ @Primary
WebTestClient webTestClient(@LocalServerPort int port) {
return WebTestClient.bindToServer()
.baseUrl("http://localhost:" + port + "/aai/" + schemaVersions.getDefaultVersion())
})
.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();
+ }
}
--- /dev/null
+/**
+ * ============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();
+ }
+}
</parent>
<groupId>org.onap.aai.resources</groupId>
<artifactId>resources</artifactId>
- <version>1.14.5-SNAPSHOT</version>
+ <version>1.14.6-SNAPSHOT</version>
<name>aai-resources</name>
<packaging>pom</packaging>
<modules>
major_version=1
minor_version=14
-patch_version=4
+patch_version=6
base_version=${major_version}.${minor_version}.${patch_version}