NONRTRIC - Adding information consumer before information type
[nonrtric.git] / test / prodstub / README.md
1 ## producer stub - a stub interface to simulate data producers ##
2
3 The producer stub is intended for function tests of simulate data producers.
4 The simulator handles the callbacks for supervision of producers as well as create/update and delete jobs.
5 As an intial step, the indended job and producers, with supported types, are setup (armed) in the simulator.
6 In addition, specific response codes can configured for each callback request.
7
8
9 # Ports and certificates
10 The prodstub normally opens the port 8092 for http. If a certificate and a key are provided the simulator will also open port 8093 for https.
11 The certificate and key shall be placed in the same dir and the dir shall be mounted to /usr/src/app/cert in the container.
12
13 | Port     | Protocol |
14 | -------- | ----- |
15 | 8092     | http  |
16 | 8093     | https |
17
18 The dir cert contains a self-signed cert. Use the script generate_cert_and_key.sh to generate a new certificate and key. The password of the certificate must be set 'test'.
19 The same urls are availables on both the http port 8092 and the https port 8093. If using curl and https, the flag -k shall be given to make curl ignore checking the certificate.
20
21
22 ### Prodstub interface ###
23
24 >Create callback<br>
25 This method receives a callback for create job. The request shall contain a job json. The request is checked towards what has been setup (armed) and the response will be set accordingly. <br>
26 ```URI and payload, (POST): /callbacks/job/<producer_id>,  <job-json>```<br>
27 ```response: 200/201 (or configured response) or 400 for other errors```
28
29 >Delete callback<br>
30 This method receives a callback for delete job. The request is checked towards what has been setup (armed) and the response will be set accordingly. <br>
31 ```URI and payload, (DELETE): /callbacks/job/<producer_id>```<br>
32 ```response: 204 (or configured response) or 400 for other errors```
33
34 >Supervision callback<br>
35 This method receives a callback for producer supervision. The request is checked towards what has been setup (armed) and the response will be set accordingly. <br>
36 ```URI and payload, (GET): /callbacks/supervision/<producer_id>```<br>
37 ```response: 200 (or configured response) or 400 for other errors```
38
39
40 ### Control interface ###
41
42 The control interface can be used by any test script.
43 The following REST operations are available:
44
45 >Arm a job create<br>
46 This method arms a job for creation and sets an optional response code for create/update<br>
47 ```URI and payload, (PUT): /arm/create/<producer_id>/<job_id>[?response=<resonsecode>]```<br>
48 ```response: 200 or 400 for other errors```
49
50 >Arm a job delete<br>
51 This method arms a job for deletion and sets an optional response code for delete<br>
52 ```URI and payload, (PUT): /arm/delete/<producer_id>/<job_id>[?response=<resonsecode>]```<br>
53 ```response: 200 or 400 for other errors```
54
55 >Arm a producer supervision<br>
56 This method arms a supervision and sets an optional response code for supervision calls<br>
57 ```URI and payload, (PUT): /arm/delete/<producer_id>[?response=<resonsecode>]```<br>
58 ```response: 200 or 400 for other errors```
59
60 >Arm a type for a producer<br>
61 This method arms a type for a producer<br>
62 ```URI and payload, (PUT): /arm/type/<producer_id>/<ype-id>```<br>
63 ```response: 200 or 400 for other errors```
64
65 >Disarm a type for a producer<br>
66 This method disarms a type for a producer<br>
67 ```URI and payload, (DELETE): /arm/type/<producer_id>/<ype-id>```<br>
68 ```response: 200 or 400 for other errors```
69
70 >Get job data parameters<br>
71 This method fetches the job data parameters of a job<br>
72 ```URI and payload, (GET): /jobdata/<producer_id>job_id>```<br>
73 ```response: 200 or 400 for other errors```
74
75 >Remove job data parameters<br>
76 This method removes the job data parameters from a job<br>
77 ```URI and payload, (DELETE): /jobdata/<producer_id>job_id>```<br>
78 ```response: 200 or 400 for other errors```
79
80 >Start/stop job data delivery<br>
81 This method start (or stops) delivering job data to the configured target url. Action is either 'start' or s'stop'<br>
82 ```URI and payload, (POST): /jobdata/<producer_id>job_id>?action=action```<br>
83 ```response: 200 or 400 for other errors```
84
85 >Counter for create job<br>
86 This method returns the number of create/update calls to a job<br>
87 ```URI and payload, (GET): /counter/create/producer_id>/<job_id>```<br>
88 ```response: <integer> 200 or 400 for other errors```
89
90 >Counter for delete job<br>
91 This method returns the number of delete calls to a job<br>
92 ```URI and payload, (GET): /counter/delete/producer_id>/<job_id>```<br>
93 ```response: <integer> 200 or 400 for other errors```
94
95 >Counter for producer supervision<br>
96 This method returns the number of supervision calls to a producer<br>
97 ```URI and payload, (GET): /counter/supervision/producer_id>```<br>
98 ```response: <integer> 200 or 400 for other errors```
99
100 >Get internal db<br>
101 This method dumps the internal db of producer and jobs as a json file<br>
102 ```URI and payload, (GET): /status```<br>
103 ```response: <json> 200 or 400 for other errors```
104
105 >Reset<br>
106 This method makes a full reset by removing all producers and jobs<br>
107 ```URI and payload, (GET or PUT or POST): /reset```<br>
108 ```response: <json> 200 or 400 for other errors```
109
110
111 ### Build and start ###
112
113 >Build image<br>
114 ```docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t producer-stub .```
115
116 >Start the image on both http and https<br>
117 ```docker run --rm -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub```
118
119 It will listen to http 8092 port and https 8093 port(using default certificates) at the same time.
120
121 >Start the image on http and https<br>
122 By default, this image has default certificates under /usr/src/app/cert
123 file "cert.crt" is the certificate file
124 file "key.crt" is the key file
125 file "generate_cert_and_key.sh" is a shell script to generate certificate and key
126 file "pass" stores the password when you run the shell script
127
128 Start the container without specifing external certificates:
129 ```docker run --rm -it --p 8092:8092 -p 8093:8093 producer-stub```
130
131 It will listen to http 8092 port and https 8093 port(using default certificates) at the same time.
132
133 This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose"
134 In 'docker run', use field:
135 --volume "$PWD/certificate:/usr/src/app/cert" a1test
136 ```docker run --rm -it --p 8092:8092 -p 8093:8093 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" producer-stub```
137 In 'docker-compose.yml', use field:
138 volumes:
139       - ./certificate:/usr/src/app/cert:ro
140
141 The script ```prodstub-build-start.sh``` do the build and docker run in one go. This starts the stub container in stand-alone mode for basic test.<br>If the producer-stub should be executed manually with the agent, replace docker run with this command to connect to the docker network with the correct service name (--name shall be the same as configured in consul for the read and write streams).
142 ```docker run --rm -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub```
143
144
145 ### Basic test ###
146
147 Basic test is made with the script ```basic_test.sh nonsecure|secure``` which tests all the available urls with a subset of the possible operations. Choose nonsecure for http and secure for https. Use the script ```prodstub-build-start.sh``` to start the producer-stub in a container first.
148
149
150
151
152 ## License
153
154 Copyright (C) 2020 Nordix Foundation. All rights reserved.
155 Licensed under the Apache License, Version 2.0 (the "License");
156 you may not use this file except in compliance with the License.
157 You may obtain a copy of the License at
158
159      http://www.apache.org/licenses/LICENSE-2.0
160
161 Unless required by applicable law or agreed to in writing, software
162 distributed under the License is distributed on an "AS IS" BASIS,
163 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
164 See the License for the specific language governing permissions and
165 limitations under the License.