* ================================================================================\r
* 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 Nordix Foundation.\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
\r
package org.onap.policy.api.main.rest;\r
\r
+import jakarta.ws.rs.core.Response.Status;\r
import java.util.List;\r
import java.util.UUID;\r
-import javax.ws.rs.core.Response.Status;\r
import lombok.RequiredArgsConstructor;\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
import org.onap.policy.models.base.PfModelRuntimeException;\r
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
import org.springframework.context.annotation.Profile;\r
-import org.springframework.http.HttpMethod;\r
-import org.springframework.http.HttpStatus;\r
import org.springframework.http.ResponseEntity;\r
import org.springframework.web.bind.annotation.RestController;\r
\r
@Profile("default")\r
public class ApiRestController extends CommonRestController implements PolicyDesignApi {\r
\r
- private enum Target {\r
- POLICY,\r
- POLICY_TYPE,\r
- OTHER\r
- }\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
* Retrieves all versions of a particular policy type.\r
*\r
* @param policyTypeId the ID of specified policy type\r
- *\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicyType(\r
- String policyTypeId,\r
- UUID requestId) {\r
+ String policyTypeId,\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
* Retrieves specified version of a particular policy type.\r
*\r
* @param policyTypeId the ID of specified policy type\r
- * @param versionId the version of specified policy type\r
- *\r
+ * @param versionId the version of specified policy type\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicyType(\r
- String policyTypeId,\r
- String versionId,\r
- UUID requestId) {\r
+ String policyTypeId,\r
+ String versionId,\r
+ UUID requestId) {\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
* Retrieves latest version of a particular policy type.\r
*\r
* @param policyTypeId the ID of specified policy type\r
- *\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicyType(\r
- String policyTypeId,\r
- UUID requestId) {\r
+ String policyTypeId,\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
* Creates a new policy type.\r
*\r
* @param body the body of policy type following TOSCA definition\r
- *\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> createPolicyType(\r
- ToscaServiceTemplate body,\r
- UUID requestId) {\r
+ ToscaServiceTemplate body,\r
+ UUID requestId) {\r
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body));\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
* Deletes specified version of a particular policy type.\r
*\r
* @param policyTypeId the ID of specified policy type\r
- * @param versionId the version of specified policy type\r
- *\r
+ * @param versionId the version of specified policy type\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> deleteSpecificVersionOfPolicyType(\r
- String policyTypeId,\r
- String versionId,\r
- UUID requestId) {\r
+ String policyTypeId,\r
+ String versionId,\r
+ UUID requestId) {\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
/**\r
* Retrieves all versions of a particular policy.\r
*\r
- * @param policyTypeId the ID of specified policy type\r
+ * @param policyTypeId the ID of specified policy type\r
* @param policyTypeVersion the version of specified policy type\r
- *\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getAllPolicies(\r
- String policyTypeId,\r
- String policyTypeVersion,\r
- PolicyFetchMode mode,\r
- UUID requestId) {\r
+ String policyTypeId,\r
+ String policyTypeVersion,\r
+ PolicyFetchMode mode,\r
+ UUID requestId) {\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
/**\r
* Retrieves all versions of a particular policy.\r
*\r
- * @param policyTypeId the ID of specified policy type\r
+ * @param policyTypeId the ID of specified policy type\r
* @param policyTypeVersion the version of specified policy type\r
- * @param policyId the ID of specified policy\r
- *\r
+ * @param policyId the ID of specified policy\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getAllVersionsOfPolicy(\r
- String policyId,\r
- String policyTypeId,\r
- String policyTypeVersion,\r
- PolicyFetchMode mode,\r
- UUID requestId) {\r
+ String policyId,\r
+ String policyTypeId,\r
+ String policyTypeVersion,\r
+ PolicyFetchMode mode,\r
+ UUID requestId) {\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
/**\r
* Retrieves the specified version of a particular policy.\r
*\r
- * @param policyTypeId the ID of specified policy type\r
+ * @param policyTypeId the ID of specified policy type\r
* @param policyTypeVersion the version of specified policy type\r
- * @param policyId the ID of specified policy\r
- * @param policyVersion the version of specified policy\r
- *\r
+ * @param policyId the ID of specified policy\r
+ * @param policyVersion the version of specified policy\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getSpecificVersionOfPolicy(\r
- String policyId,\r
- String policyTypeId,\r
- String policyTypeVersion,\r
- String policyVersion,\r
- PolicyFetchMode mode,\r
- UUID requestId) {\r
+ String policyId,\r
+ String policyTypeId,\r
+ String policyTypeVersion,\r
+ String policyVersion,\r
+ PolicyFetchMode mode,\r
+ UUID requestId) {\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
/**\r
* Retrieves the latest version of a particular policy.\r
*\r
- * @param policyTypeId the ID of specified policy type\r
+ * @param policyTypeId the ID of specified policy type\r
* @param policyTypeVersion the version of specified policy type\r
- * @param policyId the ID of specified policy\r
- *\r
+ * @param policyId the ID of specified policy\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getLatestVersionOfPolicy(\r
- String policyId,\r
- String policyTypeId,\r
- String policyTypeVersion,\r
- PolicyFetchMode mode,\r
- UUID requestId) {\r
+ String policyId,\r
+ String policyTypeId,\r
+ String policyTypeVersion,\r
+ PolicyFetchMode mode,\r
+ UUID requestId) {\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
/**\r
* Creates a new policy for a particular policy type and version.\r
*\r
- * @param policyTypeId the ID of specified policy type\r
+ * @param policyTypeId the ID of specified policy type\r
* @param policyTypeVersion the version of specified policy type\r
- * @param body the body of policy following TOSCA definition\r
- *\r
+ * @param body the body of policy following TOSCA definition\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> createPolicy(\r
- String policyTypeId,\r
- String policyTypeVersion,\r
- ToscaServiceTemplate body,\r
- UUID requestId) {\r
+ String policyTypeId,\r
+ String policyTypeVersion,\r
+ ToscaServiceTemplate body,\r
+ UUID requestId) {\r
if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) {\r
NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST,\r
"/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body));\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
/**\r
* Deletes the specified version of a particular policy.\r
*\r
- * @param policyTypeId the ID of specified policy type\r
+ * @param policyTypeId the ID of specified policy type\r
* @param policyTypeVersion the version of specified policy type\r
- * @param policyId the ID of specified policy\r
- * @param policyVersion the version of specified policy\r
- *\r
+ * @param policyId the ID of specified policy\r
+ * @param policyVersion the version of specified policy\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\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
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getPolicies(\r
- PolicyFetchMode mode,\r
- UUID requestId) {\r
+ PolicyFetchMode mode,\r
+ UUID requestId) {\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
/**\r
* Retrieves the specified version of a particular policy.\r
*\r
- * @param policyId the Name of specified policy\r
+ * @param policyId the Name of specified policy\r
* @param policyVersion the version of specified policy\r
- *\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\r
public ResponseEntity<ToscaServiceTemplate> getSpecificPolicy(\r
- String policyId,\r
- String policyVersion,\r
- PolicyFetchMode mode,\r
- UUID requestId) {\r
+ String policyId,\r
+ String policyVersion,\r
+ PolicyFetchMode mode,\r
+ UUID requestId) {\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
* Creates one or more new policies in one call.\r
*\r
* @param body the body of policy following TOSCA definition\r
- *\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\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
/**\r
* Deletes the specified version of a particular policy.\r
*\r
- * @param policyId the ID of specified policy\r
+ * @param policyId the ID of specified policy\r
* @param policyVersion the version of specified policy\r
- *\r
* @return the Response object containing the results of the API operation\r
*/\r
@Override\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