summaryrefslogtreecommitdiffstats
path: root/docs/api/api.rst
blob: 928782fe786e4f2443005a37d63f1ab2d8367f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.. This work is licensed under a
.. Creative Commons Attribution 4.0 International License.
.. http://creativecommons.org/licenses/by/4.0

.. _api-label:

Policy Life Cycle API
#####################

.. contents::
    :depth: 2 


Policy life cycle API comprises of policy design API and policy deployment API. This documentation focuses on policy 
design API. Policy design API is publicly exposed for clients to Create/Read/Update/Delete (CRUD) policy types, policy type 
implementation and policies which can be recognized and executable by appropriate policy engines incorporated in ONAP 
policy framework. Policy design API backend is running in an independent building block component of policy framework 
that provides REST service for aforementioned CRUD behaviors. Policy design API component interacts with a policy database 
for storing and fetching new policies or policy types as needed. Apart from CRUD, API is also exposed for clients to retrieve
healthcheck status of this API REST service and statistics report including a variety of counters that reflect the history 
of API invocation.

Starting from Dublin release, we strictly follow `TOSCA Specification <http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.1/TOSCA-Simple-Profile-YAML-v1.1.pdf>`_ 
to define policy type and policy. Policy type is equivalent to policy model mentioned by clients before Dublin release.
Both policy type and policy are included in a TOSCA Service Template which is used as the entity passed into API POST call 
and the entity returned by API GET and DELETE calls. More details are presented in following sessions.
We encourage clients to compose all kinds of policies and corresponding policy types in well-formed TOSCA Service Template. 
One Service Template can contain one or more policies and policy types. Each policy type can have multiple policies created 
atop. In other words, different policies can match the same or different policy types. Existence of a policy type is a prerequisite
of creating such type of policies. In the payload body of each policy to create, policy type name and version should be indicated and
the specified policy type should be valid and existing in policy database. 

In El Alto release, to ease policy creation, we preload several widely used policy types in policy database. Below is a table summarizing 
preloaded policy types.

.. csv-table::
   :header: "Policy Type Name", "Payload"
   :widths: 15,10

   "Controlloop.Guard.Blacklist", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.Blacklist.yaml>`_
   "Controlloop.Guard.FrequencyLimiter", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml>`_
   "Controlloop.Guard.MinMax", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.MinMax.yaml>`_
   "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>`_
   "Controlloop.Operational", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.Operational.yaml>`_
   "Monitoring.TCA", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml>`_
   "Monitoring.Collectors", `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>`_
   "Optimization", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.Optimization.yaml>`_
   "Optimization.AffinityPolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml>`_
   "Optimization.DistancePolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml>`_
   "Optimization.HpaPolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml>`_
   "Optimization.OptimizationPolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml>`_
   "Optimization.PciPolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.PciPolicy.yaml>`_
   "Optimization.QueryPolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml>`_
   "Optimization.SubscriberPolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml>`_
   "Optimization.Vim_fit", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.Vim_fit.yaml>`_
   "Optimization.VnfPolicy", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml>`_

Also, in El Alto release, We provide backward compatibility support for controlloop operational and guard 
policies encoded in legacy format. Below is a table containing sample legacy guard/operational policies and 
well-formed TOSCA monitoring policies.

.. csv-table::
   :header: "Policy Name", "Payload"
   :widths: 15,10

   "vCPE.Monitoring.Tosca", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.yaml>`_ | `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.monitoring.input.tosca.json>`_
   "vCPE.Operational.Legacy", `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.operational.input.json>`_
   "vDNS.Guard.FrequencyLimiting.Legacy", `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.guard.frequency.input.json>`_
   "vDNS.Guard.MinMax.Legacy", `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.input.json>`_
   "vDNS.Monitoring.Tosca", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.monitoring.input.tosca.yaml>`_ | `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.monitoring.input.tosca.json>`_
   "vDNS.Operational.Legacy", `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.operational.input.json>`_
   "vFirewall.Monitoring.Tosca", `yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.monitoring.input.tosca.yaml>`_ | `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.monitoring.input.tosca.json>`_
   "vFirewall.Operational.Legacy", `json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.json>`_


Below is a global API table from where swagger JSON for different types of policy design API can be downloaded.  

Global API Table
--------------------
.. csv-table::
   :header: "API name", "Swagger JSON"
   :widths: 10,5

   "Healthcheck API", ":download:`link <swagger/healthcheck-api.json>`"
   "Statistics API", ":download:`link <swagger/statistics-api.json>`"
   "Tosca Policy Type API", ":download:`link <swagger/policytype-api.json>`"
   "Tosca Policy API", ":download:`link <swagger/policy-api.json>`"
   "Legacy Guard Policy API", ":download:`link <swagger/guard-policy-api.json>`"
   "Legacy Operational Policy API", ":download:`link <swagger/operational-policy-api.json>`"

API Swagger
--------------------

It is worth noting that we use basic authorization for API access with username and password set to *healthcheck* and *zb!XztG34* respectively. 
Also, the new APIs support both *http* and *https*.

For every API call, client is encouraged to insert an uuid-type requestID as parameter. It is helpful for tracking each http transaction 
and facilitates debugging. Mostly importantly, it complies with Logging requirements v1.2. If client does not provider the requestID in API call,
one will be randomly generated and attached to response header *x-onap-requestid*.

In accordance with `ONAP API Common Versioning Strategy Guidelines <https://wiki.onap.org/display/DW/ONAP+API+Common+Versioning+Strategy+%28CVS%29+Guidelines>`_,
in the response of each API call, several custom headers are added::

    x-latestversion: 1.0.0  
    x-minorversion: 0    
    x-patchversion: 0 
    x-onap-requestid: e1763e61-9eef-4911-b952-1be1edd9812b
    
x-latestversion is used only to communicate an API's latest version.

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.

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.

x-onap-requestid is used to track REST transactions for logging purpose, as described above.
    

.. swaggerv2doc:: swagger/healthcheck-api.json

.. swaggerv2doc:: swagger/statistics-api.json

.. swaggerv2doc:: swagger/policytype-api.json

.. swaggerv2doc:: swagger/policy-api.json

It is worth noting that in POST policy API, client needs to provide a policy payload encoded in well-formed TOSCA Service Template, and 
in the JSON payload, "type" field value should strictly match the policy type name embedded in the API path (case sensitive). 
Otherwise, it will complain the policy type does not exist. Please check out the sample policies in above policy table.

.. swaggerv2doc:: swagger/guard-policy-api.json

It is worth noting that guard policy name should start with one of the three: *guard.frequency.*, *guard.minmax.*, or *guard.blacklist.*.
Otherwise, it will complain that guard policy type cannot be found (does not exist). Apart from policy name, the policy version specified 
in API path should be an integer, e.g. 1, 2, 10, instead of "1.0.0", "2.0.1", etc.
These naming restrictions will disappear after we evolve to use well-formed TOSCA Service Template for guard policies and 
legacy policy design API is then deprecated.

.. swaggerv2doc:: swagger/operational-policy-api.json

Likewise, the policy version specified in operational policy API path should be an integer too, e.g. 1, 2, 10, instead of 
"1.0.0", "2.0.1", etc. This restriction will disappear after we deprecate legacy policy design API in the near future release.


Regarding DELETE APIs for both TOSCA policies and legacy policies, we only expose API to delete one particular version of policy 
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, 
they will need to delete one by one.  

Sample API Curl Commands
-------------------------

From API client perspective, using *http* or *https* does not have much difference in curl command. 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. 

JSON payload for POST calls can be downloaded from policy table above.

Create vFirewall Monitoring Policy::
  curl --user 'healthcheck:zb!XztG34' -X POST "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies" -H "Accept: application/json" -H "Content-Type: application/json" -d @vFirewall.policy.monitoring.input.tosca.json

Get vFirewall Monitoring Policy::
  curl --user 'healthcheck:zb!XztG34' -X GET "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.vfirewall.tca/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json"
  
Delete vFirewall Monitoring Policy::
  curl --user 'healthcheck:zb!XztG34' -X DELETE "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/1.0.0/policies/onap.vfirewall.tca/versions/1.0.0" -H "Accept: application/json" -H "Content-Type: application/json"

Create vFirewall Operational Policy::
  curl --user 'healthcheck:zb!XztG34' -X POST "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies" -H "Accept: application/json" -H "Content-Type: application/json" -d @vFirewall.policy.operational.input.json
  
Get vFirewall Operational Policy::
  curl --user 'healthcheck:zb!XztG34' -X GET "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig/versions/1" -H "Accept: application/json" -H "Content-Type: application/json"
  
Delete vFirewall Operational Policy::
  curl --user 'healthcheck:zb!XztG34' -X DELETE "http://{ip}:{port}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/operational.modifyconfig/versions/1" -H "Accept: application/json" -H "Content-Type: application/json"