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