diff options
author | Ajith Sreekumar <ajith.sreekumar@bell.ca> | 2022-03-22 16:40:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-03-22 16:40:27 +0000 |
commit | 88a8b0cfc60bf640015ab3339a065b6254be6ea9 (patch) | |
tree | 1b92522c724024234e61bbd5758d6ea02795c578 /main | |
parent | 2e15dfa79186f731920003abaaa208b4829fe606 (diff) | |
parent | 9902e51b342e0047b7057f25c31145ea86face6a (diff) |
Merge "API healthcheck must return healthcheck report object"
Diffstat (limited to 'main')
4 files changed, 18 insertions, 13 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java b/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java index f75013c9..1909e199 100644 --- a/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java +++ b/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java @@ -26,7 +26,6 @@ import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.errors.concepts.ErrorResponse; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.transaction.TransactionException; @@ -42,7 +41,7 @@ public class ServiceExceptionHandler { * @param exception the exception */ @AfterThrowing(pointcut = "execution(* org.onap.policy.api.main.service.*.*(..))", throwing = "exception") - public ResponseEntity<Object> handleServiceException(JoinPoint joinPoint, RuntimeException exception) { + public void handleServiceException(JoinPoint joinPoint, RuntimeException exception) { if (exception instanceof PolicyApiRuntimeException || exception instanceof PfModelRuntimeException) { throw exception; } else { @@ -64,10 +63,10 @@ public class ServiceExceptionHandler { */ @AfterThrowing(pointcut = "execution(* org.onap.policy.api.main..*.*(..))" + " && !execution(* org.onap.policy.api.main.rest.provider.statistics.*.*(..))", throwing = "exception") - public ResponseEntity<Object> handleTransactionException(JoinPoint joinPoint, TransactionException exception) { + public void handleTransactionException(JoinPoint joinPoint, TransactionException exception) { final var errorResponse = new ErrorResponse(); errorResponse.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR); errorResponse.setErrorMessage(exception.getMessage()); throw new PolicyApiRuntimeException(exception.getMessage(), exception.getCause(), errorResponse, null); } -}
\ No newline at end of file +} diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java index d6f6d6af..a734b2d6 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java @@ -136,8 +136,9 @@ public class ApiRestController extends CommonRestController { public ResponseEntity<HealthCheckReport> getHealthCheck(
@RequestHeader(name = REQUEST_ID_NAME, required = false)
@ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId) {
- updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);
- return makeOkResponse(requestId, healthCheckProvider.performHealthCheck());
+ final var report = healthCheckProvider.performHealthCheck();
+ updateApiStatisticsCounter(Target.OTHER, HttpStatus.resolve(report.getCode()), HttpMethod.GET);
+ return makeResponse(requestId, report, report.getCode());
}
/**
@@ -1151,4 +1152,4 @@ public class ApiRestController extends CommonRestController { }
}
}
-}
\ No newline at end of file +}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java index ce479bc0..ef288e47 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java @@ -31,6 +31,7 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
@@ -79,7 +80,12 @@ public class CommonRestController { protected final Coder coder = new StandardCoder();
protected <T> ResponseEntity<T> makeOkResponse(UUID requestId, T respEntity) {
- return CommonRestController.addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId)
+ return makeResponse(requestId, respEntity, HttpStatus.OK.value());
+ }
+
+ protected <T> ResponseEntity<T> makeResponse(UUID requestId, T respEntity, int status) {
+ return CommonRestController
+ .addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(status)), requestId)
.body(respEntity);
}
@@ -138,4 +144,4 @@ public class CommonRestController { CommonRestController.addVersionControlHeaders(ResponseEntity.status(status)),
requestId != null ? UUID.fromString(requestId) : ex.getRequestId()).body(ex.getErrorResponse());
}
-}
\ No newline at end of file +}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/healthcheck/HealthCheckProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/healthcheck/HealthCheckProvider.java index 88bb1c93..bbcfcd54 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/provider/healthcheck/HealthCheckProvider.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/healthcheck/HealthCheckProvider.java @@ -29,7 +29,6 @@ import lombok.RequiredArgsConstructor; import org.onap.policy.api.main.service.ToscaServiceTemplateService; import org.onap.policy.common.endpoints.report.HealthCheckReport; import org.onap.policy.common.utils.network.NetworkUtil; -import org.onap.policy.models.base.PfModelRuntimeException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -75,9 +74,9 @@ public class HealthCheckProvider { try { toscaServiceTemplateService.getDefaultJpaToscaServiceTemplate(); return true; - } catch (PfModelRuntimeException pfme) { - LOGGER.warn("Api to database connection check failed. Details - ", pfme); + } catch (Exception ex) { + LOGGER.warn("Api to database connection check failed. Details: ", ex); return false; } } -}
\ No newline at end of file +} |