+ fi
+
+ __log_test_pass
+ return 0
+}
+
+# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
+# args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
+# (Function for test scripts)
+ecs_api_idc_get_job() {
+ __log_test_start $@
+
+ if [ $# -ne 2 ] && [ $# -ne 7 ]; then
+ __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
+ return 1
+ fi
+ query="/data-consumer/v1/info-jobs/$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 7 ]; then
+ body=${res:0:${#res}-3}
+
+ if [ -f $7 ]; then
+ jobfile=$(cat $7)
+ jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
+ else
+ __log_test_fail_general "Job template file "$6", does not exist"
+ return 1
+ fi
+ targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
+ 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: PUT /data-consumer/v1/info-jobs/{infoJobId}
+# args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
+# (Function for test scripts)
+ecs_api_idc_put_job() {
+ __log_test_start $@
+
+ if [ $# -lt 7 ] || [ $# -gt 8 ]; then
+ __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
+ return 1
+ fi
+ if [ -f $7 ]; then
+ jobfile=$(cat $7)
+ jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
+ else
+ __log_test_fail_general "Job template file "$7", does not exist"
+ return 1
+ fi
+
+ inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
+ file="./tmp/.p.json"
+ echo "$inputJson" > $file
+
+ query="/data-consumer/v1/info-jobs/$2"
+
+ if [ $# -eq 8 ]; then
+ if [ $8 == "VALIDATE" ]; then
+ query=$query"?typeCheck=true"
+ fi
+ fi
+
+ 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 /data-consumer/v1/info-jobs/{infoJobId}
+# args: <response-code> <job-id>
+# (Function for test scripts)
+ecs_api_idc_delete_job() {
+ __log_test_start $@
+
+ if [ $# -ne 2 ]; then
+ __print_err "<response-code> <job-id>" $@
+ return 1
+ fi
+ query="/data-consumer/v1/info-jobs/$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 /data-consumer/v1/info-types/{infoTypeId}
+# args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
+# (Function for test scripts)
+ecs_api_idc_get_type() {
+ __log_test_start $@
+
+ if [ $# -lt 2 ] || [ $# -gt 5 ]; then
+ __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
+ return 1
+ fi
+
+ query="/data-consumer/v1/info-types/$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}
+ if [ -f $3 ]; then
+ schema=$(cat $3)
+ else
+ __log_test_fail_general "Schema file "$3", does not exist"
+ return 1
+ fi
+ if [ $# -eq 5 ]; then
+ targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
+ else
+ targetJson="{\"job_data_schema\":$schema}"
+ 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 /data-consumer/v1/info-jobs/{infoJobId}/status
+# This test only status during an optional timeout. No test of the list of producers
+# args: <response-code> <job-id> [<status> [<timeout>]]
+# (Function for test scripts)
+ecs_api_idc_get_job_status() {
+ __log_test_start $@
+
+ if [ $# -lt 2 ] && [ $# -gt 4 ]; then
+ __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
+ return 1
+ fi
+
+ query="/data-consumer/v1/info-jobs/$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="{\"info_job_status\": \"$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
+
+ __log_test_pass
+ return 0
+}
+
+# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
+# This function test status and the list of producers with and optional timeout
+# args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
+# (Function for test scripts)
+ecs_api_idc_get_job_status2() {
+
+ __log_test_start $@
+ param_error=0
+ if [ $# -lt 2 ]; then
+ param_error=1
+ fi
+ args=("$@")
+ timeout=0
+ if [ $# -gt 2 ]; then
+ if [ $# -lt 4 ]; then
+ param_error=1
+ fi
+ targetJson="{\"info_job_status\": \"$3\""
+ if [ "$4" == "EMPTYPROD" ]; then
+ targetJson=$targetJson",\"producers\": []}"
+ if [ $# -gt 4 ]; then
+ timeout=$5
+ fi
+ else
+ targetJson=$targetJson",\"producers\": ["
+ if [ $# -eq $(($4+5)) ]; then
+ idx=$(($4+4))
+ timeout=${args[$idx]}
+ fi
+ for ((ecs_i = 0 ; ecs_i < $4 ; ecs_i++)); do
+ idx=$(($ecs_i+4))
+ if [ $ecs_i -gt 0 ]; then
+ targetJson=$targetJson","
+ fi
+ targetJson=$targetJson"\""${args[$idx]}"\""
+ done
+ targetJson=$targetJson"]}"
+ fi
+ fi
+
+ if [ $param_error -ne 0 ]; then
+ __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
+ return 1
+ fi
+
+ query="/data-consumer/v1/info-jobs/$2/status"
+
+ start=$SECONDS
+ for (( ; ; )); do
+ res="$(__do_curl_to_api ECS GET $query)"
+ status=${res:${#res}-3}
+
+ if [ $# -gt 2 ]; then
+ duration=$((SECONDS-start))
+ echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
+ if [ $duration -gt $timeout ]; 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 [ $# -gt 2 ] && [ $status -eq $1 ]; then
+ body=${res:0:${#res}-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
+
+ __log_test_pass
+ return 0
+}
+
+##########################################
+#### Type subscriptions ####
+##########################################
+
+# API Test function: GET /data-consumer/v1/info-type-subscription
+# args: <response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
+# (Function for test scripts)
+ecs_api_idc_get_subscription_ids() {
+ __log_test_start $@
+
+ if [ $# -lt 3 ]; then
+ __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
+ return 1
+ fi
+
+ query="/data-consumer/v1/info-type-subscription"
+ search=""
+ if [ $2 != "NOOWNER" ]; then
+ search="?owner="$2
+ fi
+
+ res="$(__do_curl_to_api ECS GET $query$search)"
+ 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 [ $3 != "EMPTY" ]; then
+ for pid in ${@:3} ; do
+ if [ "$targetJson" != "[" ]; then
+ targetJson=$targetJson","
+ fi
+ targetJson=$targetJson"\"$pid\""
+ done
+ fi
+ targetJson=$targetJson"]"
+ 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 /data-consumer/v1/info-type-subscription/{subscriptionId}
+# args: <response-code> <subscription-id> [ <owner-id> <status-uri> ]
+# (Function for test scripts)
+ecs_api_idc_get_subscription() {
+ __log_test_start $@
+
+ if [ $# -ne 2 ] && [ $# -ne 4 ]; then
+ __print_err "<response-code> <subscription-id> [ <owner-id> <status-uri> ]" $@
+ return 1
+ fi
+
+ query="/data-consumer/v1/info-type-subscription/$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="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
+ 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: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
+# args: <response-code> <subscription-id> <owner-id> <status-uri>
+# (Function for test scripts)
+ecs_api_idc_put_subscription() {
+ __log_test_start $@
+
+ if [ $# -ne 4 ]; then
+ __print_err "<response-code> <subscription-id> <owner-id> <status-uri>" $@
+ return 1
+ fi
+
+ inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
+ file="./tmp/.p.json"
+ echo "$inputJson" > $file
+
+ query="/data-consumer/v1/info-type-subscription/$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 /data-consumer/v1/info-type-subscription/{subscriptionId}
+# args: <response-code> <subscription-id>
+# (Function for test scripts)
+ecs_api_idc_delete_subscription() {
+ __log_test_start $@
+
+ if [ $# -ne 2 ]; then
+ __print_err "<response-code> <subscription-id> " $@
+ return 1
+ fi
+
+ query="/data-consumer/v1/info-type-subscription/$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
+}
+
+##########################################
+#### Reset jobs ####
+##########################################
+# Function prefix: ecs_api_admin
+
+# Admin to remove all jobs
+# args: <response-code> [ <type> ]
+# (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
+
+ __log_test_pass
+ return 0
+}
+
+##########################################
+#### Reset jobs and producers ####
+##########################################
+
+
+# Admin reset to remove all data in ecs; jobs, producers etc
+# NOTE - only works in kubernetes and the pod should not be running
+# args: -
+# (Function for test scripts)
+
+ecs_kube_pvc_reset() {
+ __log_test_start $@
+
+ pvc_name=$(kubectl get pvc -n nonrtric --no-headers -o custom-columns=":metadata.name" | grep enrichment)
+ if [ -z "$pvc_name" ]; then
+ pvc_name=enrichmentservice-pvc
+ fi
+ echo " Trying to reset pvc: "$pvc_name
+
+ __kube_clean_pvc $ECS_APP_NAME nonrtric $pvc_name /var/enrichment-coordinator-service/database