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 if [ $retcode_i -eq 0 ]; then
263 __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
264 if [ -z "$__ECS_WORKER_NODE" ]; then
265 echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW
268 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
271 echo " Retrieving host and ports for service..."
272 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
273 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
274 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
276 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
278 if [ $ECS_HTTPX == "http" ]; then
279 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
281 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
284 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
286 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
287 ECS_ADAPTER=$ECS_PATH
290 __check_included_image 'ECS'
291 if [ $? -eq 1 ]; then
292 echo -e $RED"The ECS app is not included in this test script"$ERED
293 echo -e $RED"ECS will not be started"$ERED
303 if [ "$(ls -A $DIR)" ]; then
304 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
305 rm -rf db/* &> /dev/null
306 if [ $? -ne 0 ]; then
307 echo -e $RED" Cannot remove database files in: $PWD"$ERED
312 echo " No files in mounted dir or dir does not exists"
317 export ECS_APP_NAME_ALIAS
318 export ECS_HOST_MNT_DIR
319 export ECS_CONTAINER_MNT_DIR
320 export ECS_CONFIG_MOUNT_PATH
321 export ECS_CONFIG_FILE
322 export ECS_INTERNAL_PORT
323 export ECS_EXTERNAL_PORT
324 export ECS_INTERNAL_SECURE_PORT
325 export ECS_EXTERNAL_SECURE_PORT
326 export DOCKER_SIM_NWNAME
327 export ECS_DISPLAY_NAME
329 if [ $1 == "PROXY" ]; then
330 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
331 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
332 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
333 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
335 echo " Configured with http proxy"
338 ECS_HTTP_PROXY_CONFIG_PORT=0
339 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
340 echo " Configured without http proxy"
342 export ECS_HTTP_PROXY_CONFIG_PORT
343 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
345 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
347 envsubst < $2 > $dest_file
349 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
351 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
360 # (Function for test scripts)
362 echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD
364 if [ $RUNMODE == "KUBE" ]; then
366 __check_prestarted_image "ECS"
367 if [ $? -eq 0 ]; then
368 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
369 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
373 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
374 echo " Deleting the replica set - a new will be started when the app is started"
375 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS")
376 if [ $? -ne 0 ]; then
377 echo -e $RED" Could not delete replica set "$RED
382 docker stop $ECS_APP_NAME &> ./tmp/.dockererr
383 if [ $? -ne 0 ]; then
384 __print_err "Could not stop $ECS_APP_NAME" $@
390 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
395 # Start a previously stopped ecs
397 # (Function for test scripts)
398 start_stopped_ecs() {
399 echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD
401 if [ $RUNMODE == "KUBE" ]; then
403 __check_prestarted_image "ECS"
404 if [ $? -eq 0 ]; then
405 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
406 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
407 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
411 # Tie the PMS to the same worker node it was initially started on
412 # 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
413 if [ -z "$__ECS_WORKER_NODE" ]; then
414 echo -e $RED" No initial worker node found for pod "$RED
418 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
419 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
420 tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}')
421 if [ $? -ne 0 ]; then
422 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW
424 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
427 docker start $ECS_APP_NAME &> ./tmp/.dockererr
428 if [ $? -ne 0 ]; then
429 __print_err "Could not start (the stopped) $ECS_APP_NAME" $@
435 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
436 if [ $? -ne 0 ]; then
443 # Turn on debug level tracing in ECS
445 # (Function for test scripts)
447 echo -e $BOLD"Setting ecs debug logging"$EBOLD
448 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
449 result=$(__do_curl "$curlString")
450 if [ $? -ne 0 ]; then
451 __print_err "Could not set debug mode" $@
459 # Turn on trace level tracing in ECS
461 # (Function for test scripts)
463 echo -e $BOLD"Setting ecs trace logging"$EBOLD
464 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
465 result=$(__do_curl "$curlString")
466 if [ $? -ne 0 ]; then
467 __print_err "Could not set trace mode" $@
475 # Perform curl retries when making direct call to ECS for the specified http response codes
476 # Speace separated list of http response codes
477 # args: [<response-code>]*
479 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
485 # Check the ecs logs for WARNINGs and ERRORs
487 # (Function for test scripts)
489 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
493 # Tests if a variable value in the ECS is equal to a target value and and optional timeout.
494 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
495 # equal to the target or not.
496 # Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
497 # before setting pass or fail depending on if the variable value becomes equal to the target
499 # (Function for test scripts)
501 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
502 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
504 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
509 ##########################################
510 ######### A1-E Enrichment API ##########
511 ##########################################
512 #Function prefix: ecs_api_a1
514 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs
515 # args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
516 # args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
517 # (Function for test scripts)
518 ecs_api_a1_get_job_ids() {
521 if [ -z "$FLAT_A1_EI" ]; then
522 # Valid number of parameters 4,5,6 etc
523 if [ $# -lt 3 ]; then
524 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
528 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
529 # Valid number of parameters 4,5,6 etc
530 if [ $# -lt 3 ]; then
531 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
536 if [ $3 != "NOWNER" ]; then
540 if [ -z "$FLAT_A1_EI" ]; then
541 query="/A1-EI/v1/eitypes/$2/eijobs$search"
543 if [ $2 != "NOTYPE" ]; then
544 if [ -z "$search" ]; then
545 search="?eiTypeId="$2
547 search=$search"&eiTypeId="$2
550 query="/A1-EI/v1/eijobs$search"
552 res="$(__do_curl_to_api ECS GET $query)"
553 status=${res:${#res}-3}
555 if [ $status -ne $1 ]; then
556 __log_test_fail_status_code $1 $status
560 if [ $# -gt 3 ]; then
561 body=${res:0:${#res}-3}
564 for pid in ${@:4} ; do
565 if [ "$targetJson" != "[" ]; then
566 targetJson=$targetJson","
568 if [ $pid != "EMPTY" ]; then
569 targetJson=$targetJson"\"$pid\""
573 targetJson=$targetJson"]"
574 echo " TARGET JSON: $targetJson" >> $HTTPLOG
575 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
577 if [ $res -ne 0 ]; then
587 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}
588 # args: <response-code> <type-id> [<schema-file>]
589 # (Function for test scripts)
590 ecs_api_a1_get_type() {
593 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
594 __print_err "<response-code> <type-id> [<schema-file>]" $@
598 query="/A1-EI/v1/eitypes/$2"
599 res="$(__do_curl_to_api ECS GET $query)"
600 status=${res:${#res}-3}
602 if [ $status -ne $1 ]; then
603 __log_test_fail_status_code $1 $status
607 if [ $# -eq 3 ]; then
608 body=${res:0:${#res}-3}
612 __log_test_fail_general "Schema file "$3", does not exist"
615 if [ -z "$FLAT_A1_EI" ]; then
616 targetJson="{\"eiJobParametersSchema\":$schema}"
620 echo " TARGET JSON: $targetJson" >> $HTTPLOG
621 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
623 if [ $res -ne 0 ]; then
633 # API Test function: GET /A1-EI/v1/eitypes
634 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
635 # (Function for test scripts)
636 ecs_api_a1_get_type_ids() {
639 if [ $# -lt 1 ]; then
640 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
644 query="/A1-EI/v1/eitypes"
645 res="$(__do_curl_to_api ECS GET $query)"
646 status=${res:${#res}-3}
648 if [ $status -ne $1 ]; then
649 __log_test_fail_status_code $1 $status
652 if [ $# -gt 1 ]; then
653 body=${res:0:${#res}-3}
655 if [ $2 != "EMPTY" ]; then
656 for pid in ${@:2} ; do
657 if [ "$targetJson" != "[" ]; then
658 targetJson=$targetJson","
660 targetJson=$targetJson"\"$pid\""
663 targetJson=$targetJson"]"
664 echo " TARGET JSON: $targetJson" >> $HTTPLOG
665 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
667 if [ $res -ne 0 ]; then
677 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}/status
678 # args: <response-code> <type-id> <job-id> [<status>]
679 # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
680 # (Function for test scripts)
681 ecs_api_a1_get_job_status() {
684 if [ -z "$FLAT_A1_EI" ]; then
685 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
686 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
690 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
692 res="$(__do_curl_to_api ECS GET $query)"
693 status=${res:${#res}-3}
695 if [ $status -ne $1 ]; then
696 __log_test_fail_status_code $1 $status
699 if [ $# -eq 4 ]; then
700 body=${res:0:${#res}-3}
701 targetJson="{\"operationalState\": \"$4\"}"
702 echo " TARGET JSON: $targetJson" >> $HTTPLOG
703 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
705 if [ $res -ne 0 ]; then
711 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
712 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
713 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
717 query="/A1-EI/v1/eijobs/$2/status"
721 res="$(__do_curl_to_api ECS GET $query)"
722 status=${res:${#res}-3}
724 if [ $# -eq 4 ]; then
725 duration=$((SECONDS-start))
726 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
727 if [ $duration -gt $4 ]; then
729 duration=-1 #Last iteration
732 duration=-1 #single test, no wait
735 if [ $status -ne $1 ]; then
736 if [ $duration -eq -1 ]; then
737 __log_test_fail_status_code $1 $status
741 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
742 body=${res:0:${#res}-3}
743 targetJson="{\"eiJobStatus\": \"$3\"}"
744 echo " TARGET JSON: $targetJson" >> $HTTPLOG
745 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
747 if [ $res -ne 0 ]; then
748 if [ $duration -eq -1 ]; then
753 duration=-1 #Goto pass
756 if [ $duration -eq -1 ]; then
757 if [ $# -eq 4 ]; then
772 # API Test function: GET /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
773 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
774 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
775 # (Function for test scripts)
776 ecs_api_a1_get_job() {
779 if [ -z "$FLAT_A1_EI" ]; then
780 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
781 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
784 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
786 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
787 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
788 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
791 query="/A1-EI/v1/eijobs/$2"
793 res="$(__do_curl_to_api ECS GET $query)"
794 status=${res:${#res}-3}
796 if [ $status -ne $1 ]; then
797 __log_test_fail_status_code $1 $status
801 if [ -z "$FLAT_A1_EI" ]; then
802 if [ $# -eq 6 ]; then
803 body=${res:0:${#res}-3}
807 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
809 __log_test_fail_general "Job template file "$6", does not exist"
812 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
813 echo " TARGET JSON: $targetJson" >> $HTTPLOG
814 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
816 if [ $res -ne 0 ]; then
822 if [ $# -eq 7 ]; then
823 body=${res:0:${#res}-3}
827 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
829 __log_test_fail_general "Job template file "$6", does not exist"
832 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
833 echo " TARGET JSON: $targetJson" >> $HTTPLOG
834 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
836 if [ $res -ne 0 ]; then
847 # API Test function: DELETE /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
848 # args: <response-code> <type-id> <job-id>
849 # args (flat uri structure): <response-code> <job-id>
850 # (Function for test scripts)
851 ecs_api_a1_delete_job() {
854 if [ -z "$FLAT_A1_EI" ]; then
855 if [ $# -ne 3 ]; then
856 __print_err "<response-code> <type-id> <job-id>" $@
860 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
862 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
863 if [ $# -ne 2 ]; then
864 __print_err "<response-code> <job-id>" $@
867 query="/A1-EI/v1/eijobs/$2"
869 res="$(__do_curl_to_api ECS DELETE $query)"
870 status=${res:${#res}-3}
872 if [ $status -ne $1 ]; then
873 __log_test_fail_status_code $1 $status
881 # API Test function: PUT /A1-EI/v1/eitypes/{eiTypeId}/eijobs/{eiJobId}
882 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
883 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
884 # (Function for test scripts)
885 ecs_api_a1_put_job() {
888 if [ -z "$FLAT_A1_EI" ]; then
889 if [ $# -lt 6 ]; then
890 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
895 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
897 __log_test_fail_general "Job template file "$6", does not exist"
901 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
903 echo "$inputJson" > $file
905 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
907 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
908 if [ $# -lt 7 ]; then
909 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
914 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
916 __log_test_fail_general "Job template file "$7", does not exist"
920 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
922 echo "$inputJson" > $file
924 query="/A1-EI/v1/eijobs/$2"
927 res="$(__do_curl_to_api ECS PUT $query $file)"
928 status=${res:${#res}-3}
930 if [ $status -ne $1 ]; then
931 __log_test_fail_status_code $1 $status
940 ##########################################
941 #### Enrichment Data Producer API ####
942 ##########################################
943 # Function prefix: ecs_api_edp
945 # API Test function: GET /ei-producer/v1/eitypes
946 # API Test function: GET /data-producer/v1/info-types
947 # args: <response-code> [ EMPTY | <type-id>+]
948 # (Function for test scripts)
949 ecs_api_edp_get_type_ids() {
952 if [ $# -lt 1 ]; then
953 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
956 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
957 query="/data-producer/v1/info-types"
959 query="/ei-producer/v1/eitypes"
961 res="$(__do_curl_to_api ECS GET $query)"
962 status=${res:${#res}-3}
964 if [ $status -ne $1 ]; then
965 __log_test_fail_status_code $1 $status
969 if [ $# -gt 1 ]; then
970 body=${res:0:${#res}-3}
972 if [ $2 != "EMPTY" ]; then
973 for pid in ${@:2} ; do
974 if [ "$targetJson" != "[" ]; then
975 targetJson=$targetJson","
977 targetJson=$targetJson"\"$pid\""
980 targetJson=$targetJson"]"
981 echo " TARGET JSON: $targetJson" >> $HTTPLOG
982 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
984 if [ $res -ne 0 ]; then
994 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
995 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
996 # args: <response-code> <producer-id> [<status> [<timeout>]]
997 # (Function for test scripts)
998 ecs_api_edp_get_producer_status() {
1001 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
1002 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
1005 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1006 query="/data-producer/v1/info-producers/$2/status"
1008 query="/ei-producer/v1/eiproducers/$2/status"
1012 res="$(__do_curl_to_api ECS GET $query)"
1013 status=${res:${#res}-3}
1015 if [ $# -eq 4 ]; then
1016 duration=$((SECONDS-start))
1017 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1018 if [ $duration -gt $4 ]; then
1020 duration=-1 #Last iteration
1023 duration=-1 #single test, no wait
1026 if [ $status -ne $1 ]; then
1027 if [ $duration -eq -1 ]; then
1028 __log_test_fail_status_code $1 $status
1032 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1033 body=${res:0:${#res}-3}
1034 targetJson="{\"operational_state\": \"$3\"}"
1035 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1036 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1038 if [ $res -ne 0 ]; then
1039 if [ $duration -eq -1 ]; then
1040 __log_test_fail_body
1044 duration=-1 #Goto pass
1047 if [ $duration -eq -1 ]; then
1048 if [ $# -eq 4 ]; then
1060 # API Test function: GET /ei-producer/v1/eiproducers
1061 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
1062 # (Function for test scripts)
1063 ecs_api_edp_get_producer_ids() {
1066 if [ $# -lt 1 ]; then
1067 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1071 query="/ei-producer/v1/eiproducers"
1072 res="$(__do_curl_to_api ECS GET $query)"
1073 status=${res:${#res}-3}
1075 if [ $status -ne $1 ]; then
1076 __log_test_fail_status_code $1 $status
1080 if [ $# -gt 1 ]; then
1081 body=${res:0:${#res}-3}
1084 for pid in ${@:2} ; do
1085 if [ "$targetJson" != "[" ]; then
1086 targetJson=$targetJson","
1088 if [ $pid != "EMPTY" ]; then
1089 targetJson=$targetJson"\"$pid\""
1093 targetJson=$targetJson"]"
1094 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1095 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1097 if [ $res -ne 0 ]; then
1098 __log_test_fail_body
1107 # API Test function: GET /ei-producer/v1/eiproducers
1108 # API Test function: GET /data-producer/v1/info-producers
1109 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1110 # (Function for test scripts)
1111 ecs_api_edp_get_producer_ids_2() {
1114 if [ $# -lt 1 ]; then
1115 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1118 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1119 query="/data-producer/v1/info-producers"
1120 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1121 query=$query"?info_type_id=$2"
1124 query="/ei-producer/v1/eiproducers"
1125 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1126 query=$query"?ei_type_id=$2"
1129 res="$(__do_curl_to_api ECS GET $query)"
1130 status=${res:${#res}-3}
1132 if [ $status -ne $1 ]; then
1133 __log_test_fail_status_code $1 $status
1137 if [ $# -gt 2 ]; then
1138 body=${res:0:${#res}-3}
1141 for pid in ${@:3} ; do
1142 if [ "$targetJson" != "[" ]; then
1143 targetJson=$targetJson","
1145 if [ $pid != "EMPTY" ]; then
1146 targetJson=$targetJson"\"$pid\""
1150 targetJson=$targetJson"]"
1151 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1152 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1154 if [ $res -ne 0 ]; then
1155 __log_test_fail_body
1164 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1165 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1166 # (Function for test scripts)
1167 ecs_api_edp_get_type() {
1171 if [ $# -eq 2 ]; then
1174 if [ $# -gt 3 ]; then
1177 if [ $paramError -ne 0 ]; then
1178 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1182 query="/ei-producer/v1/eitypes/$2"
1183 res="$(__do_curl_to_api ECS GET $query)"
1184 status=${res:${#res}-3}
1186 if [ $status -ne $1 ]; then
1187 __log_test_fail_status_code $1 $status
1190 if [ $# -gt 3 ]; then
1191 body=${res:0:${#res}-3}
1196 __log_test_fail_general "Job template file "$3", does not exist"
1201 if [ $4 != "EMPTY" ]; then
1202 for pid in ${@:4} ; do
1203 if [ "$targetJson" != "" ]; then
1204 targetJson=$targetJson","
1206 targetJson=$targetJson"\"$pid\""
1209 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1211 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1212 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1214 if [ $res -ne 0 ]; then
1215 __log_test_fail_body
1223 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1224 # API Test function: GET /data-producer/v1/info-types/{infoTypeId}
1225 # args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1226 # (Function for test scripts)
1227 ecs_api_edp_get_type_2() {
1231 if [ $# -eq 2 ]; then
1234 if [ $# -eq 3 ]; then
1237 if [ $paramError -ne 0 ]; then
1238 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1241 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1242 query="/data-producer/v1/info-types/$2"
1244 query="/ei-producer/v1/eitypes/$2"
1247 res="$(__do_curl_to_api ECS GET $query)"
1248 status=${res:${#res}-3}
1250 if [ $status -ne $1 ]; then
1251 __log_test_fail_status_code $1 $status
1254 if [ $# -eq 3 ]; then
1255 body=${res:0:${#res}-3}
1260 __log_test_fail_general "Job template file "$3", does not exist"
1263 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1264 targetJson="{\"info_job_data_schema\":$schema}"
1266 targetJson="{\"ei_job_data_schema\":$schema}"
1269 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1270 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1272 if [ $res -ne 0 ]; then
1273 __log_test_fail_body
1281 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1282 # API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
1283 # args: (v1_2) <response-code> <type-id> <job-schema-file>
1284 # (Function for test scripts)
1285 ecs_api_edp_put_type_2() {
1288 if [ $# -ne 3 ]; then
1289 __print_err "<response-code> <type-id> <job-schema-file>" $@
1293 if [ ! -f $3 ]; then
1294 __log_test_fail_general "Job schema file "$3", does not exist"
1297 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1299 input_json="{\"info_job_data_schema\":$schema}"
1300 file="./tmp/put_type.json"
1301 echo $input_json > $file
1303 query="/data-producer/v1/info-types/$2"
1306 input_json="{\"ei_job_data_schema\":$schema}"
1307 file="./tmp/put_type.json"
1308 echo $input_json > $file
1310 query="/ei-producer/v1/eitypes/$2"
1312 res="$(__do_curl_to_api ECS PUT $query $file)"
1313 status=${res:${#res}-3}
1315 if [ $status -ne $1 ]; then
1316 __log_test_fail_status_code $1 $status
1324 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1325 # API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
1326 # args: (v1_2) <response-code> <type-id>
1327 # (Function for test scripts)
1328 ecs_api_edp_delete_type_2() {
1331 if [ $# -ne 2 ]; then
1332 __print_err "<response-code> <type-id>" $@
1336 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1337 query="/data-producer/v1/info-types/$2"
1339 query="/ei-producer/v1/eitypes/$2"
1341 res="$(__do_curl_to_api ECS DELETE $query)"
1342 status=${res:${#res}-3}
1344 if [ $status -ne $1 ]; then
1345 __log_test_fail_status_code $1 $status
1353 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1354 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1355 # (Function for test scripts)
1356 ecs_api_edp_get_producer() {
1359 #Possible arg count: 2, 5 6, 8, 10 etc
1361 if [ $# -eq 2 ]; then
1364 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1367 variablecount=$(($#-4))
1368 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1372 if [ $paramError -ne 0 ]; then
1373 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1377 query="/ei-producer/v1/eiproducers/$2"
1378 res="$(__do_curl_to_api ECS GET $query)"
1379 status=${res:${#res}-3}
1381 if [ $status -ne $1 ]; then
1382 __log_test_fail_status_code $1 $status
1386 if [ $# -gt 2 ]; then
1387 body=${res:0:${#res}-3}
1389 if [ $# -gt 5 ]; then
1391 for ((i=0; i<$(($#-5)); i=i+2)); do
1392 if [ "$targetJson" != "[" ]; then
1393 targetJson=$targetJson","
1395 if [ -f ${arr[$i+1]} ]; then
1396 schema=$(cat ${arr[$i+1]})
1398 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1402 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1405 targetJson=$targetJson"]"
1406 if [ $# -gt 4 ]; then
1407 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1409 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1410 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1412 if [ $res -ne 0 ]; then
1413 __log_test_fail_body
1422 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1423 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
1424 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1425 # (Function for test scripts)
1426 ecs_api_edp_get_producer_2() {
1429 #Possible arg count: 2, 5, 6, 7, 8 etc
1431 if [ $# -eq 2 ]; then
1434 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1437 if [ $# -ge 5 ]; then
1441 if [ $paramError -ne 0 ]; then
1442 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1445 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1446 query="/data-producer/v1/info-producers/$2"
1448 query="/ei-producer/v1/eiproducers/$2"
1450 res="$(__do_curl_to_api ECS GET $query)"
1451 status=${res:${#res}-3}
1453 if [ $status -ne $1 ]; then
1454 __log_test_fail_status_code $1 $status
1458 if [ $# -gt 2 ]; then
1459 body=${res:0:${#res}-3}
1461 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1463 for ((i=0; i<$(($#-4)); i=i+1)); do
1464 if [ "$targetJson" != "[" ]; then
1465 targetJson=$targetJson","
1467 targetJson=$targetJson"\"${arr[$i]}\""
1470 targetJson=$targetJson"]"
1471 if [ $# -gt 4 ]; then
1472 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1473 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1475 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1478 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1479 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1481 if [ $res -ne 0 ]; then
1482 __log_test_fail_body
1491 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1492 # API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
1493 # args: <response-code> <producer-id>
1494 # (Function for test scripts)
1495 ecs_api_edp_delete_producer() {
1498 if [ $# -lt 2 ]; then
1499 __print_err "<response-code> <producer-id>" $@
1502 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1503 query="/data-producer/v1/info-producers/$2"
1505 query="/ei-producer/v1/eiproducers/$2"
1507 res="$(__do_curl_to_api ECS DELETE $query)"
1508 status=${res:${#res}-3}
1510 if [ $status -ne $1 ]; then
1511 __log_test_fail_status_code $1 $status
1519 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1520 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1521 # (Function for test scripts)
1522 ecs_api_edp_put_producer() {
1525 #Valid number of parametrer 5,6,8,10,
1527 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1529 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1532 if [ $paramError -ne 0 ]; then
1533 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1538 if [ $# -gt 5 ]; then
1540 for ((i=0; i<$(($#-5)); i=i+2)); do
1541 if [ "$inputJson" != "[" ]; then
1542 inputJson=$inputJson","
1544 if [ -f ${arr[$i+1]} ]; then
1545 schema=$(cat ${arr[$i+1]})
1547 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1550 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1553 inputJson="\"supported_ei_types\":"$inputJson"]"
1555 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1557 inputJson="{"$inputJson"}"
1559 file="./tmp/.p.json"
1560 echo "$inputJson" > $file
1561 query="/ei-producer/v1/eiproducers/$2"
1562 res="$(__do_curl_to_api ECS PUT $query $file)"
1563 status=${res:${#res}-3}
1565 if [ $status -ne $1 ]; then
1566 __log_test_fail_status_code $1 $status
1574 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1575 # API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
1576 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1577 # (Function for test scripts)
1578 ecs_api_edp_put_producer_2() {
1581 #Valid number of parametrer 5,6,8,10,
1583 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1585 elif [ $# -ge 5 ]; then
1588 if [ $paramError -ne 0 ]; then
1589 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1594 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1596 for ((i=0; i<$(($#-4)); i=i+1)); do
1597 if [ "$inputJson" != "[" ]; then
1598 inputJson=$inputJson","
1600 inputJson=$inputJson"\""${arr[$i]}"\""
1603 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1604 inputJson="\"supported_info_types\":"$inputJson"]"
1606 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
1608 inputJson="{"$inputJson"}"
1610 file="./tmp/.p.json"
1611 echo "$inputJson" > $file
1612 query="/data-producer/v1/info-producers/$2"
1614 inputJson="\"supported_ei_types\":"$inputJson"]"
1616 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1618 inputJson="{"$inputJson"}"
1620 file="./tmp/.p.json"
1621 echo "$inputJson" > $file
1622 query="/ei-producer/v1/eiproducers/$2"
1624 res="$(__do_curl_to_api ECS PUT $query $file)"
1625 status=${res:${#res}-3}
1627 if [ $status -ne $1 ]; then
1628 __log_test_fail_status_code $1 $status
1636 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1637 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1638 # (Function for test scripts)
1639 ecs_api_edp_get_producer_jobs() {
1642 #Valid number of parameter 2,3,7,11
1644 if [ $# -eq 2 ]; then
1647 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1650 variablecount=$(($#-2))
1651 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1654 if [ $paramError -eq 1 ]; then
1655 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1659 query="/ei-producer/v1/eiproducers/$2/eijobs"
1660 res="$(__do_curl_to_api ECS GET $query)"
1661 status=${res:${#res}-3}
1662 if [ $status -ne $1 ]; then
1663 __log_test_fail_status_code $1 $status
1666 if [ $# -gt 2 ]; then
1667 body=${res:0:${#res}-3}
1669 if [ $# -gt 3 ]; then
1671 for ((i=0; i<$(($#-3)); i=i+5)); do
1672 if [ "$targetJson" != "[" ]; then
1673 targetJson=$targetJson","
1675 if [ -f ${arr[$i+4]} ]; then
1676 jobfile=$(cat ${arr[$i+4]})
1677 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1679 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1682 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}"
1685 targetJson=$targetJson"]"
1687 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1688 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1690 if [ $res -ne 0 ]; then
1691 __log_test_fail_body
1700 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1701 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
1702 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1703 # (Function for test scripts)
1704 ecs_api_edp_get_producer_jobs_2() {
1707 #Valid number of parameter 2,3,7,11
1709 if [ $# -eq 2 ]; then
1712 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1715 variablecount=$(($#-2))
1716 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1719 if [ $paramError -eq 1 ]; then
1720 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1723 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1724 query="/data-producer/v1/info-producers/$2/info-jobs"
1726 query="/ei-producer/v1/eiproducers/$2/eijobs"
1728 res="$(__do_curl_to_api ECS GET $query)"
1729 status=${res:${#res}-3}
1730 if [ $status -ne $1 ]; then
1731 __log_test_fail_status_code $1 $status
1734 if [ $# -gt 2 ]; then
1735 body=${res:0:${#res}-3}
1737 if [ $# -gt 3 ]; then
1739 for ((i=0; i<$(($#-3)); i=i+5)); do
1740 if [ "$targetJson" != "[" ]; then
1741 targetJson=$targetJson","
1743 if [ -f ${arr[$i+4]} ]; then
1744 jobfile=$(cat ${arr[$i+4]})
1745 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1747 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1750 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1751 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1753 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\":\"????\"}"
1757 targetJson=$targetJson"]"
1759 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1760 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1762 if [ $res -ne 0 ]; then
1763 __log_test_fail_body
1772 ##########################################
1773 #### Service status ####
1774 ##########################################
1775 # Function prefix: ecs_api_service
1777 # API Test function: GET /status
1778 # args: <response-code>
1779 # (Function for test scripts)
1780 ecs_api_service_status() {
1783 if [ $# -lt 1 ]; then
1784 __print_err "<response-code>" $@
1787 res="$(__do_curl_to_api ECS GET /status)"
1788 status=${res:${#res}-3}
1789 if [ $status -ne $1 ]; then
1790 __log_test_fail_status_code $1 $status
1797 ###########################################
1798 ######### Info data consumer API ##########
1799 ###########################################
1800 #Function prefix: ecs_api_idc
1803 # API Test function: GET /data-consumer/v1/info-types
1804 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
1805 # (Function for test scripts)
1806 ecs_api_idc_get_type_ids() {
1809 if [ $# -lt 1 ]; then
1810 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1814 query="/data-consumer/v1/info-types"
1815 res="$(__do_curl_to_api ECS GET $query)"
1816 status=${res:${#res}-3}
1818 if [ $status -ne $1 ]; then
1819 __log_test_fail_status_code $1 $status
1822 if [ $# -gt 1 ]; then
1823 body=${res:0:${#res}-3}
1825 if [ $2 != "EMPTY" ]; then
1826 for pid in ${@:2} ; do
1827 if [ "$targetJson" != "[" ]; then
1828 targetJson=$targetJson","
1830 targetJson=$targetJson"\"$pid\""
1833 targetJson=$targetJson"]"
1834 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1835 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1837 if [ $res -ne 0 ]; then
1838 __log_test_fail_body
1847 # API Test function: GET /data-consumer/v1/info-jobs
1848 # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1849 # (Function for test scripts)
1850 ecs_api_idc_get_job_ids() {
1853 # Valid number of parameters 4,5,6 etc
1854 if [ $# -lt 3 ]; then
1855 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1859 if [ $3 != "NOWNER" ]; then
1863 if [ $2 != "NOTYPE" ]; then
1864 if [ -z "$search" ]; then
1865 search="?infoTypeId="$2
1867 search=$search"&infoTypeId="$2
1870 query="/data-consumer/v1/info-jobs$search"
1872 res="$(__do_curl_to_api ECS GET $query)"
1873 status=${res:${#res}-3}
1875 if [ $status -ne $1 ]; then
1876 __log_test_fail_status_code $1 $status
1880 if [ $# -gt 3 ]; then
1881 body=${res:0:${#res}-3}
1884 for pid in ${@:4} ; do
1885 if [ "$targetJson" != "[" ]; then
1886 targetJson=$targetJson","
1888 if [ $pid != "EMPTY" ]; then
1889 targetJson=$targetJson"\"$pid\""
1893 targetJson=$targetJson"]"
1894 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1895 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1897 if [ $res -ne 0 ]; then
1898 __log_test_fail_body
1907 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1908 # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1909 # (Function for test scripts)
1910 ecs_api_idc_get_job() {
1913 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1914 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1917 query="/data-consumer/v1/info-jobs/$2"
1918 res="$(__do_curl_to_api ECS GET $query)"
1919 status=${res:${#res}-3}
1921 if [ $status -ne $1 ]; then
1922 __log_test_fail_status_code $1 $status
1926 if [ $# -eq 7 ]; then
1927 body=${res:0:${#res}-3}
1931 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1933 __log_test_fail_general "Job template file "$6", does not exist"
1936 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1937 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1938 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1940 if [ $res -ne 0 ]; then
1941 __log_test_fail_body
1951 # API Test function: PUT /data-consumer/v1/info-jobs/{infoJobId}
1952 # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1953 # (Function for test scripts)
1954 ecs_api_idc_put_job() {
1957 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1958 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1963 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1965 __log_test_fail_general "Job template file "$7", does not exist"
1969 inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1970 file="./tmp/.p.json"
1971 echo "$inputJson" > $file
1973 query="/data-consumer/v1/info-jobs/$2"
1975 if [ $# -eq 8 ]; then
1976 if [ $8 == "VALIDATE" ]; then
1977 query=$query"?typeCheck=true"
1981 res="$(__do_curl_to_api ECS PUT $query $file)"
1982 status=${res:${#res}-3}
1984 if [ $status -ne $1 ]; then
1985 __log_test_fail_status_code $1 $status
1993 # API Test function: DELETE /data-consumer/v1/info-jobs/{infoJobId}
1994 # args: <response-code> <job-id>
1995 # (Function for test scripts)
1996 ecs_api_idc_delete_job() {
1999 if [ $# -ne 2 ]; then
2000 __print_err "<response-code> <job-id>" $@
2003 query="/data-consumer/v1/info-jobs/$2"
2004 res="$(__do_curl_to_api ECS DELETE $query)"
2005 status=${res:${#res}-3}
2007 if [ $status -ne $1 ]; then
2008 __log_test_fail_status_code $1 $status
2016 # API Test function: GET /data-consumer/v1/info-types/{infoTypeId}
2017 # args: <response-code> <type-id> [<schema-file>]
2018 # (Function for test scripts)
2019 ecs_api_idc_get_type() {
2022 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2023 __print_err "<response-code> <type-id> [<schema-file>]" $@
2027 query="/data-consumer/v1/info-types/$2"
2028 res="$(__do_curl_to_api ECS GET $query)"
2029 status=${res:${#res}-3}
2031 if [ $status -ne $1 ]; then
2032 __log_test_fail_status_code $1 $status
2036 if [ $# -eq 3 ]; then
2037 body=${res:0:${#res}-3}
2041 __log_test_fail_general "Schema file "$3", does not exist"
2044 targetJson="{\"job_data_schema\":$schema}"
2045 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2046 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2048 if [ $res -ne 0 ]; then
2049 __log_test_fail_body
2058 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2059 # args: <response-code> <job-id> [<status> [<timeout>]]
2060 # (Function for test scripts)
2061 ecs_api_idc_get_job_status() {
2064 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2065 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2069 query="/data-consumer/v1/info-jobs/$2/status"
2073 res="$(__do_curl_to_api ECS GET $query)"
2074 status=${res:${#res}-3}
2076 if [ $# -eq 4 ]; then
2077 duration=$((SECONDS-start))
2078 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2079 if [ $duration -gt $4 ]; then
2081 duration=-1 #Last iteration
2084 duration=-1 #single test, no wait
2087 if [ $status -ne $1 ]; then
2088 if [ $duration -eq -1 ]; then
2089 __log_test_fail_status_code $1 $status
2093 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2094 body=${res:0:${#res}-3}
2095 targetJson="{\"info_job_status\": \"$3\"}"
2096 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2097 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2099 if [ $res -ne 0 ]; then
2100 if [ $duration -eq -1 ]; then
2101 __log_test_fail_body
2105 duration=-1 #Goto pass
2108 if [ $duration -eq -1 ]; then
2109 if [ $# -eq 4 ]; then
2124 ##########################################
2125 #### Reset jobs ####
2126 ##########################################
2127 # Function prefix: ecs_api_admin
2129 # Admin to remove all jobs
2130 # args: <response-code> [ <type> ]
2131 # (Function for test scripts)
2133 ecs_api_admin_reset() {
2136 if [ -z "$FLAT_A1_EI" ]; then
2137 query="/A1-EI/v1/eitypes/$2/eijobs"
2139 query="/A1-EI/v1/eijobs"
2141 res="$(__do_curl_to_api ECS GET $query)"
2142 status=${res:${#res}-3}
2144 if [ $status -ne 200 ]; then
2145 __log_test_fail_status_code $1 $status
2149 #Remove brackets and response code
2150 body=${res:1:${#res}-4}
2151 list=$(echo ${body//,/ })
2152 list=$(echo ${list//[/})
2153 list=$(echo ${list//]/})
2154 list=$(echo ${list//\"/})
2156 for job in $list; do
2157 if [ -z "$FLAT_A1_EI" ]; then
2158 echo "Not supported for non-flat EI api"
2160 query="/A1-EI/v1/eijobs/$job"
2161 res="$(__do_curl_to_api ECS DELETE $query)"
2162 status=${res:${#res}-3}
2163 if [ $status -ne 204 ]; then
2164 __log_test_fail_status_code $1 $status
2167 echo " Deleted job: "$job
2175 ##########################################
2176 #### Reset jobs and producers ####
2177 ##########################################
2180 # Admin reset to remove all data in ecs; jobs, producers etc
2181 # NOTE - only works in kubernetes and the pod should not be running
2183 # (Function for test scripts)
2185 ecs_kube_pvc_reset() {
2188 __kube_clean_pvc $ECS_APP_NAME nonrtric enrichmentservice-pvc /var/enrichment-coordinator-service/database