blob: 61c529790735346caa6fb89b7431f8101d765f6b [file] [log] [blame]
BjornMagnussonXAc5655db2023-03-17 14:55:16 +01001#!/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
20SD=$(dirname -- "$0")
21echo "script-home: "$SD
22cd $SD
23CWD=$PWD
24
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020025VARIANT=$1
26NODE_COUNT=$2
27EVT_COUNT=$3
28NODE_NAME_BASE=$4
29FILE_EXT=$5
30TYPE=$6
31SRV_COUNT=$7
32HIST=$8
BjornMagnussonXAc5655db2023-03-17 14:55:16 +010033
34FTPES_PORT=2021
35SFTP_PORT=2022
36HTTPS_PORT=443
37
38print_usage() {
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020039 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]"
BjornMagnussonXAc5655db2023-03-17 14:55:16 +010040 exit 1
41}
42echo $@
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020043if [ $# -lt 7 ] && [ $# -gt 8 ]; then
BjornMagnussonXAc5655db2023-03-17 14:55:16 +010044 print_usage
45fi
46
47if [ $TYPE == "sftp" ]; then
48 echo "sftp servers not yet supported"
49elif [ $TYPE == "ftpes" ]; then
50 echo "ftpes servers not yet supported"
51elif [ $TYPE == "https" ]; then
52 :
53else
54 print_usage
55fi
56
57if [ $FILE_EXT != "xml.gz" ]; then
58 echo "only xml.gz format supported"
59 print_usage
60fi
61
62HIST_LEN=0
63if [ ! -z "$HIST" ]; then
64 if [ $HIST != "hist" ]; then
65 print_usage
66 fi
67 HIST_LEN=96
68fi
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020069PUSHMSG=""
70if [ $VARIANT == "ves" ]; then
71 PUSHMSG="to ves-collector"
72elif [ $VARIANT == "file-ready" ]; then
73 PUSHMSG="to file-ready topic"
74fi
BjornMagnussonXAc5655db2023-03-17 14:55:16 +010075
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020076# Unix time of 20230515.0700
BjornMagnussonXAc5655db2023-03-17 14:55:16 +010077# 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
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020078BEGINTIME=1684134000
BjornMagnussonXAc5655db2023-03-17 14:55:16 +010079# 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
81TIMEZONE="+0100"
82CURTIME=$BEGINTIME
83
84BATCHSIZE=1000
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020085if [ $VARIANT == "ves" ]; then
86 BATCHSIZE=20
87fi
BjornMagnussonXAc5655db2023-03-17 14:55:16 +010088
89CNTR=0
90TCNTR=0
91
92for (( i=0; i<$EVT_COUNT; i++)); do
93
94 if [ $CNTR -eq 0 ]; then
95 rm .out.json
96 touch .out.json
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +020097 if [ $VARIANT == "ves" ]; then
98 echo '{"eventList": [' > .out.json
99 fi
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100100 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
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100118 FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
119 let SRV_ID=$j%$SRV_COUNT
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100120 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
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +0200137
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
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100146 echo $EVT >> .out.json
147 else
148 NO="$NODE_NAME_BASE-$j"
149
150 let SRV_ID=$j%$SRV_COUNT
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100151 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
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100166 FN="A$ST$TIMEZONE-$ET${TIMEZONE}_$NO.$FILE_EXT"
167 fi
168 echo "FILENAME "$FN
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +0200169 SRV="pm-https-server-$SRV_ID.pm-https-server.ran"
170 URL="https://$SRV:$HTTPS_PORT/files/$FN"
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100171 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
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +0200177 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
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100185 echo $EVT >> .out.json
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100186 fi
187
188 let CNTR=CNTR+1
189 let TCNTR=TCNTR+1
190 if [ $CNTR -ge $BATCHSIZE ]; then
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +0200191 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
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100198 rm .out.json
199 touch .out.json
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +0200200 if [ $VARIANT == "ves" ]; then
201 echo '{"eventList": [' > .out.json
202 fi
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100203 CNTR=0
204 fi
205 done
206done
207if [ $CNTR -ne 0 ]; then
BjornMagnussonXA6ab531b2023-05-15 11:23:35 +0200208 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
BjornMagnussonXAc5655db2023-03-17 14:55:16 +0100215fi
216
217echo "Pushed $TCNTR events"