Add get deployed endpoints for legacy policies
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / LegacyApiRestController.java
index 54155a6..89ca042 100644 (file)
@@ -31,6 +31,7 @@ import io.swagger.annotations.Authorization;
 import io.swagger.annotations.Extension;
 import io.swagger.annotations.ExtensionProperty;
 import io.swagger.annotations.ResponseHeader;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 import javax.ws.rs.Consumes;
@@ -42,6 +43,7 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.tuple.Pair;
 import org.onap.policy.api.main.rest.provider.LegacyGuardPolicyProvider;
 import org.onap.policy.api.main.rest.provider.LegacyOperationalPolicyProvider;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -185,6 +187,65 @@ public class LegacyApiRestController extends CommonRestController {
         }
     }
 
+    /**
+     * Retrieves deployed versions of a particular guard policy in PDP groups.
+     *
+     * @param policyId the ID of specified policy
+     *
+     * @return the Response object containing the results of the API operation
+     */
+    @GET
+    @Path("/policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
+         + "policies/{policyId}/versions/deployed")
+    @ApiOperation(value = "Retrieve deployed versions of a particular guard policy in pdp groups",
+            notes = "Returns deployed versions of a specified guard policy in pdp groups",
+            response = LegacyGuardPolicyOutput.class, responseContainer = "Map",
+            responseHeaders = {
+                    @ResponseHeader(name = "X-MinorVersion",
+                                    description = "Used to request or communicate a MINOR version back from the client"
+                                                + " to the server, and from the server back to the client",
+                                    response = String.class),
+                    @ResponseHeader(name = "X-PatchVersion",
+                                    description = "Used only to communicate a PATCH version in a response for"
+                                                + " troubleshooting purposes only, and will not be provided by"
+                                                + " the client on request",
+                                    response = String.class),
+                    @ResponseHeader(name = "X-LatestVersion",
+                                    description = "Used only to communicate an API's latest version",
+                                    response = String.class),
+                    @ResponseHeader(name = "X-ONAP-RequestID",
+                                    description = "Used to track REST transactions for logging purpose",
+                                    response = UUID.class)
+            },
+            authorizations = @Authorization(value = "basicAuth"),
+            tags = { "Legacy Guard Policy", },
+            extensions = {
+                    @Extension(name = "interface info", properties = {
+                            @ExtensionProperty(name = "api-version", value = "1.0.0"),
+                            @ExtensionProperty(name = "last-mod-release", value = "Dublin")
+                    })
+            })
+    @ApiResponses(value = {
+            @ApiResponse(code = 401, message = "Authentication Error"),
+            @ApiResponse(code = 403, message = "Authorization Error"),
+            @ApiResponse(code = 404, message = "Resource Not Found"),
+            @ApiResponse(code = 500, message = "Internal Server Error")
+        })
+    public Response getDeployedVersionsOfGuardPolicy(
+            @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+            @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+
+        try (LegacyGuardPolicyProvider guardPolicyProvider = new LegacyGuardPolicyProvider()) {
+            Map<Pair<String, String>, Map<String, LegacyGuardPolicyOutput>> deployedGuardPolicies =
+                    guardPolicyProvider.fetchDeployedGuardPolicies(policyId);
+            return makeOkResponse(requestId, deployedGuardPolicies);
+        } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("GET /policytypes/onap.policies.controlloop.Guard/versions/1.0.0/"
+                + "policies/{}/versions/deployed", policyId, pfme);
+            return makeErrorResponse(requestId, pfme);
+        }
+    }
+
     /**
      * Creates a new guard policy.
      *
@@ -424,6 +485,65 @@ public class LegacyApiRestController extends CommonRestController {
         }
     }
 
+    /**
+     * Retrieves deployed versions of a particular operational policy in PDP groups.
+     *
+     * @param policyId the ID of specified policy
+     *
+     * @return the Response object containing the results of the API operation
+     */
+    @GET
+    @Path("/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+         + "policies/{policyId}/versions/deployed")
+    @ApiOperation(value = "Retrieve deployed versions of a particular operational policy in pdp groups",
+            notes = "Returns deployed versions of a specified operational policy in pdp groups",
+            response = LegacyOperationalPolicy.class, responseContainer = "List",
+            responseHeaders = {
+                    @ResponseHeader(name = "X-MinorVersion",
+                                    description = "Used to request or communicate a MINOR version back from the client"
+                                                + " to the server, and from the server back to the client",
+                                    response = String.class),
+                    @ResponseHeader(name = "X-PatchVersion",
+                                    description = "Used only to communicate a PATCH version in a response for"
+                                                + " troubleshooting purposes only, and will not be provided by"
+                                                + " the client on request",
+                                    response = String.class),
+                    @ResponseHeader(name = "X-LatestVersion",
+                                    description = "Used only to communicate an API's latest version",
+                                    response = String.class),
+                    @ResponseHeader(name = "X-ONAP-RequestID",
+                                    description = "Used to track REST transactions for logging purpose",
+                                    response = UUID.class)
+            },
+            authorizations = @Authorization(value = "basicAuth"),
+            tags = { "Legacy Operational Policy", },
+            extensions = {
+                    @Extension(name = "interface info", properties = {
+                            @ExtensionProperty(name = "api-version", value = "1.0.0"),
+                            @ExtensionProperty(name = "last-mod-release", value = "Dublin")
+                    })
+            })
+    @ApiResponses(value = {
+            @ApiResponse(code = 401, message = "Authentication Error"),
+            @ApiResponse(code = 403, message = "Authorization Error"),
+            @ApiResponse(code = 404, message = "Resource Not Found"),
+            @ApiResponse(code = 500, message = "Internal Server Error")
+        })
+    public Response getDeployedVersionsOfOperationalPolicy(
+            @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,
+            @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {
+
+        try (LegacyOperationalPolicyProvider operationalPolicyProvider = new LegacyOperationalPolicyProvider()) {
+            Map<Pair<String, String>, List<LegacyOperationalPolicy>> deployedOperationalPolicies =
+                    operationalPolicyProvider.fetchDeployedOperationalPolicies(policyId);
+            return makeOkResponse(requestId, deployedOperationalPolicies);
+        } catch (PfModelException | PfModelRuntimeException pfme) {
+            LOGGER.error("GET /policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+                + "policies/{}/versions/deployed", policyId, pfme);
+            return makeErrorResponse(requestId, pfme);
+        }
+    }
+
     /**
      * Creates a new operational policy.
      *