Fix links in api doc
[policy/parent.git] / docs / api / api.rst
1 .. This work is licensed under a
2 .. Creative Commons Attribution 4.0 International License.
3 .. http://creativecommons.org/licenses/by/4.0
4
5 .. _api-label:
6
7 Policy Life Cycle API
8 #####################
9
10 .. contents::
11     :depth: 2 
12
13
14 Policy life cycle API comprises of policy design API and policy deployment API. This documentation focuses on policy 
15 design API. Policy design API is publicly exposed for clients to Create/Read/Update/Delete (CRUD) policy types, policy type 
16 implementation and policies which can be recognized and executable by appropriate policy engines incorporated in ONAP 
17 policy framework. Policy design API backend is running in an independent building block component of policy framework 
18 that provides REST service for aforementioned CRUD behaviors. Policy design API component interacts with a policy database 
19 for storing and fetching new policies or policy types as needed. Apart from CRUD, API is also exposed for clients to retrieve
20 healthcheck status of this API REST service and statistics report including a variety of counters that reflect the history 
21 of API invocation.
22
23 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>`_ 
24 to define policy type and policy. Policy type is equivalent to policy model mentioned by clients before Dublin release.
25 Both policy type and policy are included in a TOSCA Service Template which is used as the entity passed into API POST call 
26 and the entity returned by API GET and DELETE calls. More details are presented in following sessions.
27 We encourage clients to compose all kinds of policies and corresponding policy types in well-formed TOSCA Service Template. 
28 One Service Template can contain one or more policies and policy types. Each policy type can have multiple policies created 
29 atop. In other words, different policies can match the same or different policy types. Existence of a policy type is a prerequisite
30 of creating such type of policies. In the payload body of each policy to create, policy type name and version should be indicated and
31 the specified policy type should be valid and existing in policy database. 
32
33 In El Alto release, to ease policy creation, we preload several widely used policy types in policy database. Below is a table summarizing 
34 preloaded policy types.
35
36 .. csv-table::
37    :header: "Policy Type Name", "Payload"
38    :widths: 15,10
39
40    "Controlloop.Guard.Blacklist", `onap.policies.controlloop.guard.Blacklist.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.Blacklist.yaml>`_
41    "Controlloop.Guard.FrequencyLimiter", `onap.policies.controlloop.guard.FrequencyLimiter.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml>`_
42    "Controlloop.Guard.MinMax", `onap.policies.controlloop.guard.MinMax.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.guard.MinMax.yaml>`_
43    "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>`_
44    "Controlloop.Operational", `onap.policies.controlloop.Operational.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.controlloop.Operational.yaml>`_
45    "Monitoring.TCA", `onap.policies.monitoring.cdap.tca.hi.lo.app.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml>`_
46    "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>`_
47    "Optimization", `onap.policies.Optimization.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.Optimization.yaml>`_
48    "Optimization.AffinityPolicy", `onap.policies.optimization.AffinityPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.AffinityPolicy.yaml>`_
49    "Optimization.DistancePolicy", `onap.policies.optimization.DistancePolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.DistancePolicy.yaml>`_
50    "Optimization.HpaPolicy", `onap.policies.optimization.HpaPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.HpaPolicy.yaml>`_
51    "Optimization.OptimizationPolicy", `onap.policies.optimization.OptimizationPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.OptimizationPolicy.yaml>`_
52    "Optimization.PciPolicy", `onap.policies.optimization.PciPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.PciPolicy.yaml>`_
53    "Optimization.QueryPolicy", `onap.policies.optimization.QueryPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.QueryPolicy.yaml>`_
54    "Optimization.SubscriberPolicy", `onap.policies.optimization.SubscriberPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.SubscriberPolicy.yaml>`_
55    "Optimization.Vim_fit", `onap.policies.optimization.Vim_fit.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.Vim_fit.yaml>`_
56    "Optimization.VnfPolicy", `onap.policies.optimization.VnfPolicy.yaml <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policytypes/onap.policies.optimization.VnfPolicy.yaml>`_
57
58 Also, in El Alto release, We provide backward compatibility support for controlloop operational and guard 
59 policies encoded in legacy format. Below is a table containing sample legacy guard/operational policies and 
60 well-formed TOSCA monitoring policies.
61
62 .. csv-table::
63    :header: "Policy Name", "Payload"
64    :widths: 15,10
65
66    "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>`_
67    "vCPE.Operational.Legacy", `vCPE.policy.operational.input.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vCPE.policy.operational.input.json>`_
68    "vDNS.Guard.FrequencyLimiting.Legacy", `vDNS.policy.guard.frequency.input.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.guard.frequency.input.json>`_
69    "vDNS.Guard.MinMax.Legacy", `vDNS.policy.guard.minmax.input.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.guard.minmax.input.json>`_
70    "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>`_
71    "vDNS.Operational.Legacy", `vDNS.policy.operational.input.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vDNS.policy.operational.input.json>`_
72    "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>`_
73    "vFirewall.Operational.Legacy", `vFirewall.policy.operational.input.json <https://github.com/onap/policy-models/blob/master/models-examples/src/main/resources/policies/vFirewall.policy.operational.input.json>`_
74
75
76 Below is a global API table from where swagger JSON for different types of policy design API can be downloaded.  
77
78 Global API Table
79 --------------------
80 .. csv-table::
81    :header: "API name", "Swagger JSON"
82    :widths: 10,5
83
84    "Healthcheck API", ":download:`link <swagger/healthcheck-api.json>`"
85    "Statistics API", ":download:`link <swagger/statistics-api.json>`"
86    "Tosca Policy Type API", ":download:`link <swagger/policytype-api.json>`"
87    "Tosca Policy API", ":download:`link <swagger/policy-api.json>`"
88    "Legacy Guard Policy API", ":download:`link <swagger/guard-policy-api.json>`"
89    "Legacy Operational Policy API", ":download:`link <swagger/operational-policy-api.json>`"
90
91 API Swagger
92 --------------------
93
94 It is worth noting that we use basic authorization for API access with username and password set to *healthcheck* and *zb!XztG34* respectively. 
95 Also, the new APIs support both *http* and *https*.
96
97 For every API call, client is encouraged to insert an uuid-type requestID as parameter. It is helpful for tracking each http transaction 
98 and facilitates debugging. Mostly importantly, it complies with Logging requirements v1.2. If client does not provider the requestID in API call,
99 one will be randomly generated and attached to response header *x-onap-requestid*.
100
101 In accordance with `ONAP API Common Versioning Strategy Guidelines <https://wiki.onap.org/display/DW/ONAP+API+Common+Versioning+Strategy+%28CVS%29+Guidelines>`_,
102 in the response of each API call, several custom headers are added::
103
104     x-latestversion: 1.0.0  
105     x-minorversion: 0    
106     x-patchversion: 0 
107     x-onap-requestid: e1763e61-9eef-4911-b952-1be1edd9812b
108     
109 x-latestversion is used only to communicate an API's latest version.
110
111 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.
112
113 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.
114
115 x-onap-requestid is used to track REST transactions for logging purpose, as described above.
116     
117
118 .. swaggerv2doc:: swagger/healthcheck-api.json
119
120 .. swaggerv2doc:: swagger/statistics-api.json
121
122 .. swaggerv2doc:: swagger/policytype-api.json
123
124 .. swaggerv2doc:: swagger/policy-api.json
125
126 It is worth noting that in POST policy API, client needs to provide a policy payload encoded in well-formed TOSCA Service Template, and 
127 in the JSON payload, "type" field value should strictly match the policy type name embedded in the API path (case sensitive). 
128 Otherwise, it will complain the policy type does not exist. Please check out the sample policies in above policy table.
129
130 .. swaggerv2doc:: swagger/guard-policy-api.json
131
132 It is worth noting that guard policy name should start with one of the three: *guard.frequency.*, *guard.minmax.*, or *guard.blacklist.*.
133 Otherwise, it will complain that guard policy type cannot be found (does not exist). Apart from policy name, the policy version specified 
134 in API path should be an integer, e.g. 1, 2, 10, instead of "1.0.0", "2.0.1", etc.
135 These naming restrictions will disappear after we evolve to use well-formed TOSCA Service Template for guard policies and 
136 legacy policy design API is then deprecated.
137
138 .. swaggerv2doc:: swagger/operational-policy-api.json
139
140 Likewise, the policy version specified in operational policy API path should be an integer too, e.g. 1, 2, 10, instead of 
141 "1.0.0", "2.0.1", etc. This restriction will disappear after we deprecate legacy policy design API in the near future release.
142
143
144 Regarding DELETE APIs for both TOSCA policies and legacy policies, we only expose API to delete one particular version of policy 
145 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, 
146 they will need to delete one by one.  
147
148 Sample API Curl Commands
149 -------------------------
150
151 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*) 
152 for POST, GET and DELETE monitoring and operational policies that are used in vFirewall use case. 
153
154 JSON payload for POST calls can be downloaded from policy table above.
155
156 Create vFirewall Monitoring Policy::
157   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
158
159 Get vFirewall Monitoring Policy::
160   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"
161   
162 Delete vFirewall Monitoring Policy::
163   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"
164
165 Create vFirewall Operational Policy::
166   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
167   
168 Get vFirewall Operational Policy::
169   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"
170   
171 Delete vFirewall Operational Policy::
172   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"
173
174