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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 # This is a script that contains container/service management functions and test functions for ECS
22 ################ Test engine functions ################
24 # Create the image var used during the test
25 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
28 __check_and_create_image_var ECS "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $1 "$ECS_DISPLAY_NAME"
31 # Pull image from remote repo or use locally built image
32 # arg: <pull-policy-override> <pull-policy-original>
33 # <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34 # <pull-policy-original> Shall be used for images that does not allow overriding
35 # Both var may contain: 'remote', 'remote-remove' or 'local'
37 __check_and_pull_image $1 "$ECS_DISPLAY_NAME" $ECS_APP_NAME $ECS_IMAGE
40 # Build image (only for simulator or interfaces stubs owned by the test environment)
41 # arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42 # <image-tag-suffix> is present only for images with staging, snapshot,release tags
44 echo -e $RED" Image for app ECS shall never be built"$ERED
47 # Generate a string for each included image using the app display name and a docker images format string
48 # arg: <docker-images-format-string> <file-to-append>
50 echo -e "$ECS_DISPLAY_NAME\t$(docker images --format $1 $ECS_IMAGE)" >> $2
53 # Scale kubernetes resources to zero
54 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
55 # This function is called for apps fully managed by the test script
56 __ECS_kube_scale_zero() {
57 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
60 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
61 # This function is called for prestarted apps not managed by the test script.
62 __ECS_kube_scale_zero_and_wait() {
63 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice
66 # Delete all kube resouces for the app
67 # This function is called for apps managed by the test script.
68 __ECS_kube_delete_all() {
69 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
73 # This function is called for apps managed by the test script.
74 # args: <log-dir> <file-prexix>
75 __ECS_store_docker_logs() {
76 docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1
78 #######################################################
82 # Host name may be changed if app started by kube
85 ECS_HOST_NAME=$LOCALHOST_NAME
86 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
88 # ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
89 ECS_ADAPTER_TYPE="REST"
92 # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
95 ###########################
97 ###########################
99 # All calls to ECS will be directed to the ECS REST interface from now on
101 # (Function for test scripts)
102 use_ecs_rest_http() {
103 echo -e $BOLD"ECS protocol setting"$EBOLD
104 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
106 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
108 ECS_ADAPTER_TYPE="REST"
109 ECS_ADAPTER=$ECS_PATH
113 # All calls to ECS will be directed to the ECS REST interface from now on
115 # (Function for test scripts)
116 use_ecs_rest_https() {
117 echo -e $BOLD"ECS protocol setting"$EBOLD
118 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
120 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
122 ECS_ADAPTER_TYPE="REST"
123 ECS_ADAPTER=$ECS_PATH
127 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
129 # (Function for test scripts)
130 use_ecs_dmaap_http() {
131 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
132 echo -e $RED" - NOT SUPPORTED - "$ERED
133 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
134 ECS_ADAPTER_TYPE="MR-HTTP"
138 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
140 # (Function for test scripts)
141 use_ecs_dmaap_https() {
142 echo -e $BOLD"RICSIM protocol setting"$EBOLD
143 echo -e $RED" - NOT SUPPORTED - "$ERED
144 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
145 ECS_ADAPTER_TYPE="MR-HTTPS"
150 # args: PROXY|NOPROXY <config-file>
151 # (Function for test scripts)
154 echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
156 if [ $RUNMODE == "KUBE" ]; then
158 # Check if app shall be fully managed by the test script
159 __check_included_image "ECS"
162 # Check if app shall only be used by the testscipt
163 __check_prestarted_image "ECS"
166 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
167 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
168 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
171 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
172 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
173 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
178 if [ $retcode_p -eq 0 ]; then
179 echo -e " Using existing $ECS_APP_NAME deployment and service"
180 echo " Setting ECS replicas=1"
181 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
184 # Check if app shall be fully managed by the test script
185 if [ $retcode_i -eq 0 ]; then
186 echo -e " Creating $ECS_APP_NAME app and expose service"
188 #Check if nonrtric namespace exists, if not create it
189 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
192 export KUBE_NONRTRIC_NAMESPACE
194 export ECS_INTERNAL_PORT
195 export ECS_INTERNAL_SECURE_PORT
196 export ECS_EXTERNAL_PORT
197 export ECS_EXTERNAL_SECURE_PORT
198 export ECS_CONFIG_MOUNT_PATH
199 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
200 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
201 export ECS_CONTAINER_MNT_DIR
203 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
204 #Create a unique path for the pv each time to prevent a previous volume to be reused
205 export ECS_PV_PATH="ecsdata-"$(date +%s)
207 if [ $1 == "PROXY" ]; then
208 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
209 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
210 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
211 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
213 echo " Configured with http proxy"
216 ECS_HTTP_PROXY_CONFIG_PORT=0
217 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
218 echo " Configured without http proxy"
220 export ECS_HTTP_PROXY_CONFIG_PORT
221 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
223 # Create config map for config
224 datafile=$PWD/tmp/$ECS_CONFIG_FILE
226 output_yaml=$PWD/tmp/ecs_cfc.yaml
227 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
230 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
231 output_yaml=$PWD/tmp/ecs_pv.yaml
232 __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
235 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
236 output_yaml=$PWD/tmp/ecs_pvc.yaml
237 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
240 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
241 output_yaml=$PWD/tmp/ecs_svc.yaml
242 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
245 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
246 output_yaml=$PWD/tmp/ecs_app.yaml
247 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
250 echo " Retrieving host and ports for service..."
251 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
252 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
253 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
255 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
257 if [ $ECS_HTTPX == "http" ]; then
258 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
260 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
263 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
265 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
266 ECS_ADAPTER=$ECS_PATH
269 __check_included_image 'ECS'
270 if [ $? -eq 1 ]; then
271 echo -e $RED"The ECS app is not included in this test script"$ERED
272 echo -e $RED"ECS will not be started"$ERED
282 if [ "$(ls -A $DIR)" ]; then
283 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
284 rm -rf db/* &> /dev/null
285 if [ $? -ne 0 ]; then
286 echo -e $RED" Cannot remove database files in: $PWD"$ERED
291 echo " No files in mounted dir or dir does not exists"
296 export ECS_APP_NAME_ALIAS
297 export ECS_HOST_MNT_DIR
298 export ECS_CONTAINER_MNT_DIR
299 export ECS_CONFIG_MOUNT_PATH
300 export ECS_CONFIG_FILE
301 export ECS_INTERNAL_PORT
302 export ECS_EXTERNAL_PORT
303 export ECS_INTERNAL_SECURE_PORT
304 export ECS_EXTERNAL_SECURE_PORT
305 export DOCKER_SIM_NWNAME
306 export ECS_DISPLAY_NAME
308 if [ $1 == "PROXY" ]; then
309 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
310 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
311 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
312 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
314 echo " Configured with http proxy"
317 ECS_HTTP_PROXY_CONFIG_PORT=0
318 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
319 echo " Configured without http proxy"
321 export ECS_HTTP_PROXY_CONFIG_PORT
322 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
324 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
326 envsubst < $2 > $dest_file
328 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
330 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
338 # (Function for test scripts)
340 echo -e $BOLD"Re-starting ECS"$EBOLD
341 docker restart $ECS_APP_NAME &> ./tmp/.dockererr
342 if [ $? -ne 0 ]; then
343 __print_err "Could not restart $ECS_APP_NAME" $@
349 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
354 # Turn on debug level tracing in ECS
356 # (Function for test scripts)
358 echo -e $BOLD"Setting ecs debug logging"$EBOLD
359 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
360 result=$(__do_curl "$curlString")
361 if [ $? -ne 0 ]; then
362 __print_err "Could not set debug mode" $@
370 # Turn on trace level tracing in ECS
372 # (Function for test scripts)
374 echo -e $BOLD"Setting ecs trace logging"$EBOLD
375 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
376 result=$(__do_curl "$curlString")
377 if [ $? -ne 0 ]; then
378 __print_err "Could not set trace mode" $@
386 # Perform curl retries when making direct call to ECS for the specified http response codes
387 # Speace separated list of http response codes
388 # args: [<response-code>]*
390 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
396 # Check the ecs logs for WARNINGs and ERRORs
398 # (Function for test scripts)
400 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
404 # Tests if a variable value in the ECS is equal to a target value and and optional timeout.
405 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
406 # equal to the target or not.
407 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
408 # before setting pass or fail depending on if the variable value becomes equal to the target
410 # (Function for test scripts)
412 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
413 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
415 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
420 ##########################################
421 ######### A1-E Enrichment API ##########
422 ##########################################
423 #Function prefix: ecs_api_a1
425 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs
426 # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
427 # args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
428 # (Function for test scripts)
429 ecs_api_a1_get_job_ids() {
432 if [ -z "$FLAT_A1_EI" ]; then
433 # Valid number of parameters 4,5,6 etc
434 if [ $# -lt 3 ]; then
435 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
439 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
440 # Valid number of parameters 4,5,6 etc
441 if [ $# -lt 3 ]; then
442 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
447 if [ $3 != "NOWNER" ]; then
451 if [ -z "$FLAT_A1_EI" ]; then
452 query="/A1-EI/v1/eitypes/$2/eijobs$search"
454 if [ $2 != "NOTYPE" ]; then
455 if [ -z "$search" ]; then
456 search="?eiTypeId="$2
458 search=$search"&eiTypeId="$2
461 query="/A1-EI/v1/eijobs$search"
463 res="$(__do_curl_to_api ECS GET $query)"
464 status=${res:${#res}-3}
466 if [ $status -ne $1 ]; then
467 __log_test_fail_status_code $1 $status
471 if [ $# -gt 3 ]; then
472 body=${res:0:${#res}-3}
475 for pid in ${@:4} ; do
476 if [ "$targetJson" != "[" ]; then
477 targetJson=$targetJson","
479 if [ $pid != "EMPTY" ]; then
480 targetJson=$targetJson"\"$pid\""
484 targetJson=$targetJson"]"
485 echo " TARGET JSON: $targetJson" >> $HTTPLOG
486 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
488 if [ $res -ne 0 ]; then
498 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}
499 # args: <response-code> <type-id> [<schema-file>]
500 # (Function for test scripts)
501 ecs_api_a1_get_type() {
504 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
505 __print_err "<response-code> <type-id> [<schema-file>]" $@
509 query="/A1-EI/v1/eitypes/$2"
510 res="$(__do_curl_to_api ECS GET $query)"
511 status=${res:${#res}-3}
513 if [ $status -ne $1 ]; then
514 __log_test_fail_status_code $1 $status
518 if [ $# -eq 3 ]; then
519 body=${res:0:${#res}-3}
523 __log_test_fail_general "Schema file "$3", does not exist"
526 if [ -z "$FLAT_A1_EI" ]; then
527 targetJson="{\"eiJobParametersSchema\":$schema}"
531 echo " TARGET JSON: $targetJson" >> $HTTPLOG
532 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
534 if [ $res -ne 0 ]; then
544 # API Test function: GET /A1-EI/v1/eitypes
545 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
546 # (Function for test scripts)
547 ecs_api_a1_get_type_ids() {
550 if [ $# -lt 1 ]; then
551 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
555 query="/A1-EI/v1/eitypes"
556 res="$(__do_curl_to_api ECS GET $query)"
557 status=${res:${#res}-3}
559 if [ $status -ne $1 ]; then
560 __log_test_fail_status_code $1 $status
563 if [ $# -gt 1 ]; then
564 body=${res:0:${#res}-3}
566 if [ $2 != "EMPTY" ]; then
567 for pid in ${@:2} ; do
568 if [ "$targetJson" != "[" ]; then
569 targetJson=$targetJson","
571 targetJson=$targetJson"\"$pid\""
574 targetJson=$targetJson"]"
575 echo " TARGET JSON: $targetJson" >> $HTTPLOG
576 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
578 if [ $res -ne 0 ]; then
588 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status
589 # args: <response-code> <type-id> <job-id> [<status>]
590 # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
591 # (Function for test scripts)
592 ecs_api_a1_get_job_status() {
595 if [ -z "$FLAT_A1_EI" ]; then
596 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
597 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
601 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
603 res="$(__do_curl_to_api ECS GET $query)"
604 status=${res:${#res}-3}
606 if [ $status -ne $1 ]; then
607 __log_test_fail_status_code $1 $status
610 if [ $# -eq 4 ]; then
611 body=${res:0:${#res}-3}
612 targetJson="{\"operationalState\": \"$4\"}"
613 echo " TARGET JSON: $targetJson" >> $HTTPLOG
614 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
616 if [ $res -ne 0 ]; then
622 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
623 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
624 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
628 query="/A1-EI/v1/eijobs/$2/status"
632 res="$(__do_curl_to_api ECS GET $query)"
633 status=${res:${#res}-3}
635 if [ $# -eq 4 ]; then
636 duration=$((SECONDS-start))
637 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
638 if [ $duration -gt $4 ]; then
640 duration=-1 #Last iteration
643 duration=-1 #single test, no wait
646 if [ $status -ne $1 ]; then
647 if [ $duration -eq -1 ]; then
648 __log_test_fail_status_code $1 $status
652 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
653 body=${res:0:${#res}-3}
654 targetJson="{\"eiJobStatus\": \"$3\"}"
655 echo " TARGET JSON: $targetJson" >> $HTTPLOG
656 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
658 if [ $res -ne 0 ]; then
659 if [ $duration -eq -1 ]; then
664 duration=-1 #Goto pass
667 if [ $duration -eq -1 ]; then
668 if [ $# -eq 4 ]; then
683 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
684 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
685 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
686 # (Function for test scripts)
687 ecs_api_a1_get_job() {
690 if [ -z "$FLAT_A1_EI" ]; then
691 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
692 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
695 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
697 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
698 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
699 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
702 query="/A1-EI/v1/eijobs/$2"
704 res="$(__do_curl_to_api ECS GET $query)"
705 status=${res:${#res}-3}
707 if [ $status -ne $1 ]; then
708 __log_test_fail_status_code $1 $status
712 if [ -z "$FLAT_A1_EI" ]; then
713 if [ $# -eq 6 ]; then
714 body=${res:0:${#res}-3}
718 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
720 _log_test_fail_general "Job template file "$6", does not exist"
723 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
724 echo " TARGET JSON: $targetJson" >> $HTTPLOG
725 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
727 if [ $res -ne 0 ]; then
733 if [ $# -eq 7 ]; then
734 body=${res:0:${#res}-3}
738 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
740 _log_test_fail_general "Job template file "$6", does not exist"
743 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
744 echo " TARGET JSON: $targetJson" >> $HTTPLOG
745 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
747 if [ $res -ne 0 ]; then
758 # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
759 # args: <response-code> <type-id> <job-id>
760 # args (flat uri structure): <response-code> <job-id>
761 # (Function for test scripts)
762 ecs_api_a1_delete_job() {
765 if [ -z "$FLAT_A1_EI" ]; then
766 if [ $# -ne 3 ]; then
767 __print_err "<response-code> <type-id> <job-id>" $@
771 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
773 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
774 if [ $# -ne 2 ]; then
775 __print_err "<response-code> <job-id>" $@
778 query="/A1-EI/v1/eijobs/$2"
780 res="$(__do_curl_to_api ECS DELETE $query)"
781 status=${res:${#res}-3}
783 if [ $status -ne $1 ]; then
784 __log_test_fail_status_code $1 $status
792 # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
793 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
794 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
795 # (Function for test scripts)
796 ecs_api_a1_put_job() {
799 if [ -z "$FLAT_A1_EI" ]; then
800 if [ $# -lt 6 ]; then
801 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
806 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
808 _log_test_fail_general "Job template file "$6", does not exist"
812 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
814 echo "$inputJson" > $file
816 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
818 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
819 if [ $# -lt 7 ]; then
820 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
825 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
827 _log_test_fail_general "Job template file "$7", does not exist"
831 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
833 echo "$inputJson" > $file
835 query="/A1-EI/v1/eijobs/$2"
838 res="$(__do_curl_to_api ECS PUT $query $file)"
839 status=${res:${#res}-3}
841 if [ $status -ne $1 ]; then
842 __log_test_fail_status_code $1 $status
851 ##########################################
852 #### Enrichment Data Producer API ####
853 ##########################################
854 # Function prefix: ecs_api_edp
856 # API Test function: GET /ei-producer/v1/eitypes
857 # args: <response-code> [ EMPTY | <type-id>+]
858 # (Function for test scripts)
859 ecs_api_edp_get_type_ids() {
862 if [ $# -lt 1 ]; then
863 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
867 query="/ei-producer/v1/eitypes"
868 res="$(__do_curl_to_api ECS GET $query)"
869 status=${res:${#res}-3}
871 if [ $status -ne $1 ]; then
872 __log_test_fail_status_code $1 $status
876 if [ $# -gt 1 ]; then
877 body=${res:0:${#res}-3}
879 if [ $2 != "EMPTY" ]; then
880 for pid in ${@:2} ; do
881 if [ "$targetJson" != "[" ]; then
882 targetJson=$targetJson","
884 targetJson=$targetJson"\"$pid\""
887 targetJson=$targetJson"]"
888 echo " TARGET JSON: $targetJson" >> $HTTPLOG
889 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
891 if [ $res -ne 0 ]; then
901 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
902 # args: <response-code> <producer-id> [<status> [<timeout>]]
903 # (Function for test scripts)
904 ecs_api_edp_get_producer_status() {
907 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
908 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
912 query="/ei-producer/v1/eiproducers/$2/status"
915 res="$(__do_curl_to_api ECS GET $query)"
916 status=${res:${#res}-3}
918 if [ $# -eq 4 ]; then
919 duration=$((SECONDS-start))
920 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
921 if [ $duration -gt $4 ]; then
923 duration=-1 #Last iteration
926 duration=-1 #single test, no wait
929 if [ $status -ne $1 ]; then
930 if [ $duration -eq -1 ]; then
931 __log_test_fail_status_code $1 $status
935 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
936 body=${res:0:${#res}-3}
937 targetJson="{\"operational_state\": \"$3\"}"
938 echo " TARGET JSON: $targetJson" >> $HTTPLOG
939 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
941 if [ $res -ne 0 ]; then
942 if [ $duration -eq -1 ]; then
947 duration=-1 #Goto pass
950 if [ $duration -eq -1 ]; then
951 if [ $# -eq 4 ]; then
963 # API Test function: GET /ei-producer/v1/eiproducers
964 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
965 # (Function for test scripts)
966 ecs_api_edp_get_producer_ids() {
969 if [ $# -lt 1 ]; then
970 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
974 query="/ei-producer/v1/eiproducers"
975 res="$(__do_curl_to_api ECS GET $query)"
976 status=${res:${#res}-3}
978 if [ $status -ne $1 ]; then
979 __log_test_fail_status_code $1 $status
983 if [ $# -gt 1 ]; then
984 body=${res:0:${#res}-3}
987 for pid in ${@:2} ; do
988 if [ "$targetJson" != "[" ]; then
989 targetJson=$targetJson","
991 if [ $pid != "EMPTY" ]; then
992 targetJson=$targetJson"\"$pid\""
996 targetJson=$targetJson"]"
997 echo " TARGET JSON: $targetJson" >> $HTTPLOG
998 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1000 if [ $res -ne 0 ]; then
1001 __log_test_fail_body
1010 # API Test function: GET /ei-producer/v1/eiproducers
1011 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1012 # (Function for test scripts)
1013 ecs_api_edp_get_producer_ids_2() {
1016 if [ $# -lt 1 ]; then
1017 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1021 query="/ei-producer/v1/eiproducers"
1022 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1023 query=$query"?ei_type_id=$2"
1025 res="$(__do_curl_to_api ECS GET $query)"
1026 status=${res:${#res}-3}
1028 if [ $status -ne $1 ]; then
1029 __log_test_fail_status_code $1 $status
1033 if [ $# -gt 2 ]; then
1034 body=${res:0:${#res}-3}
1037 for pid in ${@:3} ; do
1038 if [ "$targetJson" != "[" ]; then
1039 targetJson=$targetJson","
1041 if [ $pid != "EMPTY" ]; then
1042 targetJson=$targetJson"\"$pid\""
1046 targetJson=$targetJson"]"
1047 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1048 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1050 if [ $res -ne 0 ]; then
1051 __log_test_fail_body
1060 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1061 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1062 # (Function for test scripts)
1063 ecs_api_edp_get_type() {
1067 if [ $# -eq 2 ]; then
1070 if [ $# -gt 3 ]; then
1073 if [ $paramError -ne 0 ]; then
1074 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1078 query="/ei-producer/v1/eitypes/$2"
1079 res="$(__do_curl_to_api ECS GET $query)"
1080 status=${res:${#res}-3}
1082 if [ $status -ne $1 ]; then
1083 __log_test_fail_status_code $1 $status
1086 if [ $# -gt 3 ]; then
1087 body=${res:0:${#res}-3}
1092 __log_test_fail_general "Job template file "$3", does not exist"
1097 if [ $4 != "EMPTY" ]; then
1098 for pid in ${@:4} ; do
1099 if [ "$targetJson" != "" ]; then
1100 targetJson=$targetJson","
1102 targetJson=$targetJson"\"$pid\""
1105 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1107 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1108 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1110 if [ $res -ne 0 ]; then
1111 __log_test_fail_body
1119 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1120 # args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1121 # (Function for test scripts)
1122 ecs_api_edp_get_type_2() {
1126 if [ $# -eq 2 ]; then
1129 if [ $# -eq 3 ]; then
1132 if [ $paramError -ne 0 ]; then
1133 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1137 query="/ei-producer/v1/eitypes/$2"
1138 res="$(__do_curl_to_api ECS GET $query)"
1139 status=${res:${#res}-3}
1141 if [ $status -ne $1 ]; then
1142 __log_test_fail_status_code $1 $status
1145 if [ $# -eq 3 ]; then
1146 body=${res:0:${#res}-3}
1151 __log_test_fail_general "Job template file "$3", does not exist"
1155 targetJson="{\"ei_job_data_schema\":$schema}"
1157 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1158 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1160 if [ $res -ne 0 ]; then
1161 __log_test_fail_body
1169 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1170 # args: (v1_2) <response-code> <type-id> <job-schema-file>
1171 # (Function for test scripts)
1172 ecs_api_edp_put_type_2() {
1175 if [ $# -ne 3 ]; then
1176 __print_err "<response-code> <type-id> <job-schema-file>" $@
1180 if [ ! -f $3 ]; then
1181 __log_test_fail_general "Job schema file "$3", does not exist"
1185 input_json="{\"ei_job_data_schema\":$schema}"
1186 file="./tmp/put_type.json"
1187 echo $input_json > $file
1189 query="/ei-producer/v1/eitypes/$2"
1190 res="$(__do_curl_to_api ECS PUT $query $file)"
1191 status=${res:${#res}-3}
1193 if [ $status -ne $1 ]; then
1194 __log_test_fail_status_code $1 $status
1202 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1203 # args: (v1_2) <response-code> <type-id>
1204 # (Function for test scripts)
1205 ecs_api_edp_delete_type_2() {
1208 if [ $# -ne 2 ]; then
1209 __print_err "<response-code> <type-id>" $@
1213 query="/ei-producer/v1/eitypes/$2"
1214 res="$(__do_curl_to_api ECS DELETE $query)"
1215 status=${res:${#res}-3}
1217 if [ $status -ne $1 ]; then
1218 __log_test_fail_status_code $1 $status
1226 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1227 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1228 # (Function for test scripts)
1229 ecs_api_edp_get_producer() {
1232 #Possible arg count: 2, 5 6, 8, 10 etc
1234 if [ $# -eq 2 ]; then
1237 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1240 variablecount=$(($#-4))
1241 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1245 if [ $paramError -ne 0 ]; then
1246 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1250 query="/ei-producer/v1/eiproducers/$2"
1251 res="$(__do_curl_to_api ECS GET $query)"
1252 status=${res:${#res}-3}
1254 if [ $status -ne $1 ]; then
1255 __log_test_fail_status_code $1 $status
1259 if [ $# -gt 2 ]; then
1260 body=${res:0:${#res}-3}
1262 if [ $# -gt 5 ]; then
1264 for ((i=0; i<$(($#-5)); i=i+2)); do
1265 if [ "$targetJson" != "[" ]; then
1266 targetJson=$targetJson","
1268 if [ -f ${arr[$i+1]} ]; then
1269 schema=$(cat ${arr[$i+1]})
1271 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1275 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1278 targetJson=$targetJson"]"
1279 if [ $# -gt 4 ]; then
1280 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1282 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1283 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1285 if [ $res -ne 0 ]; then
1286 __log_test_fail_body
1295 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1296 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1297 # (Function for test scripts)
1298 ecs_api_edp_get_producer_2() {
1301 #Possible arg count: 2, 5, 6, 7, 8 etc
1303 if [ $# -eq 2 ]; then
1306 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1309 if [ $# -ge 5 ]; then
1313 if [ $paramError -ne 0 ]; then
1314 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1318 query="/ei-producer/v1/eiproducers/$2"
1319 res="$(__do_curl_to_api ECS GET $query)"
1320 status=${res:${#res}-3}
1322 if [ $status -ne $1 ]; then
1323 __log_test_fail_status_code $1 $status
1327 if [ $# -gt 2 ]; then
1328 body=${res:0:${#res}-3}
1330 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1332 for ((i=0; i<$(($#-4)); i=i+1)); do
1333 if [ "$targetJson" != "[" ]; then
1334 targetJson=$targetJson","
1336 targetJson=$targetJson"\"${arr[$i]}\""
1339 targetJson=$targetJson"]"
1340 if [ $# -gt 4 ]; then
1341 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1343 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1344 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1346 if [ $res -ne 0 ]; then
1347 __log_test_fail_body
1356 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1357 # args: <response-code> <producer-id>
1358 # (Function for test scripts)
1359 ecs_api_edp_delete_producer() {
1362 if [ $# -lt 2 ]; then
1363 __print_err "<response-code> <producer-id>" $@
1367 query="/ei-producer/v1/eiproducers/$2"
1368 res="$(__do_curl_to_api ECS DELETE $query)"
1369 status=${res:${#res}-3}
1371 if [ $status -ne $1 ]; then
1372 __log_test_fail_status_code $1 $status
1380 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1381 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1382 # (Function for test scripts)
1383 ecs_api_edp_put_producer() {
1386 #Valid number of parametrer 5,6,8,10,
1388 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1390 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1393 if [ $paramError -ne 0 ]; then
1394 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1399 if [ $# -gt 5 ]; then
1401 for ((i=0; i<$(($#-5)); i=i+2)); do
1402 if [ "$inputJson" != "[" ]; then
1403 inputJson=$inputJson","
1405 if [ -f ${arr[$i+1]} ]; then
1406 schema=$(cat ${arr[$i+1]})
1408 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1411 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1414 inputJson="\"supported_ei_types\":"$inputJson"]"
1416 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1418 inputJson="{"$inputJson"}"
1420 file="./tmp/.p.json"
1421 echo "$inputJson" > $file
1422 query="/ei-producer/v1/eiproducers/$2"
1423 res="$(__do_curl_to_api ECS PUT $query $file)"
1424 status=${res:${#res}-3}
1426 if [ $status -ne $1 ]; then
1427 __log_test_fail_status_code $1 $status
1435 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1436 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1437 # (Function for test scripts)
1438 ecs_api_edp_put_producer_2() {
1441 #Valid number of parametrer 5,6,8,10,
1443 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1445 elif [ $# -ge 5 ]; then
1448 if [ $paramError -ne 0 ]; then
1449 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1454 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1456 for ((i=0; i<$(($#-4)); i=i+1)); do
1457 if [ "$inputJson" != "[" ]; then
1458 inputJson=$inputJson","
1460 inputJson=$inputJson"\""${arr[$i]}"\""
1463 inputJson="\"supported_ei_types\":"$inputJson"]"
1465 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1467 inputJson="{"$inputJson"}"
1469 file="./tmp/.p.json"
1470 echo "$inputJson" > $file
1471 query="/ei-producer/v1/eiproducers/$2"
1472 res="$(__do_curl_to_api ECS PUT $query $file)"
1473 status=${res:${#res}-3}
1475 if [ $status -ne $1 ]; then
1476 __log_test_fail_status_code $1 $status
1484 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1485 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1486 # (Function for test scripts)
1487 ecs_api_edp_get_producer_jobs() {
1490 #Valid number of parameter 2,3,7,11
1492 if [ $# -eq 2 ]; then
1495 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1498 variablecount=$(($#-2))
1499 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1502 if [ $paramError -eq 1 ]; then
1503 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1507 query="/ei-producer/v1/eiproducers/$2/eijobs"
1508 res="$(__do_curl_to_api ECS GET $query)"
1509 status=${res:${#res}-3}
1510 if [ $status -ne $1 ]; then
1511 __log_test_fail_status_code $1 $status
1514 if [ $# -gt 2 ]; then
1515 body=${res:0:${#res}-3}
1517 if [ $# -gt 3 ]; then
1519 for ((i=0; i<$(($#-3)); i=i+5)); do
1520 if [ "$targetJson" != "[" ]; then
1521 targetJson=$targetJson","
1523 if [ -f ${arr[$i+4]} ]; then
1524 jobfile=$(cat ${arr[$i+4]})
1525 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1527 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1530 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}"
1533 targetJson=$targetJson"]"
1535 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1536 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1538 if [ $res -ne 0 ]; then
1539 __log_test_fail_body
1548 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1549 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1550 # (Function for test scripts)
1551 ecs_api_edp_get_producer_jobs_2() {
1554 #Valid number of parameter 2,3,7,11
1556 if [ $# -eq 2 ]; then
1559 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1562 variablecount=$(($#-2))
1563 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1566 if [ $paramError -eq 1 ]; then
1567 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1571 query="/ei-producer/v1/eiproducers/$2/eijobs"
1572 res="$(__do_curl_to_api ECS GET $query)"
1573 status=${res:${#res}-3}
1574 if [ $status -ne $1 ]; then
1575 __log_test_fail_status_code $1 $status
1578 if [ $# -gt 2 ]; then
1579 body=${res:0:${#res}-3}
1581 if [ $# -gt 3 ]; then
1583 for ((i=0; i<$(($#-3)); i=i+5)); do
1584 if [ "$targetJson" != "[" ]; then
1585 targetJson=$targetJson","
1587 if [ -f ${arr[$i+4]} ]; then
1588 jobfile=$(cat ${arr[$i+4]})
1589 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1591 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1594 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, \"last_updated\":\"????\"}"
1597 targetJson=$targetJson"]"
1599 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1600 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1602 if [ $res -ne 0 ]; then
1603 __log_test_fail_body
1612 ##########################################
1613 #### Service status ####
1614 ##########################################
1615 # Function prefix: ecs_api_service
1617 # API Test function: GET /status
1618 # args: <response-code>
1619 # (Function for test scripts)
1620 ecs_api_service_status() {
1623 if [ $# -lt 1 ]; then
1624 __print_err "<response-code> [<producer-id>]*|NOID" $@
1627 res="$(__do_curl_to_api ECS GET /status)"
1628 status=${res:${#res}-3}
1629 if [ $status -ne $1 ]; then
1630 __log_test_fail_status_code $1 $status
1638 ##########################################
1639 #### Reset jobs ####
1640 ##########################################
1641 # Function prefix: ecs_api_admin
1643 # Admin to remove all jobs
1644 # args: <response-code> [ <type> ]
1645 # (Function for test scripts)
1647 ecs_api_admin_reset() {
1650 if [ -z "$FLAT_A1_EI" ]; then
1651 query="/A1-EI/v1/eitypes/$2/eijobs"
1653 query="/A1-EI/v1/eijobs"
1655 res="$(__do_curl_to_api ECS GET $query)"
1656 status=${res:${#res}-3}
1658 if [ $status -ne 200 ]; then
1659 __log_test_fail_status_code $1 $status
1663 #Remove brackets and response code
1664 body=${res:1:${#res}-4}
1665 list=$(echo ${body//,/ })
1666 list=$(echo ${list//[/})
1667 list=$(echo ${list//]/})
1668 list=$(echo ${list//\"/})
1670 for job in $list; do
1671 if [ -z "$FLAT_A1_EI" ]; then
1672 echo "Not supported for non-flat EI api"
1674 query="/A1-EI/v1/eijobs/$job"
1675 res="$(__do_curl_to_api ECS DELETE $query)"
1676 status=${res:${#res}-3}
1677 if [ $status -ne 204 ]; then
1678 __log_test_fail_status_code $1 $status
1681 echo " Deleted job: "$job