diff options
author | Jim Hahn <jrh3@att.com> | 2020-02-27 18:50:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-27 18:50:27 +0000 |
commit | f22a6d5c2ae04a82919f7b9e7c9da5f5d459dd05 (patch) | |
tree | 3e8f45732fd35c1de51728283622acb79e906952 /feature-lifecycle/src/main/java | |
parent | 4ad5e93f11ca32ab6162b29d912169ee7a00073c (diff) | |
parent | fe4f6e1c9a4ee06c21ccee51af9eaf654e56281e (diff) |
Merge "Undeploy support for native rules PDP-D policies."
Diffstat (limited to 'feature-lifecycle/src/main/java')
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()); + } } |