59bc295a16e0e08b44f4fb3f25772fc0e8647c46
[optf/has.git] / conductor / doc / api / README.md
1 # Homing API v1
2
3 *Updated: 4 April 2017*
4
5 This document describes the Homing API, used by the Conductor service. It is a work in progress and subject to frequent revision.
6
7 # General API Information
8
9 Authenticated calls that target a known URI but that use an HTTP method the implementation does not support return a 405 Method Not Allowed status. In addition, the HTTP OPTIONS method is supported for each known URI. In both cases, the Allow response header indicates the supported HTTP methods. See the API Errors section for more information about the error response structure.
10
11 # API versions
12
13 ## List all Homing API versions
14
15 **GET** ``/``F
16
17 **Normal response codes:** 200
18
19 ```json
20 {
21   "versions": [
22     {
23       "status": "EXPERIMENTAL",
24       "id": "v1",
25       "updated": "2016-11-01T00:00:00Z",
26       "media-types": [
27         {
28           "base": "application/json",
29           "type": "application/vnd.ecomp.homing-v1+json"
30         }
31       ],
32       "links": [
33         {
34           "href": "http://135.197.226.83:8091/v1",
35           "rel": "self"
36         },
37         {
38           "href": "http://conductor.research.att.com/",
39           "type": "text/html",
40           "rel": "describedby"
41         }
42       ]
43     }
44   ]
45 }
46 ```
47
48 This operation does not accept a request body.
49
50 # Plans
51
52 ## Create a plan
53
54 **POST** ``/v1/plans``
55
56 * **Normal response codes:** 201
57 * **Error response codes:** badRequest (400), unauthorized (401), internalServerError (500)
58
59 Request an inventory plan for one or more related service demands.
60
61 The request includes or references a declarative **template**, consisting of:
62
63 * **Parameters** that can be referenced like macros
64 * **Demands** for service made against inventory
65 * **Locations** that are common to the overall plan
66 * **Constraints** made against demands, resulting in a set of inventory candidates
67 * **Optimizations** to further narrow down the remaining candidates
68
69 The response contains an inventory **plan**, consisting of one or more sets of recommended pairings of demands with an inventory candidate's attributes and region.
70
71 ### Request Parameters
72
73 | Parameter | Style | Type | Description |
74 |-----------|-------|------|-------------|
75 | ``name`` (Optional) | plain | xsd:string | A name for the new plan. If a name is not provided, it will be auto-generated based on the homing template. This name must be unique within a given Conductor environment. When deleting a plan, its name will not become available for reuse until the deletion completes successfully. Must only contain letters, numbers, hypens, full stops, underscores, and tildes (RFC 3986, Section 2.3). This parameter is immutable. |
76 | ``id`` (Optional) | plain | csapi:UUID | The UUID of the plan. UUID is assigned by Conductor if no id is provided in the request. |
77 | ``transaction_id`` | plain | csapi:UUID | The transaction id assigned by MSO. The logs should have this transaction id for tracking purposes. |
78 | ``files`` (Optional) | plain | xsd:dict | Supplies the contents of files referenced in the template. Conductor templates can explicitly reference files by using the ``get_file`` intrinsic function. The value is a JSON object, where each key is a relative or absolute URI which serves as the name of a file, and the associated value provides the contents of the file. Additionally, some template authors encode their user data in a local file. The Homing client (e.g., a CLI) can examine the template for the ``get_file`` intrinsic function (e.g., ``{get_file: file.yaml}``) and add an entry to the ``files`` map with the path to the file as the name and the file contents as the value. Do not use this parameter to provide the content of the template located at the ``template_url`` address. Instead, use the ``template`` parameter to supply the template content as part of the request. |
79 | ``template_url`` (Optional) | plain | xsd:string | A URI to the location containing the template on which to perform the operation. See the description of the ``template`` parameter for information about the expected template content located at the URI. This parameter is only required when you omit the ``template`` parameter. If you specify both parameters, this parameter is ignored. |
80 | ``template``| plain | xsd:string or xsd:dict | The template on which to perform the operation. See the [Conductor Template Guide](/doc/template/README.md) for complete information on the format. This parameter is either provided as a ``string`` or ``dict`` in the JSON request body. For ``string`` content it may be a JSON- or YAML-formatted Conductor template. For ``dict`` content it must be a direct JSON representation of the Conductor template. This parameter is required only when you omit the ``template_url`` parameter. If you specify both parameters, this value overrides the ``template_url`` parameter value. |
81 | ``timeout`` (Optional) | plain | xsd:number | The timeout for plan creation in minutes. Default is 1. |
82 | ``limit`` (Optional) | plain | xsd:number | The maximum number of recommendations to return. Default is 1. |
83
84 **NOTE**: ``files``, ``template_url``, and ``timeout`` are not yet supported.
85
86 ### Response Parameters
87
88 | Parameter | Style | Type | Description |
89 |-----------|-------|------|-------------|
90 | ``plan`` | plain | xsd:dict | The ``plan`` object. |
91 | ``id`` | plain | csapi:UUID | The UUID of the plan. |
92 | ``transaction_id`` | plain | csapi:UUID | The transaction id assigned by the MSO. |
93 | ``name`` | plain | xsd:string | The plan name. |
94 | ``status`` | plain | xsd:string | The plan status. One of ``template``, ``translated``, ``solving``, ``solved``, or ``error``. See **Plan Status** table for descriptions of each value. |
95 | ``message`` | plain | xsd:string | Additional context, if any, around the message status. If the status is ``error``, this may include a reason and suggested remediation, if available. |
96 | ``links`` | plain | xsd:list | A list of URLs for the plan. Each URL is a JSON object with an ``href`` key indicating the URL and a ``rel`` key indicating its relationship to the plan in question. There may be multiple links returned. The ``self`` relationship identifies the URL of the plan itself. |
97 | ``recommendations`` | plain | xsd:list | A list of one or more recommendations. A recommendation pairs each requested demand with an inventory provider, a single candidate, and an opaque dictionary of attributes. Refer to the Demand candidate schema in the [Conductor Template Guide](/doc/template/README.md) for further details. (Note that, when ``inventory_type`` is ``cloud`` the candidate's ``candidate_id`` field is redundant and thus omitted.) |
98
99 ### Plan Status
100
101 | Status | Description |
102 |--------|-------------|
103 | ``template`` | Plan request and homing template have been received. Awaiting translation. |
104 | ``translated`` | Homing template has been translated, and candidates have been obtained from inventory providers. Awaiting solving. |
105 | ``solving`` | Search for a solution is in progress. This may incorporate requests to service controllers for additional information. |
106 | ``solved`` | Search is complete. A solution with one or more recommendations was found. |
107 | ``not found`` | Search is complete. No recommendations were found. |
108 | ``error`` | An error was encountered. |
109
110 #### State Diagram
111
112 ```text
113                   ----------------------------------------
114                  |                                        |
115                  |                   /---> solved ---> reserving ---> done
116                  |                  /                    /
117  template -> translated -> solving ------> not found    /
118      |         ^               |    \                  / 
119      |         | conditionally |     \---> error <----/
120      |         |   (see note)  |             ^
121      |         \---------------/             |
122      \---------------------------------------/
123 ```
124 **NOTE**: When Conductor's solver service is started in non-concurrent mode (the default), it will reset any plans found waiting and stuck in the ``solving`` state back to ``translated``.
125
126 ```json
127 {
128   "name": "PLAN_NAME",
129   "template": "CONDUCTOR_TEMPLATE",
130   "limit": 3
131 }
132 ```
133
134 ```json
135 {
136   "plan": {
137     "name": "PLAN_NAME",
138     "id": "ee1c5269-c7f0-492a-8652-f0ceb15ed3bc",
139     "transaction_id": "6bca5f2b-ee7e-4637-8b58-1b4b36ed10f9",
140     "status": "solved",
141     "message", "Plan PLAN_NAME is solved.",
142     "links": [
143       {
144         "href": "http://homing/v1/plans/ee1c5269-c7f0-492a-8652-f0ceb15ed3bc",
145         "rel": "self"
146       }
147     ],
148     "recommendations": [
149       {
150         "DEMAND_NAME_1": {
151           "inventory_provider": "aai",
152           "service_resource_id": "4feb0545-69e2-424c-b3c4-b270e5f2a15d",
153           "candidate": {
154             "candidate_id": "99befee8-e8c0-425b-8f36-fb7a8098d9a9",
155             "inventory_type": "service",
156             "location_type": "aic",
157             "location_id": "dal01",
158             "host_id" : "vig20002vm001vig001"
159           },
160           "attributes": {OPAQUE-DICT}
161         },
162         "DEMAND_NAME_2": {
163           "inventory_provider": "aai",
164           "service_resource_id": "578eb063-b24a-4654-ba9e-1e5cf7eb9183",
165           "candidate": {
166             "inventory_type": "cloud",
167             "location_type": "aic",
168             "location_id": "dal02"
169           },
170           "attributes": {OPAQUE-DICT}
171         }
172       },
173       {
174         "DEMAND_NAME_1": {
175           "inventory_provider": "aai",
176           "service_resource_id": "4feb0545-69e2-424c-b3c4-b270e5f2a15d",
177           "candidate": {
178             "candidate_id": "99befee8-e8c0-425b-8f36-fb7a8098d9a9",
179             "inventory_type": "service",
180             "location_type": "aic",
181             "location_id": "dal03",
182             "host_id" : "vig20001vm001vig001"
183           },
184           "attributes": {OPAQUE-DICT}
185         },
186         "DEMAND_NAME_2": {
187           "inventory_provider": "aai",
188           "service_resource_id": "578eb063-b24a-4654-ba9e-1e5cf7eb9183",
189           "candidate": {
190             "inventory_type": "cloud",
191             "location_type": "aic",
192             "location_id": "dal04"
193           },
194           "attributes": {OPAQUE-DICT}
195         }
196       },
197       ...
198     ]
199   }
200 }
201 ```
202
203 ## Show plan details
204
205 **GET** ``/v1/plans/{plan_id}``
206
207 * **Normal response codes:** 200
208 * **Error response codes:** unauthorized (401), itemNotFound (404)
209
210 ### Request parameters
211
212 | Parameter   | Style | Type       | Description                                       |
213 |-------------|-------|------------|---------------------------------------------------|
214 | ``plan_id`` | plain | csapi:UUID | The UUID of the plan. |
215
216 ### Response Parameters
217
218 See the Response Parameters for **Create a plan**.
219
220 ## Delete a plan
221
222 **DELETE** ``/v1/plans/{plan_id}``
223
224 * **Normal response codes:** 204
225 * **Error response codes:** badRequest (400), unauthorized (401), itemNotFound (404)
226
227 ### Request parameters
228
229 | Parameter   | Style | Type       | Description                                       |
230 |-------------|-------|------------|---------------------------------------------------|
231 | ``plan_id`` | plain | csapi:UUID | The UUID of the plan.  |
232
233 This operation does not accept a request body and does not return a response body.
234
235 ## API Errors
236
237 In the event of an error with a status other than unauthorized (401), a detailed repsonse body is returned.
238
239 ### Response parameters
240
241 | Parameter   | Style | Type       | Description                                       |
242 |-------------|-------|------------|---------------------------------------------------|
243 | ``title``   | plain | xsd:string | Human-readable name.                              |
244 | ``explanation`` | plain | xsd:string | Detailed explanation with remediation (if any).   |
245 | ``code``    | plain | xsd:int    | HTTP Status Code.                                 |
246 | ``error``   | plain | xsd:dict   | Error dictionary. Keys include **message**, **traceback**, and **type**. |
247 | ``message`` | plain | xsd:string | Internal error message.                           |
248 | ``traceback`` | plain | xsd:string | Python traceback (if available).                  |
249 | ``type``    | plain | xsd:string | HTTP Status class name (from python-webob)        |
250
251 #### Examples
252
253 A plan with the name "pl an" is considered a bad request because the name contains a space.
254
255 ```json
256 {
257   "title": "Bad Request",
258   "explanation": "-> name -> pl an did not pass validation against callable: plan_name_type (must contain only uppercase and lowercase letters, decimal digits, hyphens, periods, underscores, and tildes [RFC 3986, Section 2.3])",
259   "code": 400,
260   "error": {
261     "message": "The server could not comply with the request since it is either malformed or otherwise incorrect.",
262     "type": "HTTPBadRequest"
263   }
264 }
265 ```
266
267 The HTTP COPY method was attempted but is not allowed.
268
269 ```json
270 {
271   "title": "Method Not Allowed",
272   "explanation": "The COPY method is not allowed.",
273   "code": 405,
274   "error": {
275     "message": "The server could not comply with the request since it is either malformed or otherwise incorrect.",
276     "type": "HTTPMethodNotAllowed"
277   }
278 }
279 ```
280
281 ## Contact ##
282
283 Shankar Narayanan <shankarpnsn@gmail.com>