aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
+ }
+ }
+ }
+ ]
+ }
+}