aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java174
1 files changed, 1 insertions, 173 deletions
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 47d82927..a1e6db25 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
@@ -5,7 +5,7 @@
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020-2022 Nordix Foundation.
- * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-2023 Bell Canada. 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.
@@ -32,9 +32,6 @@ import lombok.RequiredArgsConstructor;
import org.onap.policy.api.main.exception.PolicyApiRuntimeException;
import org.onap.policy.api.main.rest.genapi.PolicyDesignApi;
import org.onap.policy.api.main.rest.provider.healthcheck.HealthCheckProvider;
-import org.onap.policy.api.main.rest.provider.statistics.ApiStatisticsManager;
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsProvider;
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;
import org.onap.policy.api.main.service.ToscaServiceTemplateService;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
@@ -67,8 +64,6 @@ public class ApiRestController extends CommonRestController implements PolicyDes
private final ToscaServiceTemplateService toscaServiceTemplateService;
private final HealthCheckProvider healthCheckProvider;
- private final ApiStatisticsManager mgr;
- private final StatisticsProvider statisticsProvider;
/**
* Retrieves the healthcheck status of the API component.
@@ -78,22 +73,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes
@Override
public ResponseEntity<HealthCheckReport> getHealthCheck(UUID requestId) {
final var report = healthCheckProvider.performHealthCheck();
- updateApiStatisticsCounter(Target.OTHER, HttpStatus.resolve(report.getCode()), HttpMethod.GET);
return makeResponse(requestId, report, report.getCode());
}
/**
- * Retrieves the statistics report of the API component.
- *
- * @return the Response object containing the results of the API operation
- */
- @Override
- public ResponseEntity<StatisticsReport> getStatistics(UUID requestId) {
- updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);
- return makeOkResponse(requestId, statisticsProvider.fetchCurrentStatistics());
- }
-
- /**
* Retrieves all available policy types.
*
* @return the Response object containing the results of the API operation
@@ -102,12 +85,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
public ResponseEntity<ToscaServiceTemplate> getAllPolicyTypes(UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
final var msg = "GET /policytypes";
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -125,12 +105,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("GET /policytypes/%s", policyTypeId);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -151,12 +128,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("GET /policytypes/%s/versions/%s", policyTypeId, versionId);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -174,12 +148,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
UUID requestId) {
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("GET /policytypes/%s/versions/latest", policyTypeId);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -200,12 +171,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
}
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelRuntimeException pfme) {
final var msg = "POST /policytypes";
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.POST);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -226,12 +194,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.DELETE);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelRuntimeException pfme) {
var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.DELETE);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -253,12 +218,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("GET /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -282,13 +244,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("/policytypes/%s/versions/%s/policies/%s",
policyTypeId, policyTypeVersion, policyId);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -314,13 +273,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService
.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/%s",
policyTypeId, policyTypeVersion, policyId, policyVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -344,13 +300,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/latest",
policyTypeId, policyTypeVersion, policyId);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -377,12 +330,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelRuntimeException pfme) {
var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.POST);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -407,13 +357,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelRuntimeException pfme) {
var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",
policyTypeId, policyTypeVersion, policyId, policyVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.DELETE);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -430,12 +377,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
final var msg = "GET /policies/ --";
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
if (pfme.getErrorResponse().getResponseCode().equals(Status.NOT_FOUND)) {
pfme.getErrorResponse().setErrorMessage(ERROR_MESSAGE_NO_POLICIES_FOUND);
pfme.getErrorResponse().setErrorDetails(List.of(ERROR_MESSAGE_NO_POLICIES_FOUND));
@@ -461,12 +405,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelException | PfModelRuntimeException pfme) {
var msg = String.format("GET /policies/%s/versions/%s", policyId, policyVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.GET);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -487,12 +428,9 @@ public class ApiRestController extends CommonRestController implements PolicyDes
}
try {
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelRuntimeException pfme) {
final var msg = "POST /policies";
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.POST);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
@@ -513,120 +451,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes
try {
ToscaServiceTemplate serviceTemplate =
toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);
return makeOkResponse(requestId, serviceTemplate);
} catch (PfModelRuntimeException pfme) {
var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()
- .getStatusCode()), HttpMethod.DELETE);
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);
}
}
-
- private void updateApiStatisticsCounter(Target target, HttpStatus result, HttpMethod http) {
- mgr.updateTotalApiCallCount();
- switch (target) {
- case POLICY:
- updatePolicyStats(result, http);
- break;
- case POLICY_TYPE:
- updatePolicyTypeStats(result, http);
- break;
- default:
- mgr.updateApiCallSuccessCount();
- break;
- }
- }
-
- private void updatePolicyStats(HttpStatus result, HttpMethod http) {
- if (result.equals(HttpStatus.OK)) {
- switch (http) {
- case GET:
- mgr.updateApiCallSuccessCount();
- mgr.updateTotalPolicyGetCount();
- mgr.updatePolicyGetSuccessCount();
- break;
- case POST:
- mgr.updateApiCallSuccessCount();
- mgr.updateTotalPolicyPostCount();
- mgr.updatePolicyPostSuccessCount();
- break;
- case DELETE:
- mgr.updateApiCallSuccessCount();
- mgr.updateTotalPolicyDeleteCount();
- mgr.updatePolicyDeleteSuccessCount();
- break;
- default:
- mgr.updateApiCallSuccessCount();
- break;
- }
- } else {
- switch (http) {
- case GET:
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyGetCount();
- mgr.updatePolicyGetFailureCount();
- break;
- case POST:
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyPostCount();
- mgr.updatePolicyPostFailureCount();
- break;
- case DELETE:
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyDeleteCount();
- mgr.updatePolicyDeleteFailureCount();
- break;
- default:
- mgr.updateApiCallFailureCount();
- break;
- }
- }
- }
-
- private void updatePolicyTypeStats(HttpStatus result, HttpMethod http) {
- if (result.equals(HttpStatus.OK)) {
- switch (http) {
- case GET:
- mgr.updateApiCallSuccessCount();
- mgr.updateTotalPolicyTypeGetCount();
- mgr.updatePolicyTypeGetSuccessCount();
- break;
- case POST:
- mgr.updateApiCallSuccessCount();
- mgr.updateTotalPolicyTypePostCount();
- mgr.updatePolicyTypePostSuccessCount();
- break;
- case DELETE:
- mgr.updateApiCallSuccessCount();
- mgr.updateTotalPolicyTypeDeleteCount();
- mgr.updatePolicyTypeDeleteSuccessCount();
- break;
- default:
- mgr.updateApiCallSuccessCount();
- break;
- }
- } else {
- switch (http) {
- case GET:
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyTypeGetCount();
- mgr.updatePolicyTypeGetFailureCount();
- break;
- case POST:
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyTypePostCount();
- mgr.updatePolicyTypePostFailureCount();
- break;
- case DELETE:
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyTypeDeleteCount();
- mgr.updatePolicyTypeDeleteFailureCount();
- break;
- default:
- mgr.updateApiCallFailureCount();
- break;
- }
- }
- }
}