1 # producer stub - a stub interface to simulate data producers
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 initial step, the intended job and producers, with supported types, are setup (armed) in the simulator.
6 In addition, specific response codes can configured for each callback request.
8 ## 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.
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 available 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.
21 ### Prodstub interface
24 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>
25 ```URI and payload, (POST): /callbacks/job/<producer_id>, <job-json>```<br>
26 ```response: 200/201 (or configured response) or 400 for other errors```
29 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>
30 ```URI and payload, (DELETE): /callbacks/job/<producer_id>```<br>
31 ```response: 204 (or configured response) or 400 for other errors```
33 >Supervision callback<br>
34 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>
35 ```URI and payload, (GET): /callbacks/supervision/<producer_id>```<br>
36 ```response: 200 (or configured response) or 400 for other errors```
40 The control interface can be used by any test script.
41 The following REST operations are available:
44 This method arms a job for creation and sets an optional response code for create/update<br>
45 ```URI and payload, (PUT): /arm/create/<producer_id>/<job_id>[?response=<responsecode>]```<br>
46 ```response: 200 or 400 for other errors```
48 This method arms a job for deletion and sets an optional response code for delete<br>
49 ```URI and payload, (PUT): /arm/delete/<producer_id>/<job_id>[?response=<responsecode>]```<br>
50 ```response: 200 or 400 for other errors```
52 >Arm a producer supervision<br>
53 This method arms a supervision and sets an optional response code for supervision calls<br>
54 ```URI and payload, (PUT): /arm/delete/<producer_id>[?response=<responsecode>]```<br>
55 ```response: 200 or 400 for other errors```
57 >Arm a type for a producer<br>
58 This method arms a type for a producer<br>
59 ```URI and payload, (PUT): /arm/type/<producer_id>/<ype-id>```<br>
60 ```response: 200 or 400 for other errors```
62 >Disarm a type for a producer<br>
63 This method disarms a type for a producer<br>
64 ```URI and payload, (DELETE): /arm/type/<producer_id>/<ype-id>```<br>
65 ```response: 200 or 400 for other errors```
67 >Get job data parameters<br>
68 This method fetches the job data parameters of a job<br>
69 ```URI and payload, (GET): /jobdata/<producer_id>job_id>```<br>
70 ```response: 200 or 400 for other errors```
72 >Remove job data parameters<br>
73 This method removes the job data parameters from a job<br>
74 ```URI and payload, (DELETE): /jobdata/<producer_id>job_id>```<br>
75 ```response: 200 or 400 for other errors```
77 >Start/stop job data delivery<br>
78 This method start (or stops) delivering job data to the configured target url. Action is either 'start' or s'stop'<br>
79 ```URI and payload, (POST): /jobdata/<producer_id>job_id>?action=action```<br>
80 ```response: 200 or 400 for other errors```
82 >Counter for create job<br>
83 This method returns the number of create/update calls to a job<br>
84 ```URI and payload, (GET): /counter/create/producer_id>/<job_id>```<br>
85 ```response: <integer> 200 or 400 for other errors```
87 >Counter for delete job<br>
88 This method returns the number of delete calls to a job<br>
89 ```URI and payload, (GET): /counter/delete/producer_id>/<job_id>```<br>
90 ```response: <integer> 200 or 400 for other errors```
92 >Counter for producer supervision<br>
93 This method returns the number of supervision calls to a producer<br>
94 ```URI and payload, (GET): /counter/supervision/producer_id>```<br>
95 ```response: <integer> 200 or 400 for other errors```
98 This method dumps the internal db of producer and jobs as a json file<br>
99 ```URI and payload, (GET): /status```<br>
100 ```response: <json> 200 or 400 for other errors```
103 This method makes a full reset by removing all producers and jobs<br>
104 ```URI and payload, (GET or PUT or POST): /reset```<br>
105 ```response: <json> 200 or 400 for other errors```
110 ```docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t producer-stub .```
112 >Start the image on both http and https<br>
113 ```docker run --rm -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub```
115 It will listen to http 8092 port and https 8093 port(using default certificates) at the same time.
117 >Start the image on http and https<br>
118 By default, this image has default certificates under /usr/src/app/cert
119 file "cert.crt" is the certificate file
120 file "key.crt" is the key file
121 file "generate_cert_and_key.sh" is a shell script to generate certificate and key
122 file "pass" stores the password when you run the shell script
124 >Start the container without specifying external certificates:<br>
125 ```docker run --rm -it --p 8092:8092 -p 8093:8093 producer-stub```
127 It will listen to http 8092 port and https 8093 port(using default certificates) at the same time.
129 This certificates/key can be overridden by mounting a volume when using "docker run" or "docker-compose"
130 In 'docker run', use field:
131 >```-v "$PWD/certificate:/usr/src/app/cert"```
134 >```docker run --rm -it --p 8092:8092 -p 8093:8093 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" producer-stub```<br>
136 In 'docker-compose.yml', use field:<br>
137 >```volumes: - ./certificate:/usr/src/app/cert:ro```
139 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 a1pms, 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).
140 ```docker run --rm -it -p 8092:8092 -p 8093:8093 --name producer-stub producer-stub```
144 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 Copyright (C) 2020 Nordix Foundation. All rights reserved.
149 Licensed under the Apache License, Version 2.0 (the "License");
150 you may not use this file except in compliance with the License.
151 You may obtain a copy of the License at
153 http://www.apache.org/licenses/LICENSE-2.0
155 Unless required by applicable law or agreed to in writing, software
156 distributed under the License is distributed on an "AS IS" BASIS,
157 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
158 See the License for the specific language governing permissions and
159 limitations under the License.