summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/main/java
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-02-27 19:20:39 -0600
committerjhh <jorge.hernandez-herrero@att.com>2020-02-27 19:20:39 -0600
commit7f1a0e6e142513087aa9385786212455a1ea0f22 (patch)
treea8977301b868108220d62c8cba2733158f8d7509 /feature-lifecycle/src/main/java
parentf22a6d5c2ae04a82919f7b9e7c9da5f5d459dd05 (diff)
Undeploy support for native rules PDP-D policies.
Issue-ID: POLICY-2388 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Ic829bda9dbbb54d8883df6c642c1895cd7936823
Diffstat (limited to 'feature-lifecycle/src/main/java')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesController.java44
1 files changed, 22 insertions, 22 deletions
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 878907b0..79e2ddb8 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
@@ -26,7 +26,6 @@ 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;
@@ -52,16 +51,34 @@ public class PolicyTypeRulesController implements PolicyTypeController {
@Override
public boolean deploy(ToscaPolicy policy) {
- // TODO
- return fsm.getDomainMaker().isConformant(policy);
+ NativeDroolsPolicy nativePolicy;
+ PolicyController controller;
+ try {
+ nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class);
+ controller =
+ PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
+ } catch (CoderException e) {
+ logger.warn("Invalid Policy: {}", policy);
+ return false;
+ }
+
+ DroolsConfiguration newConfig =
+ new DroolsConfiguration(
+ nativePolicy.getProperties().getRulesArtifact().getArtifactId(),
+ nativePolicy.getProperties().getRulesArtifact().getGroupId(),
+ nativePolicy.getProperties().getRulesArtifact().getVersion());
+
+ PolicyControllerConstants.getFactory().patch(controller, newConfig);
+ return true;
}
@Override
public boolean undeploy(ToscaPolicy policy) {
PolicyController controller;
try {
- controller = getPolicyController(
- fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class));
+ NativeDroolsPolicy nativePolicy = fsm.getDomainMaker().convertTo(policy, NativeDroolsPolicy.class);
+ controller =
+ PolicyControllerConstants.getFactory().get(nativePolicy.getProperties().getController().getName());
} catch (RuntimeException | CoderException e) {
logger.warn("Invalid Policy: {}", policy);
return false;
@@ -76,21 +93,4 @@ public class PolicyTypeRulesController implements PolicyTypeController {
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());
- }
}