+ cat .dockererr
+ echo -e $RED"Exiting...."$ERED
+ exit 1
+ fi
+}
+
+# Generate a string for each included image using the app display name and a docker images format string
+# If a custom image repo is used then also the source image from the local repo is listed
+# arg: <docker-images-format-string> <file-to-append>
+__CR_image_data() {
+ echo -e "$CR_DISPLAY_NAME\t$(docker images --format $1 $CR_IMAGE)" >> $2
+ if [ ! -z "$CR_IMAGE_SOURCE" ]; then
+ echo -e "-- source image --\t$(docker images --format $1 $CR_IMAGE_SOURCE)" >> $2
+ fi
+}
+
+# Scale kubernetes resources to zero
+# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
+# This function is called for apps fully managed by the test script
+__CR_kube_scale_zero() {
+ __kube_scale_all_resources $KUBE_SIM_NAMESPACE autotest CR
+}
+
+# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
+# This function is called for pre-started apps not managed by the test script.
+__CR_kube_scale_zero_and_wait() {
+ echo -e $RED" CR app is not scaled in this state"$ERED
+}
+
+# Delete all kube resources for the app
+# This function is called for apps managed by the test script.
+__CR_kube_delete_all() {
+ __kube_delete_all_resources $KUBE_SIM_NAMESPACE autotest CR
+}
+
+# Store docker logs
+# This function is called for apps managed by the test script.
+# args: <log-dir> <file-prefix>
+__CR_store_docker_logs() {
+ if [ $RUNMODE == "KUBE" ]; then
+ for podname in $(kubectl $KUBECONF get pods -n $KUBE_SIM_NAMESPACE -l "autotest=CR" -o custom-columns=":metadata.name"); do
+ kubectl $KUBECONF logs -n $KUBE_SIM_NAMESPACE $podname --tail=-1 > $1$2_$podname.log 2>&1
+ done
+ else
+ crs=$(docker ps --filter "name=$CR_APP_NAME" --filter "network=$DOCKER_SIM_NWNAME" --filter "status=running" --format {{.Names}})
+ for crid in $crs; do
+ docker logs $crid > $1$2_$crid.log 2>&1
+ done
+ fi
+}
+
+# Initial setup of protocol, host and ports
+# This function is called for apps managed by the test script.
+# args: -
+__CR_initial_setup() {
+ use_cr_http
+}
+
+# Set app short-name, app name and namespace for logging runtime statistics of kubernetes pods or docker containers
+# For docker, the namespace shall be excluded
+# This function is called for apps managed by the test script as well as for pre-started apps.
+# args: -
+__CR_statistics_setup() {
+ for ((CR_INSTANCE=MAX_CR_APP_COUNT; CR_INSTANCE>0; CR_INSTANCE-- )); do
+ if [ $RUNMODE == "KUBE" ]; then
+ CR_INSTANCE_KUBE=$(($CR_INSTANCE-1))
+ echo -n " CR-$CR_INSTANCE_KUBE $CR_APP_NAME-$CR_INSTANCE_KUBE $KUBE_SIM_NAMESPACE "
+ else
+ echo -n " CR_$CR_INSTANCE ${CR_APP_NAME}-cr-$CR_INSTANCE "
+ fi
+ done
+}
+
+# Check application requirements, e.g. helm, the the test needs. Exit 1 if req not satisfied
+# args: -
+__CR_test_requirements() {
+ :
+}
+
+#######################################################
+
+################
+### CR functions
+################
+
+#Var to hold the current number of CR instances
+CR_APP_COUNT=1
+MAX_CR_APP_COUNT=10
+
+# Set http as the protocol to use for all communication to the Dmaap adapter
+# args: -
+# (Function for test scripts)
+use_cr_http() {
+ __cr_set_protocoll "http" $CR_INTERNAL_PORT $CR_EXTERNAL_PORT
+}
+
+# Set https as the protocol to use for all communication to the Dmaap adapter
+# args: -
+# (Function for test scripts)
+use_cr_https() {
+ __cr_set_protocoll "https" $CR_INTERNAL_SECURE_PORT $CR_EXTERNAL_SECURE_PORT
+}
+
+# Setup paths to svc/container for internal and external access
+# args: <protocol> <internal-port> <external-port>
+__cr_set_protocoll() {
+
+ echo -e $BOLD"$CR_DISPLAY_NAME protocol setting"$EBOLD
+ echo -e " Using $BOLD $1 $EBOLD towards $CR_DISPLAY_NAME"
+ ## Access to Dmaap adapter
+ for ((CR_INSTANCE=0; CR_INSTANCE<$MAX_CR_APP_COUNT; CR_INSTANCE++ )); do
+ CR_DOCKER_INSTANCE=$(($CR_INSTANCE+1))
+ # CR_SERVICE_PATH is the base path to cr
+ __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"-cr-"${CR_DOCKER_INSTANCE}":"$2 # docker access, container->container and script->container via proxy
+ if [ $RUNMODE == "KUBE" ]; then
+ __CR_SERVICE_PATH=$1"://"$CR_APP_NAME"-"$CR_INSTANCE.$CR_APP_NAME"."$KUBE_SIM_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
+ fi
+ export CR_SERVICE_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH
+ # Service paths are used in test script to provide callbacck urls to app
+ export CR_SERVICE_MR_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_MR #Only for messages from dmaap adapter/mediator
+ export CR_SERVICE_TEXT_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK_TEXT #Callbacks for text payload
+ export CR_SERVICE_APP_PATH"_"${CR_INSTANCE}=$__CR_SERVICE_PATH$CR_APP_CALLBACK #For general callbacks from apps
+
+ if [ $CR_INSTANCE -eq 0 ]; then
+ # CR_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
+ # CR_ADDAPTER need to be set before each call to CR....only set for instance 0 here
+ CR_ADAPTER_TYPE="REST"
+ CR_ADAPTER=$__CR_SERVICE_PATH
+ fi
+ done
+ echo ""
+}
+
+# Export env vars for config files, docker compose and kube resources
+# args: <proxy-flag>
+__cr_export_vars() {
+ export CR_APP_NAME
+ export CR_DISPLAY_NAME
+
+ export KUBE_SIM_NAMESPACE
+ export DOCKER_SIM_NWNAME
+
+ export CR_IMAGE
+
+ export CR_INTERNAL_PORT
+ export CR_INTERNAL_SECURE_PORT
+ export CR_EXTERNAL_PORT
+ export CR_EXTERNAL_SECURE_PORT
+
+ export CR_APP_COUNT
+}
+
+# Start the Callback receiver in the simulator group
+# args: <app-count>
+# (Function for test scripts)
+start_cr() {
+
+ echo -e $BOLD"Starting $CR_DISPLAY_NAME"$EBOLD
+
+ if [ $# -ne 1 ]; then
+ echo -e $RED" Number of CR instances missing, usage: start_cr <app-count>"$ERED
+ exit 1
+ fi
+ if [ $1 -lt 1 ] || [ $1 -gt 10 ]; then
+ echo -e $RED" Number of CR shall be 1...10, usage: start_cr <app-count>"$ERED
+ exit 1
+ fi
+ export CR_APP_COUNT=$1
+
+ if [ $RUNMODE == "KUBE" ]; then
+
+ # Check if app shall be fully managed by the test script
+ __check_included_image "CR"
+ retcode_i=$?
+
+ # Check if app shall only be used by the test script
+ __check_prestarted_image "CR"
+ retcode_p=$?
+
+ if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
+ echo -e $RED"The $CR_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
+ echo -e $RED"The $CR_APP_NAME will not be started"$ERED
+ exit
+ fi
+ if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
+ echo -e $RED"The $CR_APP_NAME app is included both as managed and prestarted in this test script"$ERED
+ echo -e $RED"The $CR_APP_NAME will not be started"$ERED
+ exit
+ fi
+
+ # Check if app shall be used - not managed - by the test script
+ if [ $retcode_p -eq 0 ]; then
+ echo -e " Using existing $CR_APP_NAME deployment and service"
+ echo " Setting CR replicas=1"
+ __kube_scale deployment $CR_APP_NAME $KUBE_SIM_NAMESPACE 1
+ fi
+
+ if [ $retcode_i -eq 0 ]; then
+ echo -e " Creating $CR_APP_NAME deployment and service"
+
+ __cr_export_vars
+
+ __kube_create_namespace $KUBE_SIM_NAMESPACE
+
+ # Create service
+ input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"svc.yaml
+ output_yaml=$PWD/tmp/cr_svc.yaml
+ __kube_create_instance service $CR_APP_NAME $input_yaml $output_yaml
+
+ # Create app
+ input_yaml=$SIM_GROUP"/"$CR_COMPOSE_DIR"/"app.yaml
+ output_yaml=$PWD/tmp/cr_app.yaml
+ __kube_create_instance app $CR_APP_NAME $input_yaml $output_yaml
+
+ fi
+
+ for ((CR_INSTANCE=0; CR_INSTANCE<$CR_APP_COUNT; CR_INSTANCE++ )); do
+ __dynvar="CR_SERVICE_PATH_"$CR_INSTANCE
+ __cr_app_name=$CR_APP_NAME"-"$CR_INSTANCE
+ __check_service_start $__cr_app_name ${!__dynvar}$CR_ALIVE_URL
+ result=$(__do_curl ${!__dynvar}/reset)
+ done
+
+ else
+ # Check if docker app shall be fully managed by the test script
+ __check_included_image 'CR'
+ if [ $? -eq 1 ]; then
+ echo -e $RED"The Callback Receiver app is not included in this test script"$ERED
+ echo -e $RED"The Callback Receiver will not be started"$ERED
+ exit
+ fi
+
+ __cr_export_vars
+
+ app_data=""
+ cntr=1
+ while [ $cntr -le $CR_APP_COUNT ]; do
+ app=$CR_APP_NAME"-cr-"$cntr
+ app_data="$app_data $app"
+ let cntr=cntr+1
+ done
+
+ echo "COMPOSE_PROJECT_NAME="$CR_APP_NAME > $SIM_GROUP/$CR_COMPOSE_DIR/.env
+
+ __start_container $CR_COMPOSE_DIR "" NODOCKERARGS $CR_APP_COUNT $app_data
+
+ cntr=1 #Counter for docker instance, starts on 1
+ cntr2=0 #Couter for env var name, starts with 0 to be compablible with kube
+ while [ $cntr -le $CR_APP_COUNT ]; do
+ app=$CR_APP_NAME"-cr-"$cntr
+ __dynvar="CR_SERVICE_PATH_"$cntr2
+ __check_service_start $app ${!__dynvar}$CR_ALIVE_URL
+ let cntr=cntr+1
+ let cntr2=cntr2+1
+ done
+ fi
+ echo ""
+}
+
+#Convert a cr path id to the value of the environment var holding the url
+# arg: <cr-path-id>
+# returns: <base-url-to-the-app>
+__cr_get_service_path(){
+ if [ $# -ne 1 ]; then
+ echo "DUMMY"
+ return 1
+ fi
+ if [ $1 -lt 0 ] || [ $1 -ge $MAX_CR_APP_COUNT ]; then
+ echo "DUMMY"
+ return 1
+ fi
+ __dynvar="CR_SERVICE_PATH_"$1
+ echo ${!__dynvar}
+ return 0