summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/main
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-02-26 18:30:18 -0600
committerjhh <jorge.hernandez-herrero@att.com>2020-02-26 18:30:18 -0600
commitfe4f6e1c9a4ee06c21ccee51af9eaf654e56281e (patch)
treeb1a2e9c5178171e3ed6a405c4fded94c2739fbfa /feature-lifecycle/src/main
parent9f75b598b3e0946cf4065bced39f9ea77a9dc3d7 (diff)
Undeploy support for native rules PDP-D policies.
Issue-ID: POLICY-2388 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Iaaf5e13a5db286928952bcb3e4cc0f526b0b133c
Diffstat (limited to 'feature-lifecycle/src/main')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeController.java2
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesController.java46
2 files changed, 45 insertions, 3 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeController.java
index ebc44e9b..2d9ca514 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeController.java
@@ -26,9 +26,9 @@ import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
-@Getter
public class PolicyTypeNativeController implements PolicyTypeController {
+ @Getter
protected final ToscaPolicyTypeIdentifier policyType;
@GsonJsonIgnore
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesController.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesController.java
index 8e928aa8..878907b0 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesController.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesController.java
@@ -23,12 +23,22 @@ package org.onap.policy.drools.lifecycle;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.drools.controller.DroolsControllerConstants;
+import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsPolicy;
+import org.onap.policy.drools.domain.models.nativ.rules.NativeDroolsRulesArtifact;
+import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
+import org.onap.policy.drools.system.PolicyController;
+import org.onap.policy.drools.system.PolicyControllerConstants;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-@Getter
public class PolicyTypeRulesController implements PolicyTypeController {
+ private static final Logger logger = LoggerFactory.getLogger(PolicyTypeRulesController.class);
+ @Getter
protected final ToscaPolicyTypeIdentifier policyType;
@GsonJsonIgnore
@@ -48,7 +58,39 @@ public class PolicyTypeRulesController implements PolicyTypeController {
@Override
public boolean undeploy(ToscaPolicy policy) {
- // TODO
+ PolicyController controller;
+ try {
+ controller = getPolicyController(
+ fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class));
+ } catch (RuntimeException | CoderException e) {
+ logger.warn("Invalid Policy: {}", policy);
+ return false;
+ }
+
+ DroolsConfiguration noConfig =
+ new DroolsConfiguration(
+ DroolsControllerConstants.NO_ARTIFACT_ID,
+ DroolsControllerConstants.NO_GROUP_ID,
+ DroolsControllerConstants.NO_VERSION);
+
+ PolicyControllerConstants.getFactory().patch(controller, noConfig);
return true;
}
+
+ private PolicyController getPolicyController(NativeDroolsPolicy domainPolicy) {
+ /*
+ * If the controller is present, it must have a name (schema validated) and as such, the
+ * controller must exist (via previously deployed controller policy).
+ */
+ if (domainPolicy.getProperties().getController() != null) {
+ return PolicyControllerConstants.getFactory().get(domainPolicy.getProperties().getController().getName());
+ }
+
+ /*
+ * Attempt to get the controller from the rules coordinates (excluding the version).
+ * The rules coordinates are mandatory (per schema validation).
+ */
+ NativeDroolsRulesArtifact rules = domainPolicy.getProperties().getRulesArtifact();
+ return PolicyControllerConstants.getFactory().get(rules.getGroupId(), rules.getArtifactId());
+ }
}