blob: 7bd71189220dbf67297467c34bcb585bbd7eaeec [file] [log] [blame]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001#!/bin/bash
2
3# ============LICENSE_START===============================================
4# Copyright (C) 2020 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# This is a script that contains container/service management function
21# and test functions for Message Router - mr stub
22
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010023################ Test engine functions ################
24
25# Create the image var used during the test
26# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
27# <image-tag-suffix> is present only for images with staging, snapshot,release tags
28__MR_imagesetup() {
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020029 __check_and_create_image_var MR "MRSTUB_IMAGE" "MRSTUB_IMAGE_BASE" "MRSTUB_IMAGE_TAG" LOCAL "$MR_STUB_DISPLAY_NAME" $IMAGE_TARGET_PLATFORM_IMG_TAG
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010030}
31
32# Create the image var used during the test
33# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
34# <image-tag-suffix> is present only for images with staging, snapshot,release tags
35__DMAAPMR_imagesetup() {
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020036 __check_and_create_image_var DMAAPMR "ONAP_DMAAPMR_IMAGE" "ONAP_DMAAPMR_IMAGE_BASE" "ONAP_DMAAPMR_IMAGE_TAG" REMOTE_RELEASE_ONAP "DMAAP Message Router" ""
37 __check_and_create_image_var DMAAPMR "ONAP_ZOOKEEPER_IMAGE" "ONAP_ZOOKEEPER_IMAGE_BASE" "ONAP_ZOOKEEPER_IMAGE_TAG" REMOTE_RELEASE_ONAP "ZooKeeper" ""
38 __check_and_create_image_var DMAAPMR "ONAP_KAFKA_IMAGE" "ONAP_KAFKA_IMAGE_BASE" "ONAP_KAFKA_IMAGE_TAG" REMOTE_RELEASE_ONAP "Kafka" ""
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010039}
40
41# Pull image from remote repo or use locally built image
42# arg: <pull-policy-override> <pull-policy-original>
43# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
44# <pull-policy-original> Shall be used for images that does not allow overriding
45# Both var may contain: 'remote', 'remote-remove' or 'local'
46__MR_imagepull() {
BjornMagnussonXAa69cd902021-04-22 23:46:10 +020047 echo -e $RED"Image for app MR shall never be pulled from remote repo"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010048}
49
50# Pull image from remote repo or use locally built image
51# arg: <pull-policy-override> <pull-policy-original>
52# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released (remote) images
53# <pull-policy-original> Shall be used for images that does not allow overriding
54# Both var may contain: 'remote', 'remote-remove' or 'local'
55__DMAAPMR_imagepull() {
BjornMagnussonXA483ee332021-04-08 01:35:24 +020056 __check_and_pull_image $2 "DMAAP Message Router" $MR_DMAAP_APP_NAME ONAP_DMAAPMR_IMAGE
57 __check_and_pull_image $2 "ZooKeeper" $MR_ZOOKEEPER_APP_NAME ONAP_ZOOKEEPER_IMAGE
58 __check_and_pull_image $2 "Kafka" $MR_KAFKA_APP_NAME ONAP_KAFKA_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010059}
60
61# Build image (only for simulator or interfaces stubs owned by the test environment)
62# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
63# <image-tag-suffix> is present only for images with staging, snapshot,release tags
64__MR_imagebuild() {
65 cd ../mrstub
66 echo " Building MR - $MR_STUB_DISPLAY_NAME - image: $MRSTUB_IMAGE"
BjornMagnussonXAd54225b2023-04-19 14:03:49 +020067 docker build $IMAGE_TARGET_PLATFORM_CMD_PARAM --build-arg NEXUS_PROXY_REPO=$NEXUS_PROXY_REPO -t $MRSTUB_IMAGE . &> .dockererr
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010068 if [ $? -eq 0 ]; then
BjornMagnussonXA483ee332021-04-08 01:35:24 +020069 echo -e $GREEN" Build Ok"$EGREEN
70 __retag_and_push_image MRSTUB_IMAGE
71 if [ $? -ne 0 ]; then
72 exit 1
73 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010074 else
BjornMagnussonXA483ee332021-04-08 01:35:24 +020075 echo -e $RED" Build Failed"$ERED
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010076 ((RES_CONF_FAIL++))
77 cat .dockererr
78 echo -e $RED"Exiting...."$ERED
79 exit 1
80 fi
81}
82
83# Build image (only for simulator or interfaces stubs owned by the test environment)
84# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
85# <image-tag-suffix> is present only for images with staging, snapshot,release tags
86__DMAAPMR_imagebuild() {
87 echo -e $RED"Image for app DMAAPMR shall never be built"$ERED
88}
89
90# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020091# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010092# arg: <docker-images-format-string> <file-to-append>
93__MR_image_data() {
94 echo -e "$MR_STUB_DISPLAY_NAME\t$(docker images --format $1 $MRSTUB_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020095 if [ ! -z "$MRSTUB_IMAGE_SOURCE" ]; then
96 echo -e "-- source image --\t$(docker images --format $1 $MRSTUB_IMAGE_SOURCE)" >> $2
97 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010098}
99
100# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +0200101# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100102# arg: <docker-images-format-string> <file-to-append>
103__DMAAPMR_image_data() {
104 echo -e "DMAAP Message Router\t$(docker images --format $1 $ONAP_DMAAPMR_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +0200105 if [ ! -z "$ONAP_DMAAPMR_IMAGE_SOURCE" ]; then
106 echo -e "-- source image --\t$(docker images --format $1 $ONAP_DMAAPMR_IMAGE_SOURCE)" >> $2
107 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100108 echo -e "ZooKeeper\t$(docker images --format $1 $ONAP_ZOOKEEPER_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +0200109 if [ ! -z "$ONAP_ZOOKEEPER_IMAGE_SOURCE" ]; then
110 echo -e "-- source image --\t$(docker images --format $1 $ONAP_ZOOKEEPER_IMAGE_SOURCE)" >> $2
111 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100112 echo -e "Kafka\t$(docker images --format $1 $ONAP_KAFKA_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +0200113 if [ ! -z "$ONAP_KAFKA_IMAGE_SOURCE" ]; then
114 echo -e "-- source image --\t$(docker images --format $1 $ONAP_KAFKA_IMAGE_SOURCE)" >> $2
115 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100116}
117
118# Scale kubernetes resources to zero
119# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
120# This function is called for apps fully managed by the test script
121__MR_kube_scale_zero() {
122 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest MR
123}
124
125# Scale kubernetes resources to zero
126# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
127# This function is called for apps fully managed by the test script
128__DMAAPMR_kube_scale_zero() {
129 __kube_scale_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
130}
131
132# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200133# This function is called for pre-started apps not managed by the test script.
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100134__MR_kube_scale_zero_and_wait() {
135 echo -e " MR replicas kept as is"
136}
137
138# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200139# This function is called for pre-started apps not managed by the test script.
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100140__DMAAPMR_kube_scale_zero_and_wait() {
141 echo -e " DMAAP replicas kept as is"
142}
143
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200144# Delete all kube resources for the app
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100145# This function is called for apps managed by the test script.
146__MR_kube_delete_all() {
147 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest MR
148}
149
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200150# Delete all kube resources for the app
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100151# This function is called for apps managed by the test script.
152__DMAAPMR_kube_delete_all() {
153 __kube_delete_all_resources $KUBE_ONAP_NAMESPACE autotest DMAAPMR
154}
155
156# Store docker logs
157# This function is called for apps managed by the test script.
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200158# args: <log-dir> <file-prefix>
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100159__MR_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100160 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100161 kubectl $KUBECONF logs -l "autotest=MR" -n $KUBE_ONAP_NAMESPACE --tail=-1 > $1$2_mr_stub.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100162 else
163 docker logs $MR_STUB_APP_NAME > $1$2_mr_stub.log 2>&1
164 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100165}
166
167# Store docker logs
168# This function is called for apps managed by the test script.
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200169# args: <log-dir> <file-prefix>
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100170__DMAAPMR_store_docker_logs() {
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100171 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAcb6113e2022-02-17 15:01:28 +0100172 for podname in $(kubectl $KUBECONF get pods -n $KUBE_ONAP_NAMESPACE -l "autotest=DMAAPMR" -o custom-columns=":metadata.name"); do
173 kubectl $KUBECONF logs -n $KUBE_ONAP_NAMESPACE $podname --tail=-1 > $1$2_$podname.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100174 done
175 else
BjornMagnussonXA05bfe482021-12-02 08:47:41 +0100176 docker logs $MR_DMAAP_APP_NAME > $1$2_mr.log 2>&1
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100177 docker logs $MR_KAFKA_APP_NAME > $1$2_mr_kafka.log 2>&1
178 docker logs $MR_ZOOKEEPER_APP_NAME > $1$2_mr_zookeeper.log 2>&1
179 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100180}
181
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100182# Initial setup of protocol, host and ports
183# This function is called for apps managed by the test script.
184# args: -
185__MR_initial_setup() {
186 use_mr_http
187}
188
189# Initial setup of protocol, host and ports
190# This function is called for apps managed by the test script.
191# args: -
192__DMAAPMR_initial_setup() {
193 : # handle by __MR_initial_setup
194}
195
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200196# Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100197# For docker, the namespace shall be excluded
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200198# This function is called for apps managed by the test script as well as for pre-started apps.
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100199# args: -
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200200__MR_statistics_setup() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100201 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100202 echo "MR-STUB $MR_STUB_APP_NAME $KUBE_ONAP_NAMESPACE"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100203 else
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100204 echo "MR-STUB $MR_STUB_APP_NAME"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100205 fi
206}
207
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200208# Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100209# For docker, the namespace shall be excluded
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200210# This function is called for apps managed by the test script as well as for pre-started apps.
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100211# args: -
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200212__DMAAPMR_statistics_setup() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100213 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100214 echo "KAFKA $MR_KAFKA_APP_NAME $KUBE_ONAP_NAMESPACE MESSAGE-ROUTER $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE ZOOKEEPER $MR_ZOOKEEPER_APP_NAME $KUBE_ONAP_NAMESPACE"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100215 else
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100216 echo "KAFKA $MR_KAFKA_APP_NAME MESSAGE-ROUTER $MR_DMAAP_APP_NAME ZOOKEEPER $MR_ZOOKEEPER_APP_NAME"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100217 fi
218}
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100219
BjornMagnussonXAe60d04e2021-12-27 13:38:01 +0100220# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
221# args: -
222__MR_test_requirements() {
223 :
224}
225
226# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
227# args: -
228__DMAAPMR_test_requirements() {
229 :
230}
231
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100232#######################################################
233
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100234# Description of port mappings when running MR-STUB only or MR-STUB + MESSAGE-ROUTER
235#
236# 'MR-STUB only' is started when only 'MR' is included in the test script. Both the test scripts and app will then use MR-STUB as a message-router simulator.
237#
238# 'MR-STUB + MESSAGE-ROUTER' is started when 'MR' and 'DMAAPMR' is included in the testscripts. DMAAPMR is the real message router including kafka and zookeeper.
239# In this configuration, MR-STUB is used by the test-script as frontend to the message-router while app are using the real message-router.
240#
241# DOCKER KUBE
242# ---------------------------------------------------------------------------------------------------------------------------------------------------
243
244# MR-STUB MR-STUB
245# +++++++ +++++++
246# localhost container service pod
247# ==============================================================================================================================================
248# 10 MR_STUB_LOCALHOST_PORT -> 13 MR_INTERNAL_PORT 15 MR_EXTERNAL_PORT -> 17 MR_INTERNAL_PORT
249# 12 MR_STUB_LOCALHOST_SECURE_PORT -> 14 MR_INTERNAL_SECURE_PORT 16 MR_EXTERNAL_SECURE_PORT -> 18 MR_INTERNAL_SECURE_PORT
250
251
252
253# MESSAGE-ROUTER MESSAGE-ROUTER
254# ++++++++++++++ ++++++++++++++
255# localhost container service pod
256# ===================================================================================================================================================
257# 20 MR_DMAAP_LOCALHOST_PORT -> 23 MR_INTERNAL_PORT 25 MR_EXTERNAL_PORT -> 27 MR_INTERNAL_PORT
258# 22 MR_DMAAP_LOCALHOST_SECURE_PORT -> 24 MR_INTERNAL_SECURE_PORT 26 MR_EXTERNAL_SECURE_PORT -> 28 MR_INTERNAL_SECURE_PORT
259
260
261# Running only the MR-STUB - apps using MR-STUB
262# DOCKER KUBE
263# localhost: 10 and 12 -
264# via proxy (script): 13 and 14 via proxy (script): 15 and 16
265# apps: 13 and 14 apps: 15 and 16
266
267# Running MR-STUB (as frontend for test script) and MESSAGE-ROUTER - apps using MESSAGE-ROUTER
268# DOCKER KUBE
269# localhost: 10 and 12 -
270# via proxy (script): 13 and 14 via proxy (script): 15 and 16
271# apps: 23 and 24 apps: 25 and 26
272#
273
274
275
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100276use_mr_http() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100277 __mr_set_protocoll "http" $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_SECURE_PORT $MR_EXTERNAL_SECURE_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100278}
279
280use_mr_https() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100281 __mr_set_protocoll "https" $MR_INTERNAL_PORT $MR_EXTERNAL_PORT $MR_INTERNAL_SECURE_PORT $MR_EXTERNAL_SECURE_PORT
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100282}
283
284# Setup paths to svc/container for internal and external access
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100285# args: <protocol> <internal-port> <external-port> <internal-secure-port> <external-secure-port>
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100286__mr_set_protocoll() {
287 echo -e $BOLD"$MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME protocol setting"$EBOLD
BjornMagnussonXA007b6452021-11-29 08:03:38 +0100288 echo -e " Using $BOLD $1 $EBOLD towards $MR_STUB_DISPLAY_NAME and $MR_DMAAP_DISPLAY_NAME"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100289
290 ## Access to Dmaap mediator
291
292 MR_HTTPX=$1
293
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100294 if [ $MR_HTTPX == "http" ]; then
295 INT_PORT=$2
296 EXT_PORT=$3
297 else
298 INT_PORT=$4
299 EXT_PORT=$5
300 fi
301
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100302 # Access via test script
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100303 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME":"$INT_PORT # access from script via proxy, docker
304 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME":"$INT_PORT # access from script via proxy, docker
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200305 MR_DMAAP_ADAPTER_HTTP="" # Access to dmaap mr via proxy - set only if app is included
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100306
307 MR_SERVICE_PATH=$MR_STUB_PATH # access container->container, docker - access pod->svc, kube
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100308 MR_KAFKA_SERVICE_PATH=""
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100309 MR_ZOOKEEPER_SERVICE_PATH=""
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100310 __check_included_image "DMAAPMR"
311 if [ $? -eq 0 ]; then
312 MR_SERVICE_PATH=$MR_DMAAP_PATH # access container->container, docker - access pod->svc, kube
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100313 MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
314
315 MR_KAFKA_SERVICE_PATH=$MR_KAFKA_APP_NAME":"$MR_KAFKA_PORT
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100316 MR_ZOOKEEPER_SERVICE_PATH=$MR_ZOOKEEPER_APP_NAME":"$MR_ZOOKEEPER_PORT
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100317 fi
318
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200319 # For directing calls from script to e.g.A1PMS via message router
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100320 # These cases shall always go though the mr-stub
321 MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME":"$2
322 MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME":"$4
323
324 MR_DMAAP_ADAPTER_TYPE="REST"
325
326
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100327
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100328 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100329 MR_STUB_PATH=$MR_HTTPX"://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$EXT_PORT # access from script via proxy, kube
330 MR_DMAAP_PATH=$MR_HTTPX"://"$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE":"$EXT_PORT # access from script via proxy, kube
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100331
332 MR_SERVICE_PATH=$MR_STUB_PATH
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100333 __check_included_image "DMAAPMR"
334 if [ $? -eq 0 ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100335 MR_SERVICE_PATH=$MR_DMAAP_PATH
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100336 MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
337 MR_KAFKA_SERVICE_PATH=$MR_KAFKA_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_KAFKA_PORT
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100338 MR_ZOOKEEPER_SERVICE_PATH=$MR_ZOOKEEPER_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_ZOOKEEPER_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100339 fi
340 __check_prestarted_image "DMAAPMR"
341 if [ $? -eq 0 ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100342 MR_SERVICE_PATH=$MR_DMAAP_PATH
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100343 MR_DMAAP_ADAPTER_HTTP=$MR_DMAAP_PATH
344 MR_KAFKA_SERVICE_PATH=$MR_KAFKA_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_KAFKA_PORT
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100345 MR_ZOOKEEPER_SERVICE_PATH=$MR_ZOOKEEPER_APP_NAME"."$KUBE_ONAP_NAMESPACE":"$MR_ZOOKEEPER_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100346 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100347
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200348 # For directing calls from script to e.g.A1PMS, via message router
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100349 # These calls shall always go though the mr-stub
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100350 MR_ADAPTER_HTTP="http://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$3
351 MR_ADAPTER_HTTPS="https://"$MR_STUB_APP_NAME.$KUBE_ONAP_NAMESPACE":"$5
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100352 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100353
354 # For calls from script to the mr-stub
355 MR_STUB_ADAPTER=$MR_STUB_PATH
356 MR_STUB_ADAPTER_TYPE="REST"
357
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100358 echo ""
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100359
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100360}
361
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100362# Export env vars for config files, docker compose and kube resources
363# args: -
364__dmaapmr_export_vars() {
365 #Docker only
366 export DOCKER_SIM_NWNAME
367 export ONAP_ZOOKEEPER_IMAGE
368 export MR_ZOOKEEPER_APP_NAME
369 export ONAP_KAFKA_IMAGE
370 export MR_KAFKA_APP_NAME
371 export ONAP_DMAAPMR_IMAGE
372 export MR_DMAAP_APP_NAME
373 export MR_DMAAP_LOCALHOST_PORT
374 export MR_INTERNAL_PORT
375 export MR_DMAAP_LOCALHOST_SECURE_PORT
376 export MR_INTERNAL_SECURE_PORT
377 export MR_DMAAP_HOST_MNT_DIR
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100378
379 export KUBE_ONAP_NAMESPACE
380 export MR_EXTERNAL_PORT
381 export MR_EXTERNAL_SECURE_PORT
382 export MR_KAFKA_PORT
383 export MR_ZOOKEEPER_PORT
384
385 export MR_KAFKA_SERVICE_PATH
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100386 export MR_ZOOKEEPER_SERVICE_PATH
BjornMagnussonXAecf34532021-11-24 08:25:15 +0100387
388 export MR_KAFKA_KUBE_NODE_PORT
389 export MR_KAFKA_DOCKER_LOCALHOST_PORT
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100390}
391
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100392# Export env vars for config files, docker compose and kube resources
393# args: -
394__mr_export_vars() {
395 #Docker only
396 export DOCKER_SIM_NWNAME
397 export MR_STUB_APP_NAME
398 export MRSTUB_IMAGE
399 export MR_INTERNAL_PORT
400 export MR_INTERNAL_SECURE_PORT
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100401 export MR_EXTERNAL_PORT
402 export MR_EXTERNAL_SECURE_PORT
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100403 export MR_STUB_LOCALHOST_PORT
404 export MR_STUB_LOCALHOST_SECURE_PORT
405 export MR_STUB_CERT_MOUNT_DIR
406 export MR_STUB_DISPLAY_NAME
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100407
408 export KUBE_ONAP_NAMESPACE
409 export MR_EXTERNAL_PORT
410
411 export MR_KAFKA_SERVICE_PATH
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100412 export MR_ZOOKEEPER_SERVICE_PATH
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100413}
414
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100415
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100416# Start the Message Router stub interface in the simulator group
417# args: -
418# (Function for test scripts)
419start_mr() {
420
421 echo -e $BOLD"Starting $MR_DMAAP_DISPLAY_NAME and/or $MR_STUB_DISPLAY_NAME"$EBOLD
422
423 if [ $RUNMODE == "KUBE" ]; then
424
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200425 # Table of possible combinations of included mr and included/pre-started dmaap-mr
426 # mr can never be pre-started
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100427 # mr can be used stand alone
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200428 # if dmaapmr is included/pre-started, then mr is needed as well as frontend
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100429
430 # Inverted logic - 0 mean true, 1 means false
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200431 # mr pre-started 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100432 # mr included 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
BjornMagnussonXAd54225b2023-04-19 14:03:49 +0200433 # dmaap pre-started 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100434 # dmaap included 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
435 # ==================================================
436 # OK 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1
437
438 __check_prestarted_image 'MR'
439 retcode_prestarted_mr=$?
440 __check_included_image 'MR'
441 retcode_included_mr=$?
442
443 __check_prestarted_image 'DMAAPMR'
444 retcode_prestarted_dmaapmr=$?
445 __check_included_image 'DMAAPMR'
446 retcode_included_dmaapmr=$?
447
448 paramerror=1
449
450 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
451 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -eq 0 ]; then
452 paramerror=0
453 fi
454 fi
455
456 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
457 if [ $retcode_prestarted_dmaapmr -eq 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
458 paramerror=0
459 fi
460 fi
461
462 if [ $retcode_prestarted_mr -ne 0 ] && [ $retcode_included_mr -eq 0 ]; then
463 if [ $retcode_prestarted_dmaapmr -ne 0 ] && [ $retcode_included_dmaapmr -ne 0 ]; then
464 paramerror=0
465 fi
466 fi
467
468 if [ $paramerror -ne 0 ]; then
469 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
470 echo -e $RED"The Message Router will not be started"$ERED
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100471 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included and/or prestarted"$ERED
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100472 exit
473 fi
474
475 if [ $retcode_prestarted_dmaapmr -eq 0 ]; then
476 echo -e " Using existing $MR_DMAAP_APP_NAME deployment and service"
477 __kube_scale deployment $MR_DMAAP_APP_NAME $KUBE_ONAP_NAMESPACE 1
478 fi
479
480 if [ $retcode_included_dmaapmr -eq 0 ]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100481
482 __dmaapmr_export_vars
483
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100484 #Check if onap namespace exists, if not create it
485 __kube_create_namespace $KUBE_ONAP_NAMESPACE
486
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100487 # copy config files
488 MR_MNT_CONFIG_BASEPATH=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_MNT_DIR
489 cp -r $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_CONFIG_DIR/* $MR_MNT_CONFIG_BASEPATH
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100490
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100491 # Create config maps - dmaapmr app
492 configfile=$MR_MNT_CONFIG_BASEPATH/mr/MsgRtrApi.properties
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100493 output_yaml=$PWD/tmp/dmaapmr_msgrtrapi_cfc.yaml
494 __kube_create_configmap dmaapmr-msgrtrapi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
495
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100496 configfile=$MR_MNT_CONFIG_BASEPATH/mr/logback.xml
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100497 output_yaml=$PWD/tmp/dmaapmr_logback_cfc.yaml
498 __kube_create_configmap dmaapmr-logback.xml $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
499
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100500 configfile=$MR_MNT_CONFIG_BASEPATH/mr/cadi.properties
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100501 output_yaml=$PWD/tmp/dmaapmr_cadi_cfc.yaml
502 __kube_create_configmap dmaapmr-cadi.properties $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
503
504 # Create config maps - kafka app
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100505 configfile=$MR_MNT_CONFIG_BASEPATH/kafka/zk_client_jaas.conf
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100506 output_yaml=$PWD/tmp/dmaapmr_zk_client_cfc.yaml
507 __kube_create_configmap dmaapmr-zk-client-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
508
509 # Create config maps - zookeeper app
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100510 configfile=$MR_MNT_CONFIG_BASEPATH/zk/zk_server_jaas.conf
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100511 output_yaml=$PWD/tmp/dmaapmr_zk_server_cfc.yaml
512 __kube_create_configmap dmaapmr-zk-server-jaas.conf $KUBE_ONAP_NAMESPACE autotest DMAAPMR $configfile $output_yaml
513
514 # Create service
515 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"svc.yaml
516 output_yaml=$PWD/tmp/dmaapmr_svc.yaml
517 __kube_create_instance service $MR_DMAAP_APP_NAME $input_yaml $output_yaml
518
519 # Create app
520 input_yaml=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR"/"app.yaml
521 output_yaml=$PWD/tmp/dmaapmr_app.yaml
522 __kube_create_instance app $MR_DMAAP_APP_NAME $input_yaml $output_yaml
523
524
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100525 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
526
BjornMagnussonXAecf34532021-11-24 08:25:15 +0100527 echo " Kafka TCP node port $MR_KAFKA_KUBE_NODE_PORT"
528
529
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100530 if [ $# -gt 0 ]; then
531 if [ $(($#%3)) -eq 0 ]; then
532 while [ $# -gt 0 ]; do
533 __dmaap_pipeclean "$1" "$2/$1" "$2/$1/$3?timeout=1000&limit=100"
534 shift; shift; shift;
535 done
536 else
537 echo -e $RED" args: start_mr [<topic-name> <base-url> <group-and-user-url>]*"$ERED
538 echo -e $RED" Got: $@"$ERED
539 exit 1
540 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100541 fi
542
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100543 echo " Current topics:"
544 curlString="$MR_DMAAP_PATH/topics"
545 result=$(__do_curl "$curlString")
546 echo $result | indent2
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100547
548 fi
549
550 if [ $retcode_included_mr -eq 0 ]; then
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100551
552 __mr_export_vars
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100553
554 if [ $retcode_prestarted_dmaapmr -eq 0 ] || [ $retcode_included_dmaapmr -eq 0 ]; then # Set topics for dmaap
555 export TOPIC_READ="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
556 export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100557 export GENERIC_TOPICS_UPLOAD_BASEURL="http://$MR_DMAAP_APP_NAME.$KUBE_ONAP_NAMESPACE:$MR_INTERNAL_PORT"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100558 else
559 export TOPIC_READ=""
560 export TOPIC_WRITE=""
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100561 export GENERIC_TOPICS_UPLOAD_BASEURL=""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100562 fi
563
564 #Check if onap namespace exists, if not create it
565 __kube_create_namespace $KUBE_ONAP_NAMESPACE
566
567 # Create service
568 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"svc.yaml
569 output_yaml=$PWD/tmp/mr_svc.yaml
570 __kube_create_instance service $MR_STUB_APP_NAME $input_yaml $output_yaml
571
572 # Create app
573 input_yaml=$SIM_GROUP"/"$MR_STUB_COMPOSE_DIR"/"app.yaml
574 output_yaml=$PWD/tmp/mr_app.yaml
575 __kube_create_instance app $MR_STUB_APP_NAME $input_yaml $output_yaml
576
577
578 fi
579
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100580 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
581
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100582 else
583
584 __check_included_image 'DMAAPMR'
585 retcode_dmaapmr=$?
586 __check_included_image 'MR'
587 retcode_mr=$?
588
589 if [ $retcode_dmaapmr -ne 0 ] && [ $retcode_mr -ne 0 ]; then
590 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
591 echo -e $RED"The Message Router will not be started"$ERED
592 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
593 exit
594 fi
595
596 if [ $retcode_dmaapmr -eq 0 ] && [ $retcode_mr -ne 0 ]; then
597 echo -e $RED"The Message Router apps 'MR' and/or 'DMAAPMR' are not included in this test script"$ERED
598 echo -e $RED"The Message Router will not be started"$ERED
599 echo -e $RED"Both MR and DAAMPMR - or - only MR - need to be included"
600 exit
601 fi
602
603 export TOPIC_READ=""
604 export TOPIC_WRITE=""
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100605 export GENERIC_TOPICS_UPLOAD_BASEURL=""
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100606 if [ $retcode_dmaapmr -eq 0 ]; then # Set topics for dmaap
607 export TOPIC_READ="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_READ_TOPIC"
608 export TOPIC_WRITE="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT/events/$MR_WRITE_TOPIC/users/mr-stub?timeout=15000&limit=100"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100609 export GENERIC_TOPICS_UPLOAD_BASEURL="http://$MR_DMAAP_APP_NAME:$MR_INTERNAL_PORT"
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100610 fi
611
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100612 __dmaapmr_export_vars
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100613
614 if [ $retcode_dmaapmr -eq 0 ]; then
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100615
616 # copy config files
617 MR_MNT_CONFIG_BASEPATH=$SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_MNT_DIR
618 cp -r $SIM_GROUP"/"$MR_DMAAP_COMPOSE_DIR$MR_DMAAP_HOST_CONFIG_DIR/* $MR_MNT_CONFIG_BASEPATH
619
620 # substitute vars
621 configfile=$MR_MNT_CONFIG_BASEPATH/mr/MsgRtrApi.properties
622 cp $configfile $configfile"_tmp"
623 envsubst < $configfile"_tmp" > $configfile
624
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100625 __start_container $MR_DMAAP_COMPOSE_DIR "" NODOCKERARGS 1 $MR_DMAAP_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100626
627 __check_service_start $MR_DMAAP_APP_NAME $MR_DMAAP_PATH$MR_DMAAP_ALIVE_URL
628
BjornMagnussonXAecf34532021-11-24 08:25:15 +0100629 echo " Kafka TCP node port $MR_KAFKA_DOCKER_LOCALHOST_PORT"
630
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100631 if [ $# -gt 0 ]; then
632 if [ $(($#%3)) -eq 0 ]; then
633 while [ $# -gt 0 ]; do
634 __dmaap_pipeclean "$1" "$2/$1" "$2/$1/$3?timeout=1000&limit=100"
635 shift; shift; shift;
636 done
637 else
638 echo -e $RED" args: start_mr [<topic-name> <base-url> <group-and-user-url>]*"$ERED
639 echo -e $RED" Got: $@"$ERED
640 exit 1
641 fi
642 fi
643
BjornMagnussonXA05bfe482021-12-02 08:47:41 +0100644 dmaap_api_print_topics
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100645 fi
646
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100647 __mr_export_vars
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100648
649 if [ $retcode_mr -eq 0 ]; then
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100650 __start_container $MR_STUB_COMPOSE_DIR "" NODOCKERARGS 1 $MR_STUB_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100651
652 __check_service_start $MR_STUB_APP_NAME $MR_STUB_PATH$MR_STUB_ALIVE_URL
653 fi
654
655 fi
656 echo ""
657 return 0
658}
659
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100660# Create a dmaap mr topic
661# args: <topic name> <topic-description>
662__create_topic() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100663 echo -ne " Creating topic: $1"$SAMELINE
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100664
665 json_topic="{\"topicName\":\"$1\",\"partitionCount\":\"2\", \"replicationCount\":\"3\", \"transactionEnabled\":\"false\",\"topicDescription\":\"$2\"}"
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100666 fname="./tmp/$1.json"
667 echo $json_topic > $fname
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100668
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100669 query="/topics/create"
670 topic_retries=10
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100671 while [ $topic_retries -gt 0 ]; do
672 let topic_retries=topic_retries-1
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100673 res="$(__do_curl_to_api DMAAPMR POST $query $fname)"
674 status=${res:${#res}-3}
675
676 if [[ $status == "2"* ]]; then
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100677 topic_retries=0
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100678 echo -e " Creating topic: $1 $GREEN OK $EGREEN"
679 else
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100680 if [ $topic_retries -eq 0 ]; then
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100681 echo -e " Creating topic: $1 $RED Failed $ERED"
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100682 ((RES_CONF_FAIL++))
683 return 1
684 else
685 sleep 1
686 fi
687 fi
688 done
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100689 echo
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100690 return 0
691}
692
693# Do a pipeclean of a topic - to overcome dmaap mr bug...
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100694# args: <topic> <post-url> <read-url> [<num-retries>]
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100695__dmaap_pipeclean() {
696 pipeclean_retries=50
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100697 if [ $# -eq 4 ]; then
698 pipeclean_retries=$4
699 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100700 echo -ne " Doing dmaap-mr pipe cleaning on topic: $1"$SAMELINE
701 while [ $pipeclean_retries -gt 0 ]; do
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100702 if [[ $1 == *".text" ]]; then
703 echo "pipeclean-$1:$pipeclean_retries" > ./tmp/__dmaap_pipeclean.txt
704 curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:text/plain -d@./tmp/__dmaap_pipeclean.txt"
705 else
706 echo "{\"pipeclean-$1\":$pipeclean_retries}" > ./tmp/__dmaap_pipeclean.json
707 curlString="$MR_DMAAP_PATH$2 -X POST -H Content-Type:application/json -d@./tmp/__dmaap_pipeclean.json"
708 fi
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100709 let pipeclean_retries=pipeclean_retries-1
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100710 result=$(__do_curl "$curlString")
711 if [ $? -ne 0 ]; then
712 sleep 1
713 else
714 curlString="$MR_DMAAP_PATH$3"
715 result=$(__do_curl "$curlString")
716 if [ $? -eq 0 ]; then
717 if [ $result != "[]" ]; then
718 echo -e " Doing dmaap-mr pipe cleaning on topic: $1 $GREEN OK $EGREEN"
719 return 0
720
721 else
722 sleep 1
723 fi
724 fi
725 fi
726 done
727 echo -e "Doing dmaap-mr pipe cleaning on topic: $1 $RED Failed $ERED"
728 return 1
729}
730
BjornMagnussonXA05bfe482021-12-02 08:47:41 +0100731# Helper function to list the current topics in DMAAP MR
732# args: -
733dmaap_api_print_topics() {
734 echo " Current topics:"
735 curlString="$MR_DMAAP_PATH/topics"
736 result=$(__do_curl "$curlString")
737 echo $result | indent2
738}
739
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100740
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100741### Generic test cases for varaible checking
742
743# Tests if a variable value in the MR stub is equal to a target value and and optional timeout.
744# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
745# equal to the target or not.
746# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
747# before setting pass or fail depending on if the variable value becomes equal to the target
748# value or not.
749# (Function for test scripts)
750mr_equal() {
751 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
752 __var_test "MR" $MR_STUB_PATH/counter/ $1 "=" $2 $3
753 else
754 ((RES_CONF_FAIL++))
755 __print_err "Wrong args to mr_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
756 fi
757}
758
759# Tests if a variable value in the MR stub is greater than a target value and and optional timeout.
760# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
761# greater than the target or not.
762# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
763# before setting pass or fail depending on if the variable value becomes greater than the target
764# value or not.
765# (Function for test scripts)
766mr_greater() {
767 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
768 __var_test "MR" $MR_STUB_PATH/counter/ $1 ">" $2 $3
769 else
770 ((RES_CONF_FAIL++))
771 __print_err "Wrong args to mr_greater, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
772 fi
773}
774
775# Read a variable value from MR sim and send to stdout. Arg: <variable-name>
776mr_read() {
777 echo "$(__do_curl $MR_STUB_PATH/counter/$1)"
778}
779
780# Print a variable value from the MR stub.
781# arg: <variable-name>
782# (Function for test scripts)
783mr_print() {
784 if [ $# != 1 ]; then
785 ((RES_CONF_FAIL++))
786 __print_err "need one arg, <mr-param>" $@
787 exit 1
788 fi
789 echo -e $BOLD"INFO(${BASH_LINENO[0]}): mrstub, $1 = $(__do_curl $MR_STUB_PATH/counter/$1)"$EBOLD
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100790}
791
792# Send json to topic in mr-stub.
793# arg: <topic-url> <json-msg>
794# (Function for test scripts)
795mr_api_send_json() {
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100796 __log_conf_start $@
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100797 if [ $# -ne 2 ]; then
798 __print_err "<topic-url> <json-msg>" $@
799 return 1
800 fi
801 query=$1
802 fname=$PWD/tmp/json_payload_to_mr.json
803 echo $2 > $fname
804 res="$(__do_curl_to_api MRSTUB POST $query $fname)"
805
806 status=${res:${#res}-3}
807 if [ $status -ne 200 ]; then
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100808 __log_conf_fail_status_code 200 $status
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100809 return 1
810 fi
811
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100812 __log_conf_ok
813 return 0
814}
815
816# Send text to topic in mr-stub.
817# arg: <topic-url> <text-msg>
818# (Function for test scripts)
819mr_api_send_text() {
820 __log_conf_start $@
821 if [ $# -ne 2 ]; then
822 __print_err "<topic-url> <text-msg>" $@
823 return 1
824 fi
825 query=$1
826 fname=$PWD/tmp/text_payload_to_mr.txt
827 echo $2 > $fname
828 res="$(__do_curl_to_api MRSTUB POST $query $fname text/plain)"
829
830 status=${res:${#res}-3}
831 if [ $status -ne 200 ]; then
832 __log_conf_fail_status_code 200 $status
833 return 1
834 fi
835
836 __log_conf_ok
837 return 0
838}
839
840# Send json file to topic in mr-stub.
841# arg: <topic-url> <json-file>
842# (Function for test scripts)
843mr_api_send_json_file() {
844 __log_conf_start $@
845 if [ $# -ne 2 ]; then
846 __print_err "<topic-url> <json-file>" $@
847 return 1
848 fi
849 query=$1
850 if [ ! -f $2 ]; then
851 __log_test_fail_general "File $2 does not exist"
852 return 1
853 fi
854 #Create json array for mr
855 datafile="tmp/mr_api_send_json_file.json"
856 { echo -n "[" ; cat $2 ; echo -n "]" ;} > $datafile
857
858 res="$(__do_curl_to_api MRSTUB POST $query $datafile)"
859
860 status=${res:${#res}-3}
861 if [ $status -ne 200 ]; then
862 __log_conf_fail_status_code 200 $status
863 return 1
864 fi
865
866 __log_conf_ok
867 return 0
868}
869
870# Send text file to topic in mr-stub.
871# arg: <topic-url> <text-file>
872# (Function for test scripts)
873mr_api_send_text_file() {
874 __log_conf_start $@
875 if [ $# -ne 2 ]; then
876 __print_err "<topic-url> <text-file>" $@
877 return 1
878 fi
879 query=$1
880 if [ ! -f $2 ]; then
881 __log_test_fail_general "File $2 does not exist"
882 return 1
883 fi
884
885 res="$(__do_curl_to_api MRSTUB POST $query $2 text/plain)"
886
887 status=${res:${#res}-3}
888 if [ $status -ne 200 ]; then
889 __log_conf_fail_status_code 200 $status
890 return 1
891 fi
892
893 __log_conf_ok
894 return 0
895}
896
897# Create json file for payload
898# arg: <size-in-kb> <filename>
899mr_api_generate_json_payload_file() {
900 __log_conf_start $@
901 if [ $# -ne 2 ]; then
902 __print_err "<topic-url> <json-file>" $@
903 return 1
904 fi
905 if [ $1 -lt 1 ] || [ $1 -gt 10000 ]; then
906 __log_conf_fail_general "Only size between 1k and 10000k supported"
907 return 1
908 fi
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100909 echo -n "{\"abcdefghijklmno\":[" > $2
910 LEN=$(($1*100-2))
911 echo -n "\""ABCDEFG"\"" >> $2
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100912 for ((idx=1; idx<$LEN; idx++))
913 do
BjornMagnussonXA79e37002021-11-22 13:36:04 +0100914 echo -n ",\"ABCDEFG\"" >> $2
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100915 done
916 echo -n "]}" >> $2
917
918 __log_conf_ok
919 return 0
920}
921
BjornMagnussonXA05bfe482021-12-02 08:47:41 +0100922# Create text file for payload
BjornMagnussonXA6fc58fd2021-11-18 08:19:45 +0100923# arg: <size-in-kb> <filename>
924mr_api_generate_text_payload_file() {
925 __log_conf_start $@
926 if [ $# -ne 2 ]; then
927 __print_err "<topic-url> <text-file>" $@
928 return 1
929 fi
930 if [ $1 -lt 1 ] || [ $1 -gt 10000 ]; then
931 __log_conf_fail_general "Only size between 1k and 10000k supported"
932 return 1
933 fi
934 echo -n "" > $2
935 LEN=$(($1*100))
936 for ((idx=0; idx<$LEN; idx++))
937 do
938 echo -n "ABCDEFGHIJ" >> $2
939 done
940
941 __log_conf_ok
BjornMagnussonXA663566c2021-11-08 10:25:07 +0100942 return 0
943}