Removing deployed from policy/api 95/102895/2
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Tue, 3 Mar 2020 17:37:27 +0000 (12:37 -0500)
committerRam Krishna Verma <ram_krishna.verma@bell.ca>
Tue, 3 Mar 2020 21:43:00 +0000 (16:43 -0500)
The deployed API has already been created in PAP as part of Policy Update Notifications work.
Removing the corresponding one from policy/api to make sure that all run time administration
of PdpGroup and deployed policies are done only via PAP.

Leaving the deployed API's in legacy controller as they will be removed together.

Issue-ID: POLICY-1941
Change-Id: Ibe131f1aab3ec6a0eec05a2c91b5a140efc61b72
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java
main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java

index f9eff4c..60ccba0 100644 (file)
@@ -36,11 +36,7 @@ import io.swagger.annotations.Info;
 import io.swagger.annotations.ResponseHeader;\r
 import io.swagger.annotations.SecurityDefinition;\r
 import io.swagger.annotations.SwaggerDefinition;\r
-\r
-import java.util.List;\r
-import java.util.Map;\r
 import java.util.UUID;\r
-\r
 import javax.ws.rs.Consumes;\r
 import javax.ws.rs.DELETE;\r
 import javax.ws.rs.GET;\r
@@ -50,8 +46,6 @@ import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;\r
 import javax.ws.rs.Produces;\r
 import javax.ws.rs.core.Response;\r
-\r
-import org.apache.commons.lang3.tuple.Pair;\r
 import org.onap.policy.api.main.rest.provider.HealthCheckProvider;\r
 import org.onap.policy.api.main.rest.provider.PolicyProvider;\r
 import org.onap.policy.api.main.rest.provider.PolicyTypeProvider;\r
@@ -62,7 +56,6 @@ import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;\r
 import org.onap.policy.models.base.PfModelException;\r
 import org.onap.policy.models.base.PfModelRuntimeException;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
@@ -695,62 +688,6 @@ public class ApiRestController extends CommonRestController {
         }\r
     }\r
 \r
-    /**\r
-     * Retrieves deployed versions of a particular policy in PDP groups.\r
-     *\r
-     * @param policyTypeId the ID of specified policy type\r
-     * @param policyTypeVersion the version of specified policy type\r
-     * @param policyId the ID of specified policy\r
-     *\r
-     * @return the Response object containing the results of the API operation\r
-     */\r
-    @GET\r
-    @Path("/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies/{policyId}/versions/deployed")\r
-    @ApiOperation(value = "Retrieve deployed versions of a particular policy in pdp groups",\r
-            notes = "Returns deployed versions of specified policy in pdp groups", response = ToscaPolicy.class,\r
-            responseContainer = "List",\r
-            responseHeaders = {\r
-                @ResponseHeader(name = "X-MinorVersion",\r
-                        description = "Used to request or communicate a MINOR version back from the client"\r
-                                + " to the server, and from the server back to the client",\r
-                        response = String.class),\r
-                @ResponseHeader(name = "X-PatchVersion",\r
-                        description = "Used only to communicate a PATCH version in a response for"\r
-                                + " troubleshooting purposes only, and will not be provided by"\r
-                                + " the client on request",\r
-                        response = String.class),\r
-                @ResponseHeader(name = "X-LatestVersion",\r
-                        description = "Used only to communicate an API's latest version", response = String.class),\r
-                @ResponseHeader(name = "X-ONAP-RequestID",\r
-                        description = "Used to track REST transactions for logging purpose", response = UUID.class)},\r
-            authorizations = @Authorization(value = "basicAuth"), tags = {"Policy",},\r
-            extensions = {@Extension(name = "interface info",\r
-                    properties = {@ExtensionProperty(name = "api-version", value = "1.0.0"),\r
-                        @ExtensionProperty(name = "last-mod-release", value = "Dublin")})})\r
-    @ApiResponses(value = {@ApiResponse(code = 401, message = "Authentication Error"),\r
-        @ApiResponse(code = 403, message = "Authorization Error"),\r
-        @ApiResponse(code = 404, message = "Resource Not Found"),\r
-        @ApiResponse(code = 500, message = "Internal Server Error")})\r
-    public Response getDeployedVersionsOfPolicy(\r
-            @PathParam("policyTypeId") @ApiParam(value = "ID of policy type", required = true) String policyTypeId,\r
-            @PathParam("policyTypeVersion") @ApiParam(value = "Version of policy type",\r
-                    required = true) String policyTypeVersion,\r
-            @PathParam("policyId") @ApiParam(value = "ID of policy", required = true) String policyId,\r
-            @HeaderParam("X-ONAP-RequestID") @ApiParam("RequestID for http transaction") UUID requestId) {\r
-\r
-        try (PolicyProvider policyProvider = new PolicyProvider()) {\r
-            Map<Pair<String, String>, List<ToscaPolicy>> deployedPolicies =\r
-                    policyProvider.fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.SUCCESS, HttpMethod.GET);\r
-            return makeOkResponse(requestId, deployedPolicies);\r
-        } catch (PfModelException | PfModelRuntimeException pfme) {\r
-            LOGGER.debug("GET /policytypes/{}/versions/{}/policies/{}/versions/deployed", policyTypeId,\r
-                    policyTypeVersion, policyId, pfme);\r
-            updateApiStatisticsCounter(Target.POLICY, Result.FAILURE, HttpMethod.GET);\r
-            return makeErrorResponse(requestId, pfme);\r
-        }\r
-    }\r
-\r
     /**\r
      * Creates a new policy for a particular policy type and version.\r
      *\r
index afed316..35d0e80 100644 (file)
 \r
 package org.onap.policy.api.main.rest.provider;\r
 \r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import org.apache.commons.lang3.tuple.Pair;\r
-import org.onap.policy.models.base.PfConceptKey;\r
 import org.onap.policy.models.base.PfModelException;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
 \r
@@ -83,24 +76,6 @@ public class PolicyProvider extends CommonModelProvider {
         return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION);\r
     }\r
 \r
-    /**\r
-     * Retrieves a list of deployed policies in each pdp group.\r
-     *\r
-     * @param policyTypeId the ID of policy type\r
-     * @param policyTypeVersion the version of policy type\r
-     * @param policyId the ID of the policy\r
-     *\r
-     * @return a list of deployed policies in each pdp group\r
-     *\r
-     * @throws PfModelException the PfModel parsing exception\r
-     */\r
-    public Map<Pair<String, String>, List<ToscaPolicy>> fetchDeployedPolicies(String policyTypeId,\r
-            String policyTypeVersion, String policyId) throws PfModelException {\r
-\r
-        return collectDeployedPolicies(policyId, new PfConceptKey(policyTypeId, policyTypeVersion),\r
-                modelsProvider::getPolicyList, List::addAll, new ArrayList<>(5));\r
-    }\r
-\r
     /**\r
      * Creates one or more new policies for the same policy type ID and version.\r
      *\r
index 7780ea7..95a2069 100644 (file)
@@ -38,7 +38,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 import javax.ws.rs.client.Client;
@@ -47,7 +46,6 @@ import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.Response;
-
 import org.glassfish.jersey.client.ClientProperties;
 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
 import org.junit.AfterClass;
@@ -881,26 +879,6 @@ public class TestApiRestServer {
         assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
     }
 
-    @Test
-    public void testGetDeployedVersionsOfPolicyJson() throws Exception {
-        testGetDeployedVersionsOfPolicy(APP_JSON);
-    }
-
-    @Test
-    public void testGetDeployedVersionsOfPolicyYaml() throws Exception {
-        testGetDeployedVersionsOfPolicy(APP_YAML);
-    }
-
-    private void testGetDeployedVersionsOfPolicy(String mediaType) throws Exception {
-        Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_DEPLOYED, mediaType);
-        assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
-        ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
-        assertEquals(
-                "could not find policy with ID onap.restart.tca and type "
-                        + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 deployed in any pdp group",
-                errorResponse.getErrorMessage());
-    }
-
     @Test
     public void testGetLatestVersionOfOperationalPolicyJson() throws Exception {
         testGetLatestVersionOfOperationalPolicy(APP_JSON);
index be9b583..f458013 100644 (file)
@@ -34,7 +34,6 @@ import java.util.ArrayList;
 import java.util.Base64;
 import java.util.Collections;
 import java.util.List;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -158,11 +157,6 @@ public class TestPolicyProvider {
         String policyTypeVersion = "1.0.0";
         String policyTypeId = "onap.policies.monitoring.cdap.tca.hi.lo.app";
 
-        // Basic Exception Throw
-        assertThatThrownBy(() -> {
-            policyProvider.fetchDeployedPolicies("dummy", "1.0.0", "dummy");
-        }).hasMessage("could not find policy with ID dummy and type dummy:1.0.0 deployed in any pdp group");
-
         try (PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(providerParams)) {
             assertEquals(0, databaseProvider.getPdpGroups("name").size());
@@ -216,23 +210,12 @@ public class TestPolicyProvider {
                 assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
             }).doesNotThrowAnyException();
 
-            // Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
-            assertThatThrownBy(() -> {
-                policyProvider.fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
-            }).hasMessage("could not find policy with ID " + policyId + " and type " + policyTypeId + ":"
-                    + policyTypeVersion + " deployed in any pdp group");
-
             // Update pdpSubGroup
             pdpSubGroup.setPolicies(new ArrayList<>());
             pdpSubGroup.getPolicies().add(new ToscaPolicyIdentifier(policyId, policyVersion));
             assertEquals(1,
                     databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
 
-            // Test fetchDeployedPolicies
-            assertThatCode(() -> {
-                policyProvider.fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
-            }).doesNotThrowAnyException();
-
             // Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
             assertThatThrownBy(() -> {
                 policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",