summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2019-04-10 16:22:25 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-10 16:22:25 +0000
commitb793c0cedf08d44de56073d24256567f50dcd1c3 (patch)
treea5241dafc9ea44503729f5eb19d185020fb7de55
parenta183c027762a5087760fe17c21b115eb4dcc21ff (diff)
parentf156e04114c5e67ad59d3b7f12e6ddf9e8442755 (diff)
Merge "Current draft of undeploy"
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java1
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java85
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteControllerV1.java (renamed from main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteControllerV1.java)22
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java120
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteControllerV1.java (renamed from main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java)19
5 files changed, 144 insertions, 103 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java
index 05ba2901..01c33611 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PapRestServer.java
@@ -30,6 +30,7 @@ import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.pap.main.parameters.RestServerParameters;
+import org.onap.policy.pap.main.rest.depundep.PdpGroupDeleteControllerV1;
import org.onap.policy.pap.main.rest.depundep.PdpGroupDeployControllerV1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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
deleted file mode 100644
index 2a1d240d..00000000
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP PAP
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.pap.main.rest;
-
-import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.tuple.Pair;
-import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
-
-/**
- * Provider for PAP component to delete PDP groups.
- */
-public class PdpGroupDeleteProvider {
-
- /**
- * Deletes a PDP group.
- *
- * @param groupName name of the PDP group 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> 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 policy.
- *
- * @param policyId id of the policy to be deleted
- * @param version policy version to delete; may be {@code null} if the policy 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.
- */
-
- /*
- * 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());
- }
-}
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/depundep/PdpGroupDeleteControllerV1.java
index e377c7ca..ca638f3e 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/depundep/PdpGroupDeleteControllerV1.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.pap.main.rest;
+package org.onap.policy.pap.main.rest.depundep;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -37,6 +37,8 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
+import org.onap.policy.pap.main.rest.PapRestControllerV1;
/**
* Class to provide REST end points for PAP component to delete a PDP group.
@@ -131,7 +133,7 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
}
/**
- * Deletes a PDP policy.
+ * Undeploys the latest version of a policy from the PDPs.
*
* @param requestId request ID used in ONAP logging
* @param policyName name of the PDP Policy to be deleted
@@ -140,8 +142,8 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
// @formatter:off
@DELETE
@Path("pdps/policies/{name}")
- @ApiOperation(value = "Delete PDP Policy",
- notes = "Deletes a PDP Policy, returning optional error details",
+ @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,
tags = {"Policy Administration (PAP) API"},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
@@ -165,14 +167,15 @@ 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) {
- Pair<Status, PdpGroupDeleteResponse> pair = provider.deletePolicy(policyName, null);
+ Pair<Status, PdpGroupDeleteResponse> pair =
+ provider.undeploy(new ToscaPolicyIdentifierOptVersion(policyName, null));
return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
.entity(pair.getRight()).build();
}
/**
- * Deletes a specific version of a PDP policy.
+ * Undeploys a specific version of a policy from the PDPs.
*
* @param requestId request ID used in ONAP logging
* @param policyName name of the PDP Policy to be deleted
@@ -182,8 +185,8 @@ public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
// @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",
+ @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,
tags = {"Policy Administration (PAP) API"},
authorizations = @Authorization(value = AUTHORIZATION_TYPE),
@@ -209,7 +212,8 @@ 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) {
- Pair<Status, PdpGroupDeleteResponse> pair = provider.deletePolicy(policyName, version);
+ Pair<Status, PdpGroupDeleteResponse> pair =
+ provider.undeploy(new ToscaPolicyIdentifierOptVersion(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/depundep/PdpGroupDeleteProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java
new file mode 100644
index 00000000..d5acc624
--- /dev/null
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/depundep/PdpGroupDeleteProvider.java
@@ -0,0 +1,120 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP PAP
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.main.rest.depundep;
+
+import java.util.function.BiFunction;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.tuple.Pair;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifierOptVersion;
+import org.onap.policy.pap.main.PolicyPapRuntimeException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provider for PAP component to delete PDP groups.
+ */
+public class PdpGroupDeleteProvider extends ProviderBase<PdpGroupDeleteResponse> {
+ private static final Logger logger = LoggerFactory.getLogger(PdpGroupDeleteProvider.class);
+
+
+ /**
+ * Constructs the object.
+ */
+ public PdpGroupDeleteProvider() {
+ super();
+ }
+
+ /**
+ * Deletes a PDP group.
+ *
+ * @param groupName name of the PDP group 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> deleteGroup(String groupName, String version) {
+
+ return Pair.of(Response.Status.OK, new PdpGroupDeleteResponse());
+ }
+
+ /**
+ * Deletes a PDP policy.
+ *
+ * @param policyIdent identifier of the policy to be undeployed
+ * @return a pair containing the status and the response
+ */
+ public Pair<Response.Status, PdpGroupDeleteResponse> undeploy(ToscaPolicyIdentifierOptVersion policyIdent) {
+
+ return process(policyIdent, this::deletePolicy);
+ }
+
+ /**
+ * Deletes a policy from its groups.
+ *
+ * @param data session data
+ * @param ident identifier of the policy to be deleted
+ */
+ private void deletePolicy(SessionData data, ToscaPolicyIdentifierOptVersion ident) {
+ try {
+ processPolicy(data, ident);
+
+ } catch (PfModelException e) {
+ // no need to log the error here, as it will be logged by the invoker
+ logger.warn("failed to deploy policy: {}", ident);
+ throw new PolicyPapRuntimeException(DB_ERROR_MSG, e);
+
+ } catch (RuntimeException e) {
+ // no need to log the error here, as it will be logged by the invoker
+ logger.warn("failed to deploy policy: {}", ident);
+ throw e;
+ }
+ }
+
+ @Override
+ public PdpGroupDeleteResponse makeResponse(String errorMsg) {
+ PdpGroupDeleteResponse resp = new PdpGroupDeleteResponse();
+ resp.setErrorDetails(errorMsg);
+ return resp;
+ }
+
+ @Override
+ protected BiFunction<PdpGroup, PdpSubGroup, Boolean> makeUpdater(ToscaPolicy policy) {
+ ToscaPolicyIdentifier desiredIdent = policy.getIdentifier();
+
+ return (group, subgroup) -> {
+
+ if (!subgroup.getPolicies().contains(desiredIdent)) {
+ // doesn't have the policy
+ return false;
+ }
+
+ // remove the policy from the subgroup
+ subgroup.getPolicies().remove(desiredIdent);
+ return true;
+ };
+ }
+}
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/depundep/TestPdpGroupDeleteControllerV1.java
index dd4fe937..e1c8c519 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/depundep/TestPdpGroupDeleteControllerV1.java
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.pap.main.rest;
+package org.onap.policy.pap.main.rest.depundep;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -28,6 +28,7 @@ import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
import org.junit.Test;
import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.onap.policy.pap.main.rest.CommonPapRestServer;
public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
@@ -88,13 +89,13 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
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());
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rawresp.getStatus());
+ assertEquals("cannot find policy: my-name", resp.getErrorDetails());
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rawresp.getStatus());
+ assertEquals("cannot find policy: my-name", resp.getErrorDetails());
// verify it fails when no authorization info is included
checkUnauthRequest(uri, req -> req.delete());
@@ -107,13 +108,13 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
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());
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rawresp.getStatus());
+ assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rawresp.getStatus());
+ assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
// verify it fails when no authorization info is included
checkUnauthRequest(uri, req -> req.delete());