aboutsummaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'feature-lifecycle/src/main')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/PolicyTypeRulesController.java44
-rw-r--r--feature-lifecycle/src/main/resources/schemas/onap.policies.native.Drools-1.0.0.schema.json21
2 files changed, 28 insertions, 37 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());
- }
}
diff --git a/feature-lifecycle/src/main/resources/schemas/onap.policies.native.Drools-1.0.0.schema.json b/feature-lifecycle/src/main/resources/schemas/onap.policies.native.Drools-1.0.0.schema.json
index 1dd766a2..8742768b 100644
--- a/feature-lifecycle/src/main/resources/schemas/onap.policies.native.Drools-1.0.0.schema.json
+++ b/feature-lifecycle/src/main/resources/schemas/onap.policies.native.Drools-1.0.0.schema.json
@@ -73,7 +73,8 @@
"type": "object",
"title": "Properties",
"required": [
- "rulesArtifact"
+ "rulesArtifact",
+ "controller"
],
"properties": {
"rulesArtifact": {
@@ -93,7 +94,7 @@
"examples": [
"org.onap.policy.controlloop"
],
- "pattern": "^(.*)$"
+ "pattern": "^(.+)$"
},
"artifactId": {
"$id": "#/properties/properties/properties/rulesArtifact/properties/artifactId",
@@ -102,7 +103,7 @@
"examples": [
"example"
],
- "pattern": "^(.*)$"
+ "pattern": "^(.+)$"
},
"version": {
"$id": "#/properties/properties/properties/rulesArtifact/properties/version",
@@ -111,7 +112,7 @@
"examples": [
"1.0.0"
],
- "pattern": "^(.*)$"
+ "pattern": "^(.+)$"
}
}
},
@@ -120,8 +121,7 @@
"type": "object",
"title": "Controller",
"required": [
- "name",
- "version"
+ "name"
],
"properties": {
"name": {
@@ -132,15 +132,6 @@
"example"
],
"pattern": "^(.+)$"
- },
- "version": {
- "$id": "#/properties/properties/properties/controller/properties/version",
- "type": "string",
- "title": "Version",
- "examples": [
- "1.0.0"
- ],
- "pattern": "^(.*)$"
}
}
}