Copyright (C) 2018 Ericsson. All rights reserved.
Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
Copyright (C) 2019,2021 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2020-2022 Bell Canada.
+ Modifications Copyright (C) 2020-2023 Bell Canada.
Modifications Copyright (C) 2022-2023 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
ToscaServiceTemplate=org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate,
ToscaNodeTemplateArray=java.util.List,
HealthCheckReport=org.onap.policy.common.endpoints.report.HealthCheckReport,
- StatisticsReport=org.onap.policy.api.main.rest.provider.statistics.StatisticsReport,
PolicyFetchMode=org.onap.policy.api.main.rest.PolicyFetchMode
</importMappings>
<configOptions>
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2022 Nordix Foundation.
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.api.main.config;
-
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-public class PolicyApiConfig {
-
- /**
- * Initialize the statistics report bean.
- *
- * @return a new instance of StatisticsReport
- */
- @Bean
- public StatisticsReport createStatisticsReport() {
- return new StatisticsReport();
- }
-}
\ No newline at end of file
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2022-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.
* @param joinPoint the point of execution
* @param exception the exception
*/
- @AfterThrowing(pointcut = "execution(* org.onap.policy.api.main..*.*(..))"
- + " && !execution(* org.onap.policy.api.main.rest.provider.statistics.*.*(..))", throwing = "exception")
+ @AfterThrowing(pointcut = "execution(* org.onap.policy.api.main..*.*(..))", throwing = "exception")
public void handleTransactionException(JoinPoint joinPoint, TransactionException exception) {
final var errorResponse = new ErrorResponse();
errorResponse.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR);
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.\r
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.\r
* Modifications Copyright (C) 2020-2022 Nordix Foundation.\r
- * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.\r
+ * Modifications Copyright (C) 2020-2023 Bell Canada. All rights reserved.\r
* ================================================================================\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
import org.onap.policy.api.main.exception.PolicyApiRuntimeException;\r
import org.onap.policy.api.main.rest.genapi.PolicyDesignApi;\r
import org.onap.policy.api.main.rest.provider.healthcheck.HealthCheckProvider;\r
-import org.onap.policy.api.main.rest.provider.statistics.ApiStatisticsManager;\r
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsProvider;\r
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;\r
import org.onap.policy.api.main.service.ToscaServiceTemplateService;\r
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;\r
import org.onap.policy.common.endpoints.report.HealthCheckReport;\r
\r
private final ToscaServiceTemplateService toscaServiceTemplateService;\r
private final HealthCheckProvider healthCheckProvider;\r
- private final ApiStatisticsManager mgr;\r
- private final StatisticsProvider statisticsProvider;\r
\r
/**\r
* Retrieves the healthcheck status of the API component.\r
@Override\r
public ResponseEntity<HealthCheckReport> getHealthCheck(UUID requestId) {\r
final var report = healthCheckProvider.performHealthCheck();\r
- updateApiStatisticsCounter(Target.OTHER, HttpStatus.resolve(report.getCode()), HttpMethod.GET);\r
return makeResponse(requestId, report, report.getCode());\r
}\r
\r
- /**\r
- * Retrieves the statistics report of the API component.\r
- *\r
- * @return the Response object containing the results of the API operation\r
- */\r
- @Override\r
- public ResponseEntity<StatisticsReport> getStatistics(UUID requestId) {\r
- updateApiStatisticsCounter(Target.OTHER, HttpStatus.OK, HttpMethod.GET);\r
- return makeOkResponse(requestId, statisticsProvider.fetchCurrentStatistics());\r
- }\r
-\r
/**\r
* Retrieves all available policy types.\r
*\r
public ResponseEntity<ToscaServiceTemplate> getAllPolicyTypes(UUID requestId) {\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(null, null);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
final var msg = "GET /policytypes";\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
UUID requestId) {\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("GET /policytypes/%s", policyTypeId);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("GET /policytypes/%s/versions/%s", policyTypeId, versionId);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
UUID requestId) {\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("GET /policytypes/%s/versions/latest", policyTypeId);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicyType(body);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.POST);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
final var msg = "POST /policytypes";\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.POST);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.OK, HttpMethod.DELETE);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("DELETE /policytypes/%s/versions/%s", policyTypeId, versionId);\r
- updateApiStatisticsCounter(Target.POLICY_TYPE, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.DELETE);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("GET /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("/policytypes/%s/versions/%s/policies/%s",\r
policyTypeId, policyTypeVersion, policyId);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService\r
.fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/%s",\r
policyTypeId, policyTypeVersion, policyId, policyVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("GET /policytypes/%s/versions/%s/policies/%s/versions/latest",\r
policyTypeId, policyTypeVersion, policyId);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.createPolicy(policyTypeId, policyTypeVersion, body);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("POST /policytypes/%s/versions/%s/policies", policyTypeId, policyTypeVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.POST);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicy(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("DELETE /policytypes/%s/versions/%s/policies/%s/versions/%s",\r
policyTypeId, policyTypeVersion, policyId, policyVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.DELETE);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
final var msg = "GET /policies/ --";\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
if (pfme.getErrorResponse().getResponseCode().equals(Status.NOT_FOUND)) {\r
pfme.getErrorResponse().setErrorMessage(ERROR_MESSAGE_NO_POLICIES_FOUND);\r
pfme.getErrorResponse().setErrorDetails(List.of(ERROR_MESSAGE_NO_POLICIES_FOUND));\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.GET);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelException | PfModelRuntimeException pfme) {\r
var msg = String.format("GET /policies/%s/versions/%s", policyId, policyVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.GET);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.createPolicies(body);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.POST);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
final var msg = "POST /policies";\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.POST);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
try {\r
ToscaServiceTemplate serviceTemplate =\r
toscaServiceTemplateService.deletePolicy(null, null, policyId, policyVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.OK, HttpMethod.DELETE);\r
return makeOkResponse(requestId, serviceTemplate);\r
} catch (PfModelRuntimeException pfme) {\r
var msg = String.format("DELETE /policies/%s/versions/%s", policyId, policyVersion);\r
- updateApiStatisticsCounter(Target.POLICY, HttpStatus.resolve(pfme.getErrorResponse().getResponseCode()\r
- .getStatusCode()), HttpMethod.DELETE);\r
throw new PolicyApiRuntimeException(msg, pfme.getCause(), pfme.getErrorResponse(), requestId);\r
}\r
}\r
-\r
- private void updateApiStatisticsCounter(Target target, HttpStatus result, HttpMethod http) {\r
- mgr.updateTotalApiCallCount();\r
- switch (target) {\r
- case POLICY:\r
- updatePolicyStats(result, http);\r
- break;\r
- case POLICY_TYPE:\r
- updatePolicyTypeStats(result, http);\r
- break;\r
- default:\r
- mgr.updateApiCallSuccessCount();\r
- break;\r
- }\r
- }\r
-\r
- private void updatePolicyStats(HttpStatus result, HttpMethod http) {\r
- if (result.equals(HttpStatus.OK)) {\r
- switch (http) {\r
- case GET:\r
- mgr.updateApiCallSuccessCount();\r
- mgr.updateTotalPolicyGetCount();\r
- mgr.updatePolicyGetSuccessCount();\r
- break;\r
- case POST:\r
- mgr.updateApiCallSuccessCount();\r
- mgr.updateTotalPolicyPostCount();\r
- mgr.updatePolicyPostSuccessCount();\r
- break;\r
- case DELETE:\r
- mgr.updateApiCallSuccessCount();\r
- mgr.updateTotalPolicyDeleteCount();\r
- mgr.updatePolicyDeleteSuccessCount();\r
- break;\r
- default:\r
- mgr.updateApiCallSuccessCount();\r
- break;\r
- }\r
- } else {\r
- switch (http) {\r
- case GET:\r
- mgr.updateApiCallFailureCount();\r
- mgr.updateTotalPolicyGetCount();\r
- mgr.updatePolicyGetFailureCount();\r
- break;\r
- case POST:\r
- mgr.updateApiCallFailureCount();\r
- mgr.updateTotalPolicyPostCount();\r
- mgr.updatePolicyPostFailureCount();\r
- break;\r
- case DELETE:\r
- mgr.updateApiCallFailureCount();\r
- mgr.updateTotalPolicyDeleteCount();\r
- mgr.updatePolicyDeleteFailureCount();\r
- break;\r
- default:\r
- mgr.updateApiCallFailureCount();\r
- break;\r
- }\r
- }\r
- }\r
-\r
- private void updatePolicyTypeStats(HttpStatus result, HttpMethod http) {\r
- if (result.equals(HttpStatus.OK)) {\r
- switch (http) {\r
- case GET:\r
- mgr.updateApiCallSuccessCount();\r
- mgr.updateTotalPolicyTypeGetCount();\r
- mgr.updatePolicyTypeGetSuccessCount();\r
- break;\r
- case POST:\r
- mgr.updateApiCallSuccessCount();\r
- mgr.updateTotalPolicyTypePostCount();\r
- mgr.updatePolicyTypePostSuccessCount();\r
- break;\r
- case DELETE:\r
- mgr.updateApiCallSuccessCount();\r
- mgr.updateTotalPolicyTypeDeleteCount();\r
- mgr.updatePolicyTypeDeleteSuccessCount();\r
- break;\r
- default:\r
- mgr.updateApiCallSuccessCount();\r
- break;\r
- }\r
- } else {\r
- switch (http) {\r
- case GET:\r
- mgr.updateApiCallFailureCount();\r
- mgr.updateTotalPolicyTypeGetCount();\r
- mgr.updatePolicyTypeGetFailureCount();\r
- break;\r
- case POST:\r
- mgr.updateApiCallFailureCount();\r
- mgr.updateTotalPolicyTypePostCount();\r
- mgr.updatePolicyTypePostFailureCount();\r
- break;\r
- case DELETE:\r
- mgr.updateApiCallFailureCount();\r
- mgr.updateTotalPolicyTypeDeleteCount();\r
- mgr.updatePolicyTypeDeleteFailureCount();\r
- break;\r
- default:\r
- mgr.updateApiCallFailureCount();\r
- break;\r
- }\r
- }\r
- }\r
}\r
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020-2022 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.
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.api.main.rest.provider.statistics;
-
-import lombok.RequiredArgsConstructor;
-import org.springframework.stereotype.Component;
-
-/**
- * Class to hold statistical data for API access.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-@Component
-@RequiredArgsConstructor
-public class ApiStatisticsManager {
-
- private final StatisticsReport report;
-
- private long totalPolicyDeleteCount;
- private long totalPolicyTypeDeleteCount;
- private long policyDeleteSuccessCount;
- private long policyDeleteFailureCount;
- private long policyTypeDeleteSuccessCount;
- private long policyTypeDeleteFailureCount;
-
- /**
- * Method to update the total api call count.
- *
- * @return the updated value of totalApiCallCount
- */
- public long updateTotalApiCallCount() {
- return ++report.totalApiCallCount;
- }
-
- /**
- * Method to update the successful api call count.
- *
- * @return the updated value of apiCallSuccessCount
- */
- public long updateApiCallSuccessCount() {
- return ++report.apiCallSuccessCount;
- }
-
- /**
- * Method to update the failed api call count.
- *
- * @return the updated value of apiCallFailureCount
- */
- public long updateApiCallFailureCount() {
- return ++report.apiCallFailureCount;
- }
-
- /**
- * Method to update the total policy GET count.
- *
- * @return the updated value of totalPolicyGetCount
- */
- public long updateTotalPolicyGetCount() {
- return ++report.totalPolicyGetCount;
- }
-
- /**
- * Method to update the total policy POST count.
- *
- * @return the updated value of totalPolicyPostCount
- */
- public long updateTotalPolicyPostCount() {
- return ++report.totalPolicyPostCount;
- }
-
- /**
- * Method to update the total policy DELETE count.
- *
- * @return the updated value of totalPolicyDeleteCount
- */
- public long updateTotalPolicyDeleteCount() {
- return ++totalPolicyDeleteCount;
- }
-
- /**
- * Method to update the total policyType GET count.
- *
- * @return the updated value of totalPolicyTypeGetCount
- */
- public long updateTotalPolicyTypeGetCount() {
- return ++report.totalPolicyTypeGetCount;
- }
-
- /**
- * Method to update the total policyType POST count.
- *
- * @return the updated value of totalPolicyTypePostCount
- */
- public long updateTotalPolicyTypePostCount() {
- return ++report.totalPolicyTypePostCount;
- }
-
- /**
- * Method to update the total policyType DELETE count.
- *
- * @return the updated value of totalPolicyTypeDeleteCount
- */
- public long updateTotalPolicyTypeDeleteCount() {
- return ++totalPolicyTypeDeleteCount;
- }
-
- /**
- * Method to update successful policy GET count.
- *
- * @return the updated value of policyGetSuccessCount
- */
- public long updatePolicyGetSuccessCount() {
- return ++report.policyGetSuccessCount;
- }
-
- /**
- * Method to update failed policy GET count.
- *
- * @return the updated value of policyGetFailureCount
- */
- public long updatePolicyGetFailureCount() {
- return ++report.policyGetFailureCount;
- }
-
- /**
- * Method to update successful policy POST count.
- *
- * @return the updated value of policyPostSuccessCount
- */
- public long updatePolicyPostSuccessCount() {
- return ++report.policyPostSuccessCount;
- }
-
- /**
- * Method to update failed policy POST count.
- *
- * @return the updated value of policyPostFailureCount
- */
- public long updatePolicyPostFailureCount() {
- return ++report.policyPostFailureCount;
- }
-
- /**
- * Method to update successful policy DELETE count.
- *
- * @return the updated value of policyDeleteSuccessCount
- */
- public long updatePolicyDeleteSuccessCount() {
- return ++policyDeleteSuccessCount;
- }
-
- /**
- * Method to update failed policy DELETE count.
- *
- * @return the updated value of policyDeleteFailureCount
- */
- public long updatePolicyDeleteFailureCount() {
- return ++policyDeleteFailureCount;
- }
-
- /**
- * Method to update successful policyType GET count.
- *
- * @return the updated value of policyTypeGetSuccessCount
- */
- public long updatePolicyTypeGetSuccessCount() {
- return ++report.policyTypeGetSuccessCount;
- }
-
- /**
- * Method to update failed policyType GET count.
- *
- * @return the updated value of policyTypeGetFailureCount
- */
- public long updatePolicyTypeGetFailureCount() {
- return ++report.policyTypeGetFailureCount;
- }
-
- /**
- * Method to update successful policyType POST count.
- *
- * @return the updated value of policyTypePostSuccessCount
- */
- public long updatePolicyTypePostSuccessCount() {
- return ++report.policyTypePostSuccessCount;
- }
-
- /**
- * Method to update failed policyType POST count.
- *
- * @return the updated value of policyTypePostFailureCount
- */
- public long updatePolicyTypePostFailureCount() {
- return ++report.policyTypePostFailureCount;
- }
-
- /**
- * Method to update successful policyType DELETE count.
- *
- * @return the updated value of policyTypeDeleteSuccessCount
- */
- public long updatePolicyTypeDeleteSuccessCount() {
- return ++policyTypeDeleteSuccessCount;
- }
-
- /**
- * Method to update failed policyType DELETE count.
- *
- * @return the updated value of policyTypePostFailureCount
- */
- public long updatePolicyTypeDeleteFailureCount() {
- return ++policyTypeDeleteFailureCount;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2022 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.
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.api.main.rest.provider.statistics;
-
-import lombok.RequiredArgsConstructor;
-import org.springframework.stereotype.Service;
-
-/**
- * Class to fetch API statistics.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-@Service
-@RequiredArgsConstructor
-public class StatisticsProvider {
-
- private final StatisticsReport report;
-
- /**
- * Return the current API statistics.
- *
- * @return Report containing API statistics
- */
- public StatisticsReport fetchCurrentStatistics() {
- report.setCode(200);
- return report;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 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.
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.api.main.rest.provider.statistics;
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * Class to represent API statistics report.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-@ToString
-@Getter
-@Setter
-public class StatisticsReport {
- private int code;
- protected long totalApiCallCount;
- protected long apiCallSuccessCount;
- protected long apiCallFailureCount;
- protected long totalPolicyGetCount;
- protected long totalPolicyPostCount;
- protected long totalPolicyTypeGetCount;
- protected long totalPolicyTypePostCount;
- protected long policyGetSuccessCount;
- protected long policyGetFailureCount;
- protected long policyPostSuccessCount;
- protected long policyPostFailureCount;
- protected long policyTypeGetSuccessCount;
- protected long policyTypeGetFailureCount;
- protected long policyTypePostSuccessCount;
- protected long policyTypePostFailureCount;
-}
\ No newline at end of file
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 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.
import org.onap.policy.api.main.rest.CommonRestController;
import org.onap.policy.api.main.rest.PolicyFetchMode;
import org.onap.policy.api.main.rest.genapi.PolicyDesignApi;
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.context.annotation.Profile;
return stubUtils.getStubbedResponse(ToscaServiceTemplate.class);
}
- @Override
- public ResponseEntity<StatisticsReport> getStatistics(
- UUID requestID) {
- return stubUtils.getStubbedResponse(StatisticsReport.class);
- }
-
}
Copyright (C) 2019-2020 Nordix Foundation.
Modifications Copyright (C) 2021 AT&T Intellectual Property.
Modification Copyright 2022 Nordix Foundation.
+ Modifications Copyright (C) 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.
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpPolicyStatus</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments</class>
independent component running rest service that takes all policy design API calls
from clients and then assign them to different API working functions. Besides
that, API is also exposed for clients to retrieve healthcheck status of this API
- rest service and the statistics report including the counters of API invocation.
+ rest service.
paths:
/healthcheck:
get:
x-interface info:
api-version: 1.0.0
last-mod-release: Dublin
- /statistics:
- get:
- tags:
- - "Policy Design"
- summary: Retrieve current statistics
- description: Returns current statistics including the counters of API invocation
- operationId: getStatistics
- parameters:
- - name: X-ONAP-RequestID
- in: header
- description: RequestID for http transaction
- schema:
- type: string
- format: uuid
- responses:
- 200:
- description: OK, the statistics report in an instance of
- [StatisticsReport](https://github.com/onap/policy-api/blob/master/main/src/main/java/org/onap/policy/api/main/rest/provider/statistics/StatisticsReport.java)
- headers:
- X-LatestVersion:
- schema:
- type: string
- X-PatchVersion:
- schema:
- type: string
- X-MinorVersion:
- schema:
- type: string
- X-onap-RequestId:
- schema:
- type: string
- format: uuid
- content:
- application/json:
- schema:
- $ref: '#/components/schemas/StatisticsReport'
- application/yaml:
- schema:
- $ref: '#/components/schemas/StatisticsReport'
- 401:
- description: Authentication Error
- headers:
- X-LatestVersion:
- schema:
- type: string
- X-PatchVersion:
- schema:
- type: string
- X-MinorVersion:
- schema:
- type: string
- X-ONAP-RequestID:
- schema:
- type: string
- format: uuid
- content: {}
- 403:
- description: Authorization Error
- headers:
- X-LatestVersion:
- schema:
- type: string
- X-PatchVersion:
- schema:
- type: string
- X-MinorVersion:
- schema:
- type: string
- X-ONAP-RequestID:
- schema:
- type: string
- format: uuid
- content: {}
- 404:
- description: Not Found
- headers:
- X-LatestVersion:
- schema:
- type: string
- X-PatchVersion:
- schema:
- type: string
- X-MinorVersion:
- schema:
- type: string
- X-onap-RequestId:
- schema:
- type: string
- format: uuid
- content: {}
- 500:
- description: Internal Server Error
- headers:
- X-LatestVersion:
- schema:
- type: string
- X-PatchVersion:
- schema:
- type: string
- X-MinorVersion:
- schema:
- type: string
- X-ONAP-RequestID:
- schema:
- type: string
- format: uuid
- content: {}
- security:
- - basicAuth: []
- x-interface info:
- api-version: 1.0.0
- last-mod-release: Dublin
components:
securitySchemes:
basicAuth:
HealthCheckReport:
title: HealthCheckReport
type: object
- StatisticsReport:
- title: StatisticsReport
- type: object
PolicyFetchMode:
title: PolicyFetchMode
- type: object
\ No newline at end of file
+ type: object
+
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 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.
+ "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/latest");
checkStubJsonGet("policytypes/380d5cb1-e43d-45b7-b10b-ebd15dfabd16/versions/1.0.0/policies/"
+ "9c65fa1f-2833-4076-a64d-5b62e35cd09b/versions/1.2.3");
- checkStubJsonGet("statistics");
checkStubJsonGet("healthcheck");
checkStubJsonPost("policies");
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020,2022-2023 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.
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.policy.api.main.PolicyApiApplication;
-import org.onap.policy.api.main.rest.provider.statistics.ApiStatisticsManager;
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;
import org.onap.policy.api.main.rest.utils.CommonTestRestController;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.security.SelfSignedKeyStore;
import org.onap.policy.models.errors.concepts.ErrorResponse;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.annotation.DirtiesContext;
private static final String APP_YAML = "application/yaml";
private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
- private static final String STATISTICS_ENDPOINT = "statistics";
private static final String OP_POLICY_NAME_VCPE = "operational.restart";
@LocalServerPort
private int apiPort;
- @Autowired
- private ApiStatisticsManager mgr;
-
/**
* Initializes parameters and set up test environment.
*
validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
}
- @Test
- public void testApiStatistics_200_Json() throws Exception {
- testApiStatistics_200(APP_JSON);
- }
-
- @Test
- public void testApiStatistics_200_Yaml() throws Exception {
- testApiStatistics_200(APP_YAML);
- }
-
- private void testApiStatistics_200(String mediaType) throws Exception {
- Invocation.Builder invocationBuilder = sendHttpsRequest(CONTEXT_PATH, STATISTICS_ENDPOINT, mediaType, apiPort);
- StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 200);
- updateApiStatistics();
- invocationBuilder = sendHttpsRequest(CONTEXT_PATH, STATISTICS_ENDPOINT, mediaType, apiPort);
- report = invocationBuilder.get(StatisticsReport.class);
- validateStatisticsReport(report, 200);
- // ApiStatisticsManager.resetAllStatistics();
- }
-
@Test
public void testReadPolicyTypesJson() throws Exception {
testReadPolicyTypes(APP_JSON);
}
- private void updateApiStatistics() {
- mgr.updateTotalApiCallCount();
- mgr.updateApiCallSuccessCount();
- mgr.updateApiCallFailureCount();
- mgr.updateTotalPolicyGetCount();
- mgr.updateTotalPolicyPostCount();
- mgr.updateTotalPolicyTypeGetCount();
- mgr.updateTotalPolicyTypePostCount();
- mgr.updatePolicyGetSuccessCount();
- mgr.updatePolicyGetFailureCount();
- mgr.updatePolicyPostSuccessCount();
- mgr.updatePolicyPostFailureCount();
- mgr.updatePolicyTypeGetSuccessCount();
- mgr.updatePolicyTypeGetFailureCount();
- mgr.updatePolicyTypePostSuccessCount();
- mgr.updatePolicyTypePostFailureCount();
- }
-
- private void validateStatisticsReport(final StatisticsReport report, final int code) {
-
- assertEquals(code, report.getCode());
- }
-
private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,
final String message, final HealthCheckReport report) {
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2019 IBM.
- * Modifications Copyright (C) 2020-2022 Bell Canada.
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.api.main.rest;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.onap.policy.api.main.PolicyApiApplication;
-import org.onap.policy.api.main.rest.provider.statistics.ApiStatisticsManager;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest(classes = PolicyApiApplication.class)
-@ActiveProfiles({ "test", "default" })
-public class TestApiStatisticsManager {
-
- @Autowired
- private ApiStatisticsManager mgr;
-
- @Test
- public void testUpdateMethods() {
- assertEquals(1, mgr.updateTotalApiCallCount());
- assertEquals(1, mgr.updateApiCallSuccessCount());
- assertEquals(1, mgr.updateApiCallFailureCount());
- assertEquals(1, mgr.updateTotalPolicyGetCount());
- assertEquals(1, mgr.updateTotalPolicyPostCount());
- assertEquals(1, mgr.updateTotalPolicyDeleteCount());
- assertEquals(1, mgr.updateTotalPolicyTypeGetCount());
- assertEquals(1, mgr.updateTotalPolicyTypePostCount());
- assertEquals(1, mgr.updateTotalPolicyTypeDeleteCount());
- assertEquals(1, mgr.updatePolicyGetSuccessCount());
- assertEquals(1, mgr.updatePolicyGetFailureCount());
- assertEquals(1, mgr.updatePolicyPostSuccessCount());
- assertEquals(1, mgr.updatePolicyPostFailureCount());
- assertEquals(1, mgr.updatePolicyDeleteSuccessCount());
- assertEquals(1, mgr.updatePolicyDeleteFailureCount());
- assertEquals(1, mgr.updatePolicyTypeGetSuccessCount());
- assertEquals(1, mgr.updatePolicyTypeGetFailureCount());
- assertEquals(1, mgr.updatePolicyTypePostSuccessCount());
- assertEquals(1, mgr.updatePolicyTypePostFailureCount());
- assertEquals(1, mgr.updatePolicyTypeDeleteSuccessCount());
- assertEquals(1, mgr.updatePolicyTypeDeleteFailureCount());
- }
-}
\ No newline at end of file
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy API
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.api.main.rest;
-
-import com.openpojo.reflection.filters.FilterClassName;
-import com.openpojo.validation.Validator;
-import com.openpojo.validation.ValidatorBuilder;
-import com.openpojo.validation.rule.impl.SetterMustExistRule;
-import com.openpojo.validation.test.impl.GetterTester;
-import com.openpojo.validation.test.impl.SetterTester;
-import org.junit.Test;
-import org.onap.policy.api.main.rest.provider.statistics.StatisticsReport;
-import org.onap.policy.common.utils.test.ToStringTester;
-
-/**
- * Class to perform unit testing of {@link StatisticsReport}.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- */
-public class TestStatisticsReport {
-
- @Test
- public void testStatisticsReport() {
- final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterMustExistRule())
- .with(new SetterTester()).with(new GetterTester()).build();
- validator.validate(StatisticsReport.class.getPackage().getName(),
- new FilterClassName(StatisticsReport.class.getName()));
- }
-}
\ No newline at end of file
============LICENSE_START=======================================================
Copyright (C) 2019-2020 Nordix Foundation.
Modifications Copyright (C) 2021 AT&T Intellectual Property.
+ Modifications Copyright (C) 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.
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpPolicyStatus</class>
- <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignment</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaCapabilityAssignments</class>
},
"response": []
},
- {
- "name": "API Statistics",
- "request": {
- "method": "GET",
- "header": [
- {
- "key": "Content-Type",
- "type": "text",
- "value": "application/json"
- },
- {
- "key": "Accept",
- "type": "text",
- "value": "application/json"
- }
- ],
- "url": {
- "raw": "{{POLICY-API-URL}}/policy/api/v1/statistics",
- "host": [
- "{{POLICY-API-URL}}"
- ],
- "path": [
- "policy",
- "api",
- "v1",
- "statistics"
- ]
- },
- "description": "This is an API to fetch current statistics information for the policy-api component."
- },
- "response": []
- },
{
"name": "Create Policy Type",
"request": {