aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2021-02-15 13:05:44 +0000
committera.sreekumar <ajith.sreekumar@bell.ca>2021-02-17 11:23:10 +0000
commitf7674432acc22a4c80967bd27d0c576cef6daa98 (patch)
treec5daf2112d4950ac632e08dbc0908be389844f3d
parentbcbdb26288e9bd6b1bd0cf8fb2d463d9f49f6333 (diff)
Updating PAP deployment API to reflect actual status
Change-Id: I5281937fe5a742916c0c86983f71e280bbe126b2 Issue-ID: POLICY-2526 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java35
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java14
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusControllerV1.java219
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusProvider.java44
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java26
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java149
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java20
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java15
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java91
9 files changed, 535 insertions, 78 deletions
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 658a13cc..0db12301 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
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +40,7 @@ import javax.ws.rs.core.Response.Status;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -101,7 +103,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
@Path("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 = PdpGroupDeleteResponse.class,
+ response = PdpGroupDeployResponse.class,
tags = {"Policy Administration (PAP) API"},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@@ -124,7 +126,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
public Response deletePolicy(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@ApiParam(value = "PDP Policy Name", required = true) @PathParam("name") String policyName) {
- return doOperation(requestId, "undeploy policy failed",
+ return doUndeployOperation(requestId, "undeploy policy failed",
() -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, null)));
}
@@ -141,7 +143,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
@Path("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 = PdpGroupDeleteResponse.class,
+ response = PdpGroupDeployResponse.class,
tags = {"Policy Administration (PAP) API"},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
responseHeaders = {
@@ -166,7 +168,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
@ApiParam(value = "PDP Policy Name", required = true) @PathParam("name") String policyName,
@ApiParam(value = "PDP Policy Version", required = true) @PathParam("version") String version) {
- return doOperation(requestId, "undeploy policy failed",
+ return doUndeployOperation(requestId, "undeploy policy failed",
() -> provider.undeploy(new ToscaConceptIdentifierOptVersion(policyName, version)));
}
@@ -192,4 +194,29 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
requestId).entity(resp).build();
}
}
+
+ /**
+ * Invokes the undeployment operation.
+ *
+ * @param requestId request ID
+ * @param errmsg error message to log if the operation throws an exception
+ * @param runnable operation to invoke
+ * @return a {@link PdpGroupDeployResponse} response entity
+ */
+ private Response doUndeployOperation(UUID requestId, String errmsg, RunnableWithPfEx runnable) {
+ try {
+ runnable.run();
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.ACCEPTED)), requestId)
+ .entity(new PdpGroupDeployResponse(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG,
+ PdpGroupDeployControllerV1.POLICY_STATUS_URI))
+ .build();
+
+ } catch (PfModelException | PfModelRuntimeException e) {
+ logger.warn(errmsg, e);
+ PdpGroupDeployResponse resp = new PdpGroupDeployResponse();
+ resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
+ requestId).entity(resp).build();
+ }
+ }
}
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 48dfd8bf..d8650f51 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
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,6 +47,12 @@ import org.slf4j.LoggerFactory;
* Class to provide REST end points for PAP component to deploy a PDP group.
*/
public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
+ 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. "
+ + "Kindly note that when a policy is successfully undeployed,"
+ + " it will no longer appear in policy status response.";
+
private static final Logger logger = LoggerFactory.getLogger(PdpGroupDeployControllerV1.class);
private final PdpGroupDeployProvider provider = new PdpGroupDeployProvider();
@@ -139,15 +146,16 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
private Response doOperation(UUID requestId, String errmsg, RunnableWithPfEx runnable) {
try {
runnable.run();
- return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.OK)), requestId)
- .entity(new PdpGroupDeployResponse()).build();
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Status.ACCEPTED)), requestId)
+ .entity(new PdpGroupDeployResponse(DEPLOYMENT_RESPONSE_MSG, POLICY_STATUS_URI))
+ .build();
} catch (PfModelException | PfModelRuntimeException e) {
logger.warn(errmsg, e);
PdpGroupDeployResponse resp = new PdpGroupDeployResponse();
resp.setErrorDetails(e.getErrorResponse().getErrorMessage());
return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
- requestId).entity(resp).build();
+ requestId).entity(resp).build();
}
}
}
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 ec7c00a9..055e129e 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
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +40,7 @@ import javax.ws.rs.core.Response;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.pap.concepts.PolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -207,6 +209,223 @@ public class PolicyStatusControllerV1 extends PapRestControllerV1 {
/**
+ * Queries status of all policies.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @return a response
+ */
+ // @formatter:off
+ @GET
+ @Path("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 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 Response getStatusOfAllPolicies(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+
+ try {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(provider.getPolicyStatus()).build();
+
+ } catch (PfModelException | PfModelRuntimeException e) {
+ logger.warn(GET_DEPLOYMENTS_FAILED, e);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
+ requestId).entity(e.getErrorResponse().getErrorMessage()).build();
+ }
+ }
+
+ /**
+ * Queries status of policies in a specific PdpGroup.
+ *
+ * @param pdpGroupName name of the PdpGroup
+ * @param requestId request ID used in ONAP logging
+ * @return a response
+ */
+ // @formatter:off
+ @GET
+ @Path("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 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 Response getStatusOfPoliciesByGroup(
+ @ApiParam(value = "PDP Group Name", required = true) @PathParam("pdpGroupName") String pdpGroupName,
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+
+ try {
+ Collection<PdpPolicyStatus> result = provider.getPolicyStatus(pdpGroupName);
+ if (result.isEmpty()) {
+ return makeNotFoundResponse(requestId);
+
+ } else {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(result).build();
+ }
+
+ } catch (PfModelException | PfModelRuntimeException e) {
+ logger.warn(GET_DEPLOYMENTS_FAILED, e);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
+ requestId).entity(e.getErrorResponse().getErrorMessage()).build();
+ }
+ }
+
+ /**
+ * Queries status of all versions of a specific policy in a specific PdpGroup.
+ *
+ * @param pdpGroupName name of the PdpGroup
+ * @param policyName name of the Policy
+ * @param requestId request ID used in ONAP logging
+ * @return a response
+ */
+ // @formatter:off
+ @GET
+ @Path("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
+
+ public Response getStatusOfPolicies(
+ @ApiParam(value = "PDP Group Name", required = true) @PathParam("pdpGroupName") String pdpGroupName,
+ @ApiParam(value = "Policy Id", required = true) @PathParam("policyName") String policyName,
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+
+ try {
+ Collection<PdpPolicyStatus> result =
+ provider.getPolicyStatus(pdpGroupName, new ToscaConceptIdentifierOptVersion(policyName, null));
+ if (result.isEmpty()) {
+ return makeNotFoundResponse(requestId);
+
+ } else {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(result).build();
+ }
+
+ } catch (PfModelException | PfModelRuntimeException e) {
+ logger.warn(GET_DEPLOYMENTS_FAILED, e);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
+ requestId).entity(e.getErrorResponse().getErrorMessage()).build();
+ }
+ }
+
+
+ /**
+ * Queries status of a specific version of a specific policy in a specific PdpGroup.
+ *
+ * @param pdpGroupName name of the PdpGroup
+ * @param policyName name of the Policy
+ * @param policyVersion version of the Policy
+ * @param requestId request ID used in ONAP logging
+ * @return a response
+ */
+ // @formatter:off
+ @GET
+ @Path("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
+
+ public Response getStatusOfPolicy(
+ @ApiParam(value = "PDP Group Name", required = true) @PathParam("pdpGroupName") String pdpGroupName,
+ @ApiParam(value = "Policy Id", required = true) @PathParam("policyName") String policyName,
+ @ApiParam(value = "Policy Version", required = true) @PathParam("policyVersion") String policyVersion,
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
+
+ try {
+ Collection<PdpPolicyStatus> result = provider.getPolicyStatus(pdpGroupName,
+ new ToscaConceptIdentifierOptVersion(policyName, policyVersion));
+ if (result.isEmpty()) {
+ return makeNotFoundResponse(requestId);
+
+ } else {
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
+ .entity(result.iterator().next()).build();
+ }
+
+ } catch (PfModelException | PfModelRuntimeException e) {
+ logger.warn(GET_DEPLOYMENTS_FAILED, e);
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
+ requestId).entity(e.getErrorResponse().getErrorMessage()).build();
+ }
+ }
+
+ /**
* Makes a "not found" response.
*
* @param requestId request ID
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusProvider.java
index 98cf47b9..8c969782 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyStatusProvider.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
package org.onap.policy.pap.main.rest;
import java.util.Collection;
+import java.util.stream.Collectors;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pap.concepts.PolicyStatus;
@@ -92,4 +94,46 @@ public class PolicyStatusProvider {
return tracker.getDeploymentStatus();
}
+
+
+ /**
+ * Gets the status of all policies.
+ *
+ * @return the status of all policies
+ * @throws PfModelException if a DB error occurs
+ */
+ public Collection<PdpPolicyStatus> getPolicyStatus() throws PfModelException {
+ try (PolicyModelsProvider dao = daoFactory.create()) {
+ return dao.getAllPolicyStatus();
+ }
+ }
+
+ /**
+ * Gets the status of policies in a PdpGroup.
+ *
+ * @param pdpGroupName the pdp group
+ * @return the deployment status of policies
+ * @throws PfModelException if a DB error occurs
+ */
+ public Collection<PdpPolicyStatus> getPolicyStatus(String pdpGroupName) throws PfModelException {
+ try (PolicyModelsProvider dao = daoFactory.create()) {
+ return dao.getGroupPolicyStatus(pdpGroupName);
+ }
+ }
+
+ /**
+ * Gets the status of a policy in a PdpGroup.
+ *
+ * @param pdpGroupName the pdp group
+ * @param policy the policy
+ * @return the deployment status of the policy
+ * @throws PfModelException if a DB error occurs
+ */
+ public Collection<PdpPolicyStatus> getPolicyStatus(String pdpGroupName, ToscaConceptIdentifierOptVersion policy)
+ throws PfModelException {
+ try (PolicyModelsProvider dao = daoFactory.create()) {
+ return dao.getAllPolicyStatus(policy).stream().filter(p -> p.getPdpGroup().equals(pdpGroupName))
+ .collect(Collectors.toList());
+ }
+ }
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java
index 985ff904..1d0c7aa7 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,13 +34,18 @@ import org.junit.Test;
public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
+ private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status";
@Test
public void testSwagger() throws Exception {
super.testSwagger(POLICY_STATUS_ENDPOINT);
-
super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}");
super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}/{version}");
+
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT);
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}");
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}");
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}");
}
@Test
@@ -52,20 +58,26 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
@Test
public void testQueryDeployedPolicies() throws Exception {
- String uri = POLICY_STATUS_ENDPOINT + "/my-name";
+ checkRequest(POLICY_STATUS_ENDPOINT + "/my-name");
+ checkRequest(POLICY_STATUS_ENDPOINT + "/my-name/1.2.3");
+ }
- Invocation.Builder invocationBuilder = sendRequest(uri);
- Response rawresp = invocationBuilder.get();
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
+ @Test
+ public void testGetStatusOfAllPolicies() throws Exception {
+ String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT;
// verify it fails when no authorization info is included
checkUnauthRequest(uri, req -> req.get());
}
@Test
- public void testQueryDeployedPolicy() throws Exception {
- String uri = POLICY_STATUS_ENDPOINT + "/my-name/1.2.3";
+ public void testGetStatusOfPolicies() throws Exception {
+ checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name");
+ checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name");
+ checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name/1.2.3");
+ }
+ private void checkRequest(String uri) throws Exception {
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java
index 44c8d828..81ed6805 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,8 @@
package org.onap.policy.pap.main.rest;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@@ -77,27 +80,12 @@ public class TestPolicyStatusProvider extends ProviderSuper {
@Test
public void testGetStatus_testAccumulate() throws PfModelException {
- PdpPolicyStatusBuilder builder = PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE)
- .policyType(POLICY_TYPE).state(State.WAITING);
-
- PdpPolicyStatus notDeployed = builder.deploy(false).policy(POLICY_B).pdpId(PDP_A).build();
-
- // remaining policies are deployed
- builder.deploy(true);
-
- // @formatter:off
- when(dao.getAllPolicyStatus()).thenReturn(List.of(
- builder.policy(POLICY_A).pdpId(PDP_A).build(),
- builder.policy(POLICY_A).pdpId(PDP_B).build(),
- notDeployed,
- builder.policy(POLICY_C).pdpId(PDP_A).build()
- ));
- // @formatter:on
+ buildPolicyStatusToReturn1();
List<PolicyStatus> result = new ArrayList<>(prov.getStatus());
Collections.sort(result, (rec1, rec2) -> rec1.getPolicy().compareTo(rec2.getPolicy()));
- assertThat(result).hasSize(2);
+ assertThat(result).hasSize(3);
Iterator<PolicyStatus> iter = result.iterator();
@@ -109,6 +97,13 @@ public class TestPolicyStatusProvider extends ProviderSuper {
assertThat(status.getSuccessCount()).isZero();
status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_B);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getIncompleteCount()).isZero();
+ assertThat(status.getFailureCount()).isZero();
+ assertThat(status.getSuccessCount()).isEqualTo(1);
+
+ status = iter.next();
assertThat(status.getPolicy()).isEqualTo(POLICY_C);
assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
assertThat(status.getIncompleteCount()).isEqualTo(1);
@@ -119,8 +114,113 @@ public class TestPolicyStatusProvider extends ProviderSuper {
@Test
public void testGetStatusToscaConceptIdentifierOptVersion() throws PfModelException {
+ ToscaConceptIdentifierOptVersion optIdent = buildPolicyStatusToReturn2();
+
+ List<PolicyStatus> result = new ArrayList<>(prov.getStatus(optIdent));
+ assertThat(result).hasSize(1);
+
+ Iterator<PolicyStatus> iter = result.iterator();
+
+ PolicyStatus status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getIncompleteCount()).isEqualTo(2);
+ assertThat(status.getFailureCount()).isZero();
+ assertThat(status.getSuccessCount()).isZero();
+ }
+
+ @Test
+ public void testGetPolicyStatus() throws PfModelException {
+
+ buildPolicyStatusToReturn1();
+
+ List<PdpPolicyStatus> result = new ArrayList<>(prov.getPolicyStatus());
+ Collections.sort(result, (rec1, rec2) -> rec1.getPolicy().compareTo(rec2.getPolicy()));
+
+ assertThat(result).hasSize(5);
+ Iterator<PdpPolicyStatus> iter = result.iterator();
+
+ PdpPolicyStatus status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getPdpId()).isEqualTo(PDP_A);
+ assertThat(status.getPdpType()).isEqualTo(MY_PDP_TYPE);
+ assertThat(status.getPdpGroup()).isEqualTo(MY_GROUP);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPdpId()).isEqualTo(PDP_B);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_B);
+ assertThat(status.getPdpId()).isEqualTo(PDP_A);
+ assertFalse(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_B);
+ assertThat(status.getPdpId()).isEqualTo(PDP_B);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.SUCCESS);
+ }
+
+ @Test
+ public void testGetPolicyStatusByGroupAndPolicyIdVersion() throws PfModelException {
+
+ ToscaConceptIdentifierOptVersion optIdent = buildPolicyStatusToReturn2();
+
+ List<PdpPolicyStatus> result = new ArrayList<>(prov.getPolicyStatus(MY_GROUP, optIdent));
+ assertThat(result).hasSize(3);
+
+ Iterator<PdpPolicyStatus> iter = result.iterator();
+
+ PdpPolicyStatus status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getPdpId()).isEqualTo(PDP_A);
+ assertThat(status.getPdpType()).isEqualTo(MY_PDP_TYPE);
+ assertThat(status.getPdpGroup()).isEqualTo(MY_GROUP);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getPdpId()).isEqualTo(PDP_B);
+ assertThat(status.getPdpType()).isEqualTo(MY_PDP_TYPE);
+ assertThat(status.getPdpGroup()).isEqualTo(MY_GROUP);
+ assertFalse(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.FAILURE);
+ }
+
+ private void buildPolicyStatusToReturn1() throws PfModelException {
+
PdpPolicyStatusBuilder builder = PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE)
- .policy(POLICY_A).policyType(POLICY_TYPE);
+ .policyType(POLICY_TYPE).state(State.WAITING);
+
+ PdpPolicyStatus notDeployed = builder.deploy(false).policy(POLICY_B).pdpId(PDP_A).build();
+
+ // remaining policies are deployed
+ builder.deploy(true);
+
+ // @formatter:off
+ when(dao.getAllPolicyStatus()).thenReturn(List.of(
+ builder.policy(POLICY_A).pdpId(PDP_A).build(),
+ builder.policy(POLICY_A).pdpId(PDP_B).build(),
+ notDeployed,
+ builder.policy(POLICY_C).pdpId(PDP_A).build(),
+ builder.policy(POLICY_B).pdpId(PDP_B).state(State.SUCCESS).build()
+ ));
+ // @formatter:on
+ }
+
+ private ToscaConceptIdentifierOptVersion buildPolicyStatusToReturn2() throws PfModelException {
+ PdpPolicyStatusBuilder builder =
+ PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE).policy(POLICY_A).policyType(POLICY_TYPE);
PdpPolicyStatus notDeployed = builder.deploy(false).pdpId(PDP_B).state(State.FAILURE).build();
@@ -136,17 +236,6 @@ public class TestPolicyStatusProvider extends ProviderSuper {
builder.policy(POLICY_A).pdpId(PDP_C).build()
));
// @formatter:on
-
- List<PolicyStatus> result = new ArrayList<>(prov.getStatus(optIdent));
- assertThat(result).hasSize(1);
-
- Iterator<PolicyStatus> iter = result.iterator();
-
- PolicyStatus status = iter.next();
- assertThat(status.getPolicy()).isEqualTo(POLICY_A);
- assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
- assertThat(status.getIncompleteCount()).isEqualTo(2);
- assertThat(status.getFailureCount()).isZero();
- assertThat(status.getSuccessCount()).isZero();
+ return optIdent;
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
index 55cf2f4c..9b80bb7e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,11 +39,13 @@ import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
import org.onap.policy.models.pap.concepts.PolicyNotification;
import org.onap.policy.models.pap.concepts.PolicyStatus;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.pap.main.PapConstants;
+import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1;
public class PdpGroupDeleteTest extends End2EndBase {
private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
@@ -136,8 +139,10 @@ public class PdpGroupDeleteTest extends End2EndBase {
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
- PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
assertNull(resp.getErrorDetails());
context.await();
@@ -157,7 +162,7 @@ public class PdpGroupDeleteTest extends End2EndBase {
assertEquals(new ToscaConceptIdentifier("onap.restart.tcaB", "1.0.0"), deleted.getPolicy());
rawresp = invocationBuilder.delete();
- resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
assertEquals("policy does not appear in any PDP group: onap.restart.tcaB null", resp.getErrorDetails());
}
@@ -188,14 +193,15 @@ public class PdpGroupDeleteTest extends End2EndBase {
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
- PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
-
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
context.await();
rawresp = invocationBuilder.delete();
- resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
assertEquals("policy does not appear in any PDP group: onap.restart.tcaC 1.0.0", resp.getErrorDetails());
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
index 3c5bed87..08974ed8 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,6 +51,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.pap.main.PapConstants;
+import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1;
public class PdpGroupDeployTest extends End2EndBase {
private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch";
@@ -115,7 +117,7 @@ public class PdpGroupDeployTest extends End2EndBase {
Entity<DeploymentGroups> entity = Entity.entity(groups, MediaType.APPLICATION_JSON);
Response rawresp = invocationBuilder.post(entity);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
context.await();
@@ -126,7 +128,9 @@ public class PdpGroupDeployTest extends End2EndBase {
// repeat - should be OK
rawresp = invocationBuilder.post(entity);
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
assertNull(resp.getErrorDetails());
// repeat with unknown group - should fail
@@ -181,8 +185,9 @@ public class PdpGroupDeployTest extends End2EndBase {
Entity<PdpDeployPolicies> entity = Entity.entity(policies, MediaType.APPLICATION_JSON);
Response rawresp = invocationBuilder.post(entity);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- System.out.println(resp.getErrorDetails());
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
assertNull(resp.getErrorDetails());
context.await();
@@ -207,7 +212,7 @@ public class PdpGroupDeployTest extends End2EndBase {
// repeat - should be OK
rawresp = invocationBuilder.post(entity);
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java
index 19a5f990..b44d4af7 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
package org.onap.policy.pap.main.rest.e2e;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.List;
import javax.ws.rs.client.Invocation;
@@ -29,9 +31,15 @@ import javax.ws.rs.core.Response;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.models.pap.concepts.PolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
public class PolicyStatusTest extends End2EndBase {
+ private static final String POLICY_NAME = "onap.restart.tca";
+ private static final String POLICY_TYPE_NAME = "onap.policies.monitoring.cdap.tca.hi.lo.app";
+ private static final String VERSION = "1.0.0";
private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
+ private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status";
/**
* Starts Main and adds policies to the DB.
@@ -54,15 +62,7 @@ public class PolicyStatusTest extends End2EndBase {
List<PolicyStatus> resp = rawresp.readEntity(new GenericType<List<PolicyStatus>>() {});
assertEquals(1, resp.size());
-
- PolicyStatus status = resp.get(0);
- assertEquals("onap.restart.tca", status.getPolicyId());
- assertEquals("1.0.0", status.getPolicyVersion());
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", status.getPolicyTypeId());
- assertEquals("1.0.0", status.getPolicyTypeVersion());
- assertEquals(0, status.getFailureCount());
- assertEquals(1, status.getIncompleteCount());
- assertEquals(0, status.getSuccessCount());
+ checkAssertions(resp.get(0));
}
@Test
@@ -75,15 +75,7 @@ public class PolicyStatusTest extends End2EndBase {
List<PolicyStatus> resp = rawresp.readEntity(new GenericType<List<PolicyStatus>>() {});
assertEquals(1, resp.size());
-
- PolicyStatus status = resp.get(0);
- assertEquals("onap.restart.tca", status.getPolicyId());
- assertEquals("1.0.0", status.getPolicyVersion());
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", status.getPolicyTypeId());
- assertEquals("1.0.0", status.getPolicyTypeVersion());
- assertEquals(0, status.getFailureCount());
- assertEquals(1, status.getIncompleteCount());
- assertEquals(0, status.getSuccessCount());
+ checkAssertions(resp.get(0));
}
@Test
@@ -95,12 +87,67 @@ public class PolicyStatusTest extends End2EndBase {
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
PolicyStatus status = rawresp.readEntity(PolicyStatus.class);
- assertEquals("onap.restart.tca", status.getPolicyId());
- assertEquals("1.0.0", status.getPolicyVersion());
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", status.getPolicyTypeId());
- assertEquals("1.0.0", status.getPolicyTypeVersion());
+ checkAssertions(status);
+ }
+
+ @Test
+ public void testGetStatusOfAllDeployedPolicies() throws Exception {
+ String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT;
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.get();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+
+ List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<List<PdpPolicyStatus>>() {});
+ assertEquals(1, resp.size());
+ checkAssertionsForDeploymentStatus(resp.get(0));
+ }
+
+ @Test
+ public void testGetStatusOfDeployedPolicies() throws Exception {
+ String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.get();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+
+ List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<List<PdpPolicyStatus>>() {});
+ assertEquals(1, resp.size());
+ checkAssertionsForDeploymentStatus(resp.get(0));
+ }
+
+ @Test
+ public void testGetStatusOfDeployedPolicy() throws Exception {
+ String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca/1.0.0";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.get();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+
+ PdpPolicyStatus status = rawresp.readEntity(PdpPolicyStatus.class);
+ checkAssertionsForDeploymentStatus(status);
+ }
+
+
+ private void checkAssertions(PolicyStatus status) {
+ assertEquals(POLICY_NAME, status.getPolicyId());
+ assertEquals(VERSION, status.getPolicyVersion());
+ assertEquals(POLICY_TYPE_NAME, status.getPolicyTypeId());
+ assertEquals(VERSION, status.getPolicyTypeVersion());
assertEquals(0, status.getFailureCount());
assertEquals(1, status.getIncompleteCount());
assertEquals(0, status.getSuccessCount());
}
+
+ private void checkAssertionsForDeploymentStatus(PdpPolicyStatus status) {
+ assertEquals(POLICY_NAME, status.getPolicy().getName());
+ assertEquals(VERSION, status.getPolicy().getVersion());
+ assertEquals(POLICY_TYPE_NAME, status.getPolicyType().getName());
+ assertEquals(VERSION, status.getPolicyType().getVersion());
+ assertEquals("policyStatus", status.getPdpGroup());
+ assertEquals("pdpB_1", status.getPdpId());
+ assertEquals("pdpTypeB", status.getPdpType());
+ assertEquals(State.WAITING, status.getState());
+ assertTrue(status.isDeploy());
+ }
}