CI: Add SonarCloud scan GHA workflow
[nonrtric/plt/ranpm.git] / docker-proj / scripts / kafka-client-send-file-ready.sh
1 #!/bin/bash
2
3 #  ============LICENSE_START===============================================
4 #  Copyright (C) 2023 Nordix Foundation. All rights reserved.
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
20 SD=$(dirname -- "$0")
21 echo "script-home: "$SD
22 cd $SD
23 CWD=$PWD
24
25 NODE_COUNT=$1
26 EVT_COUNT=$2
27 NODE_NAME_BASE=$3
28 FILE_EXT=$4
29 SRV_COUNT=$5
30
31 HTTPS_PORT=443
32
33 print_usage() {
34     echo "Usage: kafka-client-send-file-ready.sh <node-count> <num-of-events> <node-name-base> <file-extension> <num-servers>"
35     exit 1
36 }
37 echo $@
38 if [ $# -lt 5 ]; then
39     print_usage
40 fi
41
42 BEGINTIME=$(date +%s -d '1 hour ago')
43 TIMEZONE="+0100"
44 CURTIME=$BEGINTIME
45
46 BATCHSIZE=1000
47
48 CNTR=0
49 TCNTR=0
50
51 for (( i=0; i<$EVT_COUNT; i++)); do
52
53     if [ $CNTR -eq 0 ]; then
54         rm .out.json
55         touch .out.json
56     fi
57
58     echo "EVENT NO: $i for $NODE_COUNT NODES - 1 FILE PER EVENT"
59
60     let STTIMEMS=$CURTIME*1000000
61     ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
62     let CURTIME=CURTIME+900
63     let CURTIMEMS=$CURTIME*1000000
64     ET=$(date -d @$CURTIME +'%H%M')
65
66     for (( j=0; j<$NODE_COUNT; j++)); do
67
68             NO="$NODE_NAME_BASE-$j"
69
70             #FN="A20000626.2315+0200-2330+0200_$NO-$i.$FILE_EXT"
71             FN="A$ST+0200-$ET+0200_$NO-$i.$FILE_EXT"
72             let SRV_ID=$j%$SRV_COUNT
73             let SRV_ID=SRV_ID+1
74             echo "NODE "$NO
75             echo "FILENAME "$FN
76             SRV="pm-https-server-$SRV_ID"
77             echo "HTTP SERVER "$SRV
78             URL="https://$SRV:$HTTPS_PORT/generatedfiles/$FN"
79             EVT='{"event":{"commonEventHeader":{"sequence":0,"eventName":"Noti_RnNode-Ericsson_FileReady","sourceName":"'$NO'","lastEpochMicrosec":'$CURTIMEMS',"startEpochMicrosec":'$STTIMEMS',"timeZoneOffset":"UTC'$TIMEZONE'","changeIdentifier":"PM_MEAS_FILES"},"notificationFields":{"notificationFieldsVersion":"notificationFieldsVersion","changeType":"FileReady","changeIdentifier":"PM_MEAS_FILES","arrayOfNamedHashMap":[{"name":"'$FN'","hashMap":{"fileFormatType":"org.3GPP.32.435#measCollec","location":"'$URL'","fileFormatVersion":"V10","compression":"gzip"}}]}}}'
80             echo $EVT >> .out.json
81
82         let CNTR=CNTR+1
83         let TCNTR=TCNTR+1
84         if [ $CNTR -ge $BATCHSIZE ]; then
85             echo "Pushing batch of $CNTR events"
86             cat .out.json | /opt/kafka/bin/kafka-console-producer.sh --topic file-ready --broker-list kafka-1:9092
87             rm .out.json
88             touch .out.json
89             CNTR=0
90         fi
91     done
92
93 done
94 if [ $CNTR -ne 0 ]; then
95     echo "Pushing batch of $CNTR events"
96     cat .out.json | /opt/kafka/bin/kafka-console-producer.sh --topic file-ready --broker-list kafka-1:9092
97 fi
98
99 echo "Pushed $TCNTR events"