summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java89
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java29
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java47
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java28
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java52
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java50
6 files changed, 277 insertions, 18 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 46982183..16716117 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
@@ -80,7 +80,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
public Response deleteGroup(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@ApiParam(value = "PDP Group Name", required = true) @PathParam("name") String groupName) {
- Pair<Status, PdpGroupDeleteResponse> pair = provider.delete(groupName, null);
+ Pair<Status, PdpGroupDeleteResponse> pair = provider.deleteGroup(groupName, null);
return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
.entity(pair.getRight()).build();
@@ -124,7 +124,92 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
@ApiParam(value = "PDP Group Name", required = true) @PathParam("name") String groupName,
@ApiParam(value = "PDP Group Version", required = true) @PathParam("version") String version) {
- Pair<Status, PdpGroupDeleteResponse> pair = provider.delete(groupName, version);
+ Pair<Status, PdpGroupDeleteResponse> pair = provider.deleteGroup(groupName, version);
+
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
+ .entity(pair.getRight()).build();
+ }
+
+ /**
+ * Deletes a PDP policy.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param policyName name of the PDP Policy to be deleted
+ * @return a response
+ */
+ // @formatter:off
+ @DELETE
+ @Path("pdps/policies/{name}")
+ @ApiOperation(value = "Delete PDP Policy",
+ notes = "Deletes a PDP Policy, returning optional error details",
+ response = PdpGroupDeleteResponse.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 deletePolicies(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "PDP Policy Name", required = true) @PathParam("name") String policyName) {
+
+ Pair<Status, PdpGroupDeleteResponse> pair = provider.deletePolicy(policyName, null);
+
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
+ .entity(pair.getRight()).build();
+ }
+
+ /**
+ * Deletes a PDP policy.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param policyName name of the PDP Policy to be deleted
+ * @param version version to be deleted
+ * @return a response
+ */
+ // @formatter:off
+ @DELETE
+ @Path("pdps/policies/{name}/versions/{version}")
+ @ApiOperation(value = "Delete version of a PDP Policy",
+ notes = "Deletes a version of a PDP Policy, returning optional error details",
+ response = PdpGroupDeleteResponse.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 deletePoliciesVersion(
+ @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "PDP Policy Name", required = true) @PathParam("name") String policyName,
+ @ApiParam(value = "PDP Policy Version", required = true) @PathParam("version") String version) {
+
+ Pair<Status, PdpGroupDeleteResponse> pair = provider.deletePolicy(policyName, version);
return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
.entity(pair.getRight()).build();
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java
index e40b053c..f9619df3 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java
@@ -37,7 +37,34 @@ public class PdpGroupDeleteProvider {
* one version
* @return a pair containing the status and the response
*/
- public Pair<Response.Status, PdpGroupDeleteResponse> delete(String groupName, String version) {
+ public Pair<Response.Status, PdpGroupDeleteResponse> deleteGroup(String groupName, String version) {
+
+ /*
+ * TODO Lock for updates - return error if already locked.
+ */
+
+ /*
+ * TODO Make updates - sending initial messages to PDPs and arranging for
+ * listeners to complete the deletion actions (in the background). The final step
+ * for the listener is to unlock.
+ */
+
+ /*
+ * TODO Return error if unable to send updates to all PDPs.
+ */
+
+ return Pair.of(Response.Status.OK, new PdpGroupDeleteResponse());
+ }
+
+ /**
+ * Deletes a PDP group.
+ *
+ * @param policyId id of the policy to be deleted
+ * @param version group version to delete; may be {@code null} if the group has only
+ * one version
+ * @return a pair containing the status and the response
+ */
+ public Pair<Response.Status, PdpGroupDeleteResponse> deletePolicy(String policyId, String version) {
/*
* TODO Lock for updates - return error if already locked.
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 228d97c9..a0a2ee8f 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
@@ -37,6 +37,7 @@ import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.pap.concepts.PdpGroup;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+import org.onap.policy.models.pap.concepts.PdpPolicies;
/**
* Class to provide REST end points for PAP component to deploy a PDP group.
@@ -77,10 +78,52 @@ public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
@ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
// @formatter:on
- public Response deploy(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ public Response deployGroup(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
@ApiParam(value = "PDP Group Configuration", required = true) PdpGroup group) {
- Pair<Status, PdpGroupDeployResponse> pair = provider.deploy(group);
+ Pair<Status, PdpGroupDeployResponse> pair = provider.deployGroup(group);
+
+ return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
+ .entity(pair.getRight()).build();
+ }
+
+ /**
+ * Deploys or updates PDP policies.
+ *
+ * @param requestId request ID used in ONAP logging
+ * @param policies PDP policies
+ * @return a response
+ */
+ // @formatter:off
+ @POST
+ @Path("pdps/policies")
+ @ApiOperation(value = "Deploy or update PDP Policies",
+ notes = "Deploys or updates PDP Policies, returning optional error details",
+ response = PdpGroupDeployResponse.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 deployPolicies(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+ @ApiParam(value = "PDP Policies; only the name and policyVersion are required",
+ required = true) PdpPolicies policies) {
+
+ Pair<Status, PdpGroupDeployResponse> pair = provider.deployPolicies(policies);
return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
.entity(pair.getRight()).build();
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
index da3b2ded..e8ea357b 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
@@ -24,6 +24,7 @@ import javax.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.pap.concepts.PdpGroup;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+import org.onap.policy.models.pap.concepts.PdpPolicies;
/**
* Provider for PAP component to deploy PDP groups.
@@ -36,7 +37,32 @@ public class PdpGroupDeployProvider {
* @param group PDP group configuration
* @return a pair containing the status and the response
*/
- public Pair<Response.Status, PdpGroupDeployResponse> deploy(PdpGroup group) {
+ public Pair<Response.Status, PdpGroupDeployResponse> deployGroup(PdpGroup group) {
+
+ /*
+ * TODO Lock for updates - return error if already locked.
+ */
+
+ /*
+ * TODO Make updates - sending initial messages to PDPs and arranging for
+ * listeners to complete the deployment actions (in the background). The final
+ * step for the listener is to unlock.
+ */
+
+ /*
+ * TODO Return error if unable to send updates to all PDPs.
+ */
+
+ return Pair.of(Response.Status.OK, new PdpGroupDeployResponse());
+ }
+
+ /**
+ * Deploys or updates PDP policies.
+ *
+ * @param policies PDP policies
+ * @return a pair containing the status and the response
+ */
+ public Pair<Response.Status, PdpGroupDeployResponse> deployPolicies(PdpPolicies policies) {
/*
* TODO Lock for updates - return error if already locked.
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java
index 107c46ad..0384bf7e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java
@@ -31,17 +31,21 @@ import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
- private static final String DELETE_ENDPOINT = "pdps/groups";
+ private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
+ private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies";
@Test
public void testSwagger() throws Exception {
- super.testSwagger(DELETE_ENDPOINT + "/{name}");
- super.testSwagger(DELETE_ENDPOINT + "/{name}/versions/{version}");
+ super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}");
+ super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}/versions/{version}");
+
+ super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}");
+ super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}");
}
@Test
public void testDeleteGroup() throws Exception {
- String uri = DELETE_ENDPOINT + "/my-name";
+ String uri = DELETE_GROUP_ENDPOINT + "/my-name";
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
@@ -60,7 +64,45 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
@Test
public void testDeleteGroupVersion() throws Exception {
- String uri = DELETE_ENDPOINT + "/my-name/versions/1.2.3";
+ String uri = DELETE_GROUP_ENDPOINT + "/my-name/versions/1.2.3";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.delete();
+ PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ rawresp = invocationBuilder.delete();
+ resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ // verify it fails when no authorization info is included
+ checkUnauthRequest(uri, req -> req.delete());
+ }
+
+ @Test
+ public void testDeletePolicies() throws Exception {
+ String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.delete();
+ PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ rawresp = invocationBuilder.delete();
+ resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ // verify it fails when no authorization info is included
+ checkUnauthRequest(uri, req -> req.delete());
+ }
+
+ @Test
+ public void testDeletePoliciesVersion() throws Exception {
+ String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
index d49f00cc..0fc3577e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
@@ -32,22 +32,26 @@ import javax.ws.rs.core.Response;
import org.junit.Test;
import org.onap.policy.models.pap.concepts.PdpGroup;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+import org.onap.policy.models.pap.concepts.PdpPolicies;
import org.onap.policy.models.pap.concepts.PdpSubGroup;
+import org.onap.policy.pdp.common.models.Policy;
public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
- private static final String DEPLOY_ENDPOINT = "pdps";
+ private static final String DEPLOY_GROUP_ENDPOINT = "pdps";
+ private static final String DEPLOY_POLICIES_ENDPOINT = "pdps/policies";
@Test
public void testSwagger() throws Exception {
- super.testSwagger(DEPLOY_ENDPOINT);
+ super.testSwagger(DEPLOY_GROUP_ENDPOINT);
+ super.testSwagger(DEPLOY_POLICIES_ENDPOINT);
}
@Test
- public void testDeploy() throws Exception {
+ public void testDeployGroup() throws Exception {
Entity<PdpGroup> entgrp = makePdpGroupEntity();
- Invocation.Builder invocationBuilder = sendRequest(DEPLOY_ENDPOINT);
+ Invocation.Builder invocationBuilder = sendRequest(DEPLOY_GROUP_ENDPOINT);
Response rawresp = invocationBuilder.post(entgrp);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
@@ -59,7 +63,26 @@ public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
assertNull(resp.getErrorDetails());
// verify it fails when no authorization info is included
- checkUnauthRequest(DEPLOY_ENDPOINT, req -> req.post(entgrp));
+ checkUnauthRequest(DEPLOY_GROUP_ENDPOINT, req -> req.post(entgrp));
+ }
+
+ @Test
+ public void testDeployPolicies() throws Exception {
+ Entity<PdpPolicies> entgrp = makePdpPoliciesEntity();
+
+ Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
+ Response rawresp = invocationBuilder.post(entgrp);
+ PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ rawresp = invocationBuilder.post(entgrp);
+ resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ // verify it fails when no authorization info is included
+ checkUnauthRequest(DEPLOY_POLICIES_ENDPOINT, req -> req.post(entgrp));
}
private Entity<PdpGroup> makePdpGroupEntity() {
@@ -72,7 +95,20 @@ public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
group.setVersion("my-version");
group.setPdpSubgroups(Arrays.asList(subgrp));
- Entity<PdpGroup> entgrp = Entity.entity(group, MediaType.APPLICATION_JSON);
- return entgrp;
+ return Entity.entity(group, MediaType.APPLICATION_JSON);
+ }
+
+ private Entity<PdpPolicies> makePdpPoliciesEntity() {
+ Policy pol1 = new Policy();
+ pol1.setName("policy-a");
+ pol1.setPolicyVersion("1");
+
+ Policy pol2 = new Policy();
+ pol2.setName("policy-b");
+
+ PdpPolicies policies = new PdpPolicies();
+ policies.setPolicies(Arrays.asList(pol1, pol2));
+
+ return Entity.entity(policies, MediaType.APPLICATION_JSON);
}
}