61c529790735346caa6fb89b7431f8101d765f6b
[nonrtric/plt/ranpm.git] / install / scripts / kafka-client-send-genfiles-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 VARIANT=$1
26 NODE_COUNT=$2
27 EVT_COUNT=$3
28 NODE_NAME_BASE=$4
29 FILE_EXT=$5
30 TYPE=$6
31 SRV_COUNT=$7
32 HIST=$8
33
34 FTPES_PORT=2021
35 SFTP_PORT=2022
36 HTTPS_PORT=443
37
38 print_usage() {
39     echo "Usage: kafka-client-send-genfiles-file-ready.sh ves|file-ready <node-count> <num-of-events> <node-name-base> <file-extension> sftp|ftpes|https <num-servers> [hist]"
40     exit 1
41 }
42 echo $@
43 if [ $# -lt 7 ] && [ $# -gt 8 ]; then
44     print_usage
45 fi
46
47 if [ $TYPE == "sftp" ]; then
48     echo "sftp servers not yet supported"
49 elif [ $TYPE == "ftpes" ]; then
50     echo "ftpes servers not yet supported"
51 elif [ $TYPE == "https" ]; then
52     :
53 else
54     print_usage
55 fi
56
57 if [ $FILE_EXT != "xml.gz" ]; then
58     echo "only xml.gz format supported"
59     print_usage
60 fi
61
62 HIST_LEN=0
63 if [ ! -z "$HIST" ]; then
64     if [ $HIST != "hist" ]; then
65         print_usage
66     fi
67     HIST_LEN=96
68 fi
69 PUSHMSG=""
70 if [ $VARIANT == "ves" ]; then
71     PUSHMSG="to ves-collector"
72 elif [ $VARIANT == "file-ready" ]; then
73     PUSHMSG="to file-ready topic"
74 fi
75
76 # Unix time of 20230515.0700
77 # If the value is changed, make sure to set the same time to the env var GENERATED_FILE_START_TIME in kube-plt.yaml for the https-server
78 BEGINTIME=1684134000
79 # Time zone
80 # If the value is changed, make sure to set the same value to the env var GENERATED_FILE_TIMEZONE in kube-plt.yaml for the https-server
81 TIMEZONE="+0100"
82 CURTIME=$BEGINTIME
83
84 BATCHSIZE=1000
85 if [ $VARIANT == "ves" ]; then
86     BATCHSIZE=20
87 fi
88
89 CNTR=0
90 TCNTR=0
91
92 for (( i=0; i<$EVT_COUNT; i++)); do
93
94     if [ $CNTR -eq 0 ]; then
95         rm .out.json
96         touch .out.json
97         if [ $VARIANT == "ves" ]; then
98             echo '{"eventList": [' > .out.json
99         fi
100     fi
101
102     if [ "$HIST" == "" ]; then
103         echo "EVENT NO: $i for $NODE_COUNT NODES - 1 FILE PER EVENT"
104     else
105         echo "EVENT NO: $i for $NODE_COUNT NODES - $HIST_LEN FILES PER EVENT"
106     fi
107     let STTIMEMS=$CURTIME*1000000
108     ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
109     let CURTIME=CURTIME+900
110     let CURTIMEMS=$CURTIME*1000000
111     ET=$(date -d @$CURTIME +'%H%M')
112
113     for (( j=0; j<$NODE_COUNT; j++)); do
114
115         if [ "$HIST" == "" ]; then
116             NO="$NODE_NAME_BASE-$j"
117
118             FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
119             let SRV_ID=$j%$SRV_COUNT
120             echo "NODE "$NO
121             echo "FILENAME "$FN
122
123
124             if [ $TYPE == "sftp" ]; then
125                 SRV="ftp-sftp-$SRV_ID"
126                 echo "FTP SERVER "$SRV
127                 URL="sftp://onap:pano@$SRV:$SFTP_PORT/$FN"
128             elif [ $TYPE == "ftpes" ]; then
129                 SRV="ftp-ftpes-$SRV_ID"
130                 echo "FTP SERVER "$SRV
131                 URL="ftpes://onap:pano@$SRV:$FTPES_PORT/$FN"
132             elif [ $TYPE == "https" ]; then
133                 SRV="pm-https-server-$SRV_ID.pm-https-server.ran"
134                 echo "HTTP SERVER "$SRV
135                 URL="https://$SRV:$HTTPS_PORT/generatedfiles/$FN"
136             fi
137
138             if [ $VARIANT == "ves" ] && [ $CNTR -gt 0 ]; then
139                 echo "," >> .out.json
140             fi
141             if [ $VARIANT == "ves" ]; then
142                 EVT='{"commonEventHeader":{"domain":"notification","sequence":0,"eventName":"Noti_RnNode-Ericsson_FileReady","eventId":"FileReady_'$TCNTR'","priority":"Normal","version":"4.0.1","vesEventListenerVersion":"7.0.1","sourceName":"'$NO'","reportingEntityName":"'$NO'","lastEpochMicrosec":'$CURTIMEMS',"startEpochMicrosec":'$STTIMEMS',"timeZoneOffset":"UTC'$TIMEZONE'"},"notificationFields":{"notificationFieldsVersion":"2.0","changeType":"FileReady","changeIdentifier":"PM_MEAS_FILES","arrayOfNamedHashMap":[{"name":"'$FN'","hashMap":{"fileFormatType":"org.3GPP.32.435#measCollec","location":"'$URL'","fileFormatVersion":"V10","compression":"gzip"}}]}}'
143             else
144                 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"}}]}}}'
145             fi
146             echo $EVT >> .out.json
147         else
148             NO="$NODE_NAME_BASE-$j"
149
150             let SRV_ID=$j%$SRV_COUNT
151             echo "NODE "$NO
152
153             EVT_FRAG=""
154             for(( k=95; k>=0; k-- )); do
155
156                 let FID=$i-k
157                 CURTIME=$(($BEGINTIME+$FID*900))
158                 let STTIMEMS=$CURTIME*1000000
159                 ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
160                 let CURTIME=CURTIME+900
161                 let CURTIMEMS=$CURTIME*1000000
162                 ET=$(date -d @$CURTIME +'%H%M')
163                 if [ $FID -lt 0 ]; then
164                     FN="NONEXISTING_$NO.$FILE_EXT"
165                 else
166                     FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
167                 fi
168                 echo "FILENAME "$FN
169                 SRV="pm-https-server-$SRV_ID.pm-https-server.ran"
170                 URL="https://$SRV:$HTTPS_PORT/files/$FN"
171                 if [ "$EVT_FRAG" != "" ]; then
172                     EVT_FRAG=$EVT_FRAG","
173                 fi
174                 EVT_FRAG=$EVT_FRAG'{"name":"'$FN'","hashMap":{"fileFormatType":"org.3GPP.32.435#measCollec","location":"'$URL'","fileFormatVersion":"V10","compression":"gzip"}}'
175             done
176
177             if [ $VARIANT == "ves" ] && [ $CNTR -gt 0 ]; then
178                 echo "," >> .out.json
179             fi
180             if [ $VARIANT == "ves" ]; then
181                 EVT='{"commonEventHeader":{"domain":"notification","sequence":0,"eventName":"Noti_RnNode-Ericsson_FileReady","eventId":"FileReady_'$TCNTR'","priority":"Normal","version":"4.0.1","vesEventListenerVersion":"7.0.1","sourceName":"'$NO'","reportingEntityName":"'$NO'","lastEpochMicrosec":'$CURTIMEMS',"startEpochMicrosec":'$STTIMEMS',"timeZoneOffset":"UTC'$TIMEZONE'"},"notificationFields":{"notificationFieldsVersion":"2.0","changeType":"FileReady","changeIdentifier":"PM_MEAS_FILES","arrayOfNamedHashMap":[{"name":"'$FN'","hashMap":{"fileFormatType":"org.3GPP.32.435#measCollec","location":"'$URL'","fileFormatVersion":"V10","compression":"gzip"}}]}}'
182             else
183                 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"}}]}}}'
184             fi
185             echo $EVT >> .out.json
186         fi
187
188         let CNTR=CNTR+1
189         let TCNTR=TCNTR+1
190         if [ $CNTR -ge $BATCHSIZE ]; then
191             echo "Pushing batch of $CNTR events $PUSHMSG"
192             if [ $VARIANT == "ves" ]; then
193                 echo ']}' >> .out.json
194                 curl -s -X POST http://ves-collector.nonrtric:8080/eventListener/v7/eventBatch --header 'Content-Type: application/json' --data-binary @.out.json
195             else
196                 cat .out.json | kafka-console-producer --topic file-ready --broker-list kafka-1-kafka-bootstrap.nonrtric:9092
197             fi
198             rm .out.json
199             touch .out.json
200             if [ $VARIANT == "ves" ]; then
201                 echo '{"eventList": [' > .out.json
202             fi
203             CNTR=0
204         fi
205     done
206 done
207 if [ $CNTR -ne 0 ]; then
208     echo "Pushing batch of $CNTR events $PUSHMSG"
209     if [ $VARIANT == "ves" ]; then
210         echo ']}' >> .out.json
211         curl -s -X POST http://ves-collector.nonrtric:8080/eventListener/v7/eventBatch --header 'Content-Type: application/json' --data-binary @.out.json
212     else
213         cat .out.json | kafka-console-producer --topic file-ready --broker-list kafka-1-kafka-bootstrap.nonrtric:9092
214     fi
215 fi
216
217 echo "Pushed $TCNTR events"