summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'feature-lifecycle/src/main/java')
-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());
+ }
}