diff options
18 files changed, 358 insertions, 1280 deletions
diff --git a/main/pom.xml b/main/pom.xml index 60a7b1ff..6d6407e0 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -176,6 +176,9 @@ PolicyAudit=org.onap.policy.models.pap.concepts.PolicyAudit, PolicyStatus=org.onap.policy.models.pap.concepts.PolicyStatus </importMappings> + <typeMappings> + PdpStatistics=org.onap.policy.models.pdp.concepts.PdpStatistics + </typeMappings> <configOptions> <sourceFolder>src/gen/java</sourceFolder> <dateLibrary>java11</dateLibrary> diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java index 2687a302..09aea852 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/HealthCheckRestControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019,2021 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,15 +22,9 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; import lombok.RequiredArgsConstructor; import org.onap.policy.common.endpoints.report.HealthCheckReport; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** @@ -39,19 +33,12 @@ import org.springframework.web.bind.annotation.RestController; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class HealthCheckRestControllerV1 extends PapRestControllerV1 { +public class HealthCheckRestControllerV1 extends PapRestControllerV1 implements HealthCheckRestControllerV1Api { private final HealthCheckProvider provider; - @GetMapping("healthcheck") - @ApiOperation(value = "Perform healthcheck", - notes = "Returns healthy status of the Policy Administration component", - response = HealthCheckReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE)) - @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)}) + @Override public ResponseEntity<HealthCheckReport> healthcheck() { var report = provider.performHealthCheck(true); return ResponseEntity.status(report.getCode()).body(report); diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java index 01b539e3..3dd9c360 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2022 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -22,40 +22,21 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.BasicAuthDefinition; -import io.swagger.annotations.Info; -import io.swagger.annotations.SecurityDefinition; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; import java.net.HttpURLConnection; import java.util.Objects; import java.util.UUID; -import javax.ws.rs.core.MediaType; import org.onap.policy.models.base.PfModelException; import org.springframework.http.ResponseEntity.BodyBuilder; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.RequestMapping; /** * Version v1 common superclass to provide REST endpoints for PAP component. * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -// @formatter:off -@SwaggerDefinition( - info = @Info(description = - "Policy Administration is responsible for the deployment life cycle of policies as well as " - + "interworking with the mechanisms required to orchestrate the nodes and containers on which " - + "policies run. It is also responsible for the administration of policies at run time;" - + " ensuring that policies are available to users, that policies are executing correctly," - + " and that the state and status of policies is monitored", version = "v1.0", - title = "Policy Administration"), - consumes = {MediaType.APPLICATION_JSON, PapRestControllerV1.APPLICATION_YAML}, - produces = {MediaType.APPLICATION_JSON, PapRestControllerV1.APPLICATION_YAML}, - schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS}, - tags = {@Tag(name = "policy-administration", description = "Policy Administration Service Operations")}, - securityDefinition = @SecurityDefinition(basicAuthDefinitions = {@BasicAuthDefinition(key = "basicAuth")})) -// @formatter:on +@RequestMapping public class PapRestControllerV1 { public static final String APPLICATION_YAML = "application/yaml"; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateControllerV1.java index b588d08a..8d8e35cc 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateControllerV1.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019,2021 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -22,14 +22,6 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.models.base.PfModelException; @@ -39,19 +31,16 @@ import org.onap.policy.models.pdp.concepts.PdpGroups; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Class to provide REST end points for PAP component to create or update PDP groups. */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PdpGroupCreateOrUpdateControllerV1 extends PapRestControllerV1 { +public class PdpGroupCreateOrUpdateControllerV1 extends PapRestControllerV1 + implements PdpGroupCreateOrUpdateControllerV1Api { + private static final Logger logger = LoggerFactory.getLogger(PdpGroupCreateOrUpdateControllerV1.class); private final PdpGroupCreateOrUpdateProvider provider; @@ -63,41 +52,8 @@ public class PdpGroupCreateOrUpdateControllerV1 extends PapRestControllerV1 { * @param groups PDP group configuration * @return a response */ - // @formatter:off - @PostMapping("pdps/groups/batch") - @ApiOperation(value = "Create or update PDP Groups", - notes = "Create or update one or more PDP Groups, returning optional error details", - response = PdpGroupUpdateResponse.class, - tags = {"PdpGroup Create/Update"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - - public ResponseEntity<PdpGroupUpdateResponse> createOrUpdateGroups( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "List of PDP Group Configuration", required = true) @RequestBody PdpGroups groups) { + @Override + public ResponseEntity<PdpGroupUpdateResponse> createOrUpdateGroups(UUID requestId, PdpGroups groups) { return doOperation(requestId, "create groups failed", () -> provider.createOrUpdateGroups(groups)); } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java index 10db1793..f6cec4ef 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021-2022 Nordix Foundation. + * Modifications Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,14 +24,6 @@ package org.onap.policy.pap.main.rest; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Timer; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.time.Duration; import java.time.Instant; import java.util.UUID; @@ -47,19 +39,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Class to provide REST end points for PAP component to delete a PDP group. */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 { +public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 + implements PdpGroupDeleteControllerV1Api { + private static final Logger logger = LoggerFactory.getLogger(PdpGroupDeleteControllerV1.class); private final PdpGroupDeleteProvider provider; @@ -98,40 +87,8 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 { * @param groupName name of the PDP group to be deleted * @return a response */ - // @formatter:off - @DeleteMapping("pdps/groups/{name}") - @ApiOperation(value = "Delete PDP Group", - notes = "Deletes a PDP Group, returning optional error details", - response = PdpGroupDeleteResponse.class, - tags = {"PdpGroup Delete"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<PdpGroupDeleteResponse> deleteGroup( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Group Name") @PathVariable("name") String groupName) { + @Override + public ResponseEntity<PdpGroupDeleteResponse> deleteGroup(String groupName, UUID requestId) { return doOperation(requestId, () -> provider.deleteGroup(groupName)); } @@ -142,41 +99,8 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 { * @param policyName name of the PDP Policy to be deleted * @return a response */ - // @formatter:off - @DeleteMapping("pdps/policies/{name}") - @ApiOperation(value = "Undeploy a PDP Policy from PDPs", - notes = "Undeploys the latest version of a policy from the PDPs, returning optional error details", - response = PdpGroupDeployResponse.class, - tags = {"PdpGroup Delete"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<PdpGroupDeployResponse> deletePolicy( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Policy Name") @PathVariable("name") String policyName) { - + @Override + public ResponseEntity<PdpGroupDeployResponse> deletePolicy(String policyName, UUID requestId) { return doUndeployOperation(requestId, () -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, null), getPrincipal())); } @@ -189,42 +113,11 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 { * @param version version to be deleted * @return a response */ - // @formatter:off - @DeleteMapping("pdps/policies/{name}/versions/{version}") - @ApiOperation(value = "Undeploy version of a PDP Policy from PDPs", - notes = "Undeploys a specific version of a policy from the PDPs, returning optional error details", - response = PdpGroupDeployResponse.class, - tags = {"PdpGroup Delete"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on + @Override public ResponseEntity<PdpGroupDeployResponse> deletePolicyVersion( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Policy Name") @PathVariable("name") String policyName, - @ApiParam(value = "PDP Policy Version") @PathVariable("version") String version) { - + String policyName, + String version, + UUID requestId) { return doUndeployOperation(requestId, () -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, version), getPrincipal())); } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java index 5917dafc..62d0f369 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,14 +24,6 @@ package org.onap.policy.pap.main.rest; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Timer; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.time.Duration; import java.time.Instant; import java.util.UUID; @@ -47,19 +39,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * Class to provide REST end points for PAP component to deploy a PDP group. */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PdpGroupDeployControllerV1 extends PapRestControllerV1 { +public class PdpGroupDeployControllerV1 extends PapRestControllerV1 implements PdpGroupDeployControllerV1Api { public static final String POLICY_STATUS_URI = "/policy/pap/v1/policies/status"; public static final String DEPLOYMENT_RESPONSE_MSG = "Use the policy status url to fetch the latest status. " @@ -104,40 +91,8 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 { * @param groups PDP group configuration * @return a response */ - // @formatter:off - @PostMapping("pdps/deployments/batch") - @ApiOperation(value = "Updates policy deployments within specific PDP groups", - notes = "Updates policy deployments within specific PDP groups, returning optional error details", - response = PdpGroupDeployResponse.class, - tags = {"Deployments Update"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<PdpGroupDeployResponse> updateGroupPolicies( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "List of PDP Group Deployments", required = true) @RequestBody DeploymentGroups groups) { + @Override + public ResponseEntity<PdpGroupDeployResponse> updateGroupPolicies(UUID requestId, DeploymentGroups groups) { return doOperation(requestId, "update policy deployments failed", () -> provider.updateGroupPolicies(groups, getPrincipal())); } @@ -149,40 +104,8 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 { * @param policies PDP policies * @return a response */ - // @formatter:off - @PostMapping("pdps/policies") - @ApiOperation(value = "Deploy or update PDP Policies", - notes = "Deploys or updates PDP Policies, returning optional error details", - response = PdpGroupDeployResponse.class, - tags = {"Deployments Update"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<PdpGroupDeployResponse> deployPolicies( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Policies; only the name is required") @RequestBody PdpDeployPolicies policies) { + @Override + public ResponseEntity<PdpGroupDeployResponse> deployPolicies(UUID requestId, PdpDeployPolicies policies) { return doOperation(requestId, "deploy policies failed", () -> provider.deployPolicies(policies, getPrincipal())); } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java index ccc2ba1f..0b08fa22 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupHealthCheckControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019,2021 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -22,24 +22,15 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pdp.concepts.Pdps; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** @@ -49,10 +40,11 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PdpGroupHealthCheckControllerV1 extends PapRestControllerV1 { +public class PdpGroupHealthCheckControllerV1 extends PapRestControllerV1 + implements PdpGroupHealthCheckControllerV1Api { + private static final Logger logger = LoggerFactory.getLogger(PdpGroupHealthCheckControllerV1.class); private final PdpGroupHealthCheckProvider provider; /** @@ -60,41 +52,18 @@ public class PdpGroupHealthCheckControllerV1 extends PapRestControllerV1 { * * @param requestId request ID used in ONAP logging * @return a response + * @throws PfModelException Exception thrown by fetchPdpGroupHealthStatus */ - // @formatter:off - @GetMapping("pdps/healthcheck") - @ApiOperation(value = "Returns health status of all PDPs registered with PAP", - notes = "Queries health status of all PDPs, returning all pdps health status", - response = Pdps.class, - tags = {"Policy Administration (PAP) API"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<Pdps> pdpGroupHealthCheck(@ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) throws PfModelException { - Pair<HttpStatus, Pdps> pair = provider.fetchPdpGroupHealthStatus(); - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId) - .body(pair.getRight()); + @Override + public ResponseEntity<Pdps> pdpGroupHealthCheck(UUID requestId) { + try { + Pair<HttpStatus, Pdps> pair = provider.fetchPdpGroupHealthStatus(); + return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId) + .body(pair.getRight()); + } catch (PfModelException e) { + logger.warn("fetch Pdp Group Health Status failed", e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + } } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java index 18a39333..dccd5fb2 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019,2021 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,14 +22,6 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.models.base.PfModelException; @@ -39,9 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** @@ -50,9 +39,8 @@ import org.springframework.web.bind.annotation.RestController; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PdpGroupQueryControllerV1 extends PapRestControllerV1 { +public class PdpGroupQueryControllerV1 extends PapRestControllerV1 implements PdpGroupQueryControllerV1Api { private static final Logger LOGGER = LoggerFactory.getLogger(PdpGroupQueryControllerV1.class); @@ -65,43 +53,11 @@ public class PdpGroupQueryControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("pdps") - @ApiOperation(value = "Query details of all PDP groups", - notes = "Queries details of all PDP groups, returning all group details", - response = PdpGroups.class, - tags = {"PdpGroup Query"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<PdpGroups> queryGroupDetails(@ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) throws PfModelException { - + @Override + public ResponseEntity<PdpGroups> queryGroupDetails(UUID requestId) { final var pdpGroups = new PdpGroups(); pdpGroups.setGroups(pdpGroupService.getPdpGroups()); LOGGER.debug("PdpGroup Query Response - {}", pdpGroups); - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(HttpStatus.OK)), requestId) .body(pdpGroups); } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java index 38df5a5d..c67807cc 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -22,27 +22,16 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse; import org.onap.policy.models.pdp.enums.PdpState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -51,10 +40,10 @@ import org.springframework.web.bind.annotation.RestController; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 { +public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 implements PdpGroupStateChangeControllerV1Api { + private static final Logger logger = LoggerFactory.getLogger(PdpGroupHealthCheckControllerV1.class); private final PdpGroupStateChangeProvider provider; /** @@ -64,45 +53,18 @@ public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 { * @param groupName name of the PDP group to be deleted * @param state state of the PDP group * @return a response - * @throws PfModelException the exception + * @throws PfModelException Exception thrown by changeGroupState */ - // @formatter:off - @PutMapping("pdps/groups/{name}") - @ApiOperation(value = "Change state of a PDP Group", - notes = "Changes state of PDP Group, returning optional error details", - response = PdpGroupStateChangeResponse.class, - tags = {"PdpGroup State Change"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = {@Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on + @Override public ResponseEntity<PdpGroupStateChangeResponse> changeGroupState( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Group Name") @PathVariable("name") String groupName, - @ApiParam(value = "PDP Group State") @RequestParam("state") final PdpState state) throws PfModelException { - - final Pair<HttpStatus, PdpGroupStateChangeResponse> pair = provider.changeGroupState(groupName, state); - return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId) - .body(pair.getRight()); + String groupName, PdpState state, UUID requestId) { + try { + final Pair<HttpStatus, PdpGroupStateChangeResponse> pair = provider.changeGroupState(groupName, state); + return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId) + .body(pair.getRight()); + } catch (PfModelException e) { + logger.warn("changeGroupState failed", e); + } + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java index 9eeef2be..81681ff8 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyAuditControllerV1.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +19,9 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.time.Instant; import java.util.Collection; +import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.onap.policy.models.base.PfModelException; @@ -35,11 +29,6 @@ import org.onap.policy.models.pap.concepts.PolicyAudit; import org.onap.policy.pap.main.service.PolicyAuditService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -47,9 +36,8 @@ import org.springframework.web.bind.annotation.RestController; * various operations on policies. */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PolicyAuditControllerV1 extends PapRestControllerV1 { +public class PolicyAuditControllerV1 extends PapRestControllerV1 implements PolicyAuditControllerV1Api { public static final String NO_AUDIT_RECORD_FOUND = "No records found matching the input parameters"; @@ -65,51 +53,12 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit") - @ApiOperation(value = "Queries audit information for all the policies", - notes = "Queries audit information for all the policies, " - + "returning audit information for all the policies in the database", - responseContainer = "List", response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<Collection<PolicyAudit>> getAllAuditRecords( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100") @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime) - throws PfModelException { + @Override + public ResponseEntity<List<PolicyAudit>> getAllAuditRecords( + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(policyAuditService .getAuditRecords(recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); @@ -126,51 +75,13 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit/{pdpGroupName}") - @ApiOperation(value = "Queries audit information for all the policies in a PdpGroup", - notes = "Queries audit information for all the policies in a PdpGroup, " - + "returning audit information for all the policies belonging to the PdpGroup", - responseContainer = "List", response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on + @Override public ResponseEntity<Object> getAuditRecordsByGroup( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100") @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime, - @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName) throws PfModelException { + String pdpGroupName, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return makeOkOrNotFoundResponse(requestId, policyAuditService.getAuditRecords(pdpGroupName, recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); @@ -189,55 +100,15 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit/{pdpGroupName}/{policyName}/{policyVersion}") - @ApiOperation(value = "Queries audit information for a specific version of a policy in a PdpGroup", - notes = "Queries audit information for a specific version of a policy in a PdpGroup," - + " returning audit information for the policy belonging to the PdpGroup", - response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - - public ResponseEntity<Object> getAuditRecordsOfPolicy( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100", required = false) @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp", required = false) @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime, - @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName, - @ApiParam(value = "Policy Name") @PathVariable("policyName") String policyName, - @ApiParam(value = "Policy Version") @PathVariable(value = "policyVersion") String policyVersion) - throws PfModelException { + @Override + public ResponseEntity<Object> getAuditRecordsOfPolicyinPdpGroup( + String pdpGroupName, + String policyName, + String policyVersion, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return makeOkOrNotFoundResponse(requestId, policyAuditService.getAuditRecords(pdpGroupName, policyName, policyVersion, recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); @@ -255,55 +126,14 @@ public class PolicyAuditControllerV1 extends PapRestControllerV1 { * @return a response * @throws PfModelException the exception */ - // @formatter:off - @GetMapping("policies/audit/{policyName}/{policyVersion}") - @ApiOperation(value = "Queries audit information for a specific version of a policy", - notes = "Queries audit information for a specific version of a policy," - + " returning audit information for the policy", - response = PolicyAudit.class, - tags = {"Policy Audit"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - + @Override public ResponseEntity<Object> getAuditRecordsOfPolicy( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record count between 1-100") @RequestParam( - defaultValue = "10", - required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime, - @ApiParam(value = "Policy Name") @PathVariable(required = true, value = "policyName") String policyName, - @ApiParam( - value = "Policy Version") @PathVariable(required = true, value = "policyVersion") String policyVersion) - throws PfModelException { + String policyName, + String policyVersion, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return makeOkOrNotFoundResponse(requestId, policyAuditService.getAuditRecords(policyName, policyVersion, recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java index f7787fc7..2500c44f 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckControllerV1.java @@ -22,23 +22,12 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.util.Map; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** @@ -48,9 +37,9 @@ import org.springframework.web.bind.annotation.RestController; * @author Yehui Wang (yehui.wang@est.tech) */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PolicyComponentsHealthCheckControllerV1 extends PapRestControllerV1 { +public class PolicyComponentsHealthCheckControllerV1 extends PapRestControllerV1 + implements PolicyComponentsHealthCheckControllerV1Api { private final PolicyComponentsHealthCheckProvider provider; @@ -61,39 +50,8 @@ public class PolicyComponentsHealthCheckControllerV1 extends PapRestControllerV1 * @param requestId request ID used in ONAP logging * @return a response */ - // @formatter:off - @GetMapping("components/healthcheck") - @ApiOperation(value = "Returns health status of all policy components, including PAP, API, Distribution, and PDPs", - notes = "Queries health status of all policy components, returning all policy components health status", - response = Map.class, - tags = {"Consolidated Healthcheck"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - public ResponseEntity<Map<String, Object>> policyComponentsHealthCheck( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) { + @Override + public ResponseEntity<Map<String, Object>> policyComponentsHealthCheck(UUID requestId) { final Pair<HttpStatus, Map<String, Object>> pair = provider.fetchPolicyComponentsHealthStatus(); return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId) .body(pair.getRight()); diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java index b0de1e7c..e1772142 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,14 +23,6 @@ package org.onap.policy.pap.main.rest; import com.google.re2j.PatternSyntaxException; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.util.Collection; import java.util.UUID; import lombok.RequiredArgsConstructor; @@ -42,11 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -54,9 +41,8 @@ import org.springframework.web.bind.annotation.RestController; * policies. */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class PolicyStatusControllerV1 extends PapRestControllerV1 { +public class PolicyStatusControllerV1 extends PapRestControllerV1 implements PolicyStatusControllerV1Api { private static final String EMPTY_REGEX_ERROR_MESSAGE = "An empty string passed as a regex is not allowed"; private static final String EMPTY_REGEX_WARNING = ". Empty string passed as Regex."; private static final String GET_DEPLOYMENTS_FAILED = "get deployments failed"; @@ -73,41 +59,8 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { * @param regex regex for a policy name * @return a response */ - // @formatter:off - @GetMapping("policies/deployed") - @ApiOperation(value = "Queries status of all deployed policies", - notes = "Queries status of all deployed policies, returning success and failure counts of the PDPs", - responseContainer = "List", response = PolicyStatus.class, - tags = {"Policy Deployment Status"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - - public ResponseEntity<Object> queryAllDeployedPolicies( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Regex for a policy name") @RequestParam(required = false, value = "regex") String regex) { + @Override + public ResponseEntity<Object> queryAllDeployedPolicies(UUID requestId, String regex) { try { final Collection<PolicyStatus> result; if (regex == null) { @@ -137,41 +90,8 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { * @param requestId request ID used in ONAP logging * @return a response */ - // @formatter:off - @GetMapping("policies/deployed/{name}") - @ApiOperation(value = "Queries status of specific deployed policies", - notes = "Queries status of specific deployed policies, returning success and failure counts of the PDPs", - responseContainer = "List", response = PolicyStatus.class, - tags = {"Policy Deployment Status"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - - public ResponseEntity<Object> queryDeployedPolicies( - @ApiParam(value = "Policy Id") @PathVariable("name") String name, - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) { + @Override + public ResponseEntity<Object> queryDeployedPolicies(String name, UUID requestId) { try { Collection<PolicyStatus> result = provider.getStatus(new ToscaConceptIdentifierOptVersion(name, null)); @@ -197,41 +117,8 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { * @param requestId request ID used in ONAP logging * @return a response */ - // @formatter:off - @GetMapping("policies/deployed/{name}/{version}") - @ApiOperation(value = "Queries status of a specific deployed policy", - notes = "Queries status of a specific deployed policy, returning success and failure counts of the PDPs", - response = PolicyStatus.class, - tags = {"Policy Deployment Status"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - - public ResponseEntity<Object> queryDeployedPolicy(@ApiParam(value = "Policy Id") @PathVariable("name") String name, - @ApiParam(value = "Policy Version") @PathVariable("version") String version, - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) { + @Override + public ResponseEntity<Object> queryDeployedPolicy(String name, String version, UUID requestId) { try { Collection<PolicyStatus> result = provider.getStatus(new ToscaConceptIdentifierOptVersion(name, version)); @@ -258,41 +145,8 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { * @param requestId request ID used in ONAP logging * @return a response */ - // @formatter:off - @GetMapping("policies/status") - @ApiOperation(value = "Queries status of policies in all PdpGroups", - notes = "Queries status of policies in all PdpGroups, " - + "returning status of policies in all the PDPs belonging to all PdpGroups", - responseContainer = "List", response = PdpPolicyStatus.class, - tags = {"Policy Status"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - - public ResponseEntity<Object> getStatusOfAllPolicies( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) { + @Override + public ResponseEntity<Object> getStatusOfAllPolicies(UUID requestId) { try { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) @@ -315,43 +169,11 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { * @param regex regex for a policy name * @return a response */ - // @formatter:off - @GetMapping("policies/status/{pdpGroupName}") - @ApiOperation(value = "Queries status of policies in a specific PdpGroup", - notes = "Queries status of policies in a specific PdpGroup, " - + "returning status of policies in all the PDPs belonging to the PdpGroup", - responseContainer = "List", response = PdpPolicyStatus.class, - tags = {"Policy Status"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - + @Override public ResponseEntity<Object> getStatusOfPoliciesByGroup( - @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName, - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Regex for a policy name") @RequestParam(required = false, value = "regex") String regex) { + String pdpGroupName, + UUID requestId, + String regex) { try { final Collection<PdpPolicyStatus> result; @@ -384,43 +206,11 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { * @param requestId request ID used in ONAP logging * @return a response */ - // @formatter:off - @GetMapping("policies/status/{pdpGroupName}/{policyName}") - @ApiOperation(value = "Queries status of all versions of a specific policy in a specific PdpGroup", - notes = "Queries status of all versions of a specific policy in a specific PdpGroup," - + " returning status of all versions of the policy in the PDPs belonging to the PdpGroup", - responseContainer = "List", response = PdpPolicyStatus.class, - tags = {"Policy Administration (PAP) API"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on - + @Override public ResponseEntity<Object> getStatusOfPolicies( - @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName, - @ApiParam(value = "Policy Id") @PathVariable("policyName") String policyName, - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) { + String pdpGroupName, + String policyName, + UUID requestId) { try { Collection<PdpPolicyStatus> result = @@ -451,44 +241,13 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 { * @param requestId request ID used in ONAP logging * @return a response */ - // @formatter:off - @GetMapping("policies/status/{pdpGroupName}/{policyName}/{policyVersion}") - @ApiOperation(value = "Queries status of a specific version of a specific policy in a specific PdpGroup", - notes = "Queries status of a specific version of a specific policy in a specific PdpGroup," - + " returning status of the policy in the PDPs belonging to the PdpGroup", - response = PdpPolicyStatus.class, - tags = {"Policy Administration (PAP) API"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) - // @formatter:on + @Override public ResponseEntity<Object> getStatusOfPolicy( - @ApiParam(value = "PDP Group Name") @PathVariable("pdpGroupName") String pdpGroupName, - @ApiParam(value = "Policy Id") @PathVariable("policyName") String policyName, - @ApiParam(value = "Policy Version") @PathVariable("policyVersion") String policyVersion, - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) { + String pdpGroupName, + String policyName, + String policyVersion, + UUID requestId) { try { Collection<PdpPolicyStatus> result = provider.getPolicyStatus(pdpGroupName, diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java index f1251cbd..03ac3ba2 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/StatisticsRestControllerV1.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,14 +22,6 @@ package org.onap.policy.pap.main.rest; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.ResponseHeader; import java.time.Instant; import java.util.List; import java.util.Map; @@ -38,11 +30,6 @@ import lombok.RequiredArgsConstructor; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.pap.main.service.PdpStatisticsService; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestHeader; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -51,9 +38,9 @@ import org.springframework.web.bind.annotation.RestController; * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ @RestController -@RequestMapping(path = "/policy/pap/v1") @RequiredArgsConstructor -public class StatisticsRestControllerV1 extends PapRestControllerV1 { +public class StatisticsRestControllerV1 extends PapRestControllerV1 + implements StatisticsRestControllerV1Api { private final PdpStatisticsService pdpStatisticsService; @@ -63,18 +50,8 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { * * @return a response */ - @GetMapping("statistics") - @ApiOperation(value = "Fetch current statistics", - notes = "Returns current statistics of the Policy Administration component", - response = StatisticsReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE)) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)}) - public ResponseEntity<StatisticsReport> statistics( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId) { + @Override + public ResponseEntity<StatisticsReport> statistics(UUID requestId) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) .body(pdpStatisticsService.fetchCurrentStatistics()); } @@ -84,99 +61,34 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { * * @return a response */ - @GetMapping("pdps/statistics") - @ApiOperation(value = "Fetch statistics for all PDP Groups and subgroups in the system", - notes = "Returns for all PDP Groups and subgroups statistics of the Policy Administration component", - response = Map.class, tags = {"PDP Statistics"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) + @Override public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpStatistics( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "Record Count") @RequestParam( - defaultValue = "10", required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime) { + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId).body(pdpStatisticsService - .fetchDatabaseStatistics(recordCount, convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); + .fetchDatabaseStatistics(recordCount.intValue(), convertEpochtoInstant(startTime), + convertEpochtoInstant(endTime))); } + /** * get all statistics of a PDP group. * * @param groupName name of the PDP group * @return a response */ - @GetMapping("pdps/statistics/{group}") - @ApiOperation(value = "Fetch current statistics for given PDP Group", - notes = "Returns statistics for given PDP Group of the Policy Administration component", - response = Map.class, tags = {"PDP Statistics"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) + @Override public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpGroupStatistics( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Group Name") @PathVariable("group") final String groupName, - @ApiParam(value = "Record Count") @RequestParam( - defaultValue = "10", required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime) { + String groupName, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, recordCount, convertEpochtoInstant(startTime), - convertEpochtoInstant(endTime))); + .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, recordCount.intValue(), + convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); } /** @@ -186,49 +98,16 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { * @param subType type of the sub PDP group * @return a response */ - @GetMapping("pdps/statistics/{group}/{type}") - @ApiOperation(value = "Fetch statistics for the specified subgroup", - notes = "Returns statistics for the specified subgroup of the Policy Administration component", - response = Map.class, tags = {"PDP Statistics"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) + @Override public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpSubGroupStatistics( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Group Name") @PathVariable("group") final String groupName, - @ApiParam(value = "PDP SubGroup type") @PathVariable("type") final String subType, - @ApiParam(value = "Record Count") @RequestParam( - defaultValue = "10", required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime) { + String groupName, + String subType, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, recordCount, + .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, recordCount.intValue(), convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); } @@ -241,55 +120,22 @@ public class StatisticsRestControllerV1 extends PapRestControllerV1 { * @param recordCount the count of the query response, optional, default return all statistics stored * @return a response */ - @GetMapping("pdps/statistics/{group}/{type}/{pdp}") - @ApiOperation(value = "Fetch statistics for the specified pdp", - notes = "Returns statistics for the specified pdp of the Policy Administration component", - response = Map.class, - tags = {"PDP Statistics"}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension(name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - }) - }) - @ApiResponses(value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - }) + @Override public ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> pdpInstanceStatistics( - @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( - required = false, - value = REQUEST_ID_NAME) final UUID requestId, - @ApiParam(value = "PDP Group Name") @PathVariable("group") final String groupName, - @ApiParam(value = "PDP SubGroup type") @PathVariable("type") final String subType, - @ApiParam(value = "PDP Instance name") @PathVariable("pdp") final String pdpName, - @ApiParam(value = "Record Count") @RequestParam( - defaultValue = "10", required = false, - value = "recordCount") final int recordCount, - @ApiParam(value = "Start time in epoch timestamp") @RequestParam( - required = false, - value = "startTime") final Long startTime, - @ApiParam(value = "End time in epoch timestamp") @RequestParam( - required = false, - value = "endTime") final Long endTime) { + String groupName, + String subType, + String pdpName, + UUID requestId, + Integer recordCount, + Long startTime, + Long endTime) { return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.ok()), requestId) - .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, pdpName, recordCount, + .body(pdpStatisticsService.fetchDatabaseStatistics(groupName, subType, pdpName, recordCount.intValue(), convertEpochtoInstant(startTime), convertEpochtoInstant(endTime))); } private Instant convertEpochtoInstant(Long epochSecond) { return (epochSecond == null ? null : Instant.ofEpochSecond(epochSecond)); } + } diff --git a/main/src/main/resources/application.yaml b/main/src/main/resources/application.yaml index ee6383f5..9703715d 100644 --- a/main/src/main/resources/application.yaml +++ b/main/src/main/resources/application.yaml @@ -23,7 +23,8 @@ spring: server: port: 6969 - + servlet: + context-path: /policy/pap/v1 pap: name: PapGroup aaf: false diff --git a/main/src/main/resources/openapi/openapi.yaml b/main/src/main/resources/openapi/openapi.yaml index 22d85db4..281d2cc3 100644 --- a/main/src/main/resources/openapi/openapi.yaml +++ b/main/src/main/resources/openapi/openapi.yaml @@ -1,24 +1,63 @@ +# ============LICENSE_START======================================================= +# Copyright (C) 2022-2023 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========================================================= openapi: 3.0.3 info: - title: Api Documentation - description: Api Documentation + title: Policy Administration Documentation + description: Policy Administration is responsible for the deployment life cycle of policies as well as + interworking with the mechanisms required to orchestrate the nodes and containers on which + policies run. It is also responsible for the administration of policies at run time; + ensuring that policies are available to users, that policies are executing correctly, + and that the state and status of policies is monitored termsOfService: urn:tos - contact: {} + contact: + name: ONAP Support + url: https://lists.onap.org/g/onap-discuss + email: onap-discuss@lists.onap.org license: name: Apache 2.0 url: http://www.apache.org/licenses/LICENSE-2.0 version: '1.0' +externalDocs: + description: Policy Framework Documentation + url: https://docs.onap.org/projects/onap-policy-parent/en/latest servers: - - url: http://localhost:30442 - description: Inferred Url + - url: https://{server} + variables: + server: + default: policy/pap/v1 + description: This value is assigned by the service provider tags: - - name: pdp-group-controller - description: Pdp Group Controller + - name: HealthCheckRestControllerV1 + - name: PdpGroupCreateOrUpdateControllerV1 + - name: PdpGroupDeleteControllerV1 + - name: PdpGroupDeployControllerV1 + - name: PdpGroupHealthCheckControllerV1 + - name: PdpGroupQueryControllerV1 + - name: PdpGroupStateChangeControllerV1 + - name: PolicyAuditControllerV1 + - name: PolicyComponentsHealthCheckControllerV1 + - name: PolicyStatusControllerV1 + - name: StatisticsRestControllerV1 paths: - /policy/pap/v1/healthcheck: + /healthcheck: get: tags: - - pdp-group-controller + - HealthCheckRestControllerV1 summary: Perform healthcheck description: Returns healthy status of the Policy Administration component operationId: healthcheck @@ -57,10 +96,10 @@ paths: description: Internal Server Error security: - basicAuth: [] - /policy/pap/v1/pdps/healthcheck: + /pdps/healthcheck: get: tags: - - pdp-group-controller + - PdpGroupHealthCheckControllerV1 summary: Returns health status of all PDPs registered with PAP description: Queries health status of all PDPs, returning all pdps health status operationId: pdpGroupHealthCheck @@ -177,10 +216,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/groups/batch: + /pdps/groups/batch: post: tags: - - pdp-group-controller + - PdpGroupCreateOrUpdateControllerV1 summary: Create or update PDP Groups description: >- Create or update one or more PDP Groups, returning optional error @@ -319,10 +358,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/groups/{name}: + /pdps/groups/{name}: put: tags: - - pdp-group-controller + - PdpGroupStateChangeControllerV1 summary: Change state of a PDP Group description: Changes state of PDP Group, returning optional error details operationId: changeGroupState @@ -466,7 +505,7 @@ paths: last-mod-release: Dublin delete: tags: - - pdp-group-controller + - PdpGroupDeleteControllerV1 summary: Delete PDP Group description: Deletes a PDP Group, returning optional error details operationId: deleteGroup @@ -590,10 +629,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/policies/{name}: + /pdps/policies/{name}: delete: tags: - - pdp-group-controller + - PdpGroupDeleteControllerV1 summary: Undeploy a PDP Policy from PDPs description: >- Undeploys the latest version of a policy from the PDPs, returning @@ -719,10 +758,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/policies/{name}/versions/{version}: + /pdps/policies/{name}/versions/{version}: delete: tags: - - pdp-group-controller + - PdpGroupDeleteControllerV1 summary: Undeploy version of a PDP Policy from PDPs description: >- Undeploys a specific version of a policy from the PDPs, returning @@ -855,10 +894,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/deployments/batch: + /pdps/deployments/batch: post: tags: - - pdp-group-controller + - PdpGroupDeployControllerV1 summary: Updates policy deployments within specific PDP groups description: >- Updates policy deployments within specific PDP groups, returning @@ -989,10 +1028,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/policies: + /pdps/policies: post: tags: - - pdp-group-controller + - PdpGroupDeployControllerV1 summary: Deploy or update PDP Policies description: Deploys or updates PDP Policies, returning optional error details operationId: deployPolicies @@ -1121,10 +1160,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps: + /pdps: get: tags: - - pdp-group-controller + - PdpGroupQueryControllerV1 summary: Query details of all PDP groups description: Queries details of all PDP groups, returning all group details operationId: queryGroupDetails @@ -1241,10 +1280,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/audit: + /policies/audit: get: tags: - - pdp-group-controller + - PolicyAuditControllerV1 summary: Queries audit information for all the policies description: >- Queries audit information for all the policies, returning audit @@ -1265,7 +1304,10 @@ paths: style: form schema: type: integer + minimum: 1 + maximum: 100 format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -1391,10 +1433,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/audit/{pdpGroupName}: + /policies/audit/{pdpGroupName}: get: tags: - - pdp-group-controller + - PolicyAuditControllerV1 summary: Queries audit information for all the policies in a PdpGroup description: >- Queries audit information for all the policies in a PdpGroup, returning @@ -1415,7 +1457,10 @@ paths: style: form schema: type: integer + minimum: 1 + maximum: 100 format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -1446,14 +1491,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyAudit' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyAudit' + type: object 401: description: Authentication Error headers: @@ -1548,10 +1589,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/audit/{pdpGroupName}/{policyName}/{policyVersion}: + /policies/audit/{pdpGroupName}/{policyName}/{policyVersion}: get: tags: - - pdp-group-controller + - PolicyAuditControllerV1 summary: >- Queries audit information for a specific version of a policy in a PdpGroup @@ -1575,7 +1616,10 @@ paths: style: form schema: type: integer + minimum: 1 + maximum: 100 format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -1620,14 +1664,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyAudit' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyAudit' + type: object 401: description: Authentication Error headers: @@ -1722,10 +1762,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/audit/{policyName}/{policyVersion}: + /policies/audit/{policyName}/{policyVersion}: get: tags: - - pdp-group-controller + - PolicyAuditControllerV1 summary: Queries audit information for a specific version of a policy description: >- Queries audit information for a specific version of a policy, returning @@ -1746,7 +1786,10 @@ paths: style: form schema: type: integer + minimum: 1 + maximum: 100 format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -1784,14 +1827,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyAudit' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyAudit' + type: object 401: description: Authentication Error headers: @@ -1886,10 +1925,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/components/healthcheck: + /components/healthcheck: get: tags: - - pdp-group-controller + - PolicyComponentsHealthCheckControllerV1 summary: >- Returns health status of all policy components, including PAP, API, Distribution, and PDPs @@ -1915,12 +1954,12 @@ paths: schema: type: string additionalProperties: - $ref: '#/components/schemas/HealthCheckReport' + type: object application/yaml: schema: type: string additionalProperties: - $ref: '#/components/schemas/HealthCheckReport' + type: object 401: description: Authentication Error headers: @@ -2015,10 +2054,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/deployed: + /policies/deployed: get: tags: - - pdp-group-controller + - PolicyStatusControllerV1 summary: Queries status of all deployed policies description: >- Queries status of all deployed policies, returning success and failure @@ -2046,14 +2085,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object 401: description: Authentication Error headers: @@ -2148,10 +2183,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/deployed/{name}: + /policies/deployed/{name}: get: tags: - - pdp-group-controller + - PolicyStatusControllerV1 summary: Queries status of specific deployed policies description: >- Queries status of specific deployed policies, returning success and @@ -2179,14 +2214,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object 401: description: Authentication Error headers: @@ -2281,10 +2312,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/deployed/{name}/{version}: + /policies/deployed/{name}/{version}: get: tags: - - pdp-group-controller + - PolicyStatusControllerV1 summary: Queries status of a specific deployed policy description: >- Queries status of a specific deployed policy, returning success and @@ -2319,14 +2350,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object 401: description: Authentication Error headers: @@ -2421,10 +2448,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/status: + /policies/status: get: tags: - - pdp-group-controller + - PolicyStatusControllerV1 summary: Queries status of policies in all PdpGroups description: >- Queries status of policies in all PdpGroups, returning status of @@ -2445,14 +2472,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object 401: description: Authentication Error headers: @@ -2547,10 +2570,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/status/{pdpGroupName}: + /policies/status/{pdpGroupName}: get: tags: - - pdp-group-controller + - PolicyStatusControllerV1 summary: Queries status of policies in a specific PdpGroup description: >- Queries status of policies in a specific PdpGroup, returning status of @@ -2585,14 +2608,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object 401: description: Authentication Error headers: @@ -2687,10 +2706,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/status/{pdpGroupName}/{policyName}: + /policies/status/{pdpGroupName}/{policyName}: get: tags: - - pdp-group-controller + - PolicyStatusControllerV1 summary: >- Queries status of all versions of a specific policy in a specific PdpGroup @@ -2728,14 +2747,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object 401: description: Authentication Error headers: @@ -2830,10 +2845,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/policies/status/{pdpGroupName}/{policyName}/{policyVersion}: + /policies/status/{pdpGroupName}/{policyName}/{policyVersion}: get: tags: - - pdp-group-controller + - PolicyStatusControllerV1 summary: >- Queries status of a specific version of a specific policy in a specific PdpGroup @@ -2878,14 +2893,10 @@ paths: content: application/json: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object application/yaml: schema: - type: array - items: - $ref: '#/components/schemas/PolicyStatus' + type: object 401: description: Authentication Error headers: @@ -2979,11 +2990,11 @@ paths: - basicAuth: [] x-interface info: api-version: 1.0.0 - last-mod-release: Dublin - /policy/pap/v1/pdps/statistics: + last-mod-release: Dublin + /pdps/statistics: get: tags: - - pdp-group-controller + - StatisticsRestControllerV1 summary: Fetch statistics for all PDP Groups and subgroups in the system description: >- Returns for all PDP Groups and subgroups statistics of the Policy @@ -3005,6 +3016,7 @@ paths: schema: type: integer format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -3030,10 +3042,22 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/PdpStatistics' + type: string + additionalProperties: + type: string + additionalProperties: + type: array + items: + $ref: '#/components/schemas/PdpStatistics' application/yaml: schema: - $ref: '#/components/schemas/PdpStatistics' + type: string + additionalProperties: + type: string + additionalProperties: + type: array + items: + $ref: '#/components/schemas/PdpStatistics' 401: description: Authentication Error headers: @@ -3128,10 +3152,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/statistics/{group}: + /pdps/statistics/{group}: get: tags: - - pdp-group-controller + - StatisticsRestControllerV1 summary: Fetch current statistics for given PDP Group description: >- Returns statistics for given PDP Group of the Policy Administration @@ -3160,6 +3184,7 @@ paths: schema: type: integer format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -3295,10 +3320,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/statistics/{group}/{type}: + /pdps/statistics/{group}/{type}: get: tags: - - pdp-group-controller + - StatisticsRestControllerV1 summary: Fetch statistics for the specified subgroup description: >- Returns statistics for the specified subgroup of the Policy @@ -3334,6 +3359,7 @@ paths: schema: type: integer format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -3359,10 +3385,22 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/PdpStatistics' + type: string + additionalProperties: + type: string + additionalProperties: + type: array + items: + $ref: '#/components/schemas/PdpStatistics' application/yaml: schema: - $ref: '#/components/schemas/PdpStatistics' + type: string + additionalProperties: + type: string + additionalProperties: + type: array + items: + $ref: '#/components/schemas/PdpStatistics' 401: description: Authentication Error headers: @@ -3457,10 +3495,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/pdps/statistics/{group}/{type}/{pdp}: + /pdps/statistics/{group}/{type}/{pdp}: get: tags: - - pdp-group-controller + - StatisticsRestControllerV1 summary: Fetch statistics for the specified pdp description: >- Returns statistics for the specified pdp of the Policy Administration @@ -3503,6 +3541,7 @@ paths: schema: type: integer format: int32 + default: 10 - name: startTime in: query description: Start time in epoch timestamp @@ -3528,10 +3567,22 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/PdpStatistics' + type: string + additionalProperties: + type: string + additionalProperties: + type: array + items: + $ref: '#/components/schemas/PdpStatistics' application/yaml: schema: - $ref: '#/components/schemas/PdpStatistics' + type: string + additionalProperties: + type: string + additionalProperties: + type: array + items: + $ref: '#/components/schemas/PdpStatistics' 401: description: Authentication Error headers: @@ -3626,10 +3677,10 @@ paths: x-interface info: api-version: 1.0.0 last-mod-release: Dublin - /policy/pap/v1/statistics: + /statistics: get: tags: - - pdp-group-controller + - StatisticsRestControllerV1 summary: Fetch current statistics description: Returns current statistics of the Policy Administration component operationId: statistics @@ -3676,7 +3727,7 @@ components: type: object PdpState: title: PdpState - type: string + type: object PdpGroupUpdateResponse: title: PdpGroupUpdateResponse type: object diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java index 04971cce..96e36df1 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java @@ -144,10 +144,10 @@ public abstract class CommonPapRestServer { * @throws Exception if an error occurs */ protected void testSwagger(final String endpoint) throws Exception { - final Invocation.Builder invocationBuilder = - sendFqeRequest(httpsPrefix + "v3/api-docs", true, MediaType.APPLICATION_JSON); + final Invocation.Builder invocationBuilder = sendFqeRequest(httpsPrefix + + ENDPOINT_PREFIX + "v3/api-docs", true, MediaType.APPLICATION_JSON); final String resp = invocationBuilder.get(String.class); - assertTrue(resp.contains(ENDPOINT_PREFIX + endpoint)); + assertTrue(resp.contains(endpoint)); } /** diff --git a/main/src/test/resources/application-test-e2e.yaml b/main/src/test/resources/application-test-e2e.yaml index 2191a116..96ed124d 100644 --- a/main/src/test/resources/application-test-e2e.yaml +++ b/main/src/test/resources/application-test-e2e.yaml @@ -22,6 +22,8 @@ spring: implicit-strategy: org.onap.policy.common.spring.utils.CustomImplicitNamingStrategy server: port: 6969 + servlet: + context-path: /policy/pap/v1 pap: name: "PapGroupE2E" diff --git a/main/src/test/resources/application-test.yaml b/main/src/test/resources/application-test.yaml index 06d4c3ac..7a2e9fc9 100644 --- a/main/src/test/resources/application-test.yaml +++ b/main/src/test/resources/application-test.yaml @@ -23,7 +23,8 @@ spring: server: port: 6969 - + servlet: + context-path: /policy/pap/v1 pap: name: "PapGroup" aaf: false |