Merge "Minor documentation improvements"
[nonrtric.git] / test / common / ecs_api_functions.sh
index b76d43b..ba451e6 100644 (file)
 #  ============LICENSE_END=================================================
 #
 
-# This is a script that contains specific test functions for ECS NB/SB API
+# This is a script that contains container/service management functions and test functions for ECS
 
-. ../common/api_curl.sh
+## Access to ECS
+# Host name may be changed if app started by kube
+# Direct access
+ECS_HTTPX="http"
+ECS_HOST_NAME=$LOCALHOST_NAME
+ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
 
-############### EXPERIMENTAL #############
+# ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
+ECS_ADAPTER_TYPE="REST"
+ECS_ADAPTER=$ECS_PATH
+
+# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
+ECS_RETRY_CODES=""
+
+###########################
+### ECS functions
+###########################
+
+# All calls to ECS will be directed to the ECS REST interface from now on
+# args: -
+# (Function for test scripts)
+use_ecs_rest_http() {
+       echo -e $BOLD"ECS protocol setting"$EBOLD
+       echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
+       ECS_HTTPX="http"
+       ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
+
+       ECS_ADAPTER_TYPE="REST"
+       ECS_ADAPTER=$ECS_PATH
+       echo ""
+}
+
+# All calls to ECS will be directed to the ECS REST interface from now on
+# args: -
+# (Function for test scripts)
+use_ecs_rest_https() {
+       echo -e $BOLD"ECS protocol setting"$EBOLD
+       echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
+       ECS_HTTPX="https"
+       ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
+
+       ECS_ADAPTER_TYPE="REST"
+       ECS_ADAPTER=$ECS_PATH
+       echo ""
+}
+
+# All calls to ECS will be directed to the ECS dmaap interface over http from now on
+# args: -
+# (Function for test scripts)
+use_ecs_dmaap_http() {
+       echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
+       echo -e $RED" - NOT SUPPORTED - "$ERED
+       echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
+       ECS_ADAPTER_TYPE="MR-HTTP"
+       echo ""
+}
+
+# All calls to ECS will be directed to the ECS dmaap interface over https from now on
+# args: -
+# (Function for test scripts)
+use_ecs_dmaap_https() {
+       echo -e $BOLD"RICSIM protocol setting"$EBOLD
+       echo -e $RED" - NOT SUPPORTED - "$ERED
+       echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
+       ECS_ADAPTER_TYPE="MR-HTTPS"
+       echo ""
+}
+
+# Start the ECS
+# args: -
+# (Function for test scripts)
+start_ecs() {
+
+       echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
+
+       if [ $RUNMODE == "KUBE" ]; then
+
+               # Check if app shall be fully managed by the test script
+               __check_included_image "ECS"
+               retcode_i=$?
+
+               # Check if app shall only be used by the testscipt
+               __check_prestarted_image "ECS"
+               retcode_p=$?
+
+               if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
+                       echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
+                       echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
+                       exit
+               fi
+               if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
+                       echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
+                       echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
+                       exit
+               fi
+
+
+               if [ $retcode_p -eq 0 ]; then
+                       echo -e " Using existing $ECS_APP_NAME deployment and service"
+                       echo " Setting ECS replicas=1"
+                       __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
+               fi
+
+               # Check if app shall be fully managed by the test script
+               if [ $retcode_i -eq 0 ]; then
+                       echo -e " Creating $ECS_APP_NAME app and expose service"
+
+                       #Check if nonrtric namespace exists, if not create it
+                       __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
+
+                       export ECS_APP_NAME
+                       export KUBE_NONRTRIC_NAMESPACE
+                       export ECS_IMAGE
+                       export ECS_INTERNAL_PORT
+                       export ECS_INTERNAL_SECURE_PORT
+                       export ECS_EXTERNAL_PORT
+                       export ECS_EXTERNAL_SECURE_PORT
+                       export ECS_CONFIG_MOUNT_PATH
+                       export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
+                       export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
+                       export ECS_CONTAINER_MNT_DIR
+
+                       # Create config map for config
+                       datafile=$PWD/tmp/$ECS_CONFIG_FILE
+                       cp $1 $datafile
+                       output_yaml=$PWD/tmp/ecs_cfc.yaml
+                       __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
+
+                       # Create pvc
+                       input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
+                       output_yaml=$PWD/tmp/ecs_pvc.yaml
+                       __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
+
+                       # Create service
+                       input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
+                       output_yaml=$PWD/tmp/ecs_svc.yaml
+                       __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
+
+                       # Create app
+                       input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
+                       output_yaml=$PWD/tmp/ecs_app.yaml
+                       __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
+               fi
+
+               echo " Retrieving host and ports for service..."
+               ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
+               ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
+               ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
+
+               echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
+
+               if [ $ECS_HTTPX == "http" ]; then
+                       ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
+               else
+                       ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
+               fi
+
+               __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
+
+               if [ $ECS_ADAPTER_TYPE == "REST" ]; then
+                       ECS_ADAPTER=$ECS_PATH
+               fi
+       else
+               __check_included_image 'ECS'
+               if [ $? -eq 1 ]; then
+                       echo -e $RED"The ECS app is not included in this test script"$ERED
+                       echo -e $RED"ECS will not be started"$ERED
+                       exit 1
+               fi
+
+               curdir=$PWD
+               cd $SIM_GROUP
+               cd ecs
+               cd $ECS_HOST_MNT_DIR
+               cd ..
+               if [ -d db ]; then
+                       if [ "$(ls -A $DIR)" ]; then
+                               echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
+                               rm -rf db/*  &> /dev/null
+                               if [ $? -ne 0 ]; then
+                                       echo -e $RED" Cannot remove database files in: $PWD"$ERED
+                                       exit 1
+                               fi
+                       fi
+               else
+                       echo " No files in mounted dir or dir does not exists"
+               fi
+               cd $curdir
+
+               export ECS_APP_NAME
+               export ECS_APP_NAME_ALIAS
+               export ECS_HOST_MNT_DIR
+               export ECS_CONTAINER_MNT_DIR
+               export ECS_INTERNAL_PORT
+               export ECS_EXTERNAL_PORT
+               export ECS_INTERNAL_SECURE_PORT
+               export ECS_EXTERNAL_SECURE_PORT
+               export DOCKER_SIM_NWNAME
+
+               __start_container $ECS_COMPOSE_DIR NODOCKERARGS 1 $ECS_APP_NAME
+
+               __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
+       fi
+       echo ""
+       return 0
+}
+
+# Restart ECS
+# args: -
+# (Function for test scripts)
+restart_ecs() {
+       echo -e $BOLD"Re-starting ECS"$EBOLD
+       docker restart $ECS_APP_NAME &> ./tmp/.dockererr
+       if [ $? -ne 0 ]; then
+               __print_err "Could not restart $ECS_APP_NAME" $@
+               cat ./tmp/.dockererr
+               ((RES_CONF_FAIL++))
+               return 1
+       fi
+
+       __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
+       echo ""
+       return 0
+}
+
+# Turn on debug level tracing in ECS
+# args: -
+# (Function for test scripts)
+set_ecs_debug() {
+       echo -e $BOLD"Setting ecs debug logging"$EBOLD
+       curlString="$ECS_PATH$ECS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
+       result=$(__do_curl "$curlString")
+       if [ $? -ne 0 ]; then
+               __print_err "Could not set debug mode" $@
+               ((RES_CONF_FAIL++))
+               return 1
+       fi
+       echo ""
+       return 0
+}
+
+# Turn on trace level tracing in ECS
+# args: -
+# (Function for test scripts)
+set_ecs_trace() {
+       echo -e $BOLD"Setting ecs trace logging"$EBOLD
+       curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
+       result=$(__do_curl "$curlString")
+       if [ $? -ne 0 ]; then
+               __print_err "Could not set trace mode" $@
+               ((RES_CONF_FAIL++))
+               return 1
+       fi
+       echo ""
+       return 0
+}
+
+# Perform curl retries when making direct call to ECS for the specified http response codes
+# Speace separated list of http response codes
+# args: [<response-code>]*
+use_agent_retries() {
+       echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
+       ECS_AGENT_RETRY_CODES=$@
+       echo ""
+       return 0
+}
+
+
+# Tests if a variable value in the ECS is equal to a target value and and optional timeout.
+# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
+# equal to the target or not.
+# Arg: <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
+# before setting pass or fail depending on if the variable value becomes equal to the target
+# value or not.
+# (Function for test scripts)
+ecs_equal() {
+       if [ $# -eq 2 ] || [ $# -eq 3 ]; then
+               __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
+       else
+               __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
+       fi
+}
 
-##########################################
-###### Mainly only function skeletons ####
-##########################################
 
 ##########################################
-### A1-E Enrichment Data Consumer API ####
+######### A1-E Enrichment  API ##########
 ##########################################
 #Function prefix: ecs_api_a1
 
 # args (flat uri structure): <response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
 # (Function for test scripts)
 ecs_api_a1_get_job_ids() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
        if [ -z "$FLAT_A1_EI" ]; then
                # Valid number of parameters 4,5,6 etc
@@ -76,9 +350,7 @@ ecs_api_a1_get_job_ids() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
@@ -100,15 +372,12 @@ ecs_api_a1_get_job_ids() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -116,9 +385,7 @@ ecs_api_a1_get_job_ids() {
 # args: <response-code> <type-id> [<schema-file>]
 # (Function for test scripts)
 ecs_api_a1_get_type() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
                __print_err "<response-code> <type-id> [<schema-file>]" $@
@@ -130,9 +397,7 @@ ecs_api_a1_get_type() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
@@ -141,9 +406,7 @@ ecs_api_a1_get_type() {
                if [ -f $3 ]; then
                        schema=$(cat $3)
                else
-                       echo -e $RED" FAIL. Schema file "$3", does not exist"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_general "Schema file "$3", does not exist"
                        return 1
                fi
                if [ -z "$FLAT_A1_EI" ]; then
@@ -155,15 +418,12 @@ ecs_api_a1_get_type() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -171,9 +431,7 @@ ecs_api_a1_get_type() {
 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
 # (Function for test scripts)
 ecs_api_a1_get_type_ids() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
     if [ $# -lt 1 ]; then
                __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
@@ -185,9 +443,7 @@ ecs_api_a1_get_type_ids() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
        if [ $# -gt 1 ]; then
@@ -206,26 +462,21 @@ ecs_api_a1_get_type_ids() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
 # args: <response-code> <type-id> <job-id> [<status>]
-# args (flat uri structure): <response-code> <job-id> [<status>]
+# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
 # (Function for test scripts)
 ecs_api_a1_get_job_status() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
        if [ -z "$FLAT_A1_EI" ]; then
                if [ $# -ne 3 ] && [ $# -ne 4 ]; then
@@ -239,9 +490,7 @@ ecs_api_a1_get_job_status() {
                status=${res:${#res}-3}
 
                if [ $status -ne $1 ]; then
-                       echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_status_code $1 $status
                        return 1
                fi
                if [ $# -eq 4 ]; then
@@ -251,47 +500,69 @@ ecs_api_a1_get_job_status() {
                        res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                        if [ $res -ne 0 ]; then
-                               echo -e $RED" FAIL, returned body not correct"$ERED
-                               ((RES_FAIL++))
-                               __check_stop_at_error
+                               __log_test_fail_body
                                return 1
                        fi
                fi
        else
                echo -e $YELLOW"USING NOT CONFIRMED INTERFACE - FLAT URI STRUCTURE"$EYELLOW
-               if [ $# -ne 2 ] && [ $# -ne 3 ]; then
-                       __print_err "<response-code> <job-id> [<status>]" $@
+               if [ $# -lt 2 ] && [ $# -gt 4 ]; then
+                       __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
                        return 1
                fi
 
                query="/A1-EI/v1/eijobs/$2/status"
 
-               res="$(__do_curl_to_api ECS GET $query)"
-               status=${res:${#res}-3}
-
-               if [ $status -ne $1 ]; then
-                       echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
-                       return 1
-               fi
-               if [ $# -eq 3 ]; then
-                       body=${res:0:${#res}-3}
-                       targetJson="{\"eiJobStatus\": \"$3\"}"
-                       echo " TARGET JSON: $targetJson" >> $HTTPLOG
-                       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+               start=$SECONDS
+               for (( ; ; )); do
+                       res="$(__do_curl_to_api ECS GET $query)"
+                       status=${res:${#res}-3}
+
+                       if [ $# -eq 4 ]; then
+                               duration=$((SECONDS-start))
+                               echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
+                               if [ $duration -gt $4 ]; then
+                                       echo ""
+                                       duration=-1  #Last iteration
+                               fi
+                       else
+                               duration=-1 #single test, no wait
+                       fi
 
-                       if [ $res -ne 0 ]; then
-                               echo -e $RED" FAIL, returned body not correct"$ERED
-                               ((RES_FAIL++))
-                               __check_stop_at_error
-                               return 1
+                       if [ $status -ne $1 ]; then
+                               if [ $duration -eq -1 ]; then
+                                       __log_test_fail_status_code $1 $status
+                                       return 1
+                               fi
                        fi
-               fi
+                       if [ $# -ge 3 ] && [ $status -eq $1 ]; then
+                               body=${res:0:${#res}-3}
+                               targetJson="{\"eiJobStatus\": \"$3\"}"
+                               echo " TARGET JSON: $targetJson" >> $HTTPLOG
+                               res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+                               if [ $res -ne 0 ]; then
+                                       if [ $duration -eq -1 ]; then
+                                               __log_test_fail_body
+                                               return 1
+                                       fi
+                               else
+                                       duration=-1  #Goto pass
+                               fi
+                       fi
+                       if [ $duration -eq -1 ]; then
+                               if [ $# -eq 4 ]; then
+                                       echo ""
+                               fi
+                               __log_test_pass
+                               return 0
+                       else
+                               sleep 1
+                       fi
+               done
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -300,9 +571,7 @@ ecs_api_a1_get_job_status() {
 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
 # (Function for test scripts)
 ecs_api_a1_get_job() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
        if [  -z "$FLAT_A1_EI" ]; then
                if [ $# -ne 3 ] && [ $# -ne 6 ]; then
@@ -322,9 +591,7 @@ ecs_api_a1_get_job() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
@@ -336,9 +603,7 @@ ecs_api_a1_get_job() {
                                jobfile=$(cat $6)
                                jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
                        else
-                               echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED
-                               ((RES_FAIL++))
-                               __check_stop_at_error
+                               _log_test_fail_general "Job template file "$6", does not exist"
                                return 1
                        fi
                        targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
@@ -346,9 +611,7 @@ ecs_api_a1_get_job() {
                        res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                        if [ $res -ne 0 ]; then
-                               echo -e $RED" FAIL, returned body not correct"$ERED
-                               ((RES_FAIL++))
-                               __check_stop_at_error
+                               __log_test_fail_body
                                return 1
                        fi
                fi
@@ -360,26 +623,21 @@ ecs_api_a1_get_job() {
                                jobfile=$(cat $7)
                                jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
                        else
-                               echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED
-                               ((RES_FAIL++))
-                               __check_stop_at_error
+                               _log_test_fail_general "Job template file "$6", does not exist"
                                return 1
                        fi
-                       targetJson="{\"eiTypeId\": \"$3\", \"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
+                       targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
                        echo " TARGET JSON: $targetJson" >> $HTTPLOG
                        res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                        if [ $res -ne 0 ]; then
-                               echo -e $RED" FAIL, returned body not correct"$ERED
-                               ((RES_FAIL++))
-                               __check_stop_at_error
+                               __log_test_fail_body
                                return 1
                        fi
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -388,9 +646,7 @@ ecs_api_a1_get_job() {
 # args (flat uri structure): <response-code> <job-id>
 # (Function for test scripts)
 ecs_api_a1_delete_job() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
        if [  -z "$FLAT_A1_EI" ]; then
                if [ $# -ne 3 ]; then
@@ -411,14 +667,11 @@ ecs_api_a1_delete_job() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -427,9 +680,7 @@ ecs_api_a1_delete_job() {
 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
 # (Function for test scripts)
 ecs_api_a1_put_job() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
        if [  -z "$FLAT_A1_EI" ]; then
                if [ $# -lt 6 ]; then
@@ -440,9 +691,7 @@ ecs_api_a1_put_job() {
                        jobfile=$(cat $6)
                        jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
                else
-                       echo -e $RED" FAIL. Job template file "$6", does not exist"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       _log_test_fail_general "Job template file "$6", does not exist"
                        return 1
                fi
 
@@ -461,9 +710,7 @@ ecs_api_a1_put_job() {
                        jobfile=$(cat $7)
                        jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
                else
-                       echo -e $RED" FAIL. Job template file "$7", does not exist"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       _log_test_fail_general "Job template file "$7", does not exist"
                        return 1
                fi
 
@@ -478,14 +725,11 @@ ecs_api_a1_put_job() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -499,9 +743,7 @@ ecs_api_a1_put_job() {
 # args: <response-code> [ EMPTY | <type-id>+]
 # (Function for test scripts)
 ecs_api_edp_get_type_ids() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
     if [ $# -lt 1 ]; then
                __print_err "<response-code> [ EMPTY | <type-id>+]" $@
@@ -513,9 +755,7 @@ ecs_api_edp_get_type_ids() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
@@ -535,90 +775,152 @@ ecs_api_edp_get_type_ids() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
-# args: <response-code> <producer-id> [<status>]
+# args: <response-code> <producer-id> [<status> [<timeout>]]
 # (Function for test scripts)
 ecs_api_edp_get_producer_status() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
-    if [ $# -lt 2 ] || [ $# -gt 3 ]; then
-               __print_err "<response-code> <producer-id> [<status>]" $@
+    if [ $# -lt 2 ] || [ $# -gt 4 ]; then
+               __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
                return 1
        fi
 
        query="/ei-producer/v1/eiproducers/$2/status"
+       start=$SECONDS
+       for (( ; ; )); do
+               res="$(__do_curl_to_api ECS GET $query)"
+               status=${res:${#res}-3}
+
+               if [ $# -eq 4 ]; then
+                       duration=$((SECONDS-start))
+                       echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
+                       if [ $duration -gt $4 ]; then
+                               echo ""
+                               duration=-1  #Last iteration
+                       fi
+               else
+                       duration=-1 #single test, no wait
+               fi
+
+               if [ $status -ne $1 ]; then
+                       if [ $duration -eq -1 ]; then
+                               __log_test_fail_status_code $1 $status
+                               return 1
+                       fi
+               fi
+               if [ $# -ge 3 ] && [ $status -eq $1 ]; then
+                       body=${res:0:${#res}-3}
+                       targetJson="{\"operational_state\": \"$3\"}"
+                       echo " TARGET JSON: $targetJson" >> $HTTPLOG
+                       res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+                       if [ $res -ne 0 ]; then
+                               if [ $duration -eq -1 ]; then
+                                       __log_test_fail_body
+                                       return 1
+                               fi
+                       else
+                               duration=-1  #Goto pass
+                       fi
+               fi
+               if [ $duration -eq -1 ]; then
+                       if [ $# -eq 4 ]; then
+                               echo ""
+                       fi
+                       __log_test_pass
+                       return 0
+               else
+                       sleep 1
+               fi
+       done
+}
+
+
+# API Test function: GET /ei-producer/v1/eiproducers
+# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
+# (Function for test scripts)
+ecs_api_edp_get_producer_ids() {
+       __log_test_start $@
+
+    if [ $# -lt 1 ]; then
+               __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
+               return 1
+       fi
+
+       query="/ei-producer/v1/eiproducers"
     res="$(__do_curl_to_api ECS GET $query)"
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
-       if [ $# -eq 3 ]; then
+
+       if [ $# -gt 1 ]; then
                body=${res:0:${#res}-3}
-               targetJson="{\"operational_state\": \"$3\"}"
+               targetJson="["
+
+               for pid in ${@:2} ; do
+                       if [ "$targetJson" != "[" ]; then
+                               targetJson=$targetJson","
+                       fi
+                       if [ $pid != "EMPTY" ]; then
+                               targetJson=$targetJson"\"$pid\""
+                       fi
+               done
+
+               targetJson=$targetJson"]"
                echo " TARGET JSON: $targetJson" >> $HTTPLOG
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
-
 # API Test function: GET /ei-producer/v1/eiproducers
-# args: <response-code> [ EMPTY | <producer-id>+]
+# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
 # (Function for test scripts)
-ecs_api_edp_get_producer_ids() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+ecs_api_edp_get_producer_ids_2() {
+       __log_test_start $@
 
     if [ $# -lt 1 ]; then
-               __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
+               __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
                return 1
        fi
 
        query="/ei-producer/v1/eiproducers"
+       if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
+               query=$query"?ei_type_id=$2"
+       fi
     res="$(__do_curl_to_api ECS GET $query)"
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
-       if [ $# -gt 1 ]; then
+       if [ $# -gt 2 ]; then
                body=${res:0:${#res}-3}
                targetJson="["
 
-               for pid in ${@:2} ; do
+               for pid in ${@:3} ; do
                        if [ "$targetJson" != "[" ]; then
                                targetJson=$targetJson","
                        fi
@@ -632,25 +934,20 @@ ecs_api_edp_get_producer_ids() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
-# args: <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
+# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
 # (Function for test scripts)
 ecs_api_edp_get_type() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
        paramError=1
        if [ $# -eq 2 ]; then
@@ -669,9 +966,7 @@ ecs_api_edp_get_type() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
        if [ $# -gt 3 ]; then
@@ -680,9 +975,7 @@ ecs_api_edp_get_type() {
                if [ -f $3 ]; then
                        schema=$(cat $3)
                else
-                       echo -e $RED" FAIL. Job template file "$3", does not exist"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_general "Job template file "$3", does not exist"
                        return 1
                fi
 
@@ -701,40 +994,142 @@ ecs_api_edp_get_type() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
+                       return 1
+               fi
+       fi
+       __log_test_pass
+       return 0
+}
+
+# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
+# args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
+# (Function for test scripts)
+ecs_api_edp_get_type_2() {
+       __log_test_start $@
+
+       paramError=1
+       if [ $# -eq 2 ]; then
+               paramError=0
+       fi
+       if [ $# -eq 3 ]; then
+               paramError=0
+       fi
+    if [ $paramError -ne 0 ]; then
+               __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
+               return 1
+       fi
+
+       query="/ei-producer/v1/eitypes/$2"
+    res="$(__do_curl_to_api ECS GET $query)"
+    status=${res:${#res}-3}
+
+       if [ $status -ne $1 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+       if [ $# -eq 3 ]; then
+               body=${res:0:${#res}-3}
+
+               if [ -f $3 ]; then
+                       schema=$(cat $3)
+               else
+                       __log_test_fail_general "Job template file "$3", does not exist"
+                       return 1
+               fi
+
+               targetJson="{\"ei_job_data_schema\":$schema}"
+
+               echo " TARGET JSON: $targetJson" >> $HTTPLOG
+               res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+               if [ $res -ne 0 ]; then
+                       __log_test_fail_body
                        return 1
                fi
        fi
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
+       return 0
+}
+
+# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
+# args: (v1_2) <response-code> <type-id> <job-schema-file>
+# (Function for test scripts)
+ecs_api_edp_put_type_2() {
+       __log_test_start $@
+
+    if [ $# -ne 3 ]; then
+               __print_err "<response-code> <type-id> <job-schema-file>" $@
+               return 1
+       fi
+
+       if [ ! -f $3 ]; then
+               __log_test_fail_general "Job schema file "$3", does not exist"
+               return 1
+       fi
+       schema=$(cat $3)
+       input_json="{\"ei_job_data_schema\":$schema}"
+       file="./tmp/put_type.json"
+       echo $input_json > $file
+
+       query="/ei-producer/v1/eitypes/$2"
+    res="$(__do_curl_to_api ECS PUT $query $file)"
+    status=${res:${#res}-3}
+
+       if [ $status -ne $1 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+
+       __log_test_pass
+       return 0
+}
+
+# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
+# args: (v1_2) <response-code> <type-id>
+# (Function for test scripts)
+ecs_api_edp_delete_type_2() {
+       __log_test_start $@
+
+    if [ $# -ne 2 ]; then
+               __print_err "<response-code> <type-id>" $@
+               return 1
+       fi
+
+       query="/ei-producer/v1/eitypes/$2"
+    res="$(__do_curl_to_api ECS DELETE $query)"
+    status=${res:${#res}-3}
+
+       if [ $status -ne $1 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+
+       __log_test_pass
        return 0
 }
 
 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
-# args: <response-code> <producer-id> [<create-callback> <delete-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
+# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
 # (Function for test scripts)
 ecs_api_edp_get_producer() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
-       #Possible arg count: 2, 6 7, 9, 11 etc
+       #Possible arg count: 2, 5 6, 8, 10 etc
        paramError=1
        if [ $# -eq 2 ]; then
                paramError=0
        fi
-       if [ $# -eq 6 ] && [ "$6" == "EMPTY" ]; then
+       if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
                paramError=0
        fi
-       variablecount=$(($#-5))
+       variablecount=$(($#-4))
        if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
                paramError=0
        fi
 
     if [ $paramError -ne 0 ]; then
-               __print_err "<response-code> <producer-id> [<create-callback> <delete-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
+               __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
                return 1
        fi
 
@@ -743,27 +1138,23 @@ ecs_api_edp_get_producer() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
        if [ $# -gt 2 ]; then
                body=${res:0:${#res}-3}
                targetJson="["
-               if [ $# -gt 6 ]; then
-                       arr=(${@:6})
-                       for ((i=0; i<$(($#-6)); i=i+2)); do
+               if [ $# -gt 5 ]; then
+                       arr=(${@:5})
+                       for ((i=0; i<$(($#-5)); i=i+2)); do
                                if [ "$targetJson" != "[" ]; then
                                        targetJson=$targetJson","
                                fi
                                if [ -f ${arr[$i+1]} ]; then
                                        schema=$(cat ${arr[$i+1]})
                                else
-                                       echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED
-                                       ((RES_FAIL++))
-                                       __check_stop_at_error
+                                       _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
                                        return 1
                                fi
 
@@ -772,21 +1163,79 @@ ecs_api_edp_get_producer() {
                fi
                targetJson=$targetJson"]"
                if [ $# -gt 4 ]; then
-                       targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\"}"
+                       targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
+               fi
+               echo " TARGET JSON: $targetJson" >> $HTTPLOG
+               res=$(python3 ../common/compare_json.py "$targetJson" "$body")
+
+               if [ $res -ne 0 ]; then
+                       __log_test_fail_body
+                       return 1
+               fi
+       fi
+
+       __log_test_pass
+       return 0
+}
+
+# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
+# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
+# (Function for test scripts)
+ecs_api_edp_get_producer_2() {
+       __log_test_start $@
+
+       #Possible arg count: 2, 5, 6, 7, 8 etc
+       paramError=1
+       if [ $# -eq 2 ]; then
+               paramError=0
+       fi
+       if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
+               paramError=0
+       fi
+       if [ $# -ge 5 ]; then
+               paramError=0
+       fi
+
+    if [ $paramError -ne 0 ]; then
+               __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
+               return 1
+       fi
+
+       query="/ei-producer/v1/eiproducers/$2"
+    res="$(__do_curl_to_api ECS GET $query)"
+    status=${res:${#res}-3}
+
+       if [ $status -ne $1 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+
+       if [ $# -gt 2 ]; then
+               body=${res:0:${#res}-3}
+               targetJson="["
+               if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
+                       arr=(${@:5})
+                       for ((i=0; i<$(($#-4)); i=i+1)); do
+                               if [ "$targetJson" != "[" ]; then
+                                       targetJson=$targetJson","
+                               fi
+                               targetJson=$targetJson"\"${arr[$i]}\""
+                       done
+               fi
+               targetJson=$targetJson"]"
+               if [ $# -gt 4 ]; then
+                       targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
                fi
                echo " TARGET JSON: $targetJson" >> $HTTPLOG
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -794,9 +1243,7 @@ ecs_api_edp_get_producer() {
 # args: <response-code> <producer-id>
 # (Function for test scripts)
 ecs_api_edp_delete_producer() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
     if [ $# -lt 2 ]; then
                __print_err "<response-code> <producer-id>" $@
@@ -808,50 +1255,43 @@ ecs_api_edp_delete_producer() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
-# args: <response-code> <producer-id> <create-callback> <delete-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
+# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
 # (Function for test scripts)
 ecs_api_edp_put_producer() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
-       #Valid number of parametrer 6,7,9,11,
+       #Valid number of parametrer 5,6,8,10,
        paramError=1
-       if  [ $# -eq 6 ] && [ "$6" == "NOTYPE" ]; then
+       if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
                paramError=0
-       elif [ $# -gt 6 ] && [ $(($#%2)) -eq 1 ]; then
+       elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
                paramError=0
        fi
        if [ $paramError -ne 0 ]; then
-               __print_err "<response-code> <producer-id> <create-callback> <delete-callback> <supervision-callback> [<type-id> <schema-file>]+" $@
+               __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
                return 1
        fi
 
        inputJson="["
-       if [ $# -gt 6 ]; then
-               arr=(${@:6})
-               for ((i=0; i<$(($#-6)); i=i+2)); do
+       if [ $# -gt 5 ]; then
+               arr=(${@:5})
+               for ((i=0; i<$(($#-5)); i=i+2)); do
                        if [ "$inputJson" != "[" ]; then
                                inputJson=$inputJson","
                        fi
                        if [ -f ${arr[$i+1]} ]; then
                                schema=$(cat ${arr[$i+1]})
                        else
-                               echo -e $RED" FAIL. Schema file "${arr[$i+1]}", does not exist"$ERED
-                               ((RES_FAIL++))
-                               __check_stop_at_error
+                               _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
                                return 1
                        fi
                        inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
@@ -859,7 +1299,7 @@ ecs_api_edp_put_producer() {
        fi
        inputJson="\"supported_ei_types\":"$inputJson"]"
 
-       inputJson=$inputJson",\"ei_job_creation_callback_url\": \"$3\",\"ei_job_deletion_callback_url\": \"$4\",\"ei_producer_supervision_callback_url\": \"$5\""
+       inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
 
        inputJson="{"$inputJson"}"
 
@@ -870,26 +1310,70 @@ ecs_api_edp_put_producer() {
     status=${res:${#res}-3}
 
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
+       return 0
+}
+
+# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
+# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
+# (Function for test scripts)
+ecs_api_edp_put_producer_2() {
+       __log_test_start $@
+
+       #Valid number of parametrer 5,6,8,10,
+       paramError=1
+       if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
+               paramError=0
+       elif [ $# -ge 5 ]; then
+               paramError=0
+       fi
+       if [ $paramError -ne 0 ]; then
+               __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
+               return 1
+       fi
+
+       inputJson="["
+       if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
+               arr=(${@:5})
+               for ((i=0; i<$(($#-4)); i=i+1)); do
+                       if [ "$inputJson" != "[" ]; then
+                               inputJson=$inputJson","
+                       fi
+                       inputJson=$inputJson"\""${arr[$i]}"\""
+               done
+       fi
+       inputJson="\"supported_ei_types\":"$inputJson"]"
+
+       inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
+
+       inputJson="{"$inputJson"}"
+
+       file="./tmp/.p.json"
+       echo "$inputJson" > $file
+       query="/ei-producer/v1/eiproducers/$2"
+    res="$(__do_curl_to_api ECS PUT $query $file)"
+    status=${res:${#res}-3}
+
+       if [ $status -ne $1 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+
+       __log_test_pass
        return 0
 }
 
 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
-# args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <template-job-file>]+)
+# args: <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
 # (Function for test scripts)
 ecs_api_edp_get_producer_jobs() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
-       #Valid number of parameter 2,3,6,10
+       #Valid number of parameter 2,3,7,11
        paramError=1
        if [ $# -eq 2 ]; then
                paramError=0
@@ -898,11 +1382,11 @@ ecs_api_edp_get_producer_jobs() {
                paramError=0
        fi
        variablecount=$(($#-2))
-       if [ $# -gt 3 ] && [ $(($variablecount%4)) -eq 0 ]; then
+       if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
                paramError=0
        fi
        if [ $paramError -eq 1 ]; then
-               __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <template-job-file>]+)" $@
+               __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
                return 1
        fi
 
@@ -910,9 +1394,7 @@ ecs_api_edp_get_producer_jobs() {
     res="$(__do_curl_to_api ECS GET $query)"
     status=${res:${#res}-3}
        if [ $status -ne $1 ]; then
-               echo -e $RED" FAIL. Exepected status "$1", got "$status $ERED
-               ((RES_FAIL++))
-               __check_stop_at_error
+               __log_test_fail_status_code $1 $status
                return 1
        fi
        if [ $# -gt 2 ]; then
@@ -920,20 +1402,18 @@ ecs_api_edp_get_producer_jobs() {
                targetJson="["
                if [ $# -gt 3 ]; then
                        arr=(${@:3})
-                       for ((i=0; i<$(($#-3)); i=i+4)); do
+                       for ((i=0; i<$(($#-3)); i=i+5)); do
                                if [ "$targetJson" != "[" ]; then
                                        targetJson=$targetJson","
                                fi
-                               if [ -f ${arr[$i+3]} ]; then
-                                       jobfile=$(cat ${arr[$i+3]})
+                               if [ -f ${arr[$i+4]} ]; then
+                                       jobfile=$(cat ${arr[$i+4]})
                                        jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
                                else
-                                       echo -e $RED" FAIL. Job template file "${arr[$i+3]}", does not exist"$ERED
-                                       ((RES_FAIL++))
-                                       __check_stop_at_error
+                                       _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
                                        return 1
                                fi
-                               targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"ei_job_data\":$jobfile}"
+                               targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile}"
                        done
                fi
                targetJson=$targetJson"]"
@@ -942,15 +1422,12 @@ ecs_api_edp_get_producer_jobs() {
                res=$(python3 ../common/compare_json.py "$targetJson" "$body")
 
                if [ $res -ne 0 ]; then
-                       echo -e $RED" FAIL, returned body not correct"$ERED
-                       ((RES_FAIL++))
-                       __check_stop_at_error
+                       __log_test_fail_body
                        return 1
                fi
        fi
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
 
@@ -964,16 +1441,70 @@ ecs_api_edp_get_producer_jobs() {
 # args: <response-code>
 # (Function for test scripts)
 ecs_api_service_status() {
-       echo -e $BOLD"TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ $EBOLD
-    echo "TEST(${BASH_LINENO[0]}): ${FUNCNAME[0]}" $@ >> $HTTPLOG
-       ((RES_TEST++))
+       __log_test_start $@
 
     if [ $# -lt 1 ]; then
                __print_err "<response-code> [<producer-id>]*|NOID" $@
                return 1
        fi
+       res="$(__do_curl_to_api ECS GET /status)"
+    status=${res:${#res}-3}
+       if [ $status -ne $1 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+       __log_test_pass
+       return 0
+}
+
+
+##########################################
+####          Reset jobs              ####
+##########################################
+# Function prefix: ecs_api_admin
+
+# Admin to remove all jobs
+# args:
+# (Function for test scripts)
+
+ecs_api_admin_reset() {
+       __log_test_start $@
+
+       if [  -z "$FLAT_A1_EI" ]; then
+               query="/A1-EI/v1/eitypes/$2/eijobs"
+       else
+               query="/A1-EI/v1/eijobs"
+       fi
+    res="$(__do_curl_to_api ECS GET $query)"
+    status=${res:${#res}-3}
+
+       if [ $status -ne 200 ]; then
+               __log_test_fail_status_code $1 $status
+               return 1
+       fi
+
+       #Remove brackets and response code
+       body=${res:1:${#res}-4}
+       list=$(echo ${body//,/ })
+       list=$(echo ${list//[/})
+       list=$(echo ${list//]/})
+       list=$(echo ${list//\"/})
+       list=$list" "
+       for job in $list; do
+               if [  -z "$FLAT_A1_EI" ]; then
+                       echo "Not supported for non-flat EI api"
+               else
+                       query="/A1-EI/v1/eijobs/$job"
+                       res="$(__do_curl_to_api ECS DELETE $query)"
+                       status=${res:${#res}-3}
+                       if [ $status -ne 204 ]; then
+                               __log_test_fail_status_code $1 $status
+                               return 1
+                       fi
+                       echo " Deleted job: "$job
+               fi
+       done
 
-       ((RES_PASS++))
-       echo -e $GREEN" PASS"$EGREEN
+       __log_test_pass
        return 0
 }
\ No newline at end of file