06f7f76c82b05fe5e2128467de74dab8c2533087
[dcaegen2.git] / platformdoc / docs / components / component-specification / common-specification.md
1 # Common Elements of the Component Specification
2
3 This page describes the component specification (JSON) sections that are common to both Docker and CDAP components. Differences for each are pointed out below. Elements that are very different, and described in the CDAP or Docker specific pages. 
4
5 ## Component Metadata
6 Metadata refers to the properties found under the `self` JSON.  This group of properties is used to uniquely identify this component specification and identify the component that this specification is used to capture. 
7
8 Example:
9
10 ```
11 "self": {
12     "version": "1.0.0",
13     "name": "asimov.component.kpi_anomaly",
14     "description": "Classifies VNF KPI data as anomalous",
15     "component_type": "docker"
16 },
17 ```
18
19 `self` Schema:
20
21 Property Name | Type | Description
22 ------------- | ---- | -----------
23 version | string | *Required*.  Semantic version for this specification
24 name | string | *Required*.  Full name of this component which is also used as this component's catalog id.
25 description | string | *Required*. Human-readable text describing the component and the components functional purpose.
26 component_type | string | *Required*.  Identify what containerization technology this component uses: `docker` or `cdap`.
27
28 ## Interfaces
29 Interfaces are the JSON objects found under the `streams` key and the `services` key.  These are used to describe the interfaces that the component uses and the interfaces that the component provides.  The description of each interface includes the associated [data format](/components/data-formats.md).
30
31 ### Streams
32  * The `streams` JSON is for specifying data produced for consumption by other components, and the streams expected to subscribe to that is produced by other components. These are "fire and forget" type interfaces where the publisher of a stream does not expect or parse a response from the subscriber.
33 * The term `stream` here is abstract and neither refers to "CDAP streams" or "DMaaP feeds". While a stream is very likely a DMaaP feed, it could be a direct stream of data being routed via HTTP too. It abstractly refers to a sequence of data leaving a publisher.
34 * Streams have anonymous publish/subscribe semantics, which decouples the production of information from its consumption.
35 * In general, components are not aware of who they are communicating with.
36 * Instead, components that are interested in data, subscribe to the relevant stream; components that generate data publish to the relevant stream.
37 * There can be multiple publishers and subscribers to a stream. Streams are intended for unidirectional, streaming communication.
38
39
40 Streams interfaces that implement an HTTP endpoint must support POST.
41
42 Streams are split into:
43
44 Property Name | Type | Description
45 ------------- | ---- | -----------
46 subscribes | JSON list | *Required*.  List of all available stream interfaces that this component has that can be used for subscribing
47 publishes | JSON list | *Required*.  List of all stream interfaces that this component will publish onto
48
49 #### Subscribes
50
51 Example:
52
53 ```json
54 "streams": {
55     "subscribes": [{
56         "format": "dcae.vnf.kpi",
57         "version": "1.0.0",
58         "route": "/data",        // for CDAP this value is not used
59         "type": "http"
60     }],
61 ...
62 }
63 ```
64
65 This describes that `asimov.component.kpi_anomaly` exposes an HTTP endpoint called `/data` which accepts requests that have the data format of `dcae.vnf.kpi` version `1.0.0`.
66
67 `subscribes` Schema:
68
69 Property Name | Type | Description
70 ------------- | ---- | -----------
71 format | string | *Required*.  Data format id of the data format that is used by this interface
72 version | string | *Required*.  Data format version of the data format that is used by this interface
73 route | string | *Required for HTTP and data router*.  The HTTP route that this interface listens on
74 config_key | string | *Required for message_router and data router*.  The HTTP route that this interface listens on
75 type | string | *Required*. Type of stream: `http`, `message_router`, `data_router`
76
77
78 ##### Message router
79
80 Message router subscribers are http clients rather than http services and performs a http a `GET` call.  Thus, message router subscribers description is structured like message router publishers and requires `config_key`:
81
82 ```json
83 "streams": {
84     "subscribes": [{
85         "format": "dcae.some-format",
86         "version": "1.0.0",
87         "config_key": "some_format_handle",
88         "type": "message router"
89     }],
90 ...
91 }
92 ```
93
94 ##### Data router
95
96 Data router subscribers are http or https services that handle `PUT` requests from data router.  Developers must provide the `route` or url path/endpoint that is expected to handle data router requests.  This will be used to construct the delivery url needed to register the subscriber to the provisioned feed.  Developers must also provide a `config_key` because there is dynamic configuration information associated with the feed that the application will need e.g. username and password.  See the page on [DMaaP connection objects](../dcae-cli/dmaap-connection-objects) for more details on the configuration information.
97
98 Example (not tied to the larger example):
99
100 ```json
101 "streams": {
102     "subscribes": [{
103         "config_key": "some-sub-dr",
104         "format": "sandbox.platform.any",
105         "route": "/identity",
106         "type": "data_router",
107         "version": "0.1.0"
108     }],
109 ...
110 }
111 ```
112
113 #### Publishes
114
115 Example:
116
117 ```json
118 "streams": {
119 ...
120     "publishes": [{
121         "format": "asimov.format.integerClassification",
122         "version": "1.0.0",
123         "config_key": "prediction",
124         "type": "http"
125     }]
126 },
127
128 ```
129
130 This describes that `asimov.component.kpi_anomaly` publishes by making POST requests to streams that support the data format `asimov.format.integerClassification` version `1.0.0`.
131
132 `publishes` Schema:
133
134 Property Name | Type | Description
135 ------------- | ---- | -----------
136 format | string | *Required*.  Data format id of the data format that is used by this interface
137 version | string | *Required*.  Data format version of the data format that is used by this interface
138 config_key | string | *Required*.  The JSON key in the generated application configuration that will be used to pass the downstream component's (the subscriber's) connection information.
139 type | string | *Required*. Type of stream: `http`, `message router`, `data router`
140
141 ##### Message router
142
143 Message router publishers are http clients of DMaap message_router.  Developers must provide a `config_key` because there is dynamic configuration information associated with the feed that the application will need to receive e.g. topic url, username, password.  See the page on [DMaaP connection objects](../dcae-cli/dmaap-connection-objects/#message_router) for more details on the configuration information.
144
145 Example (not tied to the larger example):
146
147 ```json
148 "streams": {
149 ...
150     "publishes": [{
151         "config_key": "some-pub-mr",
152         "format": "sandbox.platform.any",
153         "type": "message_router",
154         "version": "0.1.0"
155     }]
156 }
157 ```
158
159 ##### Data router
160
161 Data router publishers are http clients that make `PUT` requests to data router.  Developers must also provide a `config_key` because there is dynamic configuration information associated with the feed that the application will need to receive e.g. publish url, username, password.  See the page on [DMaaP connection objects](../dcae-cli/dmaap-connection-objects) for more details on the configuration information.
162
163 Example (not tied to the larger example):
164
165 ```json
166 "streams": {
167 ...
168     "publishes": [{
169         "config_key": "some-pub-dr",
170         "format": "sandbox.platform.any",
171         "type": "data_router",
172         "version": "0.1.0"
173     }]
174 }
175 ```
176
177 #### Quick Reference
178
179 Refer to this [Quick Reference](/components/component-specification/streams-grid.md) for a comparison of the Streams 'Publishes' and 'Subscribes' sections.
180
181
182 ### Services
183
184 * The publish / subscribe model is a very flexible communication paradigm, but its many-to-many one-way transport is not appropriate for RPC
185 request / reply interactions, which are often required in a distributed system.
186 * Request / reply is done via a Service, which is defined by a pair of messages: one for the request and one for the reply.
187
188 Services are split into:
189
190 Property Name | Type | Description
191 ------------- | ---- | -----------
192 calls | JSON list | *Required*.  List of all service interfaces that this component will call
193 provides | JSON list | *Required*.  List of all service interfaces that this component exposes and provides
194
195 #### Calls
196 The JSON `services/calls` is for specifying that the component relies on an HTTP(S) service---the component sends that service an HTTP request, and that service responds with an HTTP reply.
197 An example of this is how string matching (SM) depends on the AAI Broker. SM performs a synchronous REST call to the AAI broker, providing it the VMNAME of the VNF, and the AAI Broker responds with additional details about the VNF. This dependency is expressed via `services/calls`. In contrast, the output of string matching (the alerts it computes) is sent directly to policy as a fire-and-forget interface, so that is an example of a `stream`. 
198
199 Example:
200
201 ```json
202 "services": {
203     "calls": [{
204         "config_key": "vnf-db",
205         "request": {
206             "format": "dcae.vnf.meta",
207             "version": "1.0.0"
208             },
209         "response": {
210             "format": "dcae.vnf.kpi",
211             "version": "1.0.0"
212             }
213     }],
214 ...
215 }
216 ```
217
218 This describes that `asimov.component.kpi_anomaly` will make HTTP calls to a downstream component that accepts requests of data format `dcae.vnf.meta` version `1.0.0` and is expecting the response to be `dcae.vnf.kpi` version `1.0.0`.
219
220 `calls` Schema:
221
222 Property Name | Type | Description
223 ------------- | ---- | -----------
224 request | JSON object | *Required*.  Description of the expected request for this downstream interface
225 response | JSON object | *Required*.  Description of the expected response for this downstream interface
226 config_key | string | *Required*.  The JSON key in the generated application configuration that will be used to pass the downstream component connection information.
227
228 The JSON object schema for both `request` and `response`:
229
230 Property Name | Type | Description
231 ------------- | ---- | -----------
232 format | string | *Required*.  Data format id of the data format that is used by this interface
233 version | string | *Required*.  Data format version of the data format that is used by this interface
234
235 #### Provides
236
237 Example:
238
239 ```json
240 "services": {
241 ...
242     "provides": [{
243         "route": "/score-vnf",
244         "request": {
245             "format": "dcae.vnf.meta",
246             "version": "1.0.0"
247             },
248         "response": {
249             "format": "asimov.format.integerClassification",
250             "version": "1.0.0"
251             }
252     }]
253 },
254 ```
255
256 This describes that `asimov.component.kpi_anomaly` provides a service interface and it is exposed on the `/score-vnf` HTTP endpoint.  The endpoint accepts requests that have the data format `dcae.vnf.meta` version `1.0.0` and gives back a response of `asimov.format.integerClassification` version `1.0.0`.
257
258 `provides` Schema for a Docker component:
259
260 Property Name | Type | Description
261 ------------- | ---- | -----------
262 request | JSON object | *Required*.  Description of the expected request for this interface
263 response | JSON object | *Required*.  Description of the expected response for this interface
264 route | string | *Required*.  The HTTP route that this interface listens on
265
266 The JSON object schema for both `request` and `response`:
267
268 Property Name | Type | Description
269 ------------- | ---- | -----------
270 format | string | *Required*.  Data format id of the data format that is used by this interface
271 version | string | *Required*.  Data format version of the data format that is used by this interface
272
273 Note, for CDAP, there is a slight variation due to the way CDAP exposes services:
274 ```
275       "provides":[                             // note this is a list of JSON
276          {  
277             "request":{  ...},
278             "response":{  ...},
279             "service_name":"name CDAP service", 
280             "service_endpoint":"greet",         // E.g the URL is /services/service_name/methods/service_endpoint
281             "verb":"GET"                        // GET, PUT, or POST
282          }
283       ]
284 ```
285
286 `provides` Schema for a CDAP component:
287
288 Property Name | Type | Description
289 ------------- | ---- | -----------
290 request | JSON object | *Required*.  Description of the expected request data format for this interface
291 response | JSON object | *Required*.  Description of the expected response for this interface
292 service_name | string | *Required*.  The CDAP service name (eg "Greeting")
293 service_endpoint | string | *Required*.  The CDAP service endpoint for this service_name (eg "/greet")
294 verb | string | *Required*.  'GET', 'PUT' or 'POST'
295
296
297 ## Parameters
298
299 `parameters` is where to specify the component's application configuration parameters that are not connection information.
300
301 Property Name | Type | Description
302 ------------- | ---- | -----------
303 parameters | JSON array | Each entry is a parameter object
304
305 Parameter object has the following available properties:
306
307 Property Name | Type | Description | Default
308 ------------- | ---- | ----------- | -------
309 name | string | *Required*. The property name that will be used as the key in the generated config |
310 value | any | *Required*.  The default value for the given parameter |
311 description | string | *Required*.  Human-readable text describing the parameter like what its for |
312 type | string | The required data type for the parameter |
313 required | boolean | An optional key that declares a parameter as required (true) or not (false) | true
314 constraints | array | The optional list of sequenced constraint clauses for the parameter. See below | 
315 entry_schema | string | The optional key that is used to declare the name of the Datatype definition for entries of set types such as the TOSCA 'list' or 'map'. Only 1 level is supported at this time | 
316 designer_editable | boolean | An optional key that declares a parameter to be editable by designer (true) or not (false) | true
317 sourced_at_deployment | boolean | An optional key that declares a parameter's value to be assigned at deployment time (true) | false
318 policy_editable | boolean | An optional key that declares a parameter to be editable by policy (true) or not (false) | true
319 policy_schema | array | The optional list of schema definitions used for policy. See below |
320
321 Example:
322
323 ```json
324 "parameters": [
325     {
326         "name": "threshold",
327         "value": 0.75,
328         "description": "Probability threshold to exceed to be anomalous"
329     }
330 ]
331 ```
332
333 Many of the parameter properties have been copied from TOSCA model property definitions and are to be used for service design composition and policy creation.  See [section 3.5.8 *Property definition*](http://docs.oasis-open.org/tosca/TOSCA-Simple-Profile-YAML/v1.1/TOSCA-Simple-Profile-YAML-v1.1.html).
334
335 The property `constraints` is a list of objects where each constraint object:
336
337 Property Name | Type | Description
338 ------------- | ---- | -----------
339 equal | | Constrains a property or parameter to a value equal to (‘=’) the value declared
340 greater_than | number | Constrains a property or parameter to a value greater than (‘>’) the value declared
341 greater_or_equal | number | Constrains a property or parameter to a value greater than or equal to (‘>=’) the value declared
342 less_than | number | Constrains a property or parameter to a value less than (‘<’) the value declared
343 less_or_equal | number | Constrains a property or parameter to a value less than or equal to (‘<=’) the value declared
344 valid_values | array | Constrains a property or parameter to a value that is in the list of declared values
345 length | number | Constrains the property or parameter to a value of a given length
346 min_length | number | Constrains the property or parameter to a value to a minimum length
347 max_length | number | Constrains the property or parameter to a value to a maximum length
348
349 `threshold` is the configuration parameter and will get set to 0.75 when the configuration gets generated.
350
351 The property `policy_schema` is a list of objects where each policy_schema object:
352
353 Property Name | Type | Description | Default
354 ------------- | ---- | ----------- | -------
355 name | string | *Required*. parameter name 
356 value | string | default value for the parameter
357 description | string | parameter description
358 type | enum | *Required*. data type of the parameter, 'string', 'number', 'boolean', 'datetime', 'list', or 'map'
359 required | boolean | is parameter required or not? | true
360 constraints | array | The optional list of sequenced constraint clauses for the parameter. See above | 
361 entry_schema | string | The optional key that is used to declare the name of the Datatype definition for certain types. entry_schema must be defined when the type is either list or map. If the type is list and the entry type is a simple type (string, number, bookean, datetime), follow with an string to describe the entry |
362 | | If the type is list and the entry type is a map, follow with an array to describe the keys for the entry map | 
363 | | If the type is list and the entry type is a list, that is not currently supported
364 | | If the type is map, follow with an aray to describe the keys for the map | 
365
366 ## Generated Application Configuration
367
368 The above example for component `asimov.component.kpi_anomaly` will get transformed into the following application configuration JSON that is fully resolved and provided at runtime by calling the `config binding service`:
369
370 ```json
371 {
372     "streams_publishes": {
373         "prediction": ["10.100.1.100:32567"]
374     },
375     "streams_subscribes": {},
376     "threshold": 0.75,
377     "services_calls": {
378         "vnf-db": ["10.100.1.101:32890"]
379     }
380 }
381 ```
382
383 ## Artifacts
384
385 `artifacts` contains a list of artifacts associated with this component.  For Docker, this is the full path (including the registry) to the Docker image. For CDAP, this is the full path to the CDAP jar.
386
387 Property Name | Type | Description
388 ------------- | ---- | -----------
389 artifacts | JSON array | Each entry is a artifact object
390
391 `artifact` Schema:
392
393 Property Name | Type | Description
394 ------------- | ---- | -----------
395 uri | string | *Required*. Uri to the artifact, full path
396 type | string | *Required*. `docker image` or `jar`
397