Chenfei Gao | 55e1f55 | 2019-05-21 13:32:30 -0400 | [diff] [blame] | 1 | .. This work is licensed under a |
| 2 | .. Creative Commons Attribution 4.0 International License. |
| 3 | .. http://creativecommons.org/licenses/by/4.0 |
Pamela Dragosh | 5fc2fdb | 2019-05-17 09:42:27 -0400 | [diff] [blame] | 4 | |
Pamela Dragosh | 9fcabd0 | 2020-05-13 07:54:15 -0400 | [diff] [blame] | 5 | .. THIS IS USED INTERNALLY IN POLICY ONLY |
Pamela Dragosh | 5fc2fdb | 2019-05-17 09:42:27 -0400 | [diff] [blame] | 6 | .. _api-label: |
| 7 | |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 8 | Policy Life Cycle API |
| 9 | ##################### |
| 10 | |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 11 | 1. Policy Life Cycle API |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 12 | ======================== |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 13 | |
| 14 | 1.1 Overview |
| 15 | ------------ |
Chenfei Gao | f5f6d35 | 2019-08-23 15:50:58 -0400 | [diff] [blame] | 16 | |
| 17 | .. contents:: |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 18 | :depth: 2 |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 19 | |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 20 | The purpose of this API is to support CRUD of TOSCA *PolicyType* and *Policy* entities. This API is provided by the |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 21 | *PolicyDevelopment* component of the Policy Framework, see the :ref:`The ONAP Policy Framework Architecture |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 22 | <architecture-label>` page. The Policy design API backend is running in an independent building block component of the |
| 23 | policy framework that provides REST services for the aforementioned CRUD behaviors. The Policy design API component interacts |
| 24 | with a policy database for storing and fetching new policies or policy types as needed. Apart from CRUD, an API is also |
| 25 | exposed for clients to retrieve healthcheck status of the API REST service and statistics report including a variety of |
| 26 | counters that reflect the history of API invocation. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 27 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 28 | We strictly follow `TOSCA Specification <http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.1/TOSCA-Simple-Profile-YAML-v1.1.pdf>`_ |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 29 | to define policy types and policies. A policy type defines the schema for a policy, expressing the properties, targets, and triggers |
| 30 | that a policy may have. The type (string, int etc) and constraints (such as the range of legal values) of each property is defined |
| 31 | in the Policy Type. Both Policy Type and policy are included in a TOSCA Service Template, which is used as the entity passed into an API |
| 32 | POST call and the entity returned by API GET and DELETE calls. More details are presented in following sections. Policy Types and Policies |
| 33 | can be composed for any given domain of application. All Policy Types and Policies must be composed as well-formed TOSCA Service Templates. |
| 34 | One Service Template can contain multiple policies and policy types. |
| 35 | |
| 36 | Child policy types can inherit from parent policy types, so a hierarchy of policy types can be built up. For example, the HpaPolicy Policy |
| 37 | Type in the table below is a child of a Resource Policy Type, which is a child of an Optimization policy. |
Eric Debeau | 1d40bf6 | 2020-08-18 10:35:28 +0200 | [diff] [blame] | 38 | See also `the examples in Github <https://github.com/onap/policy-models/tree/master/models-examples/src/main/resources/policytypes>`_. |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 39 | |
| 40 | :: |
| 41 | |
| 42 | onap.policies.Optimization.yaml |
| 43 | onap.policies.optimization.Resource.yaml |
| 44 | onap.policies.optimization.resource.AffinityPolicy.yaml |
| 45 | onap.policies.optimization.resource.DistancePolicy.yaml |
| 46 | onap.policies.optimization.resource.HpaPolicy.yaml |
| 47 | onap.policies.optimization.resource.OptimizationPolicy.yaml |
| 48 | onap.policies.optimization.resource.PciPolicy.yaml |
| 49 | onap.policies.optimization.resource.Vim_fit.yaml |
| 50 | onap.policies.optimization.resource.VnfPolicy.yaml |
| 51 | onap.policies.optimization.Service.yaml |
| 52 | onap.policies.optimization.service.QueryPolicy.yaml |
| 53 | onap.policies.optimization.service.SubscriberPolicy.yaml |
| 54 | |
| 55 | Custom data types can be defined in TOSCA for properties specified in Policy Types. Data types can also inherit from parents, so a hierarchy of data types can also be built up. |
| 56 | |
| 57 | .. warning:: |
| 58 | When creating a Policy Type, the ancestors of the Policy Type and all its custom Data Type definitions and ancestors MUST either already |
| 59 | exist in the database or MUST also be defined in the incoming TOSCA Service Template. Requests with missing or bad references are rejected |
| 60 | by the API. |
| 61 | |
| 62 | Each Policy Type can have multiple Policy instances created from it. Therefore, many Policy instances of the HpaPolicy Policy Type above can be created. When a policy is created, its Policy Type is specified in the *type* and *type_version* fields of the policy. |
| 63 | |
| 64 | .. warning:: |
| 65 | The Policy Type specified for a Policy MUST exist in the database before the policy can be created. Requests with missing or bad |
| 66 | Policy Type references are rejected by the API. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 67 | |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 68 | The API allows applications to create, update, delete, and query *PolicyType* entities so that they become available for |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 69 | use in ONAP by applications such as CLAMP. Some Policy Type entities are preloaded in the Policy Framework. |
| 70 | |
| 71 | .. warning:: |
| 72 | If a TOSCA entity (Data Type, Policy Type, or Policy with a certain version) already exists in the database and an attempt is made |
| 73 | to re-create the entity with different fields, the API will reject the request with the error message "entity in incoming fragment |
| 74 | does not equal existing entity". In such cases, delete the Policy or Policy Type and re-create it using the API. |
| 75 | |
| 76 | |
| 77 | The TOSCA fields below are valid on API calls: |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 78 | |
| 79 | ============ ======= ======== ========== =============================================================================== |
| 80 | **Field** **GET** **POST** **DELETE** **Comment** |
| 81 | ============ ======= ======== ========== =============================================================================== |
| 82 | (name) M M M The definition of the reference to the Policy Type, GET allows ranges to be |
| 83 | specified |
| 84 | version O M C GET allows ranges to be specified, must be specified if more than one version |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 85 | of the Policy Type exists and a specific version is required |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 86 | description R O N/A Desciption of the Policy Type |
| 87 | derived_from R C N/A Must be specified when a Policy Type is derived from another Policy Type such |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 88 | as in the case of derived Monitoring Policy Types. The referenced Policy Type |
| 89 | must either already exist in the database or be defined as another policy type |
| 90 | in the incoming TOSCA service template |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 91 | metadata R O N/A Metadata for the Policy Type |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 92 | properties R M N/A This field holds the specification of the specific Policy Type in ONAP. Any user |
| 93 | defined data types specified on properties must either already exist in the |
| 94 | database or be defined in the incoming TOSCA service template |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 95 | targets R O N/A A list of node types and/or group types to which the Policy Type can be applied |
| 96 | triggers R O N/A Specification of policy triggers, not currently supported in ONAP |
| 97 | ============ ======= ======== ========== =============================================================================== |
| 98 | |
| 99 | .. note:: |
| 100 | On this and subsequent tables, use the following legend: M-Mandatory, O-Optional, R-Read-only, C-Conditional. |
| 101 | Conditional means the field is mandatory when some other field is present. |
| 102 | |
| 103 | .. note:: |
| 104 | Preloaded policy types may only be queried over this API, modification or deletion of preloaded policy type |
| 105 | implementations is disabled. |
| 106 | |
| 107 | .. note:: |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 108 | Policy types that are in use (referenced by defined Policies and/or child policy types) may not be deleted. |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 109 | |
| 110 | .. note:: |
| 111 | The group types of targets in TOSCA are groups of TOSCA nodes, not PDP groups; the *target* concept in TOSCA is |
| 112 | equivalent to the Policy Enforcement Point (PEP) concept |
| 113 | |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 114 | 1.2 Preloaded policy types and policies |
| 115 | --------------------------------------- |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 116 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 117 | To ease policy creation, we preload several widely used policy types in policy database. Below is a table listing the preloaded policy types. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 118 | |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 119 | .. _policy-preload-label: |
| 120 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 121 | .. csv-table:: |
Chenfei Gao | 0a85b8b | 2019-09-10 22:22:17 -0400 | [diff] [blame] | 122 | :header: "Policy Type Name", "Payload" |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 123 | :widths: 15,10 |
| 124 | |
Pamela Dragosh | 5631660 | 2020-08-20 09:16:20 -0400 | [diff] [blame] | 125 | "Monitoring.TCA", `onap.policies.monitoring.tcagen2.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.monitoring.tcagen2.yaml>`_ |
Chenfei Gao | dfbc0ad | 2019-10-01 14:19:39 -0400 | [diff] [blame] | 126 | "Monitoring.Collectors", `onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml>`_ |
| 127 | "Optimization", `onap.policies.Optimization.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.Optimization.yaml>`_ |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 128 | "Optimization.Resource", `onap.policies.optimization.Resource.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.Resource.yaml>`_ |
| 129 | "Optimization.Resource.AffinityPolicy", `onap.policies.optimization.resource.AffinityPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml>`_ |
| 130 | "Optimization.Resource.DistancePolicy", `onap.policies.optimization.resource.DistancePolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.resource.DistancePolicy.yaml>`_ |
| 131 | "Optimization.Resource.HpaPolicy", `onap.policies.optimization.resource.HpaPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.resource.HpaPolicy.yaml>`_ |
| 132 | "Optimization.Resource.OptimizationPolicy", `onap.policies.optimization.resource.OptimizationPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.resource.OptimizationPolicy.yaml>`_ |
| 133 | "Optimization.Resource.PciPolicy", `onap.policies.optimization.resource.PciPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.resource.PciPolicy.yaml>`_ |
| 134 | "Optimization.Resource.Vim_fit", `onap.policies.optimization.resource.Vim_fit.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.resource.Vim_fit.yaml>`_ |
| 135 | "Optimization.Resource.VnfPolicy", `onap.policies.optimization.resource.VnfPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.resource.VnfPolicy.yaml>`_ |
| 136 | "Optimization.Service", `onap.policies.optimization.Service.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.Service.yaml>`_ |
| 137 | "Optimization.Service.QueryPolicy", `onap.policies.optimization.service.QueryPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.service.QueryPolicy.yaml>`_ |
| 138 | "Optimization.Service.SubscriberPolicy", `onap.policies.optimization.service.SubscriberPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml>`_ |
| 139 | "Controlloop.Guard.Common", `onap.policies.controlloop.guard.Common.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.Common.yaml>`_ |
| 140 | "Controlloop.Guard.Common.Blacklist", `onap.policies.controlloop.guard.common.Blacklist.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.Blacklist.yaml>`_ |
| 141 | "Controlloop.Guard.Common.FrequencyLimiter", `onap.policies.controlloop.guard.common.FrequencyLimiter.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.FrequencyLimiter.yaml>`_ |
| 142 | "Controlloop.Guard.Common.MinMax", `onap.policies.controlloop.guard.common.MinMax.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.MinMax.yaml>`_ |
Pamela Dragosh | cc6265e | 2020-08-21 10:53:44 -0400 | [diff] [blame] | 143 | "Controlloop.Guard.Common.Filter", `onap.policies.controlloop.guard.common.Filter.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.common.Filter.yaml>`_ |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 144 | "Controlloop.Guard.Coordination.FirstBlocksSecond", `onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.coordination.FirstBlocksSecond.yaml>`_ |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 145 | "Controlloop.Operational.Common", `onap.policies.controlloop.operational.Common.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.Common.yaml>`_ |
| 146 | "Controlloop.Operational.Common.Apex", `onap.policies.controlloop.operational.common.Apex.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Apex.yaml>`_ |
| 147 | "Controlloop.Operational.Common.Drools", `onap.policies.controlloop.operational.common.Drools.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.operational.common.Drools.yaml>`_ |
| 148 | "Naming", `onap.policies.Naming.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.Naming.yaml>`_ |
| 149 | "Native.Drools", `onap.policies.native.Drools.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.native.Drools.yaml>`_ |
| 150 | "Native.Xacml", `onap.policies.native.Xacml.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.native.Xacml.yaml>`_ |
| 151 | "Native.Apex", `onap.policies.native.Apex.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.native.Apex.yaml>`_ |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 152 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 153 | We also preload a policy in the policy database. Below is a table listing the preloaded polic(ies). |
| 154 | |
| 155 | .. csv-table:: |
| 156 | :header: "Policy Type Name", "Payload" |
| 157 | :widths: 15,10 |
| 158 | |
| 159 | "SDNC.Naming", `sdnc.policy.naming.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/sdnc.policy.naming.input.tosca.yaml>`_ |
| 160 | |
| 161 | Below is a table containing sample well-formed TOSCA compliant policies. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 162 | |
| 163 | .. csv-table:: |
Chenfei Gao | 0a85b8b | 2019-09-10 22:22:17 -0400 | [diff] [blame] | 164 | :header: "Policy Name", "Payload" |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 165 | :widths: 15,10 |
| 166 | |
Chenfei Gao | dfbc0ad | 2019-10-01 14:19:39 -0400 | [diff] [blame] | 167 | "vCPE.Monitoring.Tosca", `vCPE.policy.monitoring.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.yaml>`_ `vCPE.policy.monitoring.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.json>`_ |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 168 | "vCPE.Optimization.Tosca", `vCPE.policies.optimization.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml>`_ `vCPE.policies.optimization.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.json>`_ |
| 169 | "vCPE.Operational.Tosca", `vCPE.policy.operational.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.yaml>`_ `vCPE.policy.operational.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.operational.input.tosca.json>`_ |
| 170 | "vDNS.Guard.FrequencyLimiting.Tosca", `vDNS.policy.guard.frequencylimiter.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.guard.frequencylimiter.input.tosca.yaml>`_ |
| 171 | "vDNS.Guard.MinMax.Tosca", `vDNS.policy.guard.minmaxvnfs.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.guard.minmaxvnfs.input.tosca.yaml>`_ |
| 172 | "vDNS.Guard.Blacklist.Tosca", `vDNS.policy.guard.blacklist.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.guard.blacklist.input.tosca.yaml>`_ |
Chenfei Gao | dfbc0ad | 2019-10-01 14:19:39 -0400 | [diff] [blame] | 173 | "vDNS.Monitoring.Tosca", `vDNS.policy.monitoring.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.monitoring.input.tosca.yaml>`_ `vDNS.policy.monitoring.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.monitoring.input.tosca.json>`_ |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 174 | "vDNS.Operational.Tosca", `vDNS.policy.operational.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.operational.input.tosca.yaml>`_ `vDNS.policy.operational.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.operational.input.tosca.json>`_ |
Chenfei Gao | dfbc0ad | 2019-10-01 14:19:39 -0400 | [diff] [blame] | 175 | "vFirewall.Monitoring.Tosca", `vFirewall.policy.monitoring.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.monitoring.input.tosca.yaml>`_ `vFirewall.policy.monitoring.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.monitoring.input.tosca.json>`_ |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 176 | "vFirewall.Operational.Tosca", `vFirewall.policy.operational.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.tosca.yaml>`_ `vFirewall.policy.operational.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.tosca.json>`_ |
| 177 | "vFirewallCDS.Operational.Tosca", `vFirewallCDS.policy.operational.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewallCDS.policy.operational.input.tosca.yaml>`_ |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 178 | |
| 179 | |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 180 | 2. APIs exposed |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 181 | =============== |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 182 | |
| 183 | 2.1 Global API Table |
| 184 | -------------------- |
| 185 | |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 186 | Below you can download the swagger YAML for Policy Framework Lifecycle API. |
| 187 | You can find *Tosca Node Template Design* and *Policy Design* operations. |
a.sreekumar | 332b03d | 2020-03-27 10:26:05 +0000 | [diff] [blame] | 188 | |
Chenfei Gao | 55e1f55 | 2019-05-21 13:32:30 -0400 | [diff] [blame] | 189 | .. csv-table:: |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 190 | :header: "API name", "Swagger YAML" |
Chenfei Gao | 55e1f55 | 2019-05-21 13:32:30 -0400 | [diff] [blame] | 191 | :widths: 10,5 |
Pamela Dragosh | 5fc2fdb | 2019-05-17 09:42:27 -0400 | [diff] [blame] | 192 | |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 193 | "Policy Framework Lifecycle API", ":download:`link <https://raw.githubusercontent.com/onap/policy-api/master/main/src/main/resources/openapi/openapi.yaml>`" |
Pamela Dragosh | 5fc2fdb | 2019-05-17 09:42:27 -0400 | [diff] [blame] | 194 | |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 195 | 2.2 API Swagger |
| 196 | --------------- |
Pamela Dragosh | 5fc2fdb | 2019-05-17 09:42:27 -0400 | [diff] [blame] | 197 | |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 198 | It is worth noting that we use basic authorization for API access with username and password set to *policyadmin* and *zb!XztG34* respectively. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 199 | Also, the new APIs support both *http* and *https*. |
Pamela Dragosh | 5fc2fdb | 2019-05-17 09:42:27 -0400 | [diff] [blame] | 200 | |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 201 | For every API call, client is encouraged to insert an uuid-type requestID as parameter. |
| 202 | It is helpful for tracking each http transaction and facilitates debugging. |
| 203 | Mostly importantly, it complies with Logging requirements v1.2. |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 204 | If a client does not provide the requestID in API call, one will be randomly generated |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 205 | and attached to response header *x-onap-requestid*. |
Chenfei Gao | 55e1f55 | 2019-05-21 13:32:30 -0400 | [diff] [blame] | 206 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 207 | In accordance with `ONAP API Common Versioning Strategy Guidelines <https://wiki.onap.org/display/DW/ONAP+API+Common+Versioning+Strategy+%28CVS%29+Guidelines>`_, |
| 208 | in the response of each API call, several custom headers are added:: |
Chenfei Gao | 55e1f55 | 2019-05-21 13:32:30 -0400 | [diff] [blame] | 209 | |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 210 | x-latestversion: 1.0.0 |
| 211 | x-minorversion: 0 |
| 212 | x-patchversion: 0 |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 213 | x-onap-requestid: e1763e61-9eef-4911-b952-1be1edd9812b |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 214 | x-latestversion is used only to communicate an API's latest version. |
Chenfei Gao | 55e1f55 | 2019-05-21 13:32:30 -0400 | [diff] [blame] | 215 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 216 | x-minorversion is used to request or communicate a MINOR version back from the client to the server, and from the server back to the client. |
Chenfei Gao | 55e1f55 | 2019-05-21 13:32:30 -0400 | [diff] [blame] | 217 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 218 | x-patchversion is used only to communicate a PATCH version in a response for troubleshooting purposes only, and will not be provided by the client on request. |
| 219 | |
| 220 | x-onap-requestid is used to track REST transactions for logging purpose, as described above. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 221 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 222 | |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 223 | .. csv-table:: |
| 224 | :header: "SWAGGER" |
| 225 | :widths: 10 |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 226 | |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 227 | `To view the full SWAGGER click here <./local-swagger.html>`_ |
| 228 | |
| 229 | .. note:: |
| 230 | Note that the context-path is not present in the document, because it is in the `application.yaml <https://github.com/onap/policy-api/blob/master/main/src/main/resources/application.yaml>`_ |
| 231 | So the final url is composed by: |
| 232 | |
| 233 | .. csv-table:: |
| 234 | :header: "Scheme","Host","Context-Path","Path" |
| 235 | :widths: 3,3,3,3 |
| 236 | |
| 237 | "http","://<IP>:<PORT>","/policy/api/v1/","healthcheck" |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 238 | |
rameshiyer27 | ffd27ea | 2022-03-24 22:36:01 +0000 | [diff] [blame] | 239 | |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 240 | 2.3 Creating MetadataSet for policy |
| 241 | ----------------------------------- |
rameshiyer27 | ffd27ea | 2022-03-24 22:36:01 +0000 | [diff] [blame] | 242 | |
| 243 | The policy type implementation in tosca policy can be independently persisted to the database as metadataSets via the Tosca node template Apis . |
| 244 | The policy type implementation data can be excluded from the policy properties section of the tosca policy and the user can specify only the "metadataSetName" and "metadataSetVersion" |
| 245 | fields under the policy "metadata" section to map a specific policy type implementation to the policy during the policy creation. |
| 246 | |
| 247 | The following sample tosca service template comprises a list of tosca node templates each containing a policy type implementation data in the form of metadataSet that can be persisted to the database independently using the policy node template Api. |
| 248 | |
| 249 | .. csv-table:: |
| 250 | :header: "Tosca node template", "Payload" |
| 251 | :widths: 15,10 |
| 252 | |
| 253 | "sample.nodetemplates.metadatasets", `nodetemplates.metadatasets.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/nodetemplates/nodetemplates.metadatasets.input.tosca.yaml>`_ `nodetemplates.metadatasets.input.tosca.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/nodetemplates/nodetemplates.metadatasets.input.tosca.json>`_ |
| 254 | |
| 255 | |
| 256 | The following sample tosca policy shows the policy metadata section that maps to one of the metadataSets stored in the database prior to the policy creation. |
| 257 | |
| 258 | .. csv-table:: |
| 259 | :header: "Tosca policy", "Payload" |
| 260 | :widths: 15,10 |
| 261 | |
| 262 | "apex.decisionmaker.policy", `apex.policy.decisionmaker.input.tosca.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/apex.policy.decisionmaker.input.tosca.yaml>`_ |
| 263 | |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 264 | `The node template Apis <./local-swagger.html#tag/Tosca-Node-Template-Design>`_ |
| 265 | are introduced to handle the policy metadataSets as independent entities that can be later mapped to a tosca policy during policy creation. |
rameshiyer27 | ffd27ea | 2022-03-24 22:36:01 +0000 | [diff] [blame] | 266 | |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 267 | When making a POST policy API call, the client must not only provide well-formed JSON/YAML, |
| 268 | but also must conform to the TOSCA specification. For example. the "type" field for a TOSCA |
| 269 | policy should strictly match the policy type name it derives. |
| 270 | Please check out the sample policies in above policy table. |
| 271 | |
| 272 | Also, in the POST payload passed into each policy or policy type creation call (i.e. POST API invocation), the client needs to explicitly |
| 273 | specify the version of the policy or policy type to create. That being said, the "version" field is mandatory in the TOSCA service template |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 274 | formatted policy or policy type payload. If the version is missing, that POST call will return "406 - Not Acceptable" and |
| 275 | the policy or policy type to create will not be stored in the database. |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 276 | |
| 277 | To avoid inconsistent versions between the database and policies deployed in the PDPs, policy API REST service employs some enforcement |
| 278 | rules that validate the version specified in the POST payload when a new version is to create or an existing version to update. |
| 279 | Policy API will not blindly override the version of the policy or policy type to create/update. |
| 280 | Instead, we encourage the client to carefully select a version for the policy or policy type to change and meanwhile policy API will check the validity |
| 281 | of the version and feed an informative warning back to the client if the specified version is not good. |
| 282 | To be specific, the following rules are implemented to enforce the version: |
| 283 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 284 | 1. If the incoming version is not in the database, we simply insert it. For example: if policy version 1.0.0 is stored in the database and now |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 285 | a client wants to create the same policy with updated version 3.0.0, this POST call will succeed and return "200" to the client. |
| 286 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 287 | 2. If the incoming version is already in the database and the incoming payload is different from the same version in the database, |
| 288 | "406 - Not Acceptable" will be returned. This forces the client to update the version of the policy if the policy is changed. |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 289 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 290 | 3. If a client creates a version of a policy and wishes to update a property on the policy, they must delete that version of the policy and re-create it. |
| 291 | |
| 292 | 4. If multiple policies are included in the POST payload, policy API will also check if duplicate version exists in between |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 293 | any two policies or policy types provided in the payload. For example, a client provides a POST payload which includes two policies with the same |
| 294 | name and version but different policy properties. This POST call will fail and return "406" error back to the calling application along with a |
| 295 | message such as "duplicate policy {name}:{version} found in the payload". |
| 296 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 297 | 5. The same version validation is applied to policy types too. |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 298 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 299 | 6. To avoid unnecessary id/version inconsistency between the ones specified in the entity fields and the ones returned in the metadata field, |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 300 | "policy-id" and "policy-version" in the metadata will only be set by policy API. Any incoming explicit specification in the POST payload will be |
| 301 | ignored. For example, A POST payload has a policy with name "sample-policy-name1" and version "1.0.0" specified. In this policy, the metadata |
| 302 | also includes "policy-id": "sample-policy-name2" and "policy-version": "2.0.0". The 200 return of this POST call will have this created policy with |
| 303 | metadata including "policy-id": "sample-policy-name1" and "policy-version": "1.0.0". |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 304 | |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 305 | Regarding DELETE APIs for TOSCA compliant policies, we only expose API to delete one particular version of policy |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 306 | or policy type at a time for safety purpose. If client has the need to delete multiple or a group of policies or policy types, |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 307 | they will need to delete them one by one. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 308 | |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 309 | 2.4 Sample API Curl Commands |
| 310 | ---------------------------- |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 311 | |
liamfallon | e83e607 | 2020-05-06 13:09:09 +0100 | [diff] [blame] | 312 | From an API client perspective, using *http* or *https* does not make much difference to the curl command. |
Chenfei Gao | 6d69ff9 | 2020-01-13 13:20:34 -0500 | [diff] [blame] | 313 | Here we list some sample curl commands (using *http*) for POST, GET and DELETE monitoring and operational policies that are used in vFirewall use case. |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 314 | JSON payload for POST calls can be downloaded from policy table above. |
| 315 | |
Pamela Dragosh | f65c8ff | 2020-04-29 08:23:12 -0400 | [diff] [blame] | 316 | If you are accessing the api from the container, the default *ip* and *port* would be **https:/policy-api:6969/policy/api/v1/**. |
| 317 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 318 | Create vFirewall Monitoring Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 319 | curl --user 'policyadmin:zb!XztG34' -X POST "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/policies" -H "Accept: application/json" -H "Content-Type: application/json" -d @vFirewall.policy.monitoring.input.tosca.json |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 320 | |
| 321 | Get vFirewall Monitoring Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 322 | curl --user 'policyadmin:zb!XztG34' -X GET "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/policies/onap.vfirewall.tca/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json" |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 323 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 324 | Delete vFirewall Monitoring Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 325 | curl --user 'policyadmin:zb!XztG34' -X DELETE "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.monitoring.tcagen2/versions/1.0.0/policies/onap.vfirewall.tca/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json" |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 326 | |
| 327 | Create vFirewall Operational Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 328 | curl --user 'policyadmin:zb!XztG34' -X POST "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Drools/versions/1.0.0/policies" -H "Accept: application/json" -H "Content-Type: application/json" -d @vFirewall.policy.operational.input.tosca.json |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 329 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 330 | Get vFirewall Operational Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 331 | curl --user 'policyadmin:zb!XztG34' -X GET "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Drools/versions/1.0.0/policies/operational.modifyconfig/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json" |
Chenfei Gao | 7984ada | 2020-03-17 22:34:15 -0400 | [diff] [blame] | 332 | |
Chenfei Gao | af35b6a | 2019-05-21 17:40:21 -0400 | [diff] [blame] | 333 | Delete vFirewall Operational Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 334 | curl --user 'policyadmin:zb!XztG34' -X DELETE "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.controlloop.operational.common.Drools/versions/1.0.0/policies/operational.modifyconfig/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json" |
puthuparambil.aditya | a6c09a2 | 2020-07-27 12:09:40 +0100 | [diff] [blame] | 335 | |
| 336 | Get all available policies:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 337 | curl --user 'policyadmin:zb!XztG34' -X GET "http://{ip}:{port}/policy/api/v1/policies" -H "Accept: application/json" -H "Content-Type: application/json" |
puthuparambil.aditya | a6c09a2 | 2020-07-27 12:09:40 +0100 | [diff] [blame] | 338 | |
| 339 | Get version 1.0.0 of vFirewall Monitoring Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 340 | curl --user 'policyadmin:zb!XztG34' -X GET "http://{ip}:{port}/policy/api/v1/policies/onap.vfirewall.tca/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json" |
puthuparambil.aditya | a6c09a2 | 2020-07-27 12:09:40 +0100 | [diff] [blame] | 341 | |
| 342 | Delete version 1.0.0 of vFirewall Monitoring Policy:: |
adheli.tavares | 5bc4f5e | 2021-11-01 10:39:12 +0000 | [diff] [blame] | 343 | curl --user 'policyadmin:zb!XztG34' -X DELETE "http://{ip}:{port}/policy/api/v1/policies/onap.vfirewall.tca/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json" |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 344 | |
| 345 | |
| 346 | 3. Policy API application configuration |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 347 | ======================================= |
Rashmi Pujar | 2061a36 | 2022-04-21 22:40:50 -0400 | [diff] [blame] | 348 | |
| 349 | Starting from Jakarta Release policy-api is a Springboot based microservice. |
| 350 | |
lapentafd | a43eb54 | 2023-03-27 13:46:04 +0100 | [diff] [blame] | 351 | The policy-api application configuration is packaged as a K8S ConfigMap object via `Policy-API OOM charts <https://raw.githubusercontent.com/onap/oom/master/kubernetes/policy/components/policy-api/resources/config/apiParameters.yaml>`_ |