Merge "Minor bugs fix in ORU-app simulator" into e-release
[nonrtric.git] / dmaap-mediator-producer / README.md
1 # O-RAN-SC Non-RealTime RIC DMaaP Mediator Producer
2
3 This product is a producer of Information Coordinator Service (ICS) jobs for polling topics in DMaaP Message Router (MR) and pushing the messages to a consumer.
4
5 ## Configuration
6
7 The producer takes a number of environment variables, described below, as configuration.
8
9 >- INFO_PRODUCER_HOST  **Required**. The host for the producer.                                   Example: `https://mrproducer`
10 >- INFO_PRODUCER_PORT  Optional. The port for the product.                                        Defaults to `8085`.
11 >- INFO_COORD_ADDR     Optional. The address of the Information Coordinator.                      Defaults to `https://informationservice:8434`.
12 >- DMAAP_MR_ADDR       Optional. The address of the DMaaP Message Router.                         Defaults to `https://message-router.onap:3905`.
13 >- PRODUCER_CERT_PATH  Optional. The path to the certificate to use for https.                    Defaults to `security/producer.crt`
14 >- PRODUCER_KEY_PATH   Optional. The path to the key to the certificate to use for https.         Defaults to `security/producer.key`
15 >- LOG_LEVEL           Optional. The log level, which can be `Error`, `Warn`, `Info` or `Debug`.  Defaults to `Info`.
16
17 Any of the addresses used by this product can be configured to use https, by specifying it as the scheme of the address URI. Clients configured to use https will not use server certificate verification. The communication towards the consumers will use https if their callback address URI uses that scheme. The producer's own callback will only listen to the scheme configured in the scheme of the info producer host address.
18
19 The configured public key and cerificate shall be PEM-encoded. A self signed certificate and key are provided in the `security` folder of the project. These files should be replaced for production. To generate a self signed key and certificate, use the example code below:
20
21     openssl req -new -x509 -sha256 -key server.key -out server.crt -days 3650
22
23 The file `configs/type_config.json` contains the configuration of job types that the producer will support, see example below.
24
25     {
26        "types":
27         [
28           {
29             "id": The ID of the job type, e.g. "STD_Fault_Messages",
30             "dmaapTopicUrl": The topic URL to poll from DMaaP Message Router, e.g. "events/unauthenticated.SEC_FAULT_OUTPUT/dmaapmediatorproducer/STD_Fault_Messages"
31           },
32           {
33             "id": The ID of the job type, e.g. "Kafka_TestTopic",
34             "kafkaInputTopic": The Kafka topic to poll
35           }
36       ]
37     }
38
39 Each information type has the following properties:
40  - id the information type identity as exposed in the Information Coordination Service data consumer API
41  - dmaapTopicUrl the URL to for fetching information from  DMaaP
42  - kafkaInputTopic the Kafka topic to get input from
43
44 Either the "dmaapTopicUrl" or the "kafkaInputTopic" must be provided for each type, not both.
45
46 ## Functionality
47
48 At start up the producer will register the configured job types in ICS and also register itself as a producer supporting these types. If ICS is unavailable, the producer will retry to connect indefinetely. The same goes for MR.
49
50 Once the initial registration is done, the producer will constantly poll MR and/or Kafka for all configured job types. When receiving messages for a type, it will distribute these messages to all jobs registered for the type. If no jobs for that type are registered, the messages will be discarded. If a consumer is unavailable for distribution, the messages will be discarded for that consumer until it is available again.
51
52 The producer provides a REST API that fulfills the ICS Data producer API, see [Data producer (callbacks)](<https://docs.o-ran-sc.org/projects/o-ran-sc-nonrtric/en/latest/ics-api.html#tag/Data-producer-(callbacks)>). The health check method returns the registration status of the producer in ICS as JSON. It also provides a method to control the log level of the producer. The available log levels are the same as the ones used in the configuration above.
53
54     PUT https://mrproducer:8085/admin/log?level=<new level>
55
56 The Swagger documentation of the producer's API is also available, through the `/swagger` path.
57
58 When an Information Job is created in the Information Coordinator Service Consumer API, it is possible to define a number of job specific properties. For an Information type that has a Kafka topic defined, the following Json schema defines the properties that can be used:
59
60
61 ```sh
62 {
63   "$schema": "http://json-schema.org/draft-04/schema#",
64   "type": "object",
65   "properties": {
66     "bufferTimeout": {
67       "type": "object",
68       "properties": {
69         "maxSize": {
70           "type": "integer"
71         },
72         "maxTimeMiliseconds": {
73           "type": "integer"
74         }
75       },
76       "additionalProperties": false,
77       "required": [
78         "maxSize",
79         "maxTimeMiliseconds"
80       ]
81     }
82   },
83   "additionalProperties": false
84 }
85 ```
86 -bufferTimeout, can be used to reduce the number of REST calls to the consumer. If defined, a number of objects will be
87  buffered and sent in one REST call to the consumer.
88  The buffered objects will be put in a Json array and quoted. Example;
89    Object1 and Object2 may be posted in one call -->  ["Object1", "Object2"]
90  The bufferTimeout is a Json object and the parameters in the object are:
91    - maxSize the maximum number of buffered objects before posting
92    - maxTimeMiliseconds the maximum delay time to buffer before posting
93  If no bufferTimeout is specified, each object will be posted as received in separate calls (not quoted and put in a Json array).
94
95
96 For an information type that only has a DMaaP topic, the following Json schema is used:
97
98 ```sh
99 {
100   "$schema": "http://json-schema.org/draft-04/schema#",
101   "type": "object",
102   "properties": {
103   },
104   "additionalProperties": false
105 }
106
107 ## Development
108
109 To make it easy to test during development of the producer, three stubs are provided in the `stub` folder.
110
111 One, under the `dmaap` folder, called `dmaap` that stubs MR and respond with an array with one message with `eventSeverity` alternating between `NORMAL` and `CRITICAL`. The default port is `3905`, but this can be overridden by passing a `-port <PORT>` flag when starting the stub. To build and start the stub, do the following:
112 >1. cd stub/dmaap
113 >2. go build
114 >3. ./dmaap [-port \<PORT>]
115
116 An ICS stub, under the `ics` folder, that listens for registration calls from the producer. When it gets a call it prints out the data of the call. By default, it listens to the port `8434`, but his can be overridden by passing a `-port [PORT]` flag when starting the stub. To build and start the stub, do the following:
117 >1. cd stub/ics
118 >2. go build [-port \<PORT>]
119 >3. ./ics
120
121 One, under the `consumer` folder, called `consumer` that at startup will register a job of type `STD_Fault_Messages` in ICS, if it is available, and then listen for REST calls and print the body of them. By default, it listens to the port `40935`, but his can be overridden by passing a `-port <PORT>` flag when starting the stub. To build and start the stub, do the following:
122 >1. cd stub/consumer
123 >2. go build
124 >3. ./consumer [-port \<PORT>]
125
126 Mocks needed for unit tests have been generated using `github.com/stretchr/testify/mock` and are checked in under the `mocks` folder. **Note!** Keep in mind that if any of the mocked interfaces change, a new mock for that interface must be generated and checked in.
127
128 ## License
129
130 Copyright (C) 2021 Nordix Foundation.
131 Licensed under the Apache License, Version 2.0 (the "License")
132 you may not use this file except in compliance with the License.
133 You may obtain a copy of the License at
134
135       http://www.apache.org/licenses/LICENSE-2.0
136
137 Unless required by applicable law or agreed to in writing, software
138 distributed under the License is distributed on an "AS IS" BASIS,
139 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
140 See the License for the specific language governing permissions and
141 limitations under the License.
142
143 For more information about license please see the [LICENSE](LICENSE.txt) file for details.