Onboarding documentation update for CLI
[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 ## Meta Schema Definition
6
7 The component specification is represented (and validated) against this
8 [Component Spec json schema](https://codecloud.web.att.com/projects/ST_DCAECNTR/repos/component-json-schemas/browse/component-spec-schema.json) and described below:
9
10 The "Meta Schema" implementation defines how component specification JSON schemas can be written to define user input. It is itself a JSON schema (thus it is a "meta schema").  It requires the name of the component entry, component type (either 'cdap' or 'docker') and a description under "self" object. The meta schema version must be specified as the value of the "version" key.  Then the input schema itself is described.
11
12 The table below shows the four types of schema descriptions supported
13 There are four types of schema descriptions objects - jsonschema for inline standard JSON Schema definitions of JSON inputs, delimitedschema for delimited data input using a JSON description defined by AT&T, unstructured for unstructured text, and reference that allows a pointer to another artifact for a schema.  The reference allows for XML schema, but can be used as a pointer to JSON, Delimited Format, and Unstructured schemas as well.
14
15 ## Component Metadata
16 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. 
17
18 Example:
19
20 ```
21 "self": {
22     "version": "1.0.0",
23     "name": "asimov.component.kpi_anomaly",
24     "description": "Classifies VNF KPI data as anomalous",
25     "component_type": "docker"
26 },
27 ```
28
29 `self` Schema:
30
31 Property Name | Type | Description
32 ------------- | ---- | -----------
33 version | string | *Required*.  Semantic version for this specification
34 name | string | *Required*.  Full name of this component which is also used as this component's catalog id.
35 description | string | *Required*. Human-readable text describing the component and the components functional purpose.
36 component_type | string | *Required*.  Identify what containerization technology this component uses: `docker` or `cdap`.
37
38 ## Interfaces
39 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).
40
41 ### Streams
42  * 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.
43 * 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.
44 * Streams have anonymous publish/subscribe semantics, which decouples the production of information from its consumption.
45 Like the component specification, the data format specification is represented/validated against this
46 [Data Format json schema](https://codecloud.web.att.com/projects/ST_DCAECNTR/repos/component-json-schemas/browse/data-format-schema.json)
47
48 * In general, components are not aware of who they are communicating with.
49 * Instead, components that are interested in data, subscribe to the relevant stream; components that generate data publish to the relevant stream.
50 * There can be multiple publishers and subscribers to a stream. Streams are intended for unidirectional, streaming communication.
51
52
53 Streams interfaces that implement an HTTP endpoint must support POST.
54
55 Streams are split into:
56
57 Property Name | Type | Description
58 ------------- | ---- | -----------
59 subscribes | JSON list | *Required*.  List of all available stream interfaces that this component has that can be used for subscribing
60 publishes | JSON list | *Required*.  List of all stream interfaces that this component will publish onto
61
62 #### Subscribes
63
64 Example:
65
66 ```json
67 "streams": {
68     "subscribes": [{
69         "format": "dcae.vnf.kpi",
70         "version": "1.0.0",
71         "route": "/data",        // for CDAP this value is not used
72         "type": "http"
73     }],
74 ...
75 }
76 ```
77
78 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`.
79
80 `subscribes` Schema:
81
82 Property Name | Type | Description
83 ------------- | ---- | -----------
84 format | string | *Required*.  Data format id of the data format that is used by this interface
85 version | string | *Required*.  Data format version of the data format that is used by this interface
86 route | string | *Required for HTTP and data router*.  The HTTP route that this interface listens on
87 config_key | string | *Required for message_router and data router*.  The HTTP route that this interface listens on
88 type | string | *Required*. Type of stream: `http`, `message_router`, `data_router`
89
90
91 ##### Message router
92
93 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`:
94
95 ```json
96 "streams": {
97     "subscribes": [{
98         "format": "dcae.some-format",
99         "version": "1.0.0",
100         "config_key": "some_format_handle",
101         "type": "message router"
102     }],
103 ...
104 }
105 ```
106
107 ##### Data router
108
109 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](/components/component-specification/dmaap-connection-objects/#data-router) for more details on the configuration information.
110
111 Example (not tied to the larger example):
112
113 ```json
114 "streams": {
115     "subscribes": [{
116         "config_key": "some-sub-dr",
117         "format": "sandbox.platform.any",
118         "route": "/identity",
119         "type": "data_router",
120         "version": "0.1.0"
121     }],
122 ...
123 }
124 ```
125
126 #### Publishes
127
128 Example:
129
130 ```json
131 "streams": {
132 ...
133     "publishes": [{
134         "format": "asimov.format.integerClassification",
135         "version": "1.0.0",
136         "config_key": "prediction",
137         "type": "http"
138     }]
139 },
140
141 ```
142
143 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`.
144
145 `publishes` Schema:
146
147 Property Name | Type | Description
148 ------------- | ---- | -----------
149 format | string | *Required*.  Data format id of the data format that is used by this interface
150 version | string | *Required*.  Data format version of the data format that is used by this interface
151 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.
152 type | string | *Required*. Type of stream: `http`, `message router`, `data router`
153
154 ##### Message router
155
156 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 needs to receive e.g. topic url, username, password.  See the page on [DMaaP connection objects](/components/component-specification/dmaap-connection-objects/#message-router) for more details on the configuration information.
157
158 Example (not tied to the larger example):
159
160 ```json
161 "streams": {
162 ...
163     "publishes": [{
164         "config_key": "some-pub-mr",
165         "format": "sandbox.platform.any",
166         "type": "message_router",
167         "version": "0.1.0"
168     }]
169 }
170 ```
171
172 ##### Data router
173
174 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](/components/component-specification/dmaap-connection-objects/#data-router) for more details on the configuration information.
175
176 Example (not tied to the larger example):
177
178 ```json
179 "streams": {
180 ...
181     "publishes": [{
182         "config_key": "some-pub-dr",
183         "format": "sandbox.platform.any",
184         "type": "data_router",
185         "version": "0.1.0"
186     }]
187 }
188 ```
189
190 #### Quick Reference
191
192 Refer to this [Quick Reference](/components/component-specification/streams-grid.md) for a comparison of the Streams 'Publishes' and 'Subscribes' sections.
193
194
195 ### Services
196
197 * The publish / subscribe model is a very flexible communication paradigm, but its many-to-many one-way transport is not appropriate for RPC
198 request / reply interactions, which are often required in a distributed system.
199 * Request / reply is done via a Service, which is defined by a pair of messages: one for the request and one for the reply.
200
201 Services are split into:
202
203 Property Name | Type | Description
204 ------------- | ---- | -----------
205 calls | JSON list | *Required*.  List of all service interfaces that this component will call
206 provides | JSON list | *Required*.  List of all service interfaces that this component exposes and provides
207
208 #### Calls
209 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.
210 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`. 
211
212 Example:
213
214 ```json
215 "services": {
216     "calls": [{
217         "config_key": "vnf-db",
218         "request": {
219             "format": "dcae.vnf.meta",
220             "version": "1.0.0"
221             },
222         "response": {
223             "format": "dcae.vnf.kpi",
224             "version": "1.0.0"
225             }
226     }],
227 ...
228 }
229 ```
230
231 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`.
232
233 `calls` Schema:
234
235 Property Name | Type | Description
236 ------------- | ---- | -----------
237 request | JSON object | *Required*.  Description of the expected request for this downstream interface
238 response | JSON object | *Required*.  Description of the expected response for this downstream interface
239 config_key | string | *Required*.  The JSON key in the generated application configuration that will be used to pass the downstream component connection information.
240
241 The JSON object schema for both `request` and `response`:
242
243 Property Name | Type | Description
244 ------------- | ---- | -----------
245 format | string | *Required*.  Data format id of the data format that is used by this interface
246 version | string | *Required*.  Data format version of the data format that is used by this interface
247
248 #### Provides
249
250 Example:
251
252 ```json
253 "services": {
254 ...
255     "provides": [{
256         "route": "/score-vnf",
257         "request": {
258             "format": "dcae.vnf.meta",
259             "version": "1.0.0"
260             },
261         "response": {
262             "format": "asimov.format.integerClassification",
263             "version": "1.0.0"
264             }
265     }]
266 },
267 ```
268
269 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`.
270
271 `provides` Schema for a Docker component:
272
273 Property Name | Type | Description
274 ------------- | ---- | -----------
275 request | JSON object | *Required*.  Description of the expected request for this interface
276 response | JSON object | *Required*.  Description of the expected response for this interface
277 route | string | *Required*.  The HTTP route that this interface listens on
278
279 The JSON object schema for both `request` and `response`:
280
281 Property Name | Type | Description
282 ------------- | ---- | -----------
283 format | string | *Required*.  Data format id of the data format that is used by this interface
284 version | string | *Required*.  Data format version of the data format that is used by this interface
285
286 Note, for CDAP, there is a slight variation due to the way CDAP exposes services:
287 ```
288       "provides":[                             // note this is a list of JSON
289          {  
290             "request":{  ...},
291             "response":{  ...},
292             "service_name":"name CDAP service", 
293             "service_endpoint":"greet",         // E.g the URL is /services/service_name/methods/service_endpoint
294             "verb":"GET"                        // GET, PUT, or POST
295          }
296       ]
297 ```
298
299 `provides` Schema for a CDAP component:
300
301 Property Name | Type | Description
302 ------------- | ---- | -----------
303 request | JSON object | *Required*.  Description of the expected request data format for this interface
304 response | JSON object | *Required*.  Description of the expected response for this interface
305 service_name | string | *Required*.  The CDAP service name (eg "Greeting")
306 service_endpoint | string | *Required*.  The CDAP service endpoint for this service_name (eg "/greet")
307 verb | string | *Required*.  'GET', 'PUT' or 'POST'
308
309
310 ## Parameters
311
312 `parameters` is where to specify the component's application configuration parameters that are not connection information.
313
314 Property Name | Type | Description
315 ------------- | ---- | -----------
316 parameters | JSON array | Each entry is a parameter object
317
318 Parameter object has the following available properties:
319
320 Property Name | Type | Description | Default
321 ------------- | ---- | ----------- | -------
322 name | string | *Required*. The property name that will be used as the key in the generated config |
323 value | any | *Required*.  The default value for the given parameter |
324 description | string | *Required*.  Human-readable text describing the parameter like what its for |
325 type | string | The required data type for the parameter |
326 required | boolean | An optional key that declares a parameter as required (true) or not (false) | true
327 constraints | array | The optional list of sequenced constraint clauses for the parameter. See below | 
328 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 | 
329 designer_editable | boolean | An optional key that declares a parameter to be editable by designer (true) or not (false) | 
330 sourced_at_deployment | boolean | An optional key that declares a parameter's value to be assigned at deployment time (true) |
331 policy_editable | boolean | An optional key that declares a parameter to be editable by policy (true) or not (false) | 
332 policy_schema | array | The optional list of schema definitions used for policy. See below |
333
334 Example:
335
336 ```json
337 "parameters": [
338     {
339         "name": "threshold",
340         "value": 0.75,
341         "description": "Probability threshold to exceed to be anomalous"
342     }
343 ]
344 ```
345
346 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).
347
348 The property `constraints` is a list of objects where each constraint object:
349
350 Property Name | Type | Description
351 ------------- | ---- | -----------
352 equal | | Constrains a property or parameter to a value equal to (‘=’) the value declared
353 greater_than | number | Constrains a property or parameter to a value greater than (‘>’) the value declared
354 greater_or_equal | number | Constrains a property or parameter to a value greater than or equal to (‘>=’) the value declared
355 less_than | number | Constrains a property or parameter to a value less than (‘<’) the value declared
356 less_or_equal | number | Constrains a property or parameter to a value less than or equal to (‘<=’) the value declared
357 valid_values | array | Constrains a property or parameter to a value that is in the list of declared values
358 length | number | Constrains the property or parameter to a value of a given length
359 min_length | number | Constrains the property or parameter to a value to a minimum length
360 max_length | number | Constrains the property or parameter to a value to a maximum length
361
362 `threshold` is the configuration parameter and will get set to 0.75 when the configuration gets generated.
363
364 The property `policy_schema` is a list of objects where each policy_schema object:
365
366 Property Name | Type | Description | Default
367 ------------- | ---- | ----------- | -------
368 name | string | *Required*. parameter name 
369 value | string | default value for the parameter
370 description | string | parameter description
371 type | enum | *Required*. data type of the parameter, 'string', 'number', 'boolean', 'datetime', 'list', or 'map'
372 required | boolean | is parameter required or not? | true
373 constraints | array | The optional list of sequenced constraint clauses for the parameter. See above | 
374 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 |
375 | | If the type is list and the entry type is a map, follow with an array to describe the keys for the entry map | 
376 | | If the type is list and the entry type is a list, that is not currently supported
377 | | If the type is map, follow with an aray to describe the keys for the map | 
378
379 ## Generated Application Configuration
380
381 The Platform generates configuration for the component (based on the component spec) at deployment time. The generated application configuration will be made up of the Parameters, Streams, and Services sections, after any provisioning for streams and services. The component developer can see what this configuration will look like by reviewing the [component dev command](/components/dcae_cli/commands/#run-the-dev-command).
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
398 # Working with Component Specs
399
400 Components can be added to the onboarding catalog (which first validates the component spec) by using the [dcae_cli Tool](http://dcae-platform.research.att.com/components/dcae-cli/quickstart/). Here you can also list the components, show the contents of a component, publish the component, validate the generated configuration for the component, deploy (run) and undeploy the component. For a list of these capabilities, see [Component Commands](/components/dcae-cli/commands/#component).
401
402