b14f0e7e3abe7c10a01c5e9337631b2b9b20d482
[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 #  Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
6 #  ========================================================================
7 #  Licensed under the Apache License, Version 2.0 (the "License");
8 #  you may not use this file except in compliance with the License.
9 #  You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 #  Unless required by applicable law or agreed to in writing, software
14 #  distributed under the License is distributed on an "AS IS" BASIS,
15 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 #  See the License for the specific language governing permissions and
17 #  limitations under the License.
18 #  ============LICENSE_END=================================================
19 #
20
21 SD=$(dirname -- "$0")
22 echo "script-home: "$SD
23 cd $SD
24 CWD=$PWD
25
26 VARIANT=$1
27 NODE_COUNT=$2
28 EVT_COUNT=$3
29 NODE_NAME_BASE=$4
30 FILE_EXT=$5
31 TYPE=$6
32 SRV_COUNT=$7
33 HIST=$8
34
35 FTPES_PORT=2021
36 SFTP_PORT=2022
37 HTTPS_PORT=443
38
39 print_usage() {
40     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]"
41     exit 1
42 }
43 echo $@
44 if [ $# -lt 7 ] && [ $# -gt 8 ]; then
45     print_usage
46 fi
47
48 if [ $TYPE == "sftp" ]; then
49     echo "sftp servers not yet supported"
50 elif [ $TYPE == "ftpes" ]; then
51     echo "ftpes servers not yet supported"
52 elif [ $TYPE == "https" ]; then
53     :
54 else
55     print_usage
56 fi
57
58 if [ $FILE_EXT != "xml.gz" ]; then
59     echo "only xml.gz format supported"
60     print_usage
61 fi
62
63 HIST_LEN=0
64 if [ ! -z "$HIST" ]; then
65     if [ $HIST != "hist" ]; then
66         print_usage
67     fi
68     HIST_LEN=96
69 fi
70 PUSHMSG=""
71 if [ $VARIANT == "ves" ]; then
72     PUSHMSG="to ves-collector"
73 elif [ $VARIANT == "file-ready" ]; then
74     PUSHMSG="to file-ready topic"
75 elif [ $VARIANT == "file-ready-ts28532" ]; then
76     PUSHMSG="to file-ready topic"
77 fi
78
79 # Unix time of 20230515.0700
80 # 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
81 BEGINTIME=1684134000
82 # Time zone
83 # 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
84 TIMEZONE="+0100"
85 CURTIME=$BEGINTIME
86
87 BATCHSIZE=1000
88 if [ $VARIANT == "ves" ]; then
89     BATCHSIZE=20
90 fi
91
92 CNTR=0
93 TCNTR=0
94
95 for (( i=0; i<$EVT_COUNT; i++)); do
96
97     if [ $CNTR -eq 0 ]; then
98         rm .out.json
99         touch .out.json
100         if [ $VARIANT == "ves" ]; then
101             echo '{"eventList": [' > .out.json
102         fi
103     fi
104
105     if [ "$HIST" == "" ]; then
106         echo "EVENT NO: $i for $NODE_COUNT NODES - 1 FILE PER EVENT"
107     else
108         echo "EVENT NO: $i for $NODE_COUNT NODES - $HIST_LEN FILES PER EVENT"
109     fi
110     let STTIMEMS=$CURTIME*1000000
111     ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
112     let CURTIME=CURTIME+900
113     let CURTIMEMS=$CURTIME*1000000
114     ET=$(date -d @$CURTIME +'%H%M')
115
116     for (( j=0; j<$NODE_COUNT; j++)); do
117
118         if [ "$HIST" == "" ]; then
119             NO="$NODE_NAME_BASE-$j"
120
121             FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
122             let SRV_ID=$j%$SRV_COUNT
123             echo "NODE "$NO
124             echo "FILENAME "$FN
125
126
127             if [ $TYPE == "sftp" ]; then
128                 SRV="ftp-sftp-$SRV_ID"
129                 echo "FTP SERVER "$SRV
130                 URL="sftp://onap:pano@$SRV:$SFTP_PORT/$FN"
131             elif [ $TYPE == "ftpes" ]; then
132                 SRV="ftp-ftpes-$SRV_ID"
133                 echo "FTP SERVER "$SRV
134                 URL="ftpes://onap:pano@$SRV:$FTPES_PORT/$FN"
135             elif [ $TYPE == "https" ]; then
136                 SRV="pm-https-server-$SRV_ID.pm-https-server.ran"
137                 echo "HTTP SERVER "$SRV
138                 URL="https://$SRV:$HTTPS_PORT/generatedfiles/$FN"
139             fi
140
141             if [ $VARIANT == "ves" ] && [ $CNTR -gt 0 ]; then
142                 echo "," >> .out.json
143             fi
144             if [ $VARIANT == "ves" ]; then
145                 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"}}]}}'
146             elif [ $VARIANT == "file-ready-ts28532" ]; then
147                 EVT='{"event":{"commonEventHeader":{"reportingEntityId":"","nfNamingCode":"001","timeZoneOffset":"UTC'$TIMEZONE'","version":"4.1","vesEventListenerVersion":"7.2.1","domain":"stndDefined","eventId":"ManagedElement=pynts-o-du-o1_stndDefined","eventName":"stndDefined_PyNTS_FileReady","eventType":"PyNTS_FileReady","sequence":0,"priority":"Low","reportingEntityName":"ManagementElement=pynts-o-du-o1","sourceId":"ManagementElement=pynts-o-du-o1","sourceName":"'$NO'","startEpochMicrosec":1737029100022212,"lastEpochMicrosec":1737029100022212,"nfVendorName":"pynts","stndDefinedNamespace":"3GPP-PerformanceAssurance"},"stndDefinedFields":{"schemaReference":"https://forge.3gpp.org/rep/sa5/MnS/blob/Rel-18/OpenAPI/TS28532_FileDataReportingMnS.yaml#components/schemas/NotifyFileReady","stndDefinedFieldsVersion":"1.0","data":{"href":"href1","notificationType":"notifyFileReady","fileInfoList":[{"fileSize":1288,"fileExpirationTime":"2025-01-16T12:08:00.017Z","fileCompression":"no","fileFormat":"xml","fileDataType":"Performance","fileLocation":"'$URL'","fileReadyTime":"2025-01-16T12:05:00.022Z"}],"additionalText":"Have fun!","notificationId":1,"eventTime":"2025-01-16T12:05:00.022Z","systemDN":"ManagedElement=pynts-o-du-o1"}}}}'
148             else
149                 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"}}]}}}'
150             fi
151             echo $EVT >> .out.json
152         else
153             NO="$NODE_NAME_BASE-$j"
154
155             let SRV_ID=$j%$SRV_COUNT
156             echo "NODE "$NO
157
158             EVT_FRAG=""
159             for(( k=95; k>=0; k-- )); do
160
161                 let FID=$i-k
162                 CURTIME=$(($BEGINTIME+$FID*900))
163                 let STTIMEMS=$CURTIME*1000000
164                 ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
165                 let CURTIME=CURTIME+900
166                 let CURTIMEMS=$CURTIME*1000000
167                 ET=$(date -d @$CURTIME +'%H%M')
168                 if [ $FID -lt 0 ]; then
169                     FN="NONEXISTING_$NO.$FILE_EXT"
170                 else
171                     FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
172                 fi
173                 echo "FILENAME "$FN
174                 SRV="pm-https-server-$SRV_ID.pm-https-server.ran"
175                 URL="https://$SRV:$HTTPS_PORT/files/$FN"
176                 if [ "$EVT_FRAG" != "" ]; then
177                     EVT_FRAG=$EVT_FRAG","
178                 fi
179                 EVT_FRAG=$EVT_FRAG'{"name":"'$FN'","hashMap":{"fileFormatType":"org.3GPP.32.435#measCollec","location":"'$URL'","fileFormatVersion":"V10","compression":"gzip"}}'
180             done
181
182             if [ $VARIANT == "ves" ] && [ $CNTR -gt 0 ]; then
183                 echo "," >> .out.json
184             fi
185             if [ $VARIANT == "ves" ]; then
186                 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"}}]}}'
187             elif [ $VARIANT == "file-ready-ts28532" ]; then
188                 EVT='{"event":{"commonEventHeader":{"reportingEntityId":"","nfNamingCode":"001","timeZoneOffset":"UTC'$TIMEZONE'","version":"4.1","vesEventListenerVersion":"7.2.1","domain":"stndDefined","eventId":"ManagedElement=pynts-o-du-o1_stndDefined","eventName":"stndDefined_PyNTS_FileReady","eventType":"PyNTS_FileReady","sequence":0,"priority":"Low","reportingEntityName":"ManagementElement=pynts-o-du-o1","sourceId":"ManagementElement=pynts-o-du-o1","sourceName":"'$NO'","startEpochMicrosec":1737029100022212,"lastEpochMicrosec":1737029100022212,"nfVendorName":"pynts","stndDefinedNamespace":"3GPP-PerformanceAssurance"},"stndDefinedFields":{"schemaReference":"https://forge.3gpp.org/rep/sa5/MnS/blob/Rel-18/OpenAPI/TS28532_FileDataReportingMnS.yaml#components/schemas/NotifyFileReady","stndDefinedFieldsVersion":"1.0","data":{"href":"href1","notificationType":"notifyFileReady","fileInfoList":[{"fileSize":1288,"fileExpirationTime":"2025-01-16T12:08:00.017Z","fileCompression":"no","fileFormat":"xml","fileDataType":"Performance","fileLocation":"'$URL'","fileReadyTime":"2025-01-16T12:05:00.022Z"}],"additionalText":"Have fun!","notificationId":1,"eventTime":"2025-01-16T12:05:00.022Z","systemDN":"ManagedElement=pynts-o-du-o1"}}}}'
189             else
190                 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"}}]}}}'
191             fi
192             echo $EVT >> .out.json
193         fi
194
195         let CNTR=CNTR+1
196         let TCNTR=TCNTR+1
197         if [ $CNTR -ge $BATCHSIZE ]; then
198             echo "Pushing batch of $CNTR events $PUSHMSG"
199             if [ $VARIANT == "ves" ]; then
200                 echo ']}' >> .out.json
201                 curl -s -X POST http://ves-collector.nonrtric:8080/eventListener/v7/eventBatch --header 'Content-Type: application/json' --data-binary @.out.json
202             else
203                 cat .out.json | kafka-console-producer --topic file-ready --broker-list kafka-1-kafka-bootstrap.nonrtric:9092
204             fi
205             rm .out.json
206             touch .out.json
207             if [ $VARIANT == "ves" ]; then
208                 echo '{"eventList": [' > .out.json
209             fi
210             CNTR=0
211         fi
212     done
213 done
214 if [ $CNTR -ne 0 ]; then
215     echo "Pushing batch of $CNTR events $PUSHMSG"
216     if [ $VARIANT == "ves" ]; then
217         echo ']}' >> .out.json
218         curl -s -X POST http://ves-collector.nonrtric:8080/eventListener/v7/eventBatch --header 'Content-Type: application/json' --data-binary @.out.json
219     else
220         cat .out.json | kafka-console-producer --topic file-ready --broker-list kafka-1-kafka-bootstrap.nonrtric:9092
221     fi
222 fi
223
224 echo "Pushed $TCNTR events"
OSZAR »