Modify policy provider to support GET/CREATE 53/84453/6
authorChenfei Gao <cgao@research.att.com>
Mon, 8 Apr 2019 01:33:02 +0000 (21:33 -0400)
committerChenfei Gao <cgao@research.att.com>
Wed, 10 Apr 2019 01:41:41 +0000 (21:41 -0400)
Modify policy and policy type providers to better
support GET/CREATE policy/policy types.

Issue-ID: POLICY-1442
Change-Id: I7a513be4f9dbd5b48b85a948e3bda7b6c6ab7ddb
Signed-off-by: Chenfei Gao <cgao@research.att.com>
15 files changed:
main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
main/src/main/resources/META-INF/persistence.xml
main/src/test/resources/META-INF/persistence.xml
main/src/test/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.PciPolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.Vim_fit.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml [new file with mode: 0644]
main/src/test/resources/policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.json
main/src/test/resources/policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml

index d7f152e..1cb3af5 100644 (file)
@@ -22,6 +22,8 @@
 \r
 package org.onap.policy.api.main.rest.provider;\r
 \r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
 import javax.ws.rs.core.Response;\r
@@ -31,6 +33,7 @@ import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.models.base.PfModelException;\r
 import org.onap.policy.models.pdp.concepts.PdpGroup;\r
 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;\r
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;\r
 import org.onap.policy.models.provider.PolicyModelsProvider;\r
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;\r
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;\r
@@ -74,20 +77,16 @@ public class PolicyProvider {
     public ToscaServiceTemplate fetchPolicies(String policyTypeId, String policyTypeVersion,\r
             String policyId, String policyVersion) throws PfModelException {\r
 \r
-        validatePolicyTypeExist(policyTypeId, policyTypeVersion);\r
+        ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder()\r
+                .name(policyId).version(policyVersion)\r
+                .type(policyTypeId).typeVersion(policyTypeVersion).build();\r
+        ToscaServiceTemplate serviceTemplate = modelsProvider.getFilteredPolicies(policyFilter);\r
 \r
-        ToscaServiceTemplate serviceTemplate;\r
-        if (policyId == null || policyVersion == null) {\r
-            ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder()\r
-                    .name(policyId).version(policyVersion)\r
-                    .type(policyTypeId).typeVersion(policyTypeVersion).build();\r
-            serviceTemplate = modelsProvider.getFilteredPolicies(policyFilter);\r
-        } else {\r
-            serviceTemplate = modelsProvider.getPolicies(policyId, policyVersion);\r
+        if (!hasPolicy(serviceTemplate)) {\r
+            throw new PfModelException(Response.Status.NOT_FOUND,\r
+                    constructResourceNotFoundMessage(policyTypeId, policyTypeVersion, policyId, policyVersion));\r
         }\r
 \r
-        validatePolicyTypeMatch(policyTypeId, policyTypeVersion, serviceTemplate);\r
-\r
         close();\r
         return serviceTemplate;\r
     }\r
@@ -106,14 +105,15 @@ public class PolicyProvider {
     public ToscaServiceTemplate fetchLatestPolicies(String policyTypeId, String policyTypeVersion,\r
             String policyId) throws PfModelException {\r
 \r
-        validatePolicyTypeExist(policyTypeId, policyTypeVersion);\r
-\r
         ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder()\r
                 .name(policyId).version(ToscaPolicyFilter.LATEST_VERSION)\r
                 .type(policyTypeId).typeVersion(policyTypeVersion).build();\r
         ToscaServiceTemplate serviceTemplate = modelsProvider.getFilteredPolicies(policyFilter);\r
 \r
-        validatePolicyTypeMatch(policyTypeId, policyTypeVersion, serviceTemplate);\r
+        if (!hasPolicy(serviceTemplate)) {\r
+            throw new PfModelException(Response.Status.NOT_FOUND,\r
+                    constructResourceNotFoundMessage(policyTypeId, policyTypeVersion, policyId, null));\r
+        }\r
 \r
         close();\r
         return serviceTemplate;\r
@@ -133,19 +133,25 @@ public class PolicyProvider {
     public Map<Pair<String, String>, List<ToscaPolicy>> fetchDeployedPolicies(\r
             String policyTypeId, String policyTypeVersion, String policyId) throws PfModelException {\r
 \r
-        validatePolicyTypeExist(policyTypeId, policyTypeVersion);\r
-\r
-        ToscaPolicyIdentifier policyIdentifier = new ToscaPolicyIdentifier();\r
-        policyIdentifier.setName(policyId);\r
-        PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder()\r
-                .policyType(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion))\r
-                .policy(policyIdentifier).build();\r
+        List<ToscaPolicyTypeIdentifier> policyTypes = new ArrayList<>();\r
+        policyTypes.add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion));\r
+        PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder().policyTypeList(policyTypes).build();\r
         List<PdpGroup> pdpGroups = modelsProvider.getFilteredPdpGroups(pdpGroupFilter);\r
 \r
-        //TODO: I don't know how to get policies matching policyId that are deployed in those PDP groups\r
+        if (pdpGroups.isEmpty()) {\r
+            throw new PfModelException(Response.Status.NOT_FOUND,\r
+                    constructDeploymentNotFoundMessage(policyTypeId, policyTypeVersion, policyId));\r
+        }\r
+\r
+        Map<Pair<String, String>, List<ToscaPolicy>> deployedPolicyMap = constructDeployedPolicyMap(\r
+                pdpGroups, policyId);\r
+        if (deployedPolicyMap.isEmpty()) {\r
+            throw new PfModelException(Response.Status.NOT_FOUND,\r
+                    constructDeploymentNotFoundMessage(policyTypeId, policyTypeVersion, policyId));\r
+        }\r
 \r
         close();\r
-        return null;\r
+        return deployedPolicyMap;\r
     }\r
 \r
     /**\r
@@ -186,17 +192,17 @@ public class PolicyProvider {
     public ToscaServiceTemplate deletePolicy(String policyTypeId, String policyTypeVersion,\r
                                  String policyId, String policyVersion) throws PfModelException {\r
 \r
-        validatePolicyTypeExist(policyTypeId, policyTypeVersion);\r
-\r
-        ToscaServiceTemplate serviceTemplate = modelsProvider.getPolicies(policyId, policyVersion);\r
-\r
-        validatePolicyTypeMatch(policyTypeId, policyTypeVersion, serviceTemplate);\r
         validateDeleteEligibility(policyTypeId, policyTypeVersion, policyId, policyVersion);\r
 \r
-        ToscaServiceTemplate deletedServiceTemplate = modelsProvider.deletePolicy(policyId, policyVersion);\r
+        ToscaServiceTemplate serviceTemplate = modelsProvider.deletePolicy(policyId, policyVersion);\r
+\r
+        if (!hasPolicy(serviceTemplate)) {\r
+            throw new PfModelException(Response.Status.NOT_FOUND,\r
+                    constructResourceNotFoundMessage(policyTypeId, policyTypeVersion, policyId, policyVersion));\r
+        }\r
 \r
         close();\r
-        return deletedServiceTemplate;\r
+        return serviceTemplate;\r
     }\r
 \r
     /**\r
@@ -230,14 +236,17 @@ public class PolicyProvider {
 \r
         List<Map<String, ToscaPolicy>> policies = serviceTemplate.getToscaTopologyTemplate().getPolicies();\r
         for (Map<String, ToscaPolicy> policy : policies) {\r
-            if (policy.size() != 1) {\r
+            if (policy.size() > 1) {\r
                 throw new PfModelException(Response.Status.BAD_REQUEST,\r
                         "one policy block contains more than one policies");\r
             }\r
             ToscaPolicy policyContent = policy.values().iterator().next();\r
-            if (!policyTypeId.equalsIgnoreCase(policyContent.getType())\r
-                    || !policyTypeVersion.equalsIgnoreCase(policyContent.getTypeVersion())) {\r
-                throw new PfModelException(Response.Status.BAD_REQUEST, "policy type does not match");\r
+            if (!policyTypeId.equalsIgnoreCase(policyContent.getType())) {\r
+                throw new PfModelException(Response.Status.BAD_REQUEST, "policy type id does not match");\r
+            }\r
+            if (policyContent.getTypeVersion() != null\r
+                    && !policyTypeVersion.equalsIgnoreCase(policyContent.getTypeVersion())) {\r
+                throw new PfModelException(Response.Status.BAD_REQUEST, "policy type version does not match");\r
             }\r
         }\r
     }\r
@@ -255,16 +264,101 @@ public class PolicyProvider {
     private void validateDeleteEligibility(String policyTypeId, String policyTypeVersion,\r
             String policyId, String policyVersion) throws PfModelException {\r
 \r
+        List<ToscaPolicyTypeIdentifier> policyTypes = new ArrayList<>();\r
+        policyTypes.add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion));\r
+        List<ToscaPolicyIdentifier> policies = new ArrayList<>();\r
+        policies.add(new ToscaPolicyIdentifier(policyId, policyVersion));\r
         PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder()\r
-                .policyType(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion))\r
-                .policy(new ToscaPolicyIdentifier(policyId, policyVersion)).build();\r
+                .policyTypeList(policyTypes).policyList(policies).build();\r
 \r
         List<PdpGroup> pdpGroups = modelsProvider.getFilteredPdpGroups(pdpGroupFilter);\r
+\r
         if (!pdpGroups.isEmpty()) {\r
             throw new PfModelException(Response.Status.CONFLICT, "the policy has been deployed in pdp group");\r
         }\r
     }\r
 \r
+    private Map<Pair<String, String>, List<ToscaPolicy>> constructDeployedPolicyMap(\r
+            List<PdpGroup> pdpGroups, String policyId) throws PfModelException {\r
+\r
+        Map<Pair<String, String>, List<ToscaPolicy>> deployedPolicyMap = new HashMap<>();\r
+        for (PdpGroup pdpGroup : pdpGroups) {\r
+            List<ToscaPolicyIdentifier> policyIdentifiers = new ArrayList<>();\r
+            for (PdpSubGroup pdpSubGroup : pdpGroup.getPdpSubgroups()) {\r
+                for (ToscaPolicyIdentifier policyIdentifier : pdpSubGroup.getPolicies()) {\r
+                    if (policyId.equalsIgnoreCase(policyIdentifier.getName())) {\r
+                        policyIdentifiers.add(policyIdentifier);\r
+                    }\r
+                }\r
+            }\r
+            List<ToscaPolicy> deployedPolicies = new ArrayList<>();\r
+            if (!policyIdentifiers.isEmpty()) {\r
+                for (ToscaPolicyIdentifier policyIdentifier : policyIdentifiers) {\r
+                    deployedPolicies.addAll(\r
+                            modelsProvider.getPolicyList(policyIdentifier.getName(), policyIdentifier.getVersion()));\r
+                }\r
+            }\r
+            if (!deployedPolicies.isEmpty()) {\r
+                deployedPolicyMap.put(Pair.of(pdpGroup.getName(), pdpGroup.getVersion()), deployedPolicies);\r
+            }\r
+        }\r
+        return deployedPolicyMap;\r
+    }\r
+\r
+    /**\r
+     * Constructs returned message for not found resource.\r
+     *\r
+     * @param policyTypeId the ID of policy type\r
+     * @param policyTypeVersion the version of policy type\r
+     * @param policyId the ID of policy\r
+     * @param policyVersion the version of policy\r
+     *\r
+     * @return constructed message\r
+     */\r
+    private String constructResourceNotFoundMessage(String policyTypeId, String policyTypeVersion,\r
+            String policyId, String policyVersion) {\r
+\r
+        return "policy with ID " + policyId + ":" + policyVersion\r
+                + " and type " + policyTypeId + ":" + policyTypeVersion + " does not exist";\r
+    }\r
+\r
+    /**\r
+     * Constructs returned message for not found policy deployment.\r
+     *\r
+     * @param policyTypeId the ID of policy type\r
+     * @param policyTypeVersion the version of policy type\r
+     * @param policyId the ID of policy\r
+     * @param policyVersion the version of policy\r
+     *\r
+     * @return constructed message\r
+     */\r
+    private String constructDeploymentNotFoundMessage(String policyTypeId, String policyTypeVersion,\r
+            String policyId) {\r
+\r
+        return "could not find policy with ID " + policyId + " and type "\r
+                + policyTypeId + ":" + policyTypeVersion + " deployed in any pdp group";\r
+    }\r
+\r
+    /**\r
+     * Checks if service template contains any policy.\r
+     *\r
+     * @param serviceTemplate the service template to check against\r
+     *\r
+     * @return boolean whether service template contains any policy\r
+     */\r
+    private boolean hasPolicy(ToscaServiceTemplate serviceTemplate) {\r
+\r
+        if (serviceTemplate.getToscaTopologyTemplate().getPolicies() == null) {\r
+            return false;\r
+        } else if (serviceTemplate.getToscaTopologyTemplate().getPolicies().isEmpty()) {\r
+            return false;\r
+        } else if (serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty()) {\r
+            return false;\r
+        } else {\r
+            return true;\r
+        }\r
+    }\r
+\r
     /**\r
      * Closes the connection to database.\r
      *\r
index 8fab2bd..19f3a75 100644 (file)
@@ -27,13 +27,12 @@ import javax.ws.rs.core.Response;
 import org.onap.policy.api.main.parameters.ApiParameterGroup;\r
 import org.onap.policy.common.parameters.ParameterService;\r
 import org.onap.policy.models.base.PfModelException;\r
-import org.onap.policy.models.pdp.concepts.PdpGroup;\r
-import org.onap.policy.models.pdp.concepts.PdpGroupFilter;\r
 import org.onap.policy.models.provider.PolicyModelsProvider;\r
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;\r
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;\r
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;\r
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;\r
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;\r
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;\r
 \r
 /**\r
@@ -68,13 +67,13 @@ public class PolicyTypeProvider {
     public ToscaServiceTemplate fetchPolicyTypes(String policyTypeId, String policyTypeVersion)\r
             throws PfModelException {\r
 \r
-        ToscaServiceTemplate serviceTemplate;\r
-        if (policyTypeId == null || policyTypeVersion == null) {\r
-            ToscaPolicyTypeFilter policyTypeFilter = ToscaPolicyTypeFilter.builder()\r
-                    .name(policyTypeId).version(policyTypeVersion).build();\r
-            serviceTemplate = modelsProvider.getFilteredPolicyTypes(policyTypeFilter);\r
-        } else {\r
-            serviceTemplate = modelsProvider.getPolicyTypes(policyTypeId, policyTypeVersion);\r
+        ToscaPolicyTypeFilter policyTypeFilter = ToscaPolicyTypeFilter.builder()\r
+                .name(policyTypeId).version(policyTypeVersion).build();\r
+        ToscaServiceTemplate serviceTemplate = modelsProvider.getFilteredPolicyTypes(policyTypeFilter);\r
+\r
+        if (policyTypeId != null && !hasPolicyType(serviceTemplate)) {\r
+            throw new PfModelException(Response.Status.NOT_FOUND,\r
+                    constructResourceNotFoundMessage(policyTypeId, policyTypeVersion));\r
         }\r
 \r
         close();\r
@@ -95,6 +94,10 @@ public class PolicyTypeProvider {
         ToscaPolicyTypeFilter policyTypeFilter = ToscaPolicyTypeFilter.builder()\r
                 .name(policyTypeId).version(ToscaPolicyTypeFilter.LATEST_VERSION).build();\r
         ToscaServiceTemplate serviceTemplate = modelsProvider.getFilteredPolicyTypes(policyTypeFilter);\r
+        if (serviceTemplate.getPolicyTypes().isEmpty()) {\r
+            throw new PfModelException(Response.Status.NOT_FOUND,\r
+                    constructResourceNotFoundMessage(policyTypeId, null));\r
+        }\r
 \r
         close();\r
         return serviceTemplate;\r
@@ -143,20 +146,50 @@ public class PolicyTypeProvider {
      *\r
      * @param policyTypeId the ID of policy type\r
      * @param policyTypeVersion the version of policy type\r
-     * @param policyId the ID of policy\r
-     * @param policyVersion the version of policy\r
      *\r
      * @throws PfModelException the PfModel parsing exception\r
      */\r
     private void validateDeleteEligibility(String policyTypeId, String policyTypeVersion) throws PfModelException {\r
 \r
-        PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder()\r
-                .policyType(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion)).build();\r
-\r
-        List<PdpGroup> pdpGroups = modelsProvider.getFilteredPdpGroups(pdpGroupFilter);\r
-        if (!pdpGroups.isEmpty()) {\r
+        ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder()\r
+                .type(policyTypeId).typeVersion(policyTypeVersion).build();\r
+        List<ToscaPolicy> policies = modelsProvider.getFilteredPolicyList(policyFilter);\r
+        if (!policies.isEmpty()) {\r
             throw new PfModelException(Response.Status.CONFLICT,\r
-                    "the policy type is parameterized by at least one policies that have been deployed in pdp group");\r
+                    "the policy type has been parameterized by at least one policies");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Constructs returned message for not found resource.\r
+     *\r
+     * @param policyTypeId the ID of policy type\r
+     * @param policyTypeVersion the version of policy type\r
+     *\r
+     * @return constructed message\r
+     */\r
+    private String constructResourceNotFoundMessage(String policyTypeId, String policyTypeVersion) {\r
+\r
+        return "policy type with ID " + policyTypeId + ":" + policyTypeVersion + " does not exist";\r
+    }\r
+\r
+    /**\r
+     * Checks if service template contains any policy type.\r
+     *\r
+     * @param serviceTemplate the service template to check against\r
+     *\r
+     * @return boolean whether service template contains any policy type\r
+     */\r
+    private boolean hasPolicyType(ToscaServiceTemplate serviceTemplate) {\r
+\r
+        if (serviceTemplate.getPolicyTypes() == null) {\r
+            return false;\r
+        } else if (serviceTemplate.getPolicyTypes().isEmpty()) {\r
+            return false;\r
+        } else if (serviceTemplate.getPolicyTypes().get(0).isEmpty()) {\r
+            return false;\r
+        } else {\r
+            return true;\r
         }\r
     }\r
 \r
@@ -166,6 +199,7 @@ public class PolicyTypeProvider {
      * @throws PfModelException the PfModel parsing exception\r
      */\r
     private void close() throws PfModelException {\r
+\r
         try {\r
             modelsProvider.close();\r
         } catch (Exception e) {\r
index 81be3db..8812ebf 100644 (file)
@@ -2,6 +2,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2019 Nordix Foundation.
+   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.
@@ -28,6 +29,9 @@
         <class>org.onap.policy.models.base.PfConceptKey</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
 
         <properties>
             <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
@@ -48,6 +52,9 @@
         <class>org.onap.policy.models.base.PfConceptKey</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
 
         <properties>
             <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
@@ -67,7 +74,7 @@
             <property name="eclipselink.logging.level.query" value="ALL" />
             <property name="eclipselink.logging.level.properties" value="ALL" /-->
 
-            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
+            <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
             <property name="eclipselink.ddl-generation.output-mode" value="database" />
             <property name="eclipselink.logging.level" value="INFO" />
         </properties>
index 23e8567..8812ebf 100644 (file)
@@ -2,6 +2,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2019 Nordix Foundation.
+   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.
@@ -28,6 +29,9 @@
         <class>org.onap.policy.models.base.PfConceptKey</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
 
         <properties>
             <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
         <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
         <class>org.onap.policy.models.dao.converters.Uuid2String</class>
         <class>org.onap.policy.models.base.PfConceptKey</class>
+        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
+        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
 
         <properties>
             <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
@@ -66,7 +74,7 @@
             <property name="eclipselink.logging.level.query" value="ALL" />
             <property name="eclipselink.logging.level.properties" value="ALL" /-->
 
-            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
+            <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
             <property name="eclipselink.ddl-generation.output-mode" value="database" />
             <property name="eclipselink.logging.level" value="INFO" />
         </properties>
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml
new file mode 100644 (file)
index 0000000..415e05e
--- /dev/null
@@ -0,0 +1,63 @@
+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
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml
new file mode 100644 (file)
index 0000000..a0571bc
--- /dev/null
@@ -0,0 +1,83 @@
+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
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml
new file mode 100644 (file)
index 0000000..e9e5436
--- /dev/null
@@ -0,0 +1,136 @@
+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
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml
new file mode 100644 (file)
index 0000000..cccd0b5
--- /dev/null
@@ -0,0 +1,90 @@
+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:
+                        - '*'
+                        - +
+                        - '-'
+                        - /
+                        - '%'
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.PciPolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.PciPolicy.yaml
new file mode 100644 (file)
index 0000000..2cc6d41
--- /dev/null
@@ -0,0 +1,59 @@
+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
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml
new file mode 100644 (file)
index 0000000..7c54a8d
--- /dev/null
@@ -0,0 +1,48 @@
+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
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml
new file mode 100644 (file)
index 0000000..294dcdf
--- /dev/null
@@ -0,0 +1,52 @@
+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
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.Vim_fit.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.Vim_fit.yaml
new file mode 100644 (file)
index 0000000..e4dc500
--- /dev/null
@@ -0,0 +1,57 @@
+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
diff --git a/main/src/test/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml b/main/src/test/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml
new file mode 100644 (file)
index 0000000..009df41
--- /dev/null
@@ -0,0 +1,74 @@
+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
+
index 95d7a53..292c632 100644 (file)
@@ -8,7 +8,7 @@
       }
     },
     {
-      "onap.policy.monitoring.cdap.tca.hi.lo.app": {
+      "onap.policies.monitoring.cdap.tca.hi.lo.app": {
         "derived_from": "onap.policies.Monitoring",
         "version": "1.0.0",
         "properties": {
index f8e9b75..2985603 100644 (file)
@@ -5,7 +5,7 @@ policy_types:
         derived_from: tosca.policies.Root
         description: a base policy type for all policies that governs monitoring provisioning
   -
-    onap.policy.monitoring.cdap.tca.hi.lo.app:
+    onap.policies.monitoring.cdap.tca.hi.lo.app:
         derived_from: onap.policies.Monitoring
         version: 1.0.0
         properties: