* ================================================================================
* 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.
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;
@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 = {
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)));
}
@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 = {
@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)));
}
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();
+ }
+ }
}
* 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.
* 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();
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();
}
}
}
* ================================================================================
* 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.
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;
}
+ /**
+ * 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.
*
* 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.
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;
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());
+ }
+ }
}
* ============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.
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
@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());
* 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.
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;
@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();
assertThat(status.getFailureCount()).isZero();
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);
@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();
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;
}
}
* ================================================================================
* 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.
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";
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();
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());
}
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());
}
* ================================================================================
* 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.
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";
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();
// 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
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();
// 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());
}
}
* 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.
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;
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.
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
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
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());
+ }
}