202c1e5d358bef6cdcedc3482d61fb3c6e70e5dc
[nonrtric.git] / test / mrstub / README.md
1 # mrstub - stub interface to interact with the A1PMS over Dmaap
2
3 The mrstub is intended for function tests to simulate a message router.
4 The mrstub exposes the read and write urls, used by the a1pms, as configured in consul.
5 In addition, request messages can be fed to the mrstub and the response messages can be read by polling.
6
7 ## Ports and certificates
8
9 The MR normally opens the port 3905 for http. If a certificate and a key are provided the simulator will also open port 3906 for https.
10 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.
11
12 | Port     | Protocol |
13 | -------- | ----- |
14 | 3905     | http  |
15 | 3906     | https |
16
17 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'.
18 The same urls are availables on both the http port 3905 and the https port 3906. If using curl and https, the flag -k shall be given to make curl ignore checking the certificate.
19
20 ### Message Router interface
21
22 Messages from the MR can be read using this url using http(s) GET:<br>
23 ```events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=<timeout>&limit=<limit>```<br>
24 Both 'timeout' and 'limit' are optional.
25 |Parameter|Description|
26 |---------|--------------------|
27 |limit|Optional parameter to limit the maximum number of messages to return. A value 0 < limit < 4096. If limit is not given, the limit is set to 4096.|
28 |timeout|Optional parameter to control the max length of the poll. A value in milliseconds 0 < timeout < 60000. If timeout is not given, the timeout is 10 seconds. If not messages are available when the poll starts, the poll will end as soon as there is at least one message available|
29
30 Messages to the MR can be written using this url http(s) POST/PUT:<br>
31 ```/events/A1-POLICY-AGENT-WRITE```<br>
32 One or more messages can be written in the same operation.
33
34 ### Control interface
35
36 The control interface can be used by any test script.
37 The following REST operations are available:
38
39 >Send a message to MR<br>
40 This method puts a request message in the queue for the a1pms to pick up. The returned correlationId (auto generated by the mrstub) is used when polling for the reposone message of this particular request.<br>
41 ```URI and parameters (GET): /send-request?operation=<GET|PUT|POST|DELETE>&url=<url>```<br><br>
42 ```response: <correlation-id> (http 200) or 400 for parameter error or 500 for other errors```
43
44 >Receive a message response for MR for the included correlation id<br>
45 The method is for polling of messages, returns immediately containing the received response (if any) for the supplied correlationId.<br>
46 ```URI and parameter, (GET): /receive-response?correlationId=<correlationid>```<br><br>
47 ```response: <json-array of 1 response> 200 or empty 204 or other errors 500```
48
49 >Metrics - counters<br>
50 There are a number of counters that can be read to monitor the message processing. Do a http GET on any of the current counters and an integer value will be returned with http response code 200.
51 ```/counter/requests_submitted``` - The total number of requests sent from the application<br>
52 ```/counter/requests_fetched``` - The total number of requests picked up by the a1pms<br>
53 ```/counter/responses_submitted``` - The total number of responses written by the a1pms<br>
54 ```/counter/responses_fetched``` - The total number of responses picked up by the application<br>
55 ```/counter/current_requests``` - The current number of requests waiting to be picked up by the a1pms<br>
56 ```/counter/current_responses``` - The current number of responses waiting to be picked up by the application<br>
57
58 ### Build and start
59
60 >Build image<br>
61 ```docker build --build-arg NEXUS_PROXY_REPO=nexus3.onap.org:10001/ -t mrstub .```
62
63 >Start the image on http only<br>
64 ```docker run --rm -it -p 3905:3905 mrstub```
65
66 >Start the image on http and https<br>
67 By default, this image has default certificates under /usr/src/app/cert
68 file "cert.crt" is the certificate file
69 file "key.crt" is the key file
70 file "generate_cert_and_key.sh" is a shell script to generate certificate and key
71 file "pass" stores the password when you run the shell script
72
73 >Start the a1-interface container without specifing external certificates:<br>
74 ```docker run --rm -it -p 3905:3905 -p 3906:3906 mrstub```
75
76 It will listen to http 3905 port and https 3906 port(using default certificates) at the same time.
77
78 This certificates/key can be overriden by mounting a volume when using "docker run" or "docker-compose"
79 In 'docker run', use field:<br>
80 >```-v "$PWD/certificate:/usr/src/app/cert"```<br>
81
82 eg:<br>
83 >```docker run --rm -it -p 3905:3905 -p 3906:3906 -v "/PATH_TO_CERT/cert:/usr/src/app/cert" mrstub```<br>
84
85 In 'docker-compose.yml', use field:<br>
86 >```volumes: - ./certificate:/usr/src/app/cert:ro```
87
88 The script ```mrstub-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 mrstub 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).<br>
89 >```docker run --rm -it -p 3905:3905 --network nonrtric-docker-net --name message-router mrstub```
90
91 ### Basic test
92
93 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 ```mrstub-build-start.sh``` to start the mrstub in a container first.
94
95 ## License
96
97 Copyright (C) 2020 Nordix Foundation. All rights reserved.
98 Licensed under the Apache License, Version 2.0 (the "License");
99 you may not use this file except in compliance with the License.
100 You may obtain a copy of the License at
101
102      http://www.apache.org/licenses/LICENSE-2.0
103
104 Unless required by applicable law or agreed to in writing, software
105 distributed under the License is distributed on an "AS IS" BASIS,
106 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
107 See the License for the specific language governing permissions and
108 limitations under the License.