fe63ef5aba557e12870935a37289b9bdf8a8b0ea
[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 NODE_COUNT=$1
26 EVT_COUNT=$2
27 NODE_NAME_BASE=$3
28 FILE_EXT=$4
29 TYPE=$5
30 SRV_COUNT=$6
31 HIST=$7
32
33 FTPES_PORT=2021
34 SFTP_PORT=2022
35 HTTPS_PORT=443
36
37 print_usage() {
38     echo "Usage: kafka-client-send-genfiles-file-ready.sh <node-count> <num-of-events> <node-name-base> <file-extension> sftp|ftpes|https <num-servers> [hist]"
39     exit 1
40 }
41 echo $@
42 if [ $# -lt 6 ] && [ $# -gt 7 ]; then
43     print_usage
44 fi
45
46 if [ $TYPE == "sftp" ]; then
47     echo "sftp servers not yet supported"
48 elif [ $TYPE == "ftpes" ]; then
49     echo "ftpes servers not yet supported"
50 elif [ $TYPE == "https" ]; then
51     :
52 else
53     print_usage
54 fi
55
56 if [ $FILE_EXT != "xml.gz" ]; then
57     echo "only xml.gz format supported"
58     print_usage
59 fi
60
61 HIST_LEN=0
62 if [ ! -z "$HIST" ]; then
63     if [ $HIST != "hist" ]; then
64         print_usage
65     fi
66     HIST_LEN=96
67 fi
68
69 # Unix time of 20230220.1300
70 # 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
71 BEGINTIME=1676898000
72 # Time zone
73 # 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
74 TIMEZONE="+0100"
75 CURTIME=$BEGINTIME
76
77 BATCHSIZE=1000
78
79 CNTR=0
80 TCNTR=0
81
82 for (( i=0; i<$EVT_COUNT; i++)); do
83
84     if [ $CNTR -eq 0 ]; then
85         rm .out.json
86         touch .out.json
87     fi
88
89     if [ "$HIST" == "" ]; then
90         echo "EVENT NO: $i for $NODE_COUNT NODES - 1 FILE PER EVENT"
91     else
92         echo "EVENT NO: $i for $NODE_COUNT NODES - $HIST_LEN FILES PER EVENT"
93     fi
94     let STTIMEMS=$CURTIME*1000000
95     ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
96     let CURTIME=CURTIME+900
97     let CURTIMEMS=$CURTIME*1000000
98     ET=$(date -d @$CURTIME +'%H%M')
99
100     for (( j=0; j<$NODE_COUNT; j++)); do
101
102         if [ "$HIST" == "" ]; then
103             NO="$NODE_NAME_BASE-$j"
104
105             #FN="A20000626.2315+0200-2330+0200_$NO-$i.$FILE_EXT"
106             FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
107             let SRV_ID=$j%$SRV_COUNT
108             #let SRV_ID=SRV_ID+1
109             echo "NODE "$NO
110             echo "FILENAME "$FN
111
112
113             if [ $TYPE == "sftp" ]; then
114                 SRV="ftp-sftp-$SRV_ID"
115                 echo "FTP SERVER "$SRV
116                 URL="sftp://onap:pano@$SRV:$SFTP_PORT/$FN"
117             elif [ $TYPE == "ftpes" ]; then
118                 SRV="ftp-ftpes-$SRV_ID"
119                 echo "FTP SERVER "$SRV
120                 URL="ftpes://onap:pano@$SRV:$FTPES_PORT/$FN"
121             elif [ $TYPE == "https" ]; then
122                 SRV="pm-https-server-$SRV_ID.pm-https-server.ran"
123                 echo "HTTP SERVER "$SRV
124                 URL="https://$SRV:$HTTPS_PORT/generatedfiles/$FN"
125             fi
126             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"}}]}}}'
127             echo $EVT >> .out.json
128         else
129             NO="$NODE_NAME_BASE-$j"
130
131             let SRV_ID=$j%$SRV_COUNT
132             #let SRV_ID=SRV_ID+1
133             echo "NODE "$NO
134
135             EVT_FRAG=""
136             for(( k=95; k>=0; k-- )); do
137
138                 let FID=$i-k
139                 CURTIME=$(($BEGINTIME+$FID*900))
140                 let STTIMEMS=$CURTIME*1000000
141                 ST=$(date -d @$CURTIME +'%Y%m%d.%H%M')
142                 let CURTIME=CURTIME+900
143                 let CURTIMEMS=$CURTIME*1000000
144                 ET=$(date -d @$CURTIME +'%H%M')
145                 if [ $FID -lt 0 ]; then
146                     FN="NONEXISTING_$NO.$FILE_EXT"
147                 else
148                     #FN="A20000626.2315+0200-2330+0200_$NO-$FID.$FILE_EXT"
149                     FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
150                 fi
151                 echo "FILENAME "$FN
152                 if [ $TYPE == "sftp" ]; then
153                     SRV="ftp-sftp-$SRV_ID"
154                     #echo "FTP SERVER "$SRV
155                     URL="sftp://onap:pano@$SRV:$SFTP_PORT/$FN"
156                 elif [ $TYPE == "ftpes" ]; then
157                     SRV="ftp-ftpes-$SRV_ID"
158                     #echo "FTP SERVER "$SRV
159                     URL="ftpes://onap:pano@$SRV:$FTPES_PORT/$FN"
160                 elif [ $TYPE == "https" ]; then
161                     SRV="pm-https-server-$SRV_ID.pm-https-server.ran"
162                     #echo "HTTP SERVER "$SRV
163                     URL="https://$SRV:$HTTPS_PORT/files/$FN"
164                 fi
165                 if [ "$EVT_FRAG" != "" ]; then
166                     EVT_FRAG=$EVT_FRAG","
167                 fi
168                 EVT_FRAG=$EVT_FRAG'{"name":"'$FN'","hashMap":{"fileFormatType":"org.3GPP.32.435#measCollec","location":"'$URL'","fileFormatVersion":"V10","compression":"gzip"}}'
169             done
170
171             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":['$EVT_FRAG']}}}'
172             echo $EVT >> .out.json
173
174         fi
175
176         let CNTR=CNTR+1
177         let TCNTR=TCNTR+1
178         if [ $CNTR -ge $BATCHSIZE ]; then
179             echo "Pushing batch of $CNTR events"
180             cat .out.json | kafka-console-producer --topic file-ready --broker-list kafka-1-kafka-bootstrap.nonrtric:9092
181             rm .out.json
182             touch .out.json
183             CNTR=0
184         fi
185     done
186 done
187 if [ $CNTR -ne 0 ]; then
188     echo "Pushing batch of $CNTR events"
189     cat .out.json | kafka-console-producer --topic file-ready --broker-list kafka-1-kafka-bootstrap.nonrtric:9092
190 fi
191
192 echo "Pushed $TCNTR events"