summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-11-17 14:40:16 -0600
committerjhh <jorge.hernandez-herrero@att.com>2020-11-17 14:53:22 -0600
commit6a429b8504cdd38cadb3ce9bb532d08cc5115da9 (patch)
tree480e4cdc3f4a5606792bc6f60435524b42d812e0 /feature-lifecycle/src
parentdc6c4a21d46909dad59f4bd16cb6d4fc29fcce77 (diff)
support for not validated policy types
Issue-ID: POLICY-2880 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Id816bb3edd44c34a342cd7ada95dd8f2f9d1b0a6 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java9
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java60
-rw-r--r--feature-lifecycle/src/test/resources/tosca-policy-other.json22
3 files changed, 67 insertions, 24 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java
index cf13c46d..860986d5 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java
@@ -24,6 +24,7 @@ package org.onap.policy.drools.lifecycle;
import java.util.List;
import java.util.function.BiPredicate;
import lombok.NonNull;
+import org.onap.policy.drools.policies.DomainMaker;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
@@ -161,6 +162,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
protected boolean syncPolicies(List<ToscaPolicy> policies,
BiPredicate<PolicyTypeController, ToscaPolicy> sync) {
boolean success = true;
+ DomainMaker domain = fsm.getDomainMaker();
for (ToscaPolicy policy : policies) {
ToscaPolicyTypeIdentifier policyType = policy.getTypeIdentifier();
PolicyTypeController controller = fsm.getController(policyType);
@@ -170,7 +172,12 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
continue;
}
- success = fsm.getDomainMaker().isConformant(policy) && sync.test(controller, policy) && success;
+ if (domain.isRegistered(policy.getTypeIdentifier())) {
+ success = domain.isConformant(policy) && sync.test(controller, policy) && success;
+ } else {
+ logger.info("no validator registered for policy type {}", policy.getTypeIdentifier());
+ success = sync.test(controller, policy) && success;
+ }
}
return success;
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
index ea485095..0751eb54 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
@@ -76,6 +76,10 @@ public class RestLifecycleManagerTest {
private static final String EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON =
"src/test/resources/tosca-policy-native-artifact-example.json";
+ private static final String EXAMPLE_OTHER_POLICY_NAME = "other";
+ private static final String EXAMPLE_OTHER_POLICY_JSON =
+ "src/test/resources/tosca-policy-other.json";
+
private static final String OP_POLICY_NAME_VCPE = "operational.restart";
private static final String VCPE_OPERATIONAL_DROOLS_POLICY_JSON =
"policies/vCPE.policy.operational.input.tosca.json";
@@ -231,31 +235,12 @@ public class RestLifecycleManagerTest {
if (StringUtils.isBlank(opPolicy.getName())) {
opPolicy.setName(opPolicy.getMetadata().get("policy-id"));
}
- assertTrue(
- listPost("policies/operations/validation", toString(opPolicy), Status.OK.getStatusCode()).isEmpty());
+ testNotNativePolicy(opPolicy);
- booleanPost("policies", toString(opPolicy), Status.OK.getStatusCode(), Boolean.TRUE);
- assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").isAlive());
- assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
- assertEquals(1,
- PolicyControllerConstants
- .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size());
+ /* add tosca "other" of policy type "other" with no attached type schema */
- resourceLists("policies", 3);
- get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.OK.getStatusCode());
- get("policies/example.controller/1.0.0", Status.OK.getStatusCode());
- get("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
-
- booleanDelete("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(),
- Status.OK.getStatusCode(), Boolean.TRUE);
- assertEquals(0,
- PolicyControllerConstants
- .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size());
-
- resourceLists("policies", 2);
- get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.NOT_FOUND.getStatusCode());
- get("policies/example.controller/1.0.0", Status.OK.getStatusCode());
- get("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
+ ToscaPolicy otherPolicy = getPolicyFromFile(EXAMPLE_OTHER_POLICY_JSON, EXAMPLE_OTHER_POLICY_NAME);
+ testNotNativePolicy(otherPolicy);
/* individual deploy/undeploy operations */
@@ -321,6 +306,35 @@ public class RestLifecycleManagerTest {
Status.NOT_ACCEPTABLE.getStatusCode()).isEmpty());
}
+ private void testNotNativePolicy(ToscaPolicy opPolicy) throws CoderException {
+ assertTrue(
+ listPost("policies/operations/validation", toString(opPolicy),
+ Status.OK.getStatusCode()).isEmpty());
+
+ booleanPost("policies", toString(opPolicy), Status.OK.getStatusCode(), Boolean.TRUE);
+ assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").isAlive());
+ assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained());
+ assertEquals(1,
+ PolicyControllerConstants
+ .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size());
+
+ resourceLists("policies", 3);
+ get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.OK.getStatusCode());
+ get("policies/example.controller/1.0.0", Status.OK.getStatusCode());
+ get("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
+
+ booleanDelete("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(),
+ Status.OK.getStatusCode(), Boolean.TRUE);
+ assertEquals(0,
+ PolicyControllerConstants
+ .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size());
+
+ resourceLists("policies", 2);
+ get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.NOT_FOUND.getStatusCode());
+ get("policies/example.controller/1.0.0", Status.OK.getStatusCode());
+ get("policies/example.artifact/1.0.0", Status.OK.getStatusCode());
+ }
+
private Response get(String contextPath, int statusCode) {
Response response = client.get(contextPath);
assertEquals(statusCode, response.getStatus());
diff --git a/feature-lifecycle/src/test/resources/tosca-policy-other.json b/feature-lifecycle/src/test/resources/tosca-policy-other.json
new file mode 100644
index 00000000..33aed19b
--- /dev/null
+++ b/feature-lifecycle/src/test/resources/tosca-policy-other.json
@@ -0,0 +1,22 @@
+{
+ "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+ "topology_template": {
+ "policies": [
+ {
+ "other": {
+ "type": "onap.policies.type1.type2",
+ "type_version": "1.0.0",
+ "name": "other",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "other"
+ },
+ "properties": {
+ "field1": "abc",
+ "field2": 2
+ }
+ }
+ }
+ ]
+ }
+}