ICS sample producer and consumer
[nonrtric.git] / sample-services / ics-producer-consumer / red.sh
1 #  ========================LICENSE_START=================================
2 #  O-RAN-SC
3 #
4 #  Copyright (C) 2024: OpenInfra Foundation Europe
5 #  ========================================================================
6 #  Licensed under the Apache License, Version 2.0 (the "License");
7 #  you may not use this file except in compliance with the License.
8 #  You may obtain a copy of the License at
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
12 #  Unless required by applicable law or agreed to in writing, software
13 #  distributed under the License is distributed on an "AS IS" BASIS,
14 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #  See the License for the specific language governing permissions and
16 #  limitations under the License.
17 #  ============LICENSE_END=================================================
18
19 #!/bin/bash
20 skip_build=false
21 no_console=false
22
23 # Parse command line arguments
24 while [[ $# -gt 0 ]]; do
25     case $1 in
26         --skip-build)
27             skip_build=true
28             shift
29             ;;
30         --no-console)
31             no_console=true
32             shift
33             ;;
34         *)
35             echo "Unknown option: $1"
36             exit 1
37             ;;
38     esac
39 done
40 # Source the utils script
41 source utils.sh
42
43 # Check Prerequisites
44 checkJava
45 checkDocker
46 checkDockerCompose
47
48 if ! $skip_build; then
49     # Make build the demo docker image
50     cd ./producer/
51     make build
52     cd ../consumer/
53     make build
54     cd ..
55 fi
56
57 # Start the Docker containers in detached mode
58 docker-compose up -d
59
60 # Wait for the Kafka container to be running
61 wait_for_container "kafka-zkless" "Kafka Server started"
62 space
63
64 if ! $no_console; then
65     echo "Start RedPanda Console"
66     docker-compose -f docker-composeRedPanda.yaml up -d
67     space
68
69     echo "Start NONRTRIC control panel"
70     docker-compose -f ./docker-compose/docker-compose.yaml -f ./docker-compose/control-panel/docker-compose.yaml -f ./docker-compose/nonrtric-gateway/docker-compose.yaml up -d
71     space
72 fi
73
74 # Once Kafka container is running, start the producers and consumers
75 echo "Kafka container is up and running. Starting producer and consumer..."
76 space
77
78 echo "Start 1 Producer on mytopic"
79 curl -X GET http://localhost:8080/startProducer/mytopic
80 space
81
82 echo "Start 1 Consumer on mytopic"
83 curl -X GET http://localhost:8081/startConsumer/mytopic
84 space
85
86 sleep 10
87
88 echo "Sending type1 to ICS"
89 curl -X 'PUT' \
90   'http://localhost:8083/data-producer/v1/info-types/type1' \
91   -H 'accept: application/json' \
92   -H 'Content-Type: application/json' \
93   -d '{
94   "info_job_data_schema": {
95     "$schema":"http://json-schema.org/draft-07/schema#",
96     "title":"STD_Type1_1.0.0",
97     "description":"Type 1",
98     "type":"object"
99   }
100 }'
101
102 echo "Getting types from ICS"
103 curl -X 'GET' 'http://localhost:8083/data-producer/v1/info-types/type1'
104 space
105
106 echo "Sending Producer infos to ICS"
107 curl -X 'PUT' \
108   'http://localhost:8083/data-producer/v1/info-producers/1' \
109   -H 'accept: application/json' \
110   -H 'Content-Type: application/json' \
111   -d '{
112   "info_producer_supervision_callback_url": "http://kafka-producer:8080/producer/supervision",
113   "supported_info_types": [
114     "type1"
115   ],
116   "info_job_callback_url": "http://kafka-producer:8080/producer/job"
117 }'
118
119 echo "Getting Producers Infos from ICS"
120 curl -H 'Content-Type: application/json' 'http://localhost:8083/data-producer/v1/info-producers/1'
121 space
122
123 echo "Sending Consumer Job infos to ICS"
124 curl -X 'PUT' \
125   'http://localhost:8083/data-consumer/v1/info-jobs/1' \
126   -H 'accept: application/json' \
127   -H 'Content-Type: application/json' \
128   -d '{
129   "info_type_id": "type1",
130   "job_owner": "demo",
131   "job_definition": {
132     "deliveryInfo": {
133       "topic": "mytopic",
134       "bootStrapServers": "http://kafka-zkless:9092",
135       "numberOfMessages": 0
136     }
137   },
138   "job_result_uri": "http://kafka-producer:8080/producer/job",
139   "status_notification_uri": "http://kafka-producer:8080/producer/supervision"
140 }'
141
142 echo "Getting Consumer Job Infos from ICS"
143 curl -H 'Content-Type: application/json' 'http://localhost:8083/data-consumer/v1/info-jobs/1'
144 space
145
146 echo "Sending Consumer Subscription Job infos to ICS"
147 curl -X 'PUT' \
148   'http://localhost:8083/data-consumer/v1/info-type-subscription/1' \
149   -H 'accept: application/json' \
150   -H 'Content-Type: application/json' \
151   -d '{
152   "status_result_uri": "http://kafka-consumer:8081/info-type-status",
153   "owner": "owner"
154 }'
155 echo "Getting Consumer Subscription Job infos from ICS"
156 curl -X 'GET' 'http://localhost:8083/data-consumer/v1/info-type-subscription/1' -H 'accept: application/json'
157 space
158
159 sleep 5
160 echo "ICS Producer Docker logs "
161 docker logs informationcoordinatorservice | grep -E 'o.o.i.c.r1producer.ProducerCallbacks|o.o.i.repository.InfoTypeSubscriptions'
162 space
163 echo "Demo Producer Docker logs "
164 docker logs kafka-producer | grep c.d.p.p.SimpleProducer
165 space
166 echo "Demo Consumer Docker logs "
167 docker logs kafka-consumer | grep c.d.c.c.SimpleConsumer
168 space
169
170 if ! $no_console; then
171     echo "Red Panda Console: http://localhost:8888"
172     echo "Control Panel Console: http://localhost:8181"
173 fi
174
175 echo "Done."
176
177 containers=("kafka-producer" "kafka-consumer")
178
179 for container in "${containers[@]}"; do
180   if docker logs "$container" | grep -q ERROR; then
181     echo "Errors found in logs of $container"
182     echo "FAIL"
183     exit 1
184   else
185     echo "No errors found in logs of $container"
186   fi
187 done
188 echo "SUCCESS"
189 exit 0