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
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
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
}\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
\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
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
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;
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;
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);
import java.util.Base64;
import java.util.Collections;
import java.util.List;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
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());
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",