Fix pom.xml
[dcaegen2.git] / platformdoc / docs / components / dcae-cli / walkthrough.md
1 # Walk-through
2
3 The goal of this quickstart is to provide an overview of the functionalities of the `dcae-cli` and walk you through the capabilities:
4
5 * [Adding data formats](#adding-data-formats)
6 * [Adding component](#adding-component)
7 * [Setting profile](#setting-profile)
8 * [Development and testing](#development-and-testing)
9 * [Publishing component](#publishing-component)
10 * [Shared catalog](#shared-catalog)
11
12 This walk-through uses example projects:
13
14 * [laika](ONAP URL TBD)
15 * [CDAP examples](ONAP URL TBD)
16
17 ## Adding data formats
18
19 `data_format` is the sub-command that is used to execute operations that manage [data formats](../data-formats.md).
20
21 ```
22 $ dcae_cli data_format --help
23 Usage: dcae_cli data_format [OPTIONS] COMMAND [ARGS]...
24
25 Options:
26   --help  Show this message and exit.
27
28 Commands:
29   add      Tracks a data format file SPECIFICATION...
30   list     Lists all your data formats
31   publish  Publishes data format to make publicly...
32   show     Provides more information about FORMAT
33 ```
34
35 Your data format must be in the catalog in order to use in the component specification.  Check the catalog using the `data_format list` sub-command:
36
37 ```
38 $ dcae_cli data_format list
39
40 Data formats for mh677g
41 +------+---------+-------------+--------+----------+
42 | Name | Version | Description | Status | Modified |
43 +------+---------+-------------+--------+----------+
44 |      |         |             |        |          |
45 +------+---------+-------------+--------+----------+
46 ```
47
48 The fields `name`, `version`, `description` are referenced from the data format JSON from the `self` JSON.
49
50 There are no data formats so you must add the data formats that your component specification references.  Use the `data_format add` sub-command:
51
52 Here's an example command:
53
54 ```
55 dcae_cli data_format add health.json
56 ```
57
58 Verify that it was added:
59
60 ```
61 $ dcae_cli data_format list
62
63 Data formats for mh677g
64 +-------------------------------+---------+-------------------------------------------+--------+----------------------------+
65 | Name                          | Version | Description                               | Status | Modified                   |
66 +-------------------------------+---------+-------------------------------------------+--------+----------------------------+
67 | sandbox.platform.laika.health | 0.1.0   | Data format used for the /health endpoint | staged | 2017-05-23 04:02:38.952799 |
68 +-------------------------------+---------+-------------------------------------------+--------+----------------------------+
69 ```
70
71 Go ahead and add other referenced data formats.
72
73 ## Adding component
74
75 `component` is the sub-command that is used to work with operations for components:
76
77 ```
78 $ dcae_cli component --help
79 Usage: dcae_cli component [OPTIONS] COMMAND [ARGS]...
80
81 Options:
82   --help  Show this message and exit.
83
84 Commands:
85   add
86   dev       Set up component in development for...
87   list      Lists components in the public catalog.
88   publish   Pushes COMPONENT to the public catalog
89   run       Runs the latest version of COMPONENT.
90   show      Provides more information about COMPONENT
91   undeploy  Undeploys the latest version of COMPONENT.
92 ```
93
94 Your component must be accessible from the catalog in order for it to be used.  Check the catalog using the `component list` sub-command:
95
96 ```
97 $ dcae_cli component list
98 Active profile: solutioning
99
100 +------+---------+------+-------------+--------+----------+-----------+
101 | Name | Version | Type | Description | Status | Modified | #Deployed |
102 +------+---------+------+-------------+--------+----------+-----------+
103 |      |         |      |             |        |          |           |
104 +------+---------+------+-------------+--------+----------+-----------+
105
106 Use the "--deployed" option to see more details on deployments
107 ```
108
109 The fields `name`, `version`, `type`, `description` are referenced from the component specification's `self` JSON.
110
111 There are no components so you must add your component.  Use the `component add` sub-command.  The command is the same for docker and cdap components:
112
113 ```
114 $ dcae_cli component add --help
115 Usage: dcae_cli component add [OPTIONS] SPECIFICATION
116
117 Options:
118   --update  Updates a locally added component if it has not been already
119             pushed
120   --help    Show this message and exit.
121 ```
122
123 *Note* use the `--update` flag to replace existing staged instances.
124
125 The `component dev` sub-command can be useful in validating and experimenting when crafting your component specification.  See details about `dev` under [Development and testing](#development-and-testing).
126
127 Once we add the components laika and helloworld, let's verify that they got added ok:
128
129 ```
130 $ dcae_cli component list
131 Active profile: solutioning
132
133 +-------------------------+---------+--------+---------------------------------------------------------------+--------+----------------------------+-----------+
134 | Name                    | Version | Type   | Description                                                   | Status | Modified                   | #Deployed |
135 +-------------------------+---------+--------+---------------------------------------------------------------+--------+----------------------------+-----------+
136 | cdap.helloworld.endnode | 0.8.0   | cdap   | cdap test component                                           | staged | 2017-05-23 04:14:35.588075 | 0         |
137 | sandbox.platform.laika  | 0.5.0   | docker | Web service used as a stand-alone test DCAE service compone.. | staged | 2017-05-23 04:07:44.065610 | 0         |
138 +-------------------------+---------+--------+---------------------------------------------------------------+--------+----------------------------+-----------+
139
140 Use the "--deployed" option to see more details on deployments
141 ```
142
143 ## Setting profile
144
145 `profile` is the sub-command that is used to manage profiles.  These profiles contain environment variables used to connect to different environments.  This is used in the running and deployment of your component using the `dcae_cli component run` command.  The `dcae-cli` ships with profiles for `solutioning` and `rework`.
146
147 ```
148 $ dcae_cli profiles --help
149 Usage: dcae_cli profiles [OPTIONS] COMMAND [ARGS]...
150
151 Options:
152   --help  Show this message and exit.
153
154 Commands:
155   activate  Sets profile NAME as the active profile
156   create    Creates a new profile NAME initialized with...
157   delete    Deletes profile NAME
158   list      Lists available profiles
159   set       Updates profile NAME such that KEY=VALUE
160   show      Prints the profile dictionary
161 ```
162
163 To see what variables a profile contains, you can use the `show` command, as in `dcae_cli profiles show PROFILE_NAME`
164
165 Use the `create` sub-command to create your own profile and assign new values using the `set` command.  Afterwards you will need to `activate` the profile you wish to use.  First take a look at which profile is active:
166
167 ```
168 $ dcae_cli profiles list
169    rework
170 *  solutioning
171 ```
172
173 The active profile is `solutioning` so to activate *rework* to use `rework`:
174
175 ```
176 $ dcae_cli profiles activate rework
177 ```
178
179 Check
180
181 ```
182 $ dcae_cli profiles list
183 *  rework
184    solutioning
185 ```
186
187 ## Development and testing
188
189 The following operations under the sub-command `component` are aimed to help developers with testing:
190
191 * `run`
192 * `undeploy`
193 * `dev`
194
195 ### `run`
196
197 The `run` operation is to be used for running your application in its container remotely on the activated environment.  Docker containers have the additional option to run locally on your development machine.
198
199 In order to run your application, you must have added your data formats and your component to your catalog.
200
201 Let's verify that your component is in the catalog:
202
203 ```
204 $ dcae_cli component list                                                                                       
205 Active profile: solutioning
206
207 +-------------------------+---------+--------+---------------------------------------------------------------+--------+----------------------------+-----------+
208 | Name                    | Version | Type   | Description                                                   | Status | Modified                   | #Deployed |
209 +-------------------------+---------+--------+---------------------------------------------------------------+--------+----------------------------+-----------+
210 | cdap.helloworld.endnode | 0.8.0   | cdap   | cdap test component                                           | staged | 2017-05-23 04:14:35.588075 | 0         |
211 | sandbox.platform.laika  | 0.5.0   | docker | Web service used as a stand-alone test DCAE service compone.. | staged | 2017-05-23 04:07:44.065610 | 0         |
212 +-------------------------+---------+--------+---------------------------------------------------------------+--------+----------------------------+-----------+
213
214 Use the "--deployed" option to see more details on deployments
215 ```
216
217 #### Docker
218
219 **NOTE** Make sure your Docker image has been uploaded to the shared registry.
220
221 For Docker containers, you can run either attached or unattached.  Attached means that the dcae-cli tool will launch the container and not terminate.  The dcae-cli while attached will stream in the logs of the Docker container.  Doing a Ctrl-C will terminate the run session which means undeploy your container and force a clean up automatically.
222
223 #### CDAP
224
225 **NOTE** Make sure your CDAP jar has been uploaded to Nexus.
226
227 TODO
228
229 ### `undeploy`
230
231 The `undeploy` operation is to be used to undeploy any instances of a specified component, version that you have deployed.  This includes cleaning up of configuration.
232
233 Let's undeploy `sandbox.platform.laika` that was deployed from the previous section:
234
235 ```
236 $ dcae_cli component undeploy sandbox.platform.laika:0.5.0
237 DCAE.Undeploy | WARNING | Undeploying components: 1
238 DCAE.Undeploy | WARNING | Undeployed components: 1
239 ```
240
241 ### `dev`
242
243 The `dev` operation is a convenient operation that can be useful for the development and testing of your component.  It can be used to:
244
245 * Help validate your experimental component specification before uploading to the catalog
246 * Generate the application configuration from the component specification and make it available in a test environment.  This allows you to view your resulting configuration for local development and to help debug potential related issues.
247
248 Let's say you have a component specification called `component-spec.json`:
249
250 ```
251 $ dcae_cli component dev component-spec.json 
252 Ready for component development
253
254 Setup these environment varibles. Run "source env_solutioning":
255
256 export DOCKER_HOST=SOME_DOCKER_HOST:2376
257 export SERVICE_CHECK_INTERVAL=15s
258 export CONFIG_BINDING_SERVICE=config_binding_service
259 export HOSTNAME=mh677g.95740959-63d2-492a-b964-62a6dce2591d.0-6-0.sandbox-platform-laika
260 export CONSUL_HOST=SOME_CONSUL_HOST
261 export CDAP_BROKER=cdap_broker
262 export SERVICE_NAME=mh677g.95740959-63d2-492a-b964-62a6dce2591d.0-6-0.sandbox-platform-laika
263 export SERVICE_CHECK_TIMEOUT=1s
264 export SERVICE_CHECK_HTTP=/health
265
266 Press any key to stop and to clean up
267 ```
268
269 Your application configuration is now available under the name `mh677g.95740959-63d2-492a-b964-62a6dce2591d.0-6-0.sandbox-platform-laika`.
270
271 To view the resulting configuration, you can `curl` a request to the config binding service or programmatically fetch your configuration within your application.
272
273 You need to first query Consul to get the ip and port of config binding service:
274
275 ```
276 curl http://$CONSUL_HOST:8500/v1/catalog/service/$CONFIG_BINDING_SERVICE
277 [
278   {
279     "ID": "983d5c94-c508-4a8a-9be3-5912bd09786b",
280     "Node": "realsolcnsl00",
281     "Address": "10.226.1.22",
282     "TaggedAddresses": {
283       "lan": "10.226.1.22",
284       "wan": "10.226.1.22"
285     },
286     "NodeMeta": {},
287     "ServiceID": "5f371f295c90:config_binding_service:10000",
288     "ServiceName": "config_binding_service",
289     "ServiceTags": [],
290     "ServiceAddress": "XXXX",
291     "ServicePort": 32770,
292     "ServiceEnableTagOverride": false,
293     "CreateIndex": 487,
294     "ModifyIndex": 487
295   }
296 ]
297 ```
298
299 ### DMaaP testing
300
301 Currently, the dcae-cli does not have the capability of provisioning topics.  In order to do testing with message router topics or with data router feeds, the developer must provision the topic or the feed manually and provide the connection details in the form of a JSON in a file to the dcae-cli.  This file is to be passed in when using the `run` and `dev` commands with the option `--dmaap-file`.
302
303 The structure of the DMaaP JSON is an object of config keys to matching topic or feed connection details.  Config keys are the `config_key` values specified in your component specification streams section where the streams must be type message router or data router.  Information about the associated connection details can be found on [this page](dmaap-connection-objects.md).  Please check it out.
304
305 For example, if you have a component specification that has the following streams entry:
306
307 ```json
308 "streams": {
309     "publishes": [{
310         "format": "ves",
311         "version": "1.0.0",
312         "type": "message router",
313         "config_key": "ves_connection"
314     }]
315 }
316 ```
317
318 Then to deploy and to run your component, you must use the `--dmaap-file` command and pass in a JSON that looks like:
319
320 ```json
321 {
322     "ves_connection": {
323         "type": "message_router",
324         "dmaap_info": {
325             "topic_url": "https://we-are-message-router.us:3905/events/some-topic"
326         }
327     }
328 }
329 ```
330
331 The provided DMaaP JSON is used to simulate the output of provisioning and will be used to merge with the generated application configuration at runtime.
332
333 Your final application config will look like:
334
335 ```json
336 {
337     "streams_publishes": {
338         "ves_connection": {
339             "type": "message_router",
340             "dmaap_info": {
341                 "topic_url": "https://we-are-message-router.us:3905/events/some-topic"
342             }
343         }
344     }
345 }
346 ```
347
348 #### Data router subscribers
349
350 Note for data router subscriber testing, you will need the delivery url in order to provision the subscriber to the feed.  This is constructed at deployment time and will be provided by the dcae-cli after you deploy your component.  The delivery urls will be displayed to the screen:
351
352 ```
353 DCAE.Run | WARNING | Your component is a data router subscriber. Here are the delivery urls: 
354
355         some-sub-dr: http://SOME_IP:32838/identity
356
357 ```
358
359 ## Publishing component
360
361 Once components have their component specifications crafted and validated and have been tested, components should be published in the shared onboarding catalog using the `publish` sub-command for both data formats and components.  You must publish all data formats of a component before publishing a component.
362
363 Publishing will change the status of a component, be made accessible for other developers to use, and will generate the associated TOSCA models for use in designing of compositions.
364
365 ```
366 dcae_cli component publish sandbox.platform.laika:0.5.0
367 ```
368
369 ## Shared catalog
370
371 `catalog` is the sub-command used to access and to browse the shared onboarding catalog to view components and data formats that have been published and that are being worked on.  Components and data formats have two statuses `staged` and `published`.
372
373 Staged means that the resource has been simply added and is under development.  It is to be used only by the owner.  Published means that the resource has been fully developed and tested and is ready to be shared.
374
375 Published components can be deployed by non-owners and published data formats can be used in component specifications of non-owners.
376
377 There are two available operations:
378
379 ```
380 $ dcae_cli catalog --help
381 Usage: dcae_cli catalog [OPTIONS] COMMAND [ARGS]...
382
383 Options:
384   --help  Show this message and exit.
385
386 Commands:
387   list
388   show
389 ```
390
391 Staged components can be viewed under the `list` operation using the `--expanded` flag.