Preload policy types when api starts up 68/85368/3
authorChenfei Gao <cgao@research.att.com>
Mon, 15 Apr 2019 19:56:31 +0000 (15:56 -0400)
committerChenfei Gao <cgao@research.att.com>
Tue, 16 Apr 2019 14:12:30 +0000 (10:12 -0400)
Includes:
a) Preload monitoring and optimization policy types when api
component starts up
b) Fix the failure unit testing delete policy type
c) Enhance several junit test cases to be irrespective of running orders

Issue-ID: POLICY-1441
Change-Id: Ia1ba17d58dfbc9a8ee12e789e3867b20111e9cd2
Signed-off-by: Chenfei Gao <cgao@research.att.com>
18 files changed:
main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java
main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java [new file with mode: 0644]
main/src/main/java/org/onap/policy/api/main/startstop/Main.java
main/src/main/resources/preloadedPolicyTypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.AffinityPolicy.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.DistancePolicy.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.HpaPolicy.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.OptimizationPolicy.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.PciPolicy.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.QueryPolicy.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.SubscriberPolicy.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.Vim_fit.json [new file with mode: 0644]
main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.VnfPolicy.json [new file with mode: 0644]
main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
main/src/test/resources/policies/vCPE.policy.bad.policytypeversion.json
main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.json

index 1fccb06..580ba33 100644 (file)
@@ -35,6 +35,15 @@ public class PolicyApiException extends Exception {
         super(message);
     }
 
+    /**
+     * Instantiates a new policy api exception with a caused by exception.
+     *
+     * @param exp the exception that caused this exception to be thrown
+     */
+    public PolicyApiException(final Exception exp) {
+        super(exp);
+    }
+
     /**
      * Instantiates a new policy api exception with a message and a caused by exception.
      *
diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
new file mode 100644 (file)
index 0000000..3973e62
--- /dev/null
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy API
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.api.main.startstop;
+
+import java.util.ArrayList;
+import java.util.Map;
+import org.onap.policy.api.main.exception.PolicyApiException;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.provider.PolicyModelsProviderFactory;
+import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class creates initial policy types in the database.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ */
+public class ApiDatabaseInitializer {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ApiDatabaseInitializer.class);
+
+    private StandardCoder standardCoder;
+    private PolicyModelsProviderFactory factory;
+
+    private static final String[] PRELOAD_POLICYTYPES = {
+        "preloadedPolicyTypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json",
+        "preloadedPolicyTypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.json",
+        "preloadedPolicyTypes/onap.policies.optimization.AffinityPolicy.json",
+        "preloadedPolicyTypes/onap.policies.optimization.DistancePolicy.json",
+        "preloadedPolicyTypes/onap.policies.optimization.HpaPolicy.json",
+        "preloadedPolicyTypes/onap.policies.optimization.OptimizationPolicy.json",
+        "preloadedPolicyTypes/onap.policies.optimization.PciPolicy.json",
+        "preloadedPolicyTypes/onap.policies.optimization.QueryPolicy.json",
+        "preloadedPolicyTypes/onap.policies.optimization.SubscriberPolicy.json",
+        "preloadedPolicyTypes/onap.policies.optimization.Vim_fit.json",
+        "preloadedPolicyTypes/onap.policies.optimization.VnfPolicy.json"
+    };
+
+    /**
+     * Constructs the object.
+     */
+    public ApiDatabaseInitializer() {
+        factory = new PolicyModelsProviderFactory();
+        standardCoder = new StandardCoder();
+    }
+
+    /**
+     * Initializes database by preloading policy types.
+     *
+     * @param policyModelsProviderParameters the database parameters
+     * @throws PolicyApiException in case of errors.
+     */
+    public void initializeApiDatabase(final PolicyModelsProviderParameters policyModelsProviderParameters)
+            throws PolicyApiException {
+
+        try (PolicyModelsProvider databaseProvider =
+                factory.createPolicyModelsProvider(policyModelsProviderParameters)) {
+            ToscaServiceTemplate policyTypes = new ToscaServiceTemplate();
+            policyTypes.setPolicyTypes(new ArrayList<Map<String,ToscaPolicyType>>());
+            policyTypes.setToscaDefinitionsVersion("tosca_simple_yaml_1_0_0");
+            for (String pt : PRELOAD_POLICYTYPES) {
+                String policyTypeAsString = ResourceUtils.getResourceAsString(pt);
+                if (policyTypeAsString == null) {
+                    throw new PolicyApiException("Preloading policy type cannot be found: " + pt);
+                }
+                ToscaServiceTemplate singlePolicyType = standardCoder.decode(policyTypeAsString,
+                        ToscaServiceTemplate.class);
+                if (singlePolicyType == null) {
+                    throw new PolicyApiException("Error deserializing policy type from file: " + pt);
+                }
+                // Consolidate policy types
+                for (Map<String, ToscaPolicyType> eachPolicyType : singlePolicyType.getPolicyTypes()) {
+                    policyTypes.getPolicyTypes().add(eachPolicyType);
+                }
+            }
+            ToscaServiceTemplate createdPolicyTypes = databaseProvider.createPolicyTypes(policyTypes);
+            if (createdPolicyTypes == null) {
+                throw new PolicyApiException("Error preloading policy types: " + policyTypes);
+            } else {
+                LOGGER.debug("Created initial policy types in DB - {}", createdPolicyTypes);
+            }
+        } catch (final PfModelException | CoderException exp) {
+            throw new PolicyApiException(exp);
+        }
+    }
+}
index 97d53ad..4a0fead 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- * ONAP Policy API 
- * ================================================================================ 
+ * ONAP Policy API
+ * ================================================================================
  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
  *
  */
 public class Main {
-    
+
     private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
 
     // The policy api Activator that activates the policy api service
@@ -78,6 +78,14 @@ public class Main {
             return;
         }
 
+        // Initialize database
+        try {
+            new ApiDatabaseInitializer().initializeApiDatabase(parameterGroup.getDatabaseProviderParameters());
+        } catch (final PolicyApiException e) {
+            LOGGER.error("Preloading policy types into DB failed", e);
+            return;
+        }
+
         // Now, create the activator for the policy api service
         activator = new ApiActivator(parameterGroup);
 
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.monitoring.cdap.tca.hi.lo.app.json
new file mode 100644 (file)
index 0000000..1d1a4d6
--- /dev/null
@@ -0,0 +1,223 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Monitoring": {
+                "derived_from": "tosca.policies.Root",
+                "description": "a base policy type for all policies that governs monitoring provisioning"
+            }
+        },
+        {
+            "onap.policies.monitoring.cdap.tca.hi.lo.app": {
+                "derived_from": "onap.policies.Monitoring",
+                "version": "1.0.0",
+                "properties": {
+                    "tca_policy": {
+                        "type": "map",
+                        "description": "TCA Policy JSON",
+                        "entry_schema": {
+                            "type": "onap.datatypes.monitoring.tca_policy"
+                        }
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "onap.datatypes.monitoring.metricsPerEventName": {
+                "derived_from": "tosca.datatypes.Root",
+                "properties": {
+                    "controlLoopSchemaType": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "VM",
+                                    "VNF"
+                                ]
+                            }
+                        ]
+                    },
+                    "eventName": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Event name to which thresholds need to be applied"
+                    },
+                    "policyName": {
+                        "type": "string",
+                        "required": true,
+                        "description": "TCA Policy Scope Name"
+                    },
+                    "policyScope": {
+                        "type": "string",
+                        "required": true,
+                        "description": "TCA Policy Scope"
+                    },
+                    "policyVersion": {
+                        "type": "string",
+                        "required": true,
+                        "description": "TCA Policy Scope Version"
+                    },
+                    "thresholds": {
+                        "type": "list",
+                        "required": true,
+                        "description": "Thresholds associated with eventName",
+                        "entry_schema": {
+                            "type": "onap.datatypes.monitoring.thresholds"
+                        }
+                    }
+                }
+            }
+        },
+        {
+            "onap.datatypes.monitoring.tca_policy": {
+                "derived_from": "tosca.datatypes.Root",
+                "properties": {
+                    "domain": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Domain name to which TCA needs to be applied",
+                        "default": "measurementsForVfScaling",
+                        "constraints": [
+                            {
+                                "equal": "measurementsForVfScaling"
+                            }
+                        ]
+                    },
+                    "metricsPerEventName": {
+                        "type": "list",
+                        "required": true,
+                        "description": "Contains eventName and threshold details that need to be applied to given eventName",
+                        "entry_schema": {
+                            "type": "onap.datatypes.monitoring.metricsPerEventName"
+                        }
+                    }
+                }
+            }
+        },
+        {
+            "onap.datatypes.monitoring.thresholds": {
+                "derived_from": "tosca.datatypes.Root",
+                "properties": {
+                    "closedLoopControlName": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Closed Loop Control Name associated with the threshold"
+                    },
+                    "closedLoopEventStatus": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Closed Loop Event Status of the threshold",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "ONSET",
+                                    "ABATED"
+                                ]
+                            }
+                        ]
+                    },
+                    "direction": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Direction of the threshold",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "LESS",
+                                    "LESS_OR_EQUAL",
+                                    "GREATER",
+                                    "GREATER_OR_EQUAL",
+                                    "EQUAL"
+                                ]
+                            }
+                        ]
+                    },
+                    "fieldPath": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Json field Path as per CEF message which needs to be analyzed for TCA",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedOctetsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedUnicastPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedMulticastPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedDiscardedPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedErrorPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsDelta",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedTotalPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedOctetsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedUnicastPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedMulticastPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedBroadcastPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedDiscardedPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].transmittedErrorPacketsAccumulated",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuIdle",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageInterrupt",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageNice",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSoftIrq",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSteal",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuUsageSystem",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].cpuWait",
+                                    "$.event.measurementsForVfScalingFields.cpuUsageArray[*].percentUsage",
+                                    "$.event.measurementsForVfScalingFields.meanRequestLatency",
+                                    "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryBuffered",
+                                    "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryCached",
+                                    "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryConfigured",
+                                    "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryFree",
+                                    "$.event.measurementsForVfScalingFields.memoryUsageArray[*].memoryUsed",
+                                    "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value"
+                                ]
+                            }
+                        ]
+                    },
+                    "severity": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Threshold Event Severity",
+                        "constraints": [
+                            {
+                                "valid_values": [
+                                    "CRITICAL",
+                                    "MAJOR",
+                                    "MINOR",
+                                    "WARNING",
+                                    "NORMAL"
+                                ]
+                            }
+                        ]
+                    },
+                    "thresholdValue": {
+                        "type": "integer",
+                        "required": true,
+                        "description": "Threshold value for the field Path inside CEF message"
+                    },
+                    "version": {
+                        "type": "string",
+                        "required": true,
+                        "description": "Version number associated with the threshold"
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.json
new file mode 100644 (file)
index 0000000..26f4c02
--- /dev/null
@@ -0,0 +1,28 @@
+{
+  "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+  "policy_types": [
+    {
+      "onap.policies.Monitoring": {
+        "derived_from": "tosca.policies.Root",
+        "description": "a base policy type for all policies that govern monitoring provision",
+        "version": "1.0.0"
+      }
+    },
+    {
+      "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server": {
+        "derived_from": "policy.nodes.Root",
+        "version": "1.0.0",
+        "properties": {
+          "buscontroller_feed_publishing_endpoint": {
+            "type": "string",
+            "description": "DMAAP Bus Controller feed endpoint"
+          },
+          "datafile.policy": {
+            "type": "string",
+            "description": "datafile Policy JSON as string"
+          }
+        }
+      }
+    }
+  ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.AffinityPolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.AffinityPolicy.json
new file mode 100644 (file)
index 0000000..ad4f4a9
--- /dev/null
@@ -0,0 +1,102 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.AffinityPolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "zone"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "applicableResources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "any",
+                                        "all"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "affinityProperties": {
+                        "type": "policy.data.affinityProperties_properties",
+                        "required": true
+                    },
+                    "resources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.affinityProperties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "qualifier": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "same",
+                                        "different"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "category": {
+                        "type": "string",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.DistancePolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.DistancePolicy.json
new file mode 100644 (file)
index 0000000..1291817
--- /dev/null
@@ -0,0 +1,132 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.DistancePolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "distance_to_location"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "resources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "applicableResources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "any",
+                                        "all"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "distanceProperties": {
+                        "type": "policy.data.distanceProperties_properties",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.distanceProperties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "locationInfo": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "distance": {
+                        "type": "policy.data.distance_properties",
+                        "required": true
+                    }
+                }
+            },
+            "policy.data.distance_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "value": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "operator": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "<",
+                                        "<=",
+                                        ">",
+                                        ">=",
+                                        "="
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "unit": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "km"
+                                    ]
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.HpaPolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.HpaPolicy.json
new file mode 100644 (file)
index 0000000..3f42873
--- /dev/null
@@ -0,0 +1,204 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.HpaPolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "hpa"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "resources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "flavorFeatures": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.flavorFeatures_properties"
+                        }
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.flavorFeatures_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "id": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "type": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "directives": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.directives_properties"
+                        }
+                    },
+                    "flavorProperties": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.flavorProperties_properties"
+                        }
+                    }
+                }
+            }
+        },
+        {
+            "policy.data.directives_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "type": {
+                        "type": "string"
+                    },
+                    "attributes": {
+                        "type": "list",
+                        "entry_schema": {
+                            "type": "policy.data.directives_attributes_properties"
+                        }
+                    }
+                }
+            }
+        },
+        {
+            "policy.data.directives_attributes_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "attribute_name": {
+                        "type": "string"
+                    },
+                    "attribute_value": {
+                        "type": "string"
+                    }
+                }
+            }
+        },
+        {
+            "policy.data.flavorProperties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "hpa-feature": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "mandatory": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "score": {
+                        "type": "string",
+                        "required": false
+                    },
+                    "architecture": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "hpa-version": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "directives": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.directives_properties"
+                        }
+                    },
+                    "hpa-feature-attributes": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.hpa-feature-attributes_properties"
+                        }
+                    }
+                }
+            }
+        },
+        {
+            "policy.data.hpa-feature-attributes_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "hpa-attribute-key": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "hpa-attribute-value": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "operator": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "<",
+                                        "<=",
+                                        ">",
+                                        ">=",
+                                        "=",
+                                        "!=",
+                                        "any",
+                                        "all",
+                                        "subset"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "unit": {
+                        "type": "string",
+                        "required": false
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.OptimizationPolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.OptimizationPolicy.json
new file mode 100644 (file)
index 0000000..9807d9b
--- /dev/null
@@ -0,0 +1,140 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.OptimizationPolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "placement_optimization"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "objective": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "minimize",
+                                        "maximize"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "objectiveParameter": {
+                        "type": "policy.data.objectiveParameter_properties",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.objectiveParameter_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "parameterAttributes": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.parameterAttributes_properties"
+                        }
+                    },
+                    "operator": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "*",
+                                        "+",
+                                        "-",
+                                        "/",
+                                        "%"
+                                    ]
+                                }
+                            ]
+                        }
+                    }
+                }
+            },
+            "policy.data.parameterAttributes_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "resources": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "customerLocationInfo": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "parameter": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "weight": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "operator": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "*",
+                                        "+",
+                                        "-",
+                                        "/",
+                                        "%"
+                                    ]
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.PciPolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.PciPolicy.json
new file mode 100644 (file)
index 0000000..d775f22
--- /dev/null
@@ -0,0 +1,91 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.PciPolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "pciPolicy"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "resources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "pciProperties": {
+                        "type": "list",
+                        "required": false,
+                        "entry_schema": {
+                            "type": "policy.data.pciProperties_properties"
+                        }
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.pciProperties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "algoCategory": {
+                        "type": "string",
+                        "required": false
+                    },
+                    "pciOptmizationAlgoName": {
+                        "type": "string",
+                        "required": false
+                    },
+                    "pciOptimizationNwConstraint": {
+                        "type": "string",
+                        "required": false
+                    },
+                    "pciOptimizationPriority": {
+                        "type": "string",
+                        "required": false
+                    },
+                    "pciOptimizationTimeConstraint": {
+                        "type": "string",
+                        "required": false
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.QueryPolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.QueryPolicy.json
new file mode 100644 (file)
index 0000000..d784268
--- /dev/null
@@ -0,0 +1,76 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.QueryPolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "request_param_query"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "queryProperties": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.queryProperties_properties"
+                        }
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.queryProperties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "attribute": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "value": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "attribute_location": {
+                        "type": "string",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.SubscriberPolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.SubscriberPolicy.json
new file mode 100644 (file)
index 0000000..fbc6cdb
--- /dev/null
@@ -0,0 +1,82 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.SubscriberPolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "subscriberPolicy"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "properties": {
+                        "type": "policy.data.properties_properties",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.properties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "subscriberName": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "subscriberRole": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "provStatus": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.Vim_fit.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.Vim_fit.json
new file mode 100644 (file)
index 0000000..6ef619a
--- /dev/null
@@ -0,0 +1,91 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.Vim_fit": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "vim_fit"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "applicableResources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "any",
+                                        "all"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "resources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "capacityProperties": {
+                        "type": "policy.data.capacityProperties_properties",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.capacityProperties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "controller": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "request": {
+                        "type": "string",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
diff --git a/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.VnfPolicy.json b/main/src/main/resources/preloadedPolicyTypes/onap.policies.optimization.VnfPolicy.json
new file mode 100644 (file)
index 0000000..6e46573
--- /dev/null
@@ -0,0 +1,115 @@
+{
+    "tosca_definitions_version": "tosca_simple_yaml_1_0_0",
+    "policy_types": [
+        {
+            "onap.policies.Optimization": {
+                "derived_from": "tosca.policies.Root",
+                "version": "1.0.0",
+                "description": "a base policy type for all policies that govern optimization"
+            }
+        },
+        {
+            "onap.policies.optimization.VnfPolicy": {
+                "derived_from": "onap.policies.Optimization",
+                "properties": {
+                    "policyScope": {
+                        "type": "list",
+                        "description": "scope where the policy is applicable",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "policyType": {
+                        "type": "list",
+                        "description": "type of a policy",
+                        "required": true,
+                        "matchable": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "vnfPolicy"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "identity": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "resources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string"
+                        }
+                    },
+                    "applicableResources": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "any",
+                                        "all"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "vnfProperties": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "policy.data.vnfProperties_properties"
+                        }
+                    }
+                }
+            }
+        }
+    ],
+    "data_types": [
+        {
+            "policy.data.vnfProperties_properties": {
+                "derived_from": "tosca.nodes.Root",
+                "properties": {
+                    "inventoryProvider": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "serviceType": {
+                        "type": "string",
+                        "required": true
+                    },
+                    "inventoryType": {
+                        "type": "list",
+                        "required": true,
+                        "entry_schema": {
+                            "type": "string",
+                            "constraints": [
+                                {
+                                    "valid_values": [
+                                        "serviceInstanceId",
+                                        "vnfName",
+                                        "cloudRegionId",
+                                        "vimId"
+                                    ]
+                                }
+                            ]
+                        }
+                    },
+                    "customerId": {
+                        "type": "string",
+                        "required": true
+                    }
+                }
+            }
+        }
+    ]
+}
\ No newline at end of file
index 653f467..0ae718d 100644 (file)
@@ -170,6 +170,22 @@ public class TestPolicyProvider {
             policyProvider.deletePolicy("dummy", "dummy", "dummy", "dummy");
         }).hasMessage("policy with ID dummy:dummy and type dummy:dummy does not exist");
 
+        assertThatCode(() -> {
+            String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+            ToscaServiceTemplate policyTypeServiceTemplate =
+                    standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+            policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+        }).doesNotThrowAnyException();
+
+        assertThatCode(() -> {
+            String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+            ToscaServiceTemplate policyServiceTemplate =
+                    standardCoder.decode(policyString, ToscaServiceTemplate.class);
+            ToscaServiceTemplate serviceTemplate = policyProvider
+                    .createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
+            assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
+        }).doesNotThrowAnyException();
+
         assertThatCode(() -> {
             ToscaServiceTemplate serviceTemplate = policyProvider.deletePolicy(
                     "onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
index 9dc7726..03d4933 100644 (file)
@@ -128,6 +128,14 @@ public class TestPolicyTypeProvider {
     @Test
     public void testDeletePolicyType() {
 
+        assertThatCode(() -> {
+            String policyTypeString = ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE);
+            ToscaServiceTemplate policyTypeServiceTemplate =
+                    standardCoder.decode(policyTypeString, ToscaServiceTemplate.class);
+            ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+            assertFalse(serviceTemplate.getPolicyTypes().get(0).isEmpty());
+        }).doesNotThrowAnyException();
+
         assertThatCode(() -> {
             String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
             ToscaServiceTemplate policyServiceTemplate =
index 638a4e1..23195a9 100644 (file)
@@ -6,7 +6,7 @@
                 "onap.restart.tca": {
                     "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
                     "version": "1.0.0",
-                    "typeVersion": "2.0.0",
+                    "type_version": "2.0.0",
                     "metadata": {
                         "policy-id": "onap.restart.tca"
                     },
index 0eabb57..7a63f65 100644 (file)
@@ -6,6 +6,7 @@
                 "onap.restart.tca": {
                     "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
                     "version": "1.0.0",
+                    "type_version": "1.0.0",
                     "metadata": {
                         "policy-id": "onap.restart.tca"
                     },