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 # If a custom image repo is used then also the source image from the local repo is listed
49 # arg: <docker-images-format-string> <file-to-append>
51 echo -e "$ECS_DISPLAY_NAME\t$(docker images --format $1 $ECS_IMAGE)" >> $2
52 if [ ! -z "$ECS_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $ECS_IMAGE_SOURCE)" >> $2
57 # Scale kubernetes resources to zero
58 # All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59 # This function is called for apps fully managed by the test script
60 __ECS_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
64 # Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65 # This function is called for prestarted apps not managed by the test script.
66 __ECS_kube_scale_zero_and_wait() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice
70 # Delete all kube resouces for the app
71 # This function is called for apps managed by the test script.
72 __ECS_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
77 # This function is called for apps managed by the test script.
78 # args: <log-dir> <file-prexix>
79 __ECS_store_docker_logs() {
80 docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1
82 #######################################################
86 # Host name may be changed if app started by kube
89 ECS_HOST_NAME=$LOCALHOST_NAME
90 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
92 # ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
93 ECS_ADAPTER_TYPE="REST"
96 # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
99 #Save first worker node the pod is started on
102 ###########################
104 ###########################
106 # All calls to ECS will be directed to the ECS REST interface from now on
108 # (Function for test scripts)
109 use_ecs_rest_http() {
110 echo -e $BOLD"ECS protocol setting"$EBOLD
111 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
113 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
115 ECS_ADAPTER_TYPE="REST"
116 ECS_ADAPTER=$ECS_PATH
120 # All calls to ECS will be directed to the ECS REST interface from now on
122 # (Function for test scripts)
123 use_ecs_rest_https() {
124 echo -e $BOLD"ECS protocol setting"$EBOLD
125 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
127 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
129 ECS_ADAPTER_TYPE="REST"
130 ECS_ADAPTER=$ECS_PATH
134 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
136 # (Function for test scripts)
137 use_ecs_dmaap_http() {
138 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
139 echo -e $RED" - NOT SUPPORTED - "$ERED
140 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
141 ECS_ADAPTER_TYPE="MR-HTTP"
145 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
147 # (Function for test scripts)
148 use_ecs_dmaap_https() {
149 echo -e $BOLD"RICSIM protocol setting"$EBOLD
150 echo -e $RED" - NOT SUPPORTED - "$ERED
151 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
152 ECS_ADAPTER_TYPE="MR-HTTPS"
157 # args: PROXY|NOPROXY <config-file>
158 # (Function for test scripts)
161 echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
163 if [ $RUNMODE == "KUBE" ]; then
165 # Check if app shall be fully managed by the test script
166 __check_included_image "ECS"
169 # Check if app shall only be used by the testscipt
170 __check_prestarted_image "ECS"
173 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
174 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
175 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
178 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
179 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
180 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
185 if [ $retcode_p -eq 0 ]; then
186 echo -e " Using existing $ECS_APP_NAME deployment and service"
187 echo " Setting ECS replicas=1"
188 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
191 # Check if app shall be fully managed by the test script
192 if [ $retcode_i -eq 0 ]; then
193 echo -e " Creating $ECS_APP_NAME app and expose service"
195 #Check if nonrtric namespace exists, if not create it
196 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
199 export KUBE_NONRTRIC_NAMESPACE
201 export ECS_INTERNAL_PORT
202 export ECS_INTERNAL_SECURE_PORT
203 export ECS_EXTERNAL_PORT
204 export ECS_EXTERNAL_SECURE_PORT
205 export ECS_CONFIG_MOUNT_PATH
206 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
207 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
208 export ECS_CONTAINER_MNT_DIR
210 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
211 export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc"
212 #Create a unique path for the pv each time to prevent a previous volume to be reused
213 export ECS_PV_PATH="ecsdata-"$(date +%s)
215 if [ $1 == "PROXY" ]; then
216 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
217 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
218 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
219 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
221 echo " Configured with http proxy"
224 ECS_HTTP_PROXY_CONFIG_PORT=0
225 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
226 echo " Configured without http proxy"
228 export ECS_HTTP_PROXY_CONFIG_PORT
229 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
231 # Create config map for config
232 datafile=$PWD/tmp/$ECS_CONFIG_FILE
234 output_yaml=$PWD/tmp/ecs_cfc.yaml
235 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
238 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
239 output_yaml=$PWD/tmp/ecs_pv.yaml
240 __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
243 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
244 output_yaml=$PWD/tmp/ecs_pvc.yaml
245 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
248 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
249 output_yaml=$PWD/tmp/ecs_svc.yaml
250 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
253 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
254 output_yaml=$PWD/tmp/ecs_app.yaml
255 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
258 # Tie the ECS to a worker node so that ECS will always be scheduled to the same worker node if the ECS pod is restarted
259 # A PVC of type hostPath is mounted to ECS, for persistent storage, so the ECS must always be on the node which mounted the volume
261 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
262 __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
263 if [ -z "$__ECS_WORKER_NODE" ]; then
264 echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW
267 echo " Retrieving host and ports for service..."
268 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
269 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
270 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
272 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
274 if [ $ECS_HTTPX == "http" ]; then
275 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
277 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
280 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
282 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
283 ECS_ADAPTER=$ECS_PATH
286 __check_included_image 'ECS'
287 if [ $? -eq 1 ]; then
288 echo -e $RED"The ECS app is not included in this test script"$ERED
289 echo -e $RED"ECS will not be started"$ERED
299 if [ "$(ls -A $DIR)" ]; then
300 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
301 rm -rf db/* &> /dev/null
302 if [ $? -ne 0 ]; then
303 echo -e $RED" Cannot remove database files in: $PWD"$ERED
308 echo " No files in mounted dir or dir does not exists"
313 export ECS_APP_NAME_ALIAS
314 export ECS_HOST_MNT_DIR
315 export ECS_CONTAINER_MNT_DIR
316 export ECS_CONFIG_MOUNT_PATH
317 export ECS_CONFIG_FILE
318 export ECS_INTERNAL_PORT
319 export ECS_EXTERNAL_PORT
320 export ECS_INTERNAL_SECURE_PORT
321 export ECS_EXTERNAL_SECURE_PORT
322 export DOCKER_SIM_NWNAME
323 export ECS_DISPLAY_NAME
325 if [ $1 == "PROXY" ]; then
326 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
327 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
328 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
329 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
331 echo " Configured with http proxy"
334 ECS_HTTP_PROXY_CONFIG_PORT=0
335 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
336 echo " Configured without http proxy"
338 export ECS_HTTP_PROXY_CONFIG_PORT
339 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
341 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
343 envsubst < $2 > $dest_file
345 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
347 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
356 # (Function for test scripts)
358 echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD
360 if [ $RUNMODE == "KUBE" ]; then
361 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
362 echo " Deleting the replica set - a new will be started when the app is started"
363 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS")
364 if [ $? -ne 0 ]; then
365 echo -e $RED" Could not delete replica set "$RED
370 docker stop $ECS_APP_NAME &> ./tmp/.dockererr
371 if [ $? -ne 0 ]; then
372 __print_err "Could not stop $ECS_APP_NAME" $@
378 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
383 # Start a previously stopped ecs
385 # (Function for test scripts)
386 start_stopped_ecs() {
387 echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD
389 if [ $RUNMODE == "KUBE" ]; then
391 # Tie the PMS to the same worker node it was initially started on
392 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
393 if [ -z "$__ECS_WORKER_NODE" ]; then
394 echo -e $RED" No initial worker node found for pod "$RED
398 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ECS_WORKER_NODE to deployment for $ECS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
399 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
400 tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}')
401 if [ $? -ne 0 ]; then
402 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW
404 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
408 docker start $ECS_APP_NAME &> ./tmp/.dockererr
409 if [ $? -ne 0 ]; then
410 __print_err "Could not start (the stopped) $ECS_APP_NAME" $@
416 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
417 if [ $? -ne 0 ]; then
424 # Turn on debug level tracing in ECS
426 # (Function for test scripts)
428 echo -e $BOLD"Setting ecs debug logging"$EBOLD
429 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
430 result=$(__do_curl "$curlString")
431 if [ $? -ne 0 ]; then
432 __print_err "Could not set debug mode" $@
440 # Turn on trace level tracing in ECS
442 # (Function for test scripts)
444 echo -e $BOLD"Setting ecs trace logging"$EBOLD
445 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
446 result=$(__do_curl "$curlString")
447 if [ $? -ne 0 ]; then
448 __print_err "Could not set trace mode" $@
456 # Perform curl retries when making direct call to ECS for the specified http response codes
457 # Speace separated list of http response codes
458 # args: [<response-code>]*
460 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
466 # Check the ecs logs for WARNINGs and ERRORs
468 # (Function for test scripts)
470 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
474 # Tests if a variable value in the ECS is equal to a target value and and optional timeout.
475 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
476 # equal to the target or not.
477 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
478 # before setting pass or fail depending on if the variable value becomes equal to the target
480 # (Function for test scripts)
482 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
483 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
485 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
490 ##########################################
491 ######### A1-E Enrichment API ##########
492 ##########################################
493 #Function prefix: ecs_api_a1
495 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs
496 # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
497 # args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
498 # (Function for test scripts)
499 ecs_api_a1_get_job_ids() {
502 if [ -z "$FLAT_A1_EI" ]; then
503 # Valid number of parameters 4,5,6 etc
504 if [ $# -lt 3 ]; then
505 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
509 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
510 # Valid number of parameters 4,5,6 etc
511 if [ $# -lt 3 ]; then
512 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
517 if [ $3 != "NOWNER" ]; then
521 if [ -z "$FLAT_A1_EI" ]; then
522 query="/A1-EI/v1/eitypes/$2/eijobs$search"
524 if [ $2 != "NOTYPE" ]; then
525 if [ -z "$search" ]; then
526 search="?eiTypeId="$2
528 search=$search"&eiTypeId="$2
531 query="/A1-EI/v1/eijobs$search"
533 res="$(__do_curl_to_api ECS GET $query)"
534 status=${res:${#res}-3}
536 if [ $status -ne $1 ]; then
537 __log_test_fail_status_code $1 $status
541 if [ $# -gt 3 ]; then
542 body=${res:0:${#res}-3}
545 for pid in ${@:4} ; do
546 if [ "$targetJson" != "[" ]; then
547 targetJson=$targetJson","
549 if [ $pid != "EMPTY" ]; then
550 targetJson=$targetJson"\"$pid\""
554 targetJson=$targetJson"]"
555 echo " TARGET JSON: $targetJson" >> $HTTPLOG
556 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
558 if [ $res -ne 0 ]; then
568 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}
569 # args: <response-code> <type-id> [<schema-file>]
570 # (Function for test scripts)
571 ecs_api_a1_get_type() {
574 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
575 __print_err "<response-code> <type-id> [<schema-file>]" $@
579 query="/A1-EI/v1/eitypes/$2"
580 res="$(__do_curl_to_api ECS GET $query)"
581 status=${res:${#res}-3}
583 if [ $status -ne $1 ]; then
584 __log_test_fail_status_code $1 $status
588 if [ $# -eq 3 ]; then
589 body=${res:0:${#res}-3}
593 __log_test_fail_general "Schema file "$3", does not exist"
596 if [ -z "$FLAT_A1_EI" ]; then
597 targetJson="{\"eiJobParametersSchema\":$schema}"
601 echo " TARGET JSON: $targetJson" >> $HTTPLOG
602 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
604 if [ $res -ne 0 ]; then
614 # API Test function: GET /A1-EI/v1/eitypes
615 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
616 # (Function for test scripts)
617 ecs_api_a1_get_type_ids() {
620 if [ $# -lt 1 ]; then
621 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
625 query="/A1-EI/v1/eitypes"
626 res="$(__do_curl_to_api ECS GET $query)"
627 status=${res:${#res}-3}
629 if [ $status -ne $1 ]; then
630 __log_test_fail_status_code $1 $status
633 if [ $# -gt 1 ]; then
634 body=${res:0:${#res}-3}
636 if [ $2 != "EMPTY" ]; then
637 for pid in ${@:2} ; do
638 if [ "$targetJson" != "[" ]; then
639 targetJson=$targetJson","
641 targetJson=$targetJson"\"$pid\""
644 targetJson=$targetJson"]"
645 echo " TARGET JSON: $targetJson" >> $HTTPLOG
646 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
648 if [ $res -ne 0 ]; then
658 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status
659 # args: <response-code> <type-id> <job-id> [<status>]
660 # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
661 # (Function for test scripts)
662 ecs_api_a1_get_job_status() {
665 if [ -z "$FLAT_A1_EI" ]; then
666 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
667 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
671 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
673 res="$(__do_curl_to_api ECS GET $query)"
674 status=${res:${#res}-3}
676 if [ $status -ne $1 ]; then
677 __log_test_fail_status_code $1 $status
680 if [ $# -eq 4 ]; then
681 body=${res:0:${#res}-3}
682 targetJson="{\"operationalState\": \"$4\"}"
683 echo " TARGET JSON: $targetJson" >> $HTTPLOG
684 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
686 if [ $res -ne 0 ]; then
692 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
693 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
694 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
698 query="/A1-EI/v1/eijobs/$2/status"
702 res="$(__do_curl_to_api ECS GET $query)"
703 status=${res:${#res}-3}
705 if [ $# -eq 4 ]; then
706 duration=$((SECONDS-start))
707 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
708 if [ $duration -gt $4 ]; then
710 duration=-1 #Last iteration
713 duration=-1 #single test, no wait
716 if [ $status -ne $1 ]; then
717 if [ $duration -eq -1 ]; then
718 __log_test_fail_status_code $1 $status
722 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
723 body=${res:0:${#res}-3}
724 targetJson="{\"eiJobStatus\": \"$3\"}"
725 echo " TARGET JSON: $targetJson" >> $HTTPLOG
726 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
728 if [ $res -ne 0 ]; then
729 if [ $duration -eq -1 ]; then
734 duration=-1 #Goto pass
737 if [ $duration -eq -1 ]; then
738 if [ $# -eq 4 ]; then
753 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
754 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
755 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
756 # (Function for test scripts)
757 ecs_api_a1_get_job() {
760 if [ -z "$FLAT_A1_EI" ]; then
761 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
762 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
765 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
767 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
768 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
769 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
772 query="/A1-EI/v1/eijobs/$2"
774 res="$(__do_curl_to_api ECS GET $query)"
775 status=${res:${#res}-3}
777 if [ $status -ne $1 ]; then
778 __log_test_fail_status_code $1 $status
782 if [ -z "$FLAT_A1_EI" ]; then
783 if [ $# -eq 6 ]; then
784 body=${res:0:${#res}-3}
788 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
790 _log_test_fail_general "Job template file "$6", does not exist"
793 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
794 echo " TARGET JSON: $targetJson" >> $HTTPLOG
795 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
797 if [ $res -ne 0 ]; then
803 if [ $# -eq 7 ]; then
804 body=${res:0:${#res}-3}
808 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
810 _log_test_fail_general "Job template file "$6", does not exist"
813 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
814 echo " TARGET JSON: $targetJson" >> $HTTPLOG
815 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
817 if [ $res -ne 0 ]; then
828 # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
829 # args: <response-code> <type-id> <job-id>
830 # args (flat uri structure): <response-code> <job-id>
831 # (Function for test scripts)
832 ecs_api_a1_delete_job() {
835 if [ -z "$FLAT_A1_EI" ]; then
836 if [ $# -ne 3 ]; then
837 __print_err "<response-code> <type-id> <job-id>" $@
841 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
843 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
844 if [ $# -ne 2 ]; then
845 __print_err "<response-code> <job-id>" $@
848 query="/A1-EI/v1/eijobs/$2"
850 res="$(__do_curl_to_api ECS DELETE $query)"
851 status=${res:${#res}-3}
853 if [ $status -ne $1 ]; then
854 __log_test_fail_status_code $1 $status
862 # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
863 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
864 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
865 # (Function for test scripts)
866 ecs_api_a1_put_job() {
869 if [ -z "$FLAT_A1_EI" ]; then
870 if [ $# -lt 6 ]; then
871 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
876 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
878 _log_test_fail_general "Job template file "$6", does not exist"
882 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
884 echo "$inputJson" > $file
886 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
888 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
889 if [ $# -lt 7 ]; then
890 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
895 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
897 _log_test_fail_general "Job template file "$7", does not exist"
901 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
903 echo "$inputJson" > $file
905 query="/A1-EI/v1/eijobs/$2"
908 res="$(__do_curl_to_api ECS PUT $query $file)"
909 status=${res:${#res}-3}
911 if [ $status -ne $1 ]; then
912 __log_test_fail_status_code $1 $status
921 ##########################################
922 #### Enrichment Data Producer API ####
923 ##########################################
924 # Function prefix: ecs_api_edp
926 # API Test function: GET /ei-producer/v1/eitypes
927 # args: <response-code> [ EMPTY | <type-id>+]
928 # (Function for test scripts)
929 ecs_api_edp_get_type_ids() {
932 if [ $# -lt 1 ]; then
933 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
937 query="/ei-producer/v1/eitypes"
938 res="$(__do_curl_to_api ECS GET $query)"
939 status=${res:${#res}-3}
941 if [ $status -ne $1 ]; then
942 __log_test_fail_status_code $1 $status
946 if [ $# -gt 1 ]; then
947 body=${res:0:${#res}-3}
949 if [ $2 != "EMPTY" ]; then
950 for pid in ${@:2} ; do
951 if [ "$targetJson" != "[" ]; then
952 targetJson=$targetJson","
954 targetJson=$targetJson"\"$pid\""
957 targetJson=$targetJson"]"
958 echo " TARGET JSON: $targetJson" >> $HTTPLOG
959 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
961 if [ $res -ne 0 ]; then
971 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
972 # args: <response-code> <producer-id> [<status> [<timeout>]]
973 # (Function for test scripts)
974 ecs_api_edp_get_producer_status() {
977 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
978 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
982 query="/ei-producer/v1/eiproducers/$2/status"
985 res="$(__do_curl_to_api ECS GET $query)"
986 status=${res:${#res}-3}
988 if [ $# -eq 4 ]; then
989 duration=$((SECONDS-start))
990 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
991 if [ $duration -gt $4 ]; then
993 duration=-1 #Last iteration
996 duration=-1 #single test, no wait
999 if [ $status -ne $1 ]; then
1000 if [ $duration -eq -1 ]; then
1001 __log_test_fail_status_code $1 $status
1005 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1006 body=${res:0:${#res}-3}
1007 targetJson="{\"operational_state\": \"$3\"}"
1008 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1009 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1011 if [ $res -ne 0 ]; then
1012 if [ $duration -eq -1 ]; then
1013 __log_test_fail_body
1017 duration=-1 #Goto pass
1020 if [ $duration -eq -1 ]; then
1021 if [ $# -eq 4 ]; then
1033 # API Test function: GET /ei-producer/v1/eiproducers
1034 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
1035 # (Function for test scripts)
1036 ecs_api_edp_get_producer_ids() {
1039 if [ $# -lt 1 ]; then
1040 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1044 query="/ei-producer/v1/eiproducers"
1045 res="$(__do_curl_to_api ECS GET $query)"
1046 status=${res:${#res}-3}
1048 if [ $status -ne $1 ]; then
1049 __log_test_fail_status_code $1 $status
1053 if [ $# -gt 1 ]; then
1054 body=${res:0:${#res}-3}
1057 for pid in ${@:2} ; do
1058 if [ "$targetJson" != "[" ]; then
1059 targetJson=$targetJson","
1061 if [ $pid != "EMPTY" ]; then
1062 targetJson=$targetJson"\"$pid\""
1066 targetJson=$targetJson"]"
1067 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1068 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1070 if [ $res -ne 0 ]; then
1071 __log_test_fail_body
1080 # API Test function: GET /ei-producer/v1/eiproducers
1081 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1082 # (Function for test scripts)
1083 ecs_api_edp_get_producer_ids_2() {
1086 if [ $# -lt 1 ]; then
1087 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1091 query="/ei-producer/v1/eiproducers"
1092 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1093 query=$query"?ei_type_id=$2"
1095 res="$(__do_curl_to_api ECS GET $query)"
1096 status=${res:${#res}-3}
1098 if [ $status -ne $1 ]; then
1099 __log_test_fail_status_code $1 $status
1103 if [ $# -gt 2 ]; then
1104 body=${res:0:${#res}-3}
1107 for pid in ${@:3} ; do
1108 if [ "$targetJson" != "[" ]; then
1109 targetJson=$targetJson","
1111 if [ $pid != "EMPTY" ]; then
1112 targetJson=$targetJson"\"$pid\""
1116 targetJson=$targetJson"]"
1117 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1118 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1120 if [ $res -ne 0 ]; then
1121 __log_test_fail_body
1130 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1131 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1132 # (Function for test scripts)
1133 ecs_api_edp_get_type() {
1137 if [ $# -eq 2 ]; then
1140 if [ $# -gt 3 ]; then
1143 if [ $paramError -ne 0 ]; then
1144 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1148 query="/ei-producer/v1/eitypes/$2"
1149 res="$(__do_curl_to_api ECS GET $query)"
1150 status=${res:${#res}-3}
1152 if [ $status -ne $1 ]; then
1153 __log_test_fail_status_code $1 $status
1156 if [ $# -gt 3 ]; then
1157 body=${res:0:${#res}-3}
1162 __log_test_fail_general "Job template file "$3", does not exist"
1167 if [ $4 != "EMPTY" ]; then
1168 for pid in ${@:4} ; do
1169 if [ "$targetJson" != "" ]; then
1170 targetJson=$targetJson","
1172 targetJson=$targetJson"\"$pid\""
1175 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1177 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1178 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1180 if [ $res -ne 0 ]; then
1181 __log_test_fail_body
1189 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1190 # args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1191 # (Function for test scripts)
1192 ecs_api_edp_get_type_2() {
1196 if [ $# -eq 2 ]; then
1199 if [ $# -eq 3 ]; then
1202 if [ $paramError -ne 0 ]; then
1203 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1207 query="/ei-producer/v1/eitypes/$2"
1208 res="$(__do_curl_to_api ECS GET $query)"
1209 status=${res:${#res}-3}
1211 if [ $status -ne $1 ]; then
1212 __log_test_fail_status_code $1 $status
1215 if [ $# -eq 3 ]; then
1216 body=${res:0:${#res}-3}
1221 __log_test_fail_general "Job template file "$3", does not exist"
1225 targetJson="{\"ei_job_data_schema\":$schema}"
1227 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1228 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1230 if [ $res -ne 0 ]; then
1231 __log_test_fail_body
1239 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1240 # args: (v1_2) <response-code> <type-id> <job-schema-file>
1241 # (Function for test scripts)
1242 ecs_api_edp_put_type_2() {
1245 if [ $# -ne 3 ]; then
1246 __print_err "<response-code> <type-id> <job-schema-file>" $@
1250 if [ ! -f $3 ]; then
1251 __log_test_fail_general "Job schema file "$3", does not exist"
1255 input_json="{\"ei_job_data_schema\":$schema}"
1256 file="./tmp/put_type.json"
1257 echo $input_json > $file
1259 query="/ei-producer/v1/eitypes/$2"
1260 res="$(__do_curl_to_api ECS PUT $query $file)"
1261 status=${res:${#res}-3}
1263 if [ $status -ne $1 ]; then
1264 __log_test_fail_status_code $1 $status
1272 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1273 # args: (v1_2) <response-code> <type-id>
1274 # (Function for test scripts)
1275 ecs_api_edp_delete_type_2() {
1278 if [ $# -ne 2 ]; then
1279 __print_err "<response-code> <type-id>" $@
1283 query="/ei-producer/v1/eitypes/$2"
1284 res="$(__do_curl_to_api ECS DELETE $query)"
1285 status=${res:${#res}-3}
1287 if [ $status -ne $1 ]; then
1288 __log_test_fail_status_code $1 $status
1296 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1297 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1298 # (Function for test scripts)
1299 ecs_api_edp_get_producer() {
1302 #Possible arg count: 2, 5 6, 8, 10 etc
1304 if [ $# -eq 2 ]; then
1307 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1310 variablecount=$(($#-4))
1311 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1315 if [ $paramError -ne 0 ]; then
1316 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1320 query="/ei-producer/v1/eiproducers/$2"
1321 res="$(__do_curl_to_api ECS GET $query)"
1322 status=${res:${#res}-3}
1324 if [ $status -ne $1 ]; then
1325 __log_test_fail_status_code $1 $status
1329 if [ $# -gt 2 ]; then
1330 body=${res:0:${#res}-3}
1332 if [ $# -gt 5 ]; then
1334 for ((i=0; i<$(($#-5)); i=i+2)); do
1335 if [ "$targetJson" != "[" ]; then
1336 targetJson=$targetJson","
1338 if [ -f ${arr[$i+1]} ]; then
1339 schema=$(cat ${arr[$i+1]})
1341 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1345 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1348 targetJson=$targetJson"]"
1349 if [ $# -gt 4 ]; then
1350 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1352 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1353 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1355 if [ $res -ne 0 ]; then
1356 __log_test_fail_body
1365 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1366 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1367 # (Function for test scripts)
1368 ecs_api_edp_get_producer_2() {
1371 #Possible arg count: 2, 5, 6, 7, 8 etc
1373 if [ $# -eq 2 ]; then
1376 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1379 if [ $# -ge 5 ]; then
1383 if [ $paramError -ne 0 ]; then
1384 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1388 query="/ei-producer/v1/eiproducers/$2"
1389 res="$(__do_curl_to_api ECS GET $query)"
1390 status=${res:${#res}-3}
1392 if [ $status -ne $1 ]; then
1393 __log_test_fail_status_code $1 $status
1397 if [ $# -gt 2 ]; then
1398 body=${res:0:${#res}-3}
1400 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1402 for ((i=0; i<$(($#-4)); i=i+1)); do
1403 if [ "$targetJson" != "[" ]; then
1404 targetJson=$targetJson","
1406 targetJson=$targetJson"\"${arr[$i]}\""
1409 targetJson=$targetJson"]"
1410 if [ $# -gt 4 ]; then
1411 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1413 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1414 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1416 if [ $res -ne 0 ]; then
1417 __log_test_fail_body
1426 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1427 # args: <response-code> <producer-id>
1428 # (Function for test scripts)
1429 ecs_api_edp_delete_producer() {
1432 if [ $# -lt 2 ]; then
1433 __print_err "<response-code> <producer-id>" $@
1437 query="/ei-producer/v1/eiproducers/$2"
1438 res="$(__do_curl_to_api ECS DELETE $query)"
1439 status=${res:${#res}-3}
1441 if [ $status -ne $1 ]; then
1442 __log_test_fail_status_code $1 $status
1450 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1451 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1452 # (Function for test scripts)
1453 ecs_api_edp_put_producer() {
1456 #Valid number of parametrer 5,6,8,10,
1458 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1460 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1463 if [ $paramError -ne 0 ]; then
1464 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1469 if [ $# -gt 5 ]; then
1471 for ((i=0; i<$(($#-5)); i=i+2)); do
1472 if [ "$inputJson" != "[" ]; then
1473 inputJson=$inputJson","
1475 if [ -f ${arr[$i+1]} ]; then
1476 schema=$(cat ${arr[$i+1]})
1478 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1481 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1484 inputJson="\"supported_ei_types\":"$inputJson"]"
1486 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1488 inputJson="{"$inputJson"}"
1490 file="./tmp/.p.json"
1491 echo "$inputJson" > $file
1492 query="/ei-producer/v1/eiproducers/$2"
1493 res="$(__do_curl_to_api ECS PUT $query $file)"
1494 status=${res:${#res}-3}
1496 if [ $status -ne $1 ]; then
1497 __log_test_fail_status_code $1 $status
1505 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1506 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1507 # (Function for test scripts)
1508 ecs_api_edp_put_producer_2() {
1511 #Valid number of parametrer 5,6,8,10,
1513 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1515 elif [ $# -ge 5 ]; then
1518 if [ $paramError -ne 0 ]; then
1519 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1524 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1526 for ((i=0; i<$(($#-4)); i=i+1)); do
1527 if [ "$inputJson" != "[" ]; then
1528 inputJson=$inputJson","
1530 inputJson=$inputJson"\""${arr[$i]}"\""
1533 inputJson="\"supported_ei_types\":"$inputJson"]"
1535 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1537 inputJson="{"$inputJson"}"
1539 file="./tmp/.p.json"
1540 echo "$inputJson" > $file
1541 query="/ei-producer/v1/eiproducers/$2"
1542 res="$(__do_curl_to_api ECS PUT $query $file)"
1543 status=${res:${#res}-3}
1545 if [ $status -ne $1 ]; then
1546 __log_test_fail_status_code $1 $status
1554 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1555 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1556 # (Function for test scripts)
1557 ecs_api_edp_get_producer_jobs() {
1560 #Valid number of parameter 2,3,7,11
1562 if [ $# -eq 2 ]; then
1565 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1568 variablecount=$(($#-2))
1569 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1572 if [ $paramError -eq 1 ]; then
1573 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1577 query="/ei-producer/v1/eiproducers/$2/eijobs"
1578 res="$(__do_curl_to_api ECS GET $query)"
1579 status=${res:${#res}-3}
1580 if [ $status -ne $1 ]; then
1581 __log_test_fail_status_code $1 $status
1584 if [ $# -gt 2 ]; then
1585 body=${res:0:${#res}-3}
1587 if [ $# -gt 3 ]; then
1589 for ((i=0; i<$(($#-3)); i=i+5)); do
1590 if [ "$targetJson" != "[" ]; then
1591 targetJson=$targetJson","
1593 if [ -f ${arr[$i+4]} ]; then
1594 jobfile=$(cat ${arr[$i+4]})
1595 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1597 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1600 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}"
1603 targetJson=$targetJson"]"
1605 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1606 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1608 if [ $res -ne 0 ]; then
1609 __log_test_fail_body
1618 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1619 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1620 # (Function for test scripts)
1621 ecs_api_edp_get_producer_jobs_2() {
1624 #Valid number of parameter 2,3,7,11
1626 if [ $# -eq 2 ]; then
1629 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1632 variablecount=$(($#-2))
1633 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1636 if [ $paramError -eq 1 ]; then
1637 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1641 query="/ei-producer/v1/eiproducers/$2/eijobs"
1642 res="$(__do_curl_to_api ECS GET $query)"
1643 status=${res:${#res}-3}
1644 if [ $status -ne $1 ]; then
1645 __log_test_fail_status_code $1 $status
1648 if [ $# -gt 2 ]; then
1649 body=${res:0:${#res}-3}
1651 if [ $# -gt 3 ]; then
1653 for ((i=0; i<$(($#-3)); i=i+5)); do
1654 if [ "$targetJson" != "[" ]; then
1655 targetJson=$targetJson","
1657 if [ -f ${arr[$i+4]} ]; then
1658 jobfile=$(cat ${arr[$i+4]})
1659 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1661 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1664 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\":\"????\"}"
1667 targetJson=$targetJson"]"
1669 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1670 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1672 if [ $res -ne 0 ]; then
1673 __log_test_fail_body
1682 ##########################################
1683 #### Service status ####
1684 ##########################################
1685 # Function prefix: ecs_api_service
1687 # API Test function: GET /status
1688 # args: <response-code>
1689 # (Function for test scripts)
1690 ecs_api_service_status() {
1693 if [ $# -lt 1 ]; then
1694 __print_err "<response-code> [<producer-id>]*|NOID" $@
1697 res="$(__do_curl_to_api ECS GET /status)"
1698 status=${res:${#res}-3}
1699 if [ $status -ne $1 ]; then
1700 __log_test_fail_status_code $1 $status
1708 ##########################################
1709 #### Reset jobs ####
1710 ##########################################
1711 # Function prefix: ecs_api_admin
1713 # Admin to remove all jobs
1714 # args: <response-code> [ <type> ]
1715 # (Function for test scripts)
1717 ecs_api_admin_reset() {
1720 if [ -z "$FLAT_A1_EI" ]; then
1721 query="/A1-EI/v1/eitypes/$2/eijobs"
1723 query="/A1-EI/v1/eijobs"
1725 res="$(__do_curl_to_api ECS GET $query)"
1726 status=${res:${#res}-3}
1728 if [ $status -ne 200 ]; then
1729 __log_test_fail_status_code $1 $status
1733 #Remove brackets and response code
1734 body=${res:1:${#res}-4}
1735 list=$(echo ${body//,/ })
1736 list=$(echo ${list//[/})
1737 list=$(echo ${list//]/})
1738 list=$(echo ${list//\"/})
1740 for job in $list; do
1741 if [ -z "$FLAT_A1_EI" ]; then
1742 echo "Not supported for non-flat EI api"
1744 query="/A1-EI/v1/eijobs/$job"
1745 res="$(__do_curl_to_api ECS DELETE $query)"
1746 status=${res:${#res}-3}
1747 if [ $status -ne 204 ]; then
1748 __log_test_fail_status_code $1 $status
1751 echo " Deleted job: "$job