Onboarding documentation update for CLI
[dcaegen2.git] / docs / sections / components / component-specification / cdap-specification.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.\r
2 .. http://creativecommons.org/licenses/by/4.0\r
3 \r
4 .. _cdap-specification:\r
5 \r
6 Component specification (CDAP)\r
7 ==============================\r
8 \r
9 The CDAP component specification contains the following groups of\r
10 information. Many of these are common to both CDAP and Docker components\r
11 and are therefore described in the common specification.\r
12 \r
13 -  :any:`Metadata <metadata>`\r
14 -  :any:`Interfaces <interfaces>` including the\r
15    associated :any:`Data Formats <data-formats>`\r
16 -  :any:`Parameters <parameters>` - for specifying parameters in your\r
17    AppConfig, AppPreferences, and ProgramPreferences to the Designer and\r
18    Policy. This of course is CDAP-specific and is described below.\r
19 -  :any:`Auxiliary Details <auxiliary-details>`\r
20 -  :any:`List of artifacts <artifacts>`\r
21 \r
22 Current Limitations and TODOs\r
23 -----------------------------\r
24 \r
25 -  The integration of DMD is likely to significantly change the\r
26    :any:`Interfaces <interfaces>` section in this specification.\r
27 \r
28 .. _parameters:\r
29 \r
30 Parameters\r
31 ----------\r
32 \r
33 There is a ``parameters`` section in your component specification. This\r
34 section contains three optional keys: `app_config <#appconfig>`__,\r
35 `app_preferences <#apppreferences>`__, and\r
36 `program_preferences <#programpreferences>`__:\r
37 \r
38 ::\r
39 \r
40     "parameters" : {\r
41         "app_config" : [ ...],               \r
42         "app_preferences" : [ ...],          \r
43         "program_preferences" : [...]\r
44         // any additional keys are ignored\r
45     }\r
46 \r
47 -  Each section details the parameters that are a part of each of these\r
48    CDAP constructs (see below).\r
49 -  All such parameters will be exposed to the designer and to policy for\r
50    override.\r
51 -  These parameters should have default values specified by the\r
52    component developer where necessary, i.e., parameters that *must*\r
53    come from the designer/policy should not have defaults.\r
54 -  All of these keys are optional because not every CDAP application\r
55    uses preferences and not every application uses the AppConfig.\r
56    However, you should specify at least one, or else your application\r
57    will have no parameters exposed to policy or to the DCAE designer,\r
58    which means it would be non-configurable.\r
59 -  Despite the AppConfig being optional to *specify* in the case that\r
60    you have no parameters in your AppConfig, it is *required for\r
61    processing* in your application. That is because the DCAE platform\r
62    will place important information into your AppConfig as discussed\r
63    below.\r
64 \r
65 Parameter\r
66 ~~~~~~~~~\r
67 \r
68 The following CDAP specific definitions use ``param1`` to refer to the\r
69 common parameter layout in\r
70 :any:`Parameter <parameters>`\r
71 \r
72 AppConfig\r
73 ~~~~~~~~~\r
74 \r
75 The ``app_config`` key refers to the `CDAP AppConfig <http://docs.cask.co/cdap/current/en/reference-manual/http-restful-api/configuration.html>`_.\r
76 It is expected to be a JSON:\r
77 \r
78 ::\r
79 \r
80     "app_config" : [ // list of JSON\r
81         param1,      // common parameter layout\r
82         ...\r
83     ]\r
84 \r
85 Unfortunately, at the time of writing, the AppConfig is a Java map of\r
86 ``string:string``, which means you cannot have more complex structures\r
87 (than string) as any value in your AppConfig. However, there is a way to\r
88 bypass this constraint: you can pass a JSON by encoding the JSON as a\r
89 string. E.g., the ``json.dumps()`` and it’s converse ``loads`` methods\r
90 in Python:\r
91 \r
92 ::\r
93 \r
94     >>> import json\r
95     >>> json.dumps({"foo" : "bar"})     # This is a real JSON\r
96     '{"foo": "bar"}'                    # It is now a string: pass this in as your parameter value\r
97     >>> json.loads('{"foo": "bar"}')    # Do the equivelent of this in your application\r
98     {u'foo': u'bar'}                    # ...and you'll get back a real JSON \r
99     >>>\r
100 \r
101 The final AppConfig (after the designer and policy override parameter\r
102 values) is passed into CDAP’s AppConfig API when starting the\r
103 application.\r
104 \r
105 \r
106 AppPreferences\r
107 ~~~~~~~~~~~~~~\r
108 \r
109 In addition to the CDAP AppConfig, the platform supports `Application Preferences <http://docs.cask.co/cdap/current/en/reference-manual/http-restful-api/preferences.html#set-preferences>`_.\r
110 The format of the ``app_preferences`` value is the same as the above:\r
111 \r
112 ::\r
113 \r
114     "app_preferences" : [   // list of JSON\r
115         param1,      // common parameter layout\r
116         ...\r
117     ]\r
118 \r
119 The final Application Preferences JSON (after the designer and policy\r
120 override parameter values) is passed into CDAP’s Preferences API when\r
121 starting your application.\r
122 \r
123 \r
124 ProgramPreferences\r
125 ~~~~~~~~~~~~~~~~~~\r
126 \r
127 Preferences can also be specified `per program <http://docs.cask.co/cdap/current/en/reference-manual/http-restful-api/lifecycle.html#program-lifecycle>`_\r
128 in CDAP. This key’s value is a list of JSON with the following format:\r
129 \r
130 ::\r
131 \r
132     "program_preferences" : [                // note: this is a list of JSON \r
133         {\r
134           "program_id" :   "program name 1",  // the name of this CDAP program\r
135           "program_type" : "e.g., flows",     // "must be one of flows, mapreduce, schedules, spark, workflows, workers, or services",\r
136           "program_pref" : [                  // list of JSON\r
137           param1,      // common parameter layout\r
138               ...\r
139           ]\r
140         },\r
141         // repeat for each program that receives a program_preferences JSON \r
142     ]\r
143 \r
144 Each ``program_pref`` JSON is passed into the CDAP API as the preference\r
145 for ``program_id``.\r
146 \r
147 NOTE: for CDAP, this section is very likely to change when DMD is\r
148 available. The *future* vision is\r
149 that you would publish your data as a series of files on HDFS, and DMD\r
150 will pick them up and send them to the appropriate DMaaP feeds or\r
151 directly when needed.\r
152 \r
153 .. _auxiliary-details:\r
154 \r
155 Auxiliary Details\r
156 -----------------\r
157 \r
158 *auxiliary* contains details about CDAP specific parameters.\r
159 \r
160 +----------------------+----------------------+----------------------+\r
161 | Property Name        | Type                 | Description          |\r
162 +======================+======================+======================+\r
163 | streamname           | string               | *Required*.          |\r
164 +----------------------+----------------------+----------------------+\r
165 | artifact_name        | string               |                      |\r
166 +----------------------+----------------------+----------------------+\r
167 | artifact_version     | string               | the version of your  |\r
168 |                      |                      | CDAP JAR artifact    |\r
169 +----------------------+----------------------+----------------------+\r
170 | namespace            | string               | the CDAP namespace   |\r
171 |                      |                      | to deploy into,      |\r
172 |                      |                      | default is ‘default’ |\r
173 +----------------------+----------------------+----------------------+\r
174 | programs             | array                | contains each CDAP   |\r
175 |                      |                      | entity represented   |\r
176 |                      |                      | in the artifact      |\r
177 +----------------------+----------------------+----------------------+\r
178 | program_type         | string               | CDAP entity (eg      |\r
179 |                      |                      | “flows”)             |\r
180 +----------------------+----------------------+----------------------+\r
181 | program_id           | string               | name of CDAP entity  |\r
182 |                      |                      | (eg “WhoFlow”)       |\r
183 +----------------------+----------------------+----------------------+\r
184 \r
185 Example:\r
186 \r
187 .. code:: json\r
188 \r
189     "auxiliary": {\r
190         "streamname" : "who",\r
191         "artifact_name" : "HelloWorld",\r
192         "artifact_version" : "3.4.3",\r
193         "namespace" : "hw",\r
194         "programs" : [\r
195                         {"program_type" : "flows", "program_id" : "WhoFlow"}, \r
196                         {"program_type" : "services", "program_id" : "Greeting"},\r
197                         ...\r
198                       ],\r
199     }\r
200 \r
201 The ``programs`` key is identical to the ``program_preferences`` key\r
202 discussed `above <#programpreferences>`__ except:\r
203 \r
204 -  each JSON in the list does not contain ``program_pref``\r
205 -  this is required! You must include all of your programs in this, as\r
206    it is used to start each program as well as for DCAE to perform\r
207    periodic healthchecks on your application. Don’t forget about your\r
208    services; they are programs too.\r