aboutsummaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'aai-traversal/src/main')
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java49
-rw-r--r--aai-traversal/src/main/java/org/onap/aai/rest/util/EchoResponse.java39
-rw-r--r--aai-traversal/src/main/resources/application.properties7
3 files changed, 71 insertions, 24 deletions
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java b/aai-traversal/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java
new file mode 100644
index 0000000..d44b415
--- /dev/null
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/util/EchoHealthIndicator.java
@@ -0,0 +1,49 @@
+/**
+ * ============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.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();
+ }
+
+}
diff --git a/aai-traversal/src/main/java/org/onap/aai/rest/util/EchoResponse.java b/aai-traversal/src/main/java/org/onap/aai/rest/util/EchoResponse.java
index df677d5..028ebca 100644
--- a/aai-traversal/src/main/java/org/onap/aai/rest/util/EchoResponse.java
+++ b/aai-traversal/src/main/java/org/onap/aai/rest/util/EchoResponse.java
@@ -54,6 +54,8 @@ public class EchoResponse extends RESTAPI {
public EchoResponse(AaiGraphChecker aaiGraphChecker) {
this.aaiGraphChecker = aaiGraphChecker;
}
+
+ private static final String UP_RESPONSE="{\"status\":\"UP\",\"groups\":[\"liveness\",\"readiness\"]}";
/**
* Simple health-check API that echos back the X-FromAppId and X-TransactionId
@@ -92,7 +94,7 @@ public class EchoResponse extends RESTAPI {
if (!aaiGraphChecker.isAaiGraphDbAvailable()) {
throw new AAIException("AAI_5105", "Error establishing a database connection");
}
- return generateSuccessResponse(headers, templateVars);
+ return generateSuccessResponse();
} catch (AAIException aaiException) {
ErrorLogHelper.logException(aaiException);
return generateFailureResponse(headers, templateVars, aaiException);
@@ -102,30 +104,19 @@ public class EchoResponse extends RESTAPI {
return generateFailureResponse(headers, templateVars, aaiException);
}
}
- return generateSuccessResponse(headers, templateVars);
+ return generateSuccessResponse();
}
- private Response generateSuccessResponse(HttpHeaders headers, ArrayList<String> templateVariables) {
- HashMap<AAIException, ArrayList<String>> exceptionList = new HashMap<>();
- exceptionList.put(new AAIException("AAI_0002", "OK"), templateVariables);
- try {
- return Response.status(Status.OK)
- .entity(
- ErrorLogHelper.getRESTAPIInfoResponse(new ArrayList<>(headers.getAcceptableMediaTypes()), exceptionList))
- .build();
- } catch (Exception e) {
- AAIException aaiException = new AAIException("AAI_4000", e);
- ErrorLogHelper.logException(aaiException);
- return generateFailureResponse(headers, templateVariables, aaiException);
- }
- }
+ private Response generateSuccessResponse() {
+ return Response.status(Status.OK)
+ .entity(UP_RESPONSE)
+ .build();
+ }
- private Response generateFailureResponse(HttpHeaders headers, ArrayList<String> templateVariables,
- AAIException aaiException) {
- return Response.status(aaiException.getErrorObject().getHTTPResponseCode())
- .entity(
- ErrorLogHelper.getRESTAPIErrorResponseWithLogging(
- headers.getAcceptableMediaTypes(), aaiException, templateVariables))
- .build();
- }
+ private Response generateFailureResponse(HttpHeaders headers, ArrayList<String> templateVariables,
+ AAIException aaiException) {
+ return Response.status(aaiException.getErrorObject().getHTTPResponseCode()).entity(ErrorLogHelper
+ .getRESTAPIErrorResponseWithLogging(headers.getAcceptableMediaTypes(), aaiException, templateVariables))
+ .build();
+ }
}
diff --git a/aai-traversal/src/main/resources/application.properties b/aai-traversal/src/main/resources/application.properties
index 29243ae..de08b4e 100644
--- a/aai-traversal/src/main/resources/application.properties
+++ b/aai-traversal/src/main/resources/application.properties
@@ -140,3 +140,10 @@ management.metrics.tags.group_id=aai
# management.metrics.tags.app_id=${info.build.artifact}
#Enable this option only for debug purposes. For more information: https://github.com/micrometer-metrics/micrometer/issues/1584
scrape.uri.metrics=true
+
+
+# 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