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 # args: <response-code> [ EMPTY | <type-id>+]
947 # (Function for test scripts)
948 ecs_api_edp_get_type_ids() {
951 if [ $# -lt 1 ]; then
952 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
956 query="/ei-producer/v1/eitypes"
957 res="$(__do_curl_to_api ECS GET $query)"
958 status=${res:${#res}-3}
960 if [ $status -ne $1 ]; then
961 __log_test_fail_status_code $1 $status
965 if [ $# -gt 1 ]; then
966 body=${res:0:${#res}-3}
968 if [ $2 != "EMPTY" ]; then
969 for pid in ${@:2} ; do
970 if [ "$targetJson" != "[" ]; then
971 targetJson=$targetJson","
973 targetJson=$targetJson"\"$pid\""
976 targetJson=$targetJson"]"
977 echo " TARGET JSON: $targetJson" >> $HTTPLOG
978 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
980 if [ $res -ne 0 ]; then
990 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
991 # args: <response-code> <producer-id> [<status> [<timeout>]]
992 # (Function for test scripts)
993 ecs_api_edp_get_producer_status() {
996 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
997 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
1001 query="/ei-producer/v1/eiproducers/$2/status"
1004 res="$(__do_curl_to_api ECS GET $query)"
1005 status=${res:${#res}-3}
1007 if [ $# -eq 4 ]; then
1008 duration=$((SECONDS-start))
1009 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1010 if [ $duration -gt $4 ]; then
1012 duration=-1 #Last iteration
1015 duration=-1 #single test, no wait
1018 if [ $status -ne $1 ]; then
1019 if [ $duration -eq -1 ]; then
1020 __log_test_fail_status_code $1 $status
1024 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1025 body=${res:0:${#res}-3}
1026 targetJson="{\"operational_state\": \"$3\"}"
1027 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1028 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1030 if [ $res -ne 0 ]; then
1031 if [ $duration -eq -1 ]; then
1032 __log_test_fail_body
1036 duration=-1 #Goto pass
1039 if [ $duration -eq -1 ]; then
1040 if [ $# -eq 4 ]; then
1052 # API Test function: GET /ei-producer/v1/eiproducers
1053 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
1054 # (Function for test scripts)
1055 ecs_api_edp_get_producer_ids() {
1058 if [ $# -lt 1 ]; then
1059 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1063 query="/ei-producer/v1/eiproducers"
1064 res="$(__do_curl_to_api ECS GET $query)"
1065 status=${res:${#res}-3}
1067 if [ $status -ne $1 ]; then
1068 __log_test_fail_status_code $1 $status
1072 if [ $# -gt 1 ]; then
1073 body=${res:0:${#res}-3}
1076 for pid in ${@:2} ; do
1077 if [ "$targetJson" != "[" ]; then
1078 targetJson=$targetJson","
1080 if [ $pid != "EMPTY" ]; then
1081 targetJson=$targetJson"\"$pid\""
1085 targetJson=$targetJson"]"
1086 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1087 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1089 if [ $res -ne 0 ]; then
1090 __log_test_fail_body
1099 # API Test function: GET /ei-producer/v1/eiproducers
1100 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1101 # (Function for test scripts)
1102 ecs_api_edp_get_producer_ids_2() {
1105 if [ $# -lt 1 ]; then
1106 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1110 query="/ei-producer/v1/eiproducers"
1111 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1112 query=$query"?ei_type_id=$2"
1114 res="$(__do_curl_to_api ECS GET $query)"
1115 status=${res:${#res}-3}
1117 if [ $status -ne $1 ]; then
1118 __log_test_fail_status_code $1 $status
1122 if [ $# -gt 2 ]; then
1123 body=${res:0:${#res}-3}
1126 for pid in ${@:3} ; do
1127 if [ "$targetJson" != "[" ]; then
1128 targetJson=$targetJson","
1130 if [ $pid != "EMPTY" ]; then
1131 targetJson=$targetJson"\"$pid\""
1135 targetJson=$targetJson"]"
1136 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1137 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1139 if [ $res -ne 0 ]; then
1140 __log_test_fail_body
1149 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1150 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1151 # (Function for test scripts)
1152 ecs_api_edp_get_type() {
1156 if [ $# -eq 2 ]; then
1159 if [ $# -gt 3 ]; then
1162 if [ $paramError -ne 0 ]; then
1163 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1167 query="/ei-producer/v1/eitypes/$2"
1168 res="$(__do_curl_to_api ECS GET $query)"
1169 status=${res:${#res}-3}
1171 if [ $status -ne $1 ]; then
1172 __log_test_fail_status_code $1 $status
1175 if [ $# -gt 3 ]; then
1176 body=${res:0:${#res}-3}
1181 __log_test_fail_general "Job template file "$3", does not exist"
1186 if [ $4 != "EMPTY" ]; then
1187 for pid in ${@:4} ; do
1188 if [ "$targetJson" != "" ]; then
1189 targetJson=$targetJson","
1191 targetJson=$targetJson"\"$pid\""
1194 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1196 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1197 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1199 if [ $res -ne 0 ]; then
1200 __log_test_fail_body
1208 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1209 # args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1210 # (Function for test scripts)
1211 ecs_api_edp_get_type_2() {
1215 if [ $# -eq 2 ]; then
1218 if [ $# -eq 3 ]; then
1221 if [ $paramError -ne 0 ]; then
1222 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1226 query="/ei-producer/v1/eitypes/$2"
1227 res="$(__do_curl_to_api ECS GET $query)"
1228 status=${res:${#res}-3}
1230 if [ $status -ne $1 ]; then
1231 __log_test_fail_status_code $1 $status
1234 if [ $# -eq 3 ]; then
1235 body=${res:0:${#res}-3}
1240 __log_test_fail_general "Job template file "$3", does not exist"
1244 targetJson="{\"ei_job_data_schema\":$schema}"
1246 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1247 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1249 if [ $res -ne 0 ]; then
1250 __log_test_fail_body
1258 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1259 # args: (v1_2) <response-code> <type-id> <job-schema-file>
1260 # (Function for test scripts)
1261 ecs_api_edp_put_type_2() {
1264 if [ $# -ne 3 ]; then
1265 __print_err "<response-code> <type-id> <job-schema-file>" $@
1269 if [ ! -f $3 ]; then
1270 __log_test_fail_general "Job schema file "$3", does not exist"
1274 input_json="{\"ei_job_data_schema\":$schema}"
1275 file="./tmp/put_type.json"
1276 echo $input_json > $file
1278 query="/ei-producer/v1/eitypes/$2"
1279 res="$(__do_curl_to_api ECS PUT $query $file)"
1280 status=${res:${#res}-3}
1282 if [ $status -ne $1 ]; then
1283 __log_test_fail_status_code $1 $status
1291 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1292 # args: (v1_2) <response-code> <type-id>
1293 # (Function for test scripts)
1294 ecs_api_edp_delete_type_2() {
1297 if [ $# -ne 2 ]; then
1298 __print_err "<response-code> <type-id>" $@
1302 query="/ei-producer/v1/eitypes/$2"
1303 res="$(__do_curl_to_api ECS DELETE $query)"
1304 status=${res:${#res}-3}
1306 if [ $status -ne $1 ]; then
1307 __log_test_fail_status_code $1 $status
1315 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1316 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1317 # (Function for test scripts)
1318 ecs_api_edp_get_producer() {
1321 #Possible arg count: 2, 5 6, 8, 10 etc
1323 if [ $# -eq 2 ]; then
1326 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1329 variablecount=$(($#-4))
1330 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1334 if [ $paramError -ne 0 ]; then
1335 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1339 query="/ei-producer/v1/eiproducers/$2"
1340 res="$(__do_curl_to_api ECS GET $query)"
1341 status=${res:${#res}-3}
1343 if [ $status -ne $1 ]; then
1344 __log_test_fail_status_code $1 $status
1348 if [ $# -gt 2 ]; then
1349 body=${res:0:${#res}-3}
1351 if [ $# -gt 5 ]; then
1353 for ((i=0; i<$(($#-5)); i=i+2)); do
1354 if [ "$targetJson" != "[" ]; then
1355 targetJson=$targetJson","
1357 if [ -f ${arr[$i+1]} ]; then
1358 schema=$(cat ${arr[$i+1]})
1360 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1364 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1367 targetJson=$targetJson"]"
1368 if [ $# -gt 4 ]; then
1369 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1371 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1372 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1374 if [ $res -ne 0 ]; then
1375 __log_test_fail_body
1384 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1385 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1386 # (Function for test scripts)
1387 ecs_api_edp_get_producer_2() {
1390 #Possible arg count: 2, 5, 6, 7, 8 etc
1392 if [ $# -eq 2 ]; then
1395 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1398 if [ $# -ge 5 ]; then
1402 if [ $paramError -ne 0 ]; then
1403 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1407 query="/ei-producer/v1/eiproducers/$2"
1408 res="$(__do_curl_to_api ECS GET $query)"
1409 status=${res:${#res}-3}
1411 if [ $status -ne $1 ]; then
1412 __log_test_fail_status_code $1 $status
1416 if [ $# -gt 2 ]; then
1417 body=${res:0:${#res}-3}
1419 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1421 for ((i=0; i<$(($#-4)); i=i+1)); do
1422 if [ "$targetJson" != "[" ]; then
1423 targetJson=$targetJson","
1425 targetJson=$targetJson"\"${arr[$i]}\""
1428 targetJson=$targetJson"]"
1429 if [ $# -gt 4 ]; then
1430 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1432 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1433 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1435 if [ $res -ne 0 ]; then
1436 __log_test_fail_body
1445 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1446 # args: <response-code> <producer-id>
1447 # (Function for test scripts)
1448 ecs_api_edp_delete_producer() {
1451 if [ $# -lt 2 ]; then
1452 __print_err "<response-code> <producer-id>" $@
1456 query="/ei-producer/v1/eiproducers/$2"
1457 res="$(__do_curl_to_api ECS DELETE $query)"
1458 status=${res:${#res}-3}
1460 if [ $status -ne $1 ]; then
1461 __log_test_fail_status_code $1 $status
1469 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1470 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1471 # (Function for test scripts)
1472 ecs_api_edp_put_producer() {
1475 #Valid number of parametrer 5,6,8,10,
1477 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1479 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1482 if [ $paramError -ne 0 ]; then
1483 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1488 if [ $# -gt 5 ]; then
1490 for ((i=0; i<$(($#-5)); i=i+2)); do
1491 if [ "$inputJson" != "[" ]; then
1492 inputJson=$inputJson","
1494 if [ -f ${arr[$i+1]} ]; then
1495 schema=$(cat ${arr[$i+1]})
1497 _log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1500 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1503 inputJson="\"supported_ei_types\":"$inputJson"]"
1505 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1507 inputJson="{"$inputJson"}"
1509 file="./tmp/.p.json"
1510 echo "$inputJson" > $file
1511 query="/ei-producer/v1/eiproducers/$2"
1512 res="$(__do_curl_to_api ECS PUT $query $file)"
1513 status=${res:${#res}-3}
1515 if [ $status -ne $1 ]; then
1516 __log_test_fail_status_code $1 $status
1524 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1525 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1526 # (Function for test scripts)
1527 ecs_api_edp_put_producer_2() {
1530 #Valid number of parametrer 5,6,8,10,
1532 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1534 elif [ $# -ge 5 ]; then
1537 if [ $paramError -ne 0 ]; then
1538 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1543 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1545 for ((i=0; i<$(($#-4)); i=i+1)); do
1546 if [ "$inputJson" != "[" ]; then
1547 inputJson=$inputJson","
1549 inputJson=$inputJson"\""${arr[$i]}"\""
1552 inputJson="\"supported_ei_types\":"$inputJson"]"
1554 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1556 inputJson="{"$inputJson"}"
1558 file="./tmp/.p.json"
1559 echo "$inputJson" > $file
1560 query="/ei-producer/v1/eiproducers/$2"
1561 res="$(__do_curl_to_api ECS PUT $query $file)"
1562 status=${res:${#res}-3}
1564 if [ $status -ne $1 ]; then
1565 __log_test_fail_status_code $1 $status
1573 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1574 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1575 # (Function for test scripts)
1576 ecs_api_edp_get_producer_jobs() {
1579 #Valid number of parameter 2,3,7,11
1581 if [ $# -eq 2 ]; then
1584 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1587 variablecount=$(($#-2))
1588 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1591 if [ $paramError -eq 1 ]; then
1592 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1596 query="/ei-producer/v1/eiproducers/$2/eijobs"
1597 res="$(__do_curl_to_api ECS GET $query)"
1598 status=${res:${#res}-3}
1599 if [ $status -ne $1 ]; then
1600 __log_test_fail_status_code $1 $status
1603 if [ $# -gt 2 ]; then
1604 body=${res:0:${#res}-3}
1606 if [ $# -gt 3 ]; then
1608 for ((i=0; i<$(($#-3)); i=i+5)); do
1609 if [ "$targetJson" != "[" ]; then
1610 targetJson=$targetJson","
1612 if [ -f ${arr[$i+4]} ]; then
1613 jobfile=$(cat ${arr[$i+4]})
1614 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1616 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1619 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}"
1622 targetJson=$targetJson"]"
1624 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1625 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1627 if [ $res -ne 0 ]; then
1628 __log_test_fail_body
1637 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1638 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1639 # (Function for test scripts)
1640 ecs_api_edp_get_producer_jobs_2() {
1643 #Valid number of parameter 2,3,7,11
1645 if [ $# -eq 2 ]; then
1648 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1651 variablecount=$(($#-2))
1652 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1655 if [ $paramError -eq 1 ]; then
1656 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1660 query="/ei-producer/v1/eiproducers/$2/eijobs"
1661 res="$(__do_curl_to_api ECS GET $query)"
1662 status=${res:${#res}-3}
1663 if [ $status -ne $1 ]; then
1664 __log_test_fail_status_code $1 $status
1667 if [ $# -gt 2 ]; then
1668 body=${res:0:${#res}-3}
1670 if [ $# -gt 3 ]; then
1672 for ((i=0; i<$(($#-3)); i=i+5)); do
1673 if [ "$targetJson" != "[" ]; then
1674 targetJson=$targetJson","
1676 if [ -f ${arr[$i+4]} ]; then
1677 jobfile=$(cat ${arr[$i+4]})
1678 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1680 _log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1683 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\":\"????\"}"
1686 targetJson=$targetJson"]"
1688 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1689 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1691 if [ $res -ne 0 ]; then
1692 __log_test_fail_body
1701 ##########################################
1702 #### Service status ####
1703 ##########################################
1704 # Function prefix: ecs_api_service
1706 # API Test function: GET /status
1707 # args: <response-code>
1708 # (Function for test scripts)
1709 ecs_api_service_status() {
1712 if [ $# -lt 1 ]; then
1713 __print_err "<response-code> [<producer-id>]*|NOID" $@
1716 res="$(__do_curl_to_api ECS GET /status)"
1717 status=${res:${#res}-3}
1718 if [ $status -ne $1 ]; then
1719 __log_test_fail_status_code $1 $status
1727 ##########################################
1728 #### Reset jobs ####
1729 ##########################################
1730 # Function prefix: ecs_api_admin
1732 # Admin to remove all jobs
1733 # args: <response-code> [ <type> ]
1734 # (Function for test scripts)
1736 ecs_api_admin_reset() {
1739 if [ -z "$FLAT_A1_EI" ]; then
1740 query="/A1-EI/v1/eitypes/$2/eijobs"
1742 query="/A1-EI/v1/eijobs"
1744 res="$(__do_curl_to_api ECS GET $query)"
1745 status=${res:${#res}-3}
1747 if [ $status -ne 200 ]; then
1748 __log_test_fail_status_code $1 $status
1752 #Remove brackets and response code
1753 body=${res:1:${#res}-4}
1754 list=$(echo ${body//,/ })
1755 list=$(echo ${list//[/})
1756 list=$(echo ${list//]/})
1757 list=$(echo ${list//\"/})
1759 for job in $list; do
1760 if [ -z "$FLAT_A1_EI" ]; then
1761 echo "Not supported for non-flat EI api"
1763 query="/A1-EI/v1/eijobs/$job"
1764 res="$(__do_curl_to_api ECS DELETE $query)"
1765 status=${res:${#res}-3}
1766 if [ $status -ne 204 ]; then
1767 __log_test_fail_status_code $1 $status
1770 echo " Deleted job: "$job
1778 ##########################################
1779 #### Reset jobs and producers ####
1780 ##########################################
1783 # Admin reset to remove all data in ecs; jobs, producers etc
1784 # NOTE - only works in kubernetes and the pod should not be running
1786 # (Function for test scripts)
1788 ecs_kube_pvc_reset() {
1791 __kube_clean_pvc $ECS_APP_NAME nonrtric enrichmentservice-pvc /var/enrichment-coordinator-service/database