1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
runsOnPserverrunsOnPserver# CRUD Microservice (Gizmo)
## Overview
The CRUD microservice implements a set of RESTful APIs which allow a client to perform CREATE, UPDATE, GET, and DELETE operations on verticies and edges within the A&AI graph database.
## Getting Started
### Building The Microservice
After cloning the project, execute the following Maven command from the project's top level directory to build the project:
> mvn clean install
Now, you can build your Docker image:
> docker build -t openecomp/crud-service target
### Deploying The Microservice
Push the Docker image that you have built to your Docker repository and pull it down to the location from which you will be running the service.
**Create the following directories on the host machine:**
../logs
../appconfig
../appconfig/auth
You will be mounting these as data volumes when you start the Docker container.
#### Configuring the Microservice
Create configuration file **../appconfig/crud-api.properties**
# List of hostnames/addresses of the graph database
crud.graph.host=graphhost1.onap.com,graphhost2.onap.com
# Port on which to connect to the graph database
crud.graph.port=2181
# Name of the graph on which this service will operate
crud.graph.name=aaigraphautomation
# Backend storage type for the graph. Types currently supported:
# - cassandra
# - hbase
crud.storage.backend.db=cassandra
# List of hostnames/addresses of the DMaaP/Kafka cluster on which to post notification events
event.stream.hosts=kafkahost1.onap.com,kafkahost2.onap.com
# Number of events to bath up before posting to DMaaP/Kafka
event.stream.batch-size=100
# Amount of time (in ms) to wait before sending batch of events (when batch does not reach batch-size)
event.stream.batch-timeout=60000
Create configuration file **../appconfig/auth/crud-policy.json**
This policy file defines which client certificates are authorized to use the service's APIs. An example policy file follows:
{
"roles": [
{
"name": "admin",
"functions": [
{
"name": "search", "methods": [ { "name": "GET" },{ "name": "DELETE" }, { "name": "PUT" }, { "name": "POST" } ]
}
],
"users": [
{
"username": "CN=admin, OU=My Organization Unit, O=, L=Sometown, ST=SomeProvince, C=CA"
}
]
}
]
}
Create keystore file **../appconfig/auth/tomcat\_keystore**
_tomcat\_keystore_
Create a keystore with this name containing whatever CA certificates that you want your instance of the CRUD service to accept for HTTPS traffic.
#### Start the service
You can now start the Docker container in the following manner:
docker run -d \
-p 9520:9520 \
-e CONFIG_HOME=/opt/app/crud-service/config/ \
-e KEY_STORE_PASSWORD={{obfuscated password}} \
-e KEY_MANAGER_PASSWORD=OBF:{{obfuscated password}} \
-v /<path>/logs:/opt/aai/logroot/AAI-CRUD \
-v /<path>/appconfig:/opt/app/crud-service/config \
--name crud-service \
{{your docker repo}}/crud-service
Where,
{{your docker repo}} = The Docker repository you have published your CRUD Service image to.
{{obfuscated password}} = The password for your key store/key manager after running it through the Jetty obfuscation tool.
## API Definitions
### Echo API
URL: https://<host>:9520/services/crud-api/v1/echo-service/echo/<input>
Method: GET
Success Response: 200
### Create Vertex
Vertex payload data is validated against oxm.
* Mandatory attributes are required in payload
* Data type validation is enforced
* Defaults from oxm schema used when not specified in payload
URL: https://<host>:9520/services/inventory/v8/pserver/
Method: POST
Body:
{
"properties":{
"ptnii-equip-name":"e-name",
"equip-type":"server",
"hostname":"myhost",
"equip-vendor":"HP",
"equip-model":"DL380p-nd",
"fqdn":myhost.onap.net",
"purpose":"my-purpose",
"resource-version":"1477013499",
"ipv4-oam-address":"1.2.3.4"
}
}
Success Response:
Code: 201
Content:
{
"id":"1130672",
"type":"pserver",
"url":"services/inventory/v8/pserver/1130672",
"properties":{
"ptnii-equip-name":"e-name",
"equip-type":"server",
"hostname":"myhost",
"equip-vendor":"HP",
"equip-model":"DL380p-nd",
"fqdn":myhost.onap.net",
"purpose":"my-purpose",
"resource-version":"1477013499",
"ipv4-oam-address":"1.2.3.4"
}
}
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
Optionally, a vertex can be created by posting to an endpoint which doesn't include the vertex type.
URL: https://<host>:9520/services/inventory/v8/
Method: POST
Body:
{
"type":"pserver",
"properties":{
"ptnii-equip-name":"e-name",
"equip-type":"server",
"hostname":"myhost",
"equip-vendor":"HP",
"equip-model":"DL380p-nd",
"fqdn":myhost.onap.net",
"purpose":"my-purpose",
"resource-version":"1477013499",
"ipv4-oam-address":"1.2.3.4"
}
}
Success Response:
Code: 201
Content:
{
"id":"1130672",
"type":"pserver",
"url":"services/inventory/v8/pserver/1130672",
"properties":{
"ptnii-equip-name":"e-name",
"equip-type":"server",
"hostname":"myhost",
"equip-vendor":"HP",
"equip-model":"DL380p-nd",
"fqdn":myhost.onap.net",
"purpose":"my-purpose",
"resource-version":"1477013499",
"ipv4-oam-address":"1.2.3.4"
}
}
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Get Vertex
URL: https://<host>:9520/services/inventory/v8/pserver/<id>
Method: GET
Success Response:
Code: 200
Content:
{
"id":"1130672",
"type":"pserver",
"url":"services/inventory/v8/pserver/<id>",
"properties":{
"ptnii-equip-name":"e-name",
"equip-type":"server",
"hostname":"myhost",
"equip-vendor":"HP",
"equip-model":"DL380p-nd",
"fqdn":myhost.onap.net",
"purpose":"my-purpose",
"resource-version":"1477013499",
"ipv4-oam-address":"1.2.3.4"
},
"in":[
],
"out":[
{
"id":"1crwnu-6hc-d6vp-oe08g",
"type":"has",
"target":"services/inventory/v8/vserver/40964272",
"url":"services/inventory/relationships/v8/has/1crwnu-6hc-d6vp-oe08g"
}
]
}
Error Response:
Code: 404 (NOT FOUND)
Situation: Resource Not found
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Get Vertices
URL: https://<host>:9520/services/inventory/v8/pserver/
Optional Query Param: ?equip-vendor=HP
Method: GET
Success Response:
Code: 200
Content:
[
{
"id":"950296",
"type":"pserver",
"url":"services/inventory/v8/pserver/950296"
},
{
"id":"1126576",
"type":"pserver",
"url":"services/inventory/v8/pserver/1126576"
},
{
"id":"1032384",
"type":"pserver",
"url":"services/inventory/v8/pserver/1032384"
}
]
Error Response:
Code: 404 (NOT FOUND)
Situation: Resource Not found
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Update Vertex
The PUT command is used to modify an existing vertex. By default, the vertex data is replaced by the content of the payload. However, teh following parameter can be added to the header to perform a PATCH instead of a replace:
**X-HTTP-Method-Override=Patch**
URL: https://<host>:9520/services/inventory/v8/pserver/<id>
Method: PUT
Body: Same as POST
Success Response:
Code: 201
Content: Same as POST
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Patch Vertex
URL: https://<host>:9520/services/inventory/v8/pserver/<id>
Method: PATCH (Content-Type header set to application/merge-patch+json)
Body:
{
"properties":{
"ptnii-equip-name":"e-name",
"resource-version":"1477013499",
"ipv4-oam-address":"1.2.3.99"
}
}
Success Response:
Code: 200
Content: Same as POST
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Delete Vertex
URL: https://<host>:9520/services/inventory/v8/pserver/<id>
Method: DELETE
Success Response:
Code: 200
Error Response:
Code: 404 (NOT FOUND)
Situation: Resource not found
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Create Edge
When creating an edge, the CRUD service will validate:
* properties match the defined schema
* relationship is valid between the source and target
URL: https://<host>:9520/services/inventory/relationships/v8/runsOnPserver/
Method: POST
Body:
{
"source":"services/inventory/v8/vserver/0",
"target":"services/inventory/v8/pserver/7",
"properties":{
"multiplicity":"many",
"is-parent":true,
"uses-resource":"true",
"has-del-target":"true"
}
}
Success Response:
Code: 201
Content:
{
"id":"215x5m-6hc-d6vp-oe08g",
"type":"runsOnPserver",
"url":"services/inventory/relationships/v8/has/215x5m-6hc-d6vp-oe08g",
"source":"services/inventory/v8/vserver/0",
"target":"services/inventory/v8/pserver/7",
"properties":{
"is-parent":"true",
"multiplicity":"many",
"has-del-target":"true",
"uses-resource":"true"
}
}
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
Optionally, an edge can be created by posting to an endpoint which doesn't include the edge type.
URL: https://<host>:9520/services/inventory/relationships/v8/
Method: POST
Body:
{
"type":"runsOnPserver",
"source":"services/inventory/v8/vserver/0",
"target":"services/inventory/v8/pserver/7",
"properties":{
"multiplicity":"many",
"is-parent":true,
"uses-resource":"true",
"has-del-target":"true"
}
}
Success Response:
Code: 201
Content: Same as above
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Create Edge With Auto-Population Of Edge Properties
An alternate endpoint exists for creating edges which follows all of the conventions of the above endpoints, with the addition that properties defined in the db edge rules produced by the A&AI will be automatically populated for the edge.
URL: https://<host>:9520/services/resources/relationships/runsOnPserver/
Method: POST
Body:
{
"source":"services/inventory/v8/vserver/0",
"target":"services/inventory/v8/pserver/7",
"properties":{
}
}
Success Response:
Code: 201
Content:
{
"id":"215x5m-6hc-d6vp-oe08g",
"type":"runsOnPserver",
"url":"services/inventory/relationships/v8/has/215x5m-6hc-d6vp-oe08g",
"source":"services/inventory/v8/vserver/0",
"target":"services/inventory/v8/pserver/7",
"properties":{
"contains-other-v": "NONE",
"delete-other-v": "NONE",
"SVC-INFRA": "OUT",
"prevent-delete": "IN"
}
}
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
The same option to POST to an endpoint without specifying a type in the URL exists for this endpoint as well:
URL: https://<host>:9520/services/resources/relationships/
Method: POST
Body:
{
"type":"runsOnPserver",
"source":"services/inventory/v8/vserver/0",
"target":"services/inventory/v8/pserver/7",
"properties":{
"multiplicity":"many",
"is-parent":true,
"uses-resource":"true",
"has-del-target":"true"
}
}
Success Response:
Code: 201
Content: Same as above
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Get Edge
URL: https://<host>:9520/services/inventory/relationships/v8/runsOnPserver/<id>
Method: GET
Success Response:
Code: 200
Content:
{
"id":"215x5m-6hc-d6vp-oe08g",
"type":"runsOnPserver",
"url":"services/inventory/relationships/v8/has/215x5m-6hc-d6vp-oe08g",
"source":"services/inventory/v8/vserver/8400",
"target":"services/inventory/v8/pserver/40964272",
"properties":{
"is-parent":"true",
"multiplicity":"many",
"has-del-target":"true",
"uses-resource":"true"
}
}
Error Response:
Code: 404 (NOT FOUND)
Situation: Resource Not found
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Get Edges
URL: https://<host>:9520/services/inventory/relationships/v8/runsOnPserver
Optional Query Param: ?multiplicity=many
Method: GET
Success Response:
Code: 200
Content:
[
{
"id":"1crwnu-6hc-d6vp-oe08g",
"type":"runsOnPserver",
"url":"services/inventory/relationships/v8/runsOnPserver/1crwnu-6hc-d6vp-oe08g",
"source":"services/inventory/v8/vserver/8400",
"target":"services/inventory/v8/pserver/40964272"
},
{
"id":"215x5m-6hc-d6vp-oe08g",
"type":"runsOnPserver",
"url":"services/inventory/relationships/v8/runsOnPserver/215x5m-6hc-d6vp-oe08g",
"source":"services/inventory/v8/vserver/8400",
"target":"services/inventory/v8/pserver/40964272"
}
]
Error Response:
Code: 404 (NOT FOUND)
Situation: Resource Not found
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Update Edge
The PUT command is used to modify an existing edge. By default, the edge data is replaced by the content of the payload. However, the following parameter can be added to the header to perform a PATCH instead of a replace:
**X-HTTP-Method-Override=Patch**
URL: https://<host>:9520/services/inventory/relationships/v8/runsOnPserver/<id>
Method: PUT
Body: (**Note that the source and target can not be modified)
{
"properties":{
"multiplicity":"many",
"is-parent":true,
"uses-resource":"true",
"has-del-target":"true"
}
}
Success Response:
Code: 200
Content: Same as POST
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Patch Edge
URL: https://<host>:9520/services/inventory/relationships/v8/runsOnPserver/<id>
Method: PATCH (Content-Type header set to application/merge-patch+json)
Body:
{
"properties":{
"multiplicity":"many"
}
}
Success Response:
Code: 200
Content: Same as POST
Error Response:
Code: 400 (BAD REQUEST)
Content: Error message describing the bad request failure.
Situation: Invalid Payload or schema error.
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
### Delete Edge
URL: https://<host>:9520/services/inventory/relationships/v8/runsOnPserver/<id>
Method: DELETE
Success Response:
Code: 200
Error Response:
Code: 404 (NOT FOUND)
Situation: Resource not found
Code: 403 (FORBIDDEN)
Content: Error message describing the Authorization failure.
Situation: Authorization failure.
Code: 415 (UNSUPPORTED MEDIA TYPE)
Situation: Unsupported content type .
Code: 500 (Internal Server Error)
Content: Error message describing the failure.
Situation: Any scenario not covered by the above error codes.
|