Add bulkApi documentation
[aai/aai-common.git] / docs / AAI REST API Documentation / bulkApi.rst
1 .. contents::
2    :depth: 3
3 ..
4 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
5 .. http://creativecommons.org/licenses/by/4.0
6
7 \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
8
9 =============
10  AAI Bulk API
11 =============
12
13 This page will serve as a reference for how to use the A&AI bulk API's available in 1810+.
14
15 Bulk Overview
16 =============
17
18 To execute any of the bulk api's, a client will perform a POST on the specific bulk api and include a payload indicating the nodes to be added/updated/deleted.The version (v$ ie. v14) dictates which release's REST API version the output will be based on.
19  
20 Single transaction API
21 ======================
22
23 API takes in transaction object which consists of an array of operations, the operations are executed against A&AI in a single transaction. All operations must succeed for the actions to be committed. If any of the operations fail these changes will be rolled back.
24
25 API URI
26 =======
27
28 .. code::
29
30    URI
31    POST /aai/v$/bulk/single-transaction
32    Payload
33    Skeleton 
34    {
35      "operations": [ //array of operations for this transaction
36        {
37          "action": "", //aai action to be taken, i.e put, patch, delete
38          "uri": "", //aai uri to execute action against
39          "body": {} //json object which is the body of the equivalent REST request
40        }
41      ]
42    }
43
44 Response
45
46 .. code::
47
48    Skeleton 
49    {
50      "operation-responses": [ //result of each of the request operations
51        {
52          "action": "", //aai action that was taken
53          "uri": "", //aai uri that was executed against
54          "response-status-code": , //http status code
55          "response-body": null // response body of the of the equivalent REST request
56        }
57      ]
58    }
59
60 Request-Response Examples
61 =========================
62
63 Example - 1 (Success)
64 +++++++++++++++++++++
65
66 .. code::
67
68    Request  
69    {
70        "operations": [
71            {
72                "action": "put",
73                "body": {
74                    "fqdn": "pserver-key-fqdn",
75                    "hostname": "pserver-1-key"
76                },
77                "uri": "/cloud-infrastructure/pservers/pserver/pserver-1-key"
78            },
79            {
80                "action": "patch",
81                "body": {
82                    "fqdn": "patched-fqdn"
83                },
84                "uri": "/cloud-infrastructure/pservers/pserver/pserver-1-key"
85            },
86            {
87                "action": "put",
88                "body": {
89                    "fqdn": "pserver-key-fqdn",
90                    "hostname": "pserver-2-key"
91                },
92                "uri": "/cloud-infrastructure/pservers/pserver/pserver-2-key"
93            }
94        ]
95    }
96
97 Response
98 ++++++++
99 .. code:: 
100
101    {
102        "operation-responses": [
103            {
104                "action": "put",
105                "response-body": null,
106                "response-status-code": 201,
107                "uri": "/cloud-infrastructure/pservers/pserver/pserver-1-key"
108            },
109            {
110                "action": "patch",
111                "response-body": null,
112                "response-status-code": 200,
113                "uri": "/cloud-infrastructure/pservers/pserver/pserver-1-key"
114            },
115            {
116                "action": "put",
117                "response-body": null,
118                "response-status-code": 201,
119                "uri": "/cloud-infrastructure/pservers/pserver/pserver-2-key"
120            }
121        ]
122    }
123
124 Example - 2 (Success)
125 =====================
126 Request
127 +++++++
128
129 .. code::
130
131    {
132        "operations": [
133            {
134                "action": "put",
135                "body": {
136                    "fqdn": "pserver-key-fqdn",
137                    "hostname": "pserver-key"
138                },
139                "uri": "/cloud-infrastructure/pservers/pserver/pserver-key"
140            },
141            {
142                "action": "put",
143                "body": {
144                    "city": "city",
145                    "country": "NONE",
146                    "data-center-code": "code",
147                    "identity-url": "N/A",
148                    "physical-location-id": "complex-key",
149                    "physical-location-type": "type",
150                    "postal-code": "12345",
151                    "region": "Earth",
152                    "state": "state",
153                    "street1": "street"
154                },
155                "uri": "/cloud-infrastructure/complexes/complex/complex-key"
156            },
157            {
158                "action": "put",
159                "body": {
160                    "related-link": "/aai/v13/cloud-infrastructure/pservers/pserver/pserver-key",
161                    "related-to": "pserver"
162                },
163                "uri": "/cloud-infrastructure/complexes/complex/complex-key/relationship-list/relationship"
164            },
165            {
166                "action": "delete",
167                "body": {},
168                "uri": "/network/generic-vnfs/generic-vnf/gvnf-key?resource-version=0"
169            }
170        ]
171    }
172
173 Response
174 ++++++++
175
176 .. code::
177
178    {
179        "operation-responses": [
180            {
181                "action": "put",
182                "response-body": null,
183                "response-status-code": 201,
184                "uri": "/cloud-infrastructure/pservers/pserver/pserver-key"
185            },
186            {
187                "action": "put",
188                "response-body": null,
189                "response-status-code": 201,
190                "uri": "/cloud-infrastructure/complexes/complex/complex-key"
191            },
192            {
193                "action": "put",
194                "response-body": null,
195                "response-status-code": 200,
196                "uri": "/cloud-infrastructure/complexes/complex/complex-key/relationship-list/relationship"
197            },
198            {
199                "action": "delete",
200                "response-body": null,
201                "response-status-code": 204,
202                "uri": "/network/generic-vnfs/generic-vnf/gvnf-key?resource-version=0"
203            }
204        ]
205    }
206
207 Example - 3 (Failure on mismatched resource version on delete)
208 ==============================================================
209 Request
210 +++++++
211
212 .. code::
213
214    {
215        "operations": [
216            {
217                "action": "put",
218                "body": {
219                    "fqdn": "pserver-key-fqdn",
220                    "hostname": "pserver-key"
221                },
222                "uri": "/cloud-infrastructure/pservers/pserver/pserver-key"
223            },
224            {
225                "action": "put",
226                "body": {
227                    "city": "city",
228                    "country": "NONE",
229                    "data-center-code": "code",
230                    "identity-url": "N/A",
231                    "physical-location-id": "complex-key",
232                    "physical-location-type": "type",
233                    "postal-code": "12345",
234                    "region": "Earth",
235                    "state": "state",
236                    "street1": "street"
237                },
238                "uri": "/cloud-infrastructure/complexes/complex/complex-key"
239            },
240            {
241                "action": "put",
242                "body": {
243                    "related-link": "/aai/v13/cloud-infrastructure/pservers/pserver/pserver-key",
244                    "related-to": "pserver"
245                },
246                "uri": "/cloud-infrastructure/complexes/complex/complex-key/relationship-list/relationship"
247            },
248            {
249                "action": "delete",
250                "body": {},
251                "uri": "/network/generic-vnfs/generic-vnf/gvnf-key?resource-version=1"
252            }
253        ]
254    }
255
256 Response
257 ++++++++
258
259 .. code:: 
260
261    {
262        "requestError": {
263            "serviceException": {
264                "messageId": "SVC3000",
265                "text": "Invalid input performing %1 on %2 (msg=%3) (ec=%4)",
266                "variables": [
267                    "POST",
268                    "/aai/v14/bulk-single-transaction-multi-operation",
269                    "Invalid input performing %1 on %2:Operation 3 failed with status code (412) and msg ({\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3000\",\"text\":\"Invalid input performing %1 on %2 (msg=%3) (ec=%4)\",\"variables\":[\"DELETE\",\"/network/generic-vnfs/generic-vnf/gvnf-key\",\"Precondition Failed:resource-version MISMATCH for delete of generic-vnf\",\"ERR.5.4.6131\"]}}})",
270                    "ERR.5.2.3000"
271                ]
272            }
273        }
274    } 
275