Test env updates
[nonrtric.git] / test / common / ecs_api_functions.sh
1 #!/bin/bash
2
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
9 #
10 #       http://www.apache.org/licenses/LICENSE-2.0
11 #
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=================================================
18 #
19
20 # This is a script that contains container/service management functions and test functions for ECS
21
22 ################ Test engine functions ################
23
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
27 __ECS_imagesetup() {
28         __check_and_create_image_var ECS "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $1 "$ECS_DISPLAY_NAME"
29 }
30
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'
36 __ECS_imagepull() {
37         __check_and_pull_image $1 "$ECS_DISPLAY_NAME" $ECS_APP_NAME ECS_IMAGE
38 }
39
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
43 __ECS_imagebuild() {
44         echo -e $RED" Image for app ECS shall never be built"$ERED
45 }
46
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>
50 __ECS_image_data() {
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
54         fi
55 }
56
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
62 }
63
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
68 }
69
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
74 }
75
76 # Store docker logs
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
81 }
82 #######################################################
83
84
85 ## Access to ECS
86 # Host name may be changed if app started by kube
87 # Direct access
88 ECS_HTTPX="http"
89 ECS_HOST_NAME=$LOCALHOST_NAME
90 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
91
92 # ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
93 ECS_ADAPTER_TYPE="REST"
94 ECS_ADAPTER=$ECS_PATH
95
96 # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
97 ECS_RETRY_CODES=""
98
99 #Save first worker node the pod is started on
100 __ECS_WORKER_NODE=""
101
102 ###########################
103 ### ECS functions
104 ###########################
105
106 # All calls to ECS will be directed to the ECS REST interface from now on
107 # args: -
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"
112         ECS_HTTPX="http"
113         ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
114
115         ECS_ADAPTER_TYPE="REST"
116         ECS_ADAPTER=$ECS_PATH
117         echo ""
118 }
119
120 # All calls to ECS will be directed to the ECS REST interface from now on
121 # args: -
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"
126         ECS_HTTPX="https"
127         ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
128
129         ECS_ADAPTER_TYPE="REST"
130         ECS_ADAPTER=$ECS_PATH
131         echo ""
132 }
133
134 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
135 # args: -
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"
142         echo ""
143 }
144
145 # All calls to ECS will be directed to the ECS dmaap interface over https from now on
146 # args: -
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"
153         echo ""
154 }
155
156 # Start the ECS
157 # args: PROXY|NOPROXY <config-file>
158 # (Function for test scripts)
159 start_ecs() {
160
161         echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
162
163         if [ $RUNMODE == "KUBE" ]; then
164
165                 # Check if app shall be fully managed by the test script
166                 __check_included_image "ECS"
167                 retcode_i=$?
168
169                 # Check if app shall only be used by the testscipt
170                 __check_prestarted_image "ECS"
171                 retcode_p=$?
172
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
176                         exit
177                 fi
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
181                         exit
182                 fi
183
184
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                         res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
189                         __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
190                 fi
191
192                 # Check if app shall be fully managed by the test script
193                 if [ $retcode_i -eq 0 ]; then
194                         echo -e " Creating $ECS_APP_NAME app and expose service"
195
196                         #Check if nonrtric namespace exists, if not create it
197                         __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
198
199                         export ECS_APP_NAME
200                         export KUBE_NONRTRIC_NAMESPACE
201                         export ECS_IMAGE
202                         export ECS_INTERNAL_PORT
203                         export ECS_INTERNAL_SECURE_PORT
204                         export ECS_EXTERNAL_PORT
205                         export ECS_EXTERNAL_SECURE_PORT
206                         export ECS_CONFIG_MOUNT_PATH
207                         export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
208                         export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
209                         export ECS_CONTAINER_MNT_DIR
210
211                         export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
212                         export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc"
213                         #Create a unique path for the pv each time to prevent a previous volume to be reused
214                         export ECS_PV_PATH="ecsdata-"$(date +%s)
215
216                         if [ $1 == "PROXY" ]; then
217                                 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT  #Set if proxy is started
218                                 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
219                                 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
220                                         echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
221                                 else
222                                         echo " Configured with http proxy"
223                                 fi
224                         else
225                                 ECS_HTTP_PROXY_CONFIG_PORT=0
226                                 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
227                                 echo " Configured without http proxy"
228                         fi
229                         export ECS_HTTP_PROXY_CONFIG_PORT
230                         export ECS_HTTP_PROXY_CONFIG_HOST_NAME
231
232                         # Create config map for config
233                         datafile=$PWD/tmp/$ECS_CONFIG_FILE
234                         cp $2 $datafile
235                         output_yaml=$PWD/tmp/ecs_cfc.yaml
236                         __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
237
238                         # Create pv
239                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
240                         output_yaml=$PWD/tmp/ecs_pv.yaml
241                         __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
242
243                         # Create pvc
244                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
245                         output_yaml=$PWD/tmp/ecs_pvc.yaml
246                         __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
247
248                         # Create service
249                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
250                         output_yaml=$PWD/tmp/ecs_svc.yaml
251                         __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
252
253                         # Create app
254                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
255                         output_yaml=$PWD/tmp/ecs_app.yaml
256                         __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
257                 fi
258
259                 # 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
260                 # 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
262                 # 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
263                 if [ $retcode_i -eq 0 ]; then
264                         __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
265                         if [ -z "$__ECS_WORKER_NODE" ]; then
266                                 echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW
267                         fi
268                 else
269                         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
270                 fi
271
272                 echo " Retrieving host and ports for service..."
273                 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
274                 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
275                 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
276
277                 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
278
279                 if [ $ECS_HTTPX == "http" ]; then
280                         ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
281                 else
282                         ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
283                 fi
284
285                 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
286
287                 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
288                         ECS_ADAPTER=$ECS_PATH
289                 fi
290         else
291                 __check_included_image 'ECS'
292                 if [ $? -eq 1 ]; then
293                         echo -e $RED"The ECS app is not included in this test script"$ERED
294                         echo -e $RED"ECS will not be started"$ERED
295                         exit 1
296                 fi
297
298                 curdir=$PWD
299                 cd $SIM_GROUP
300                 cd ecs
301                 cd $ECS_HOST_MNT_DIR
302                 #cd ..
303                 if [ -d db ]; then
304                         if [ "$(ls -A $DIR)" ]; then
305                                 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
306                                 rm -rf db/*  &> /dev/null
307                                 if [ $? -ne 0 ]; then
308                                         echo -e $RED" Cannot remove database files in: $PWD"$ERED
309                                         exit 1
310                                 fi
311                         fi
312                 else
313                         echo " No files in mounted dir or dir does not exists"
314                 fi
315                 cd $curdir
316
317                 export ECS_APP_NAME
318                 export ECS_APP_NAME_ALIAS
319                 export ECS_HOST_MNT_DIR
320                 export ECS_CONTAINER_MNT_DIR
321                 export ECS_CONFIG_MOUNT_PATH
322                 export ECS_CONFIG_FILE
323                 export ECS_INTERNAL_PORT
324                 export ECS_EXTERNAL_PORT
325                 export ECS_INTERNAL_SECURE_PORT
326                 export ECS_EXTERNAL_SECURE_PORT
327                 export DOCKER_SIM_NWNAME
328                 export ECS_DISPLAY_NAME
329
330                 if [ $1 == "PROXY" ]; then
331                         ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT  #Set if proxy is started
332                         ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
333                         if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
334                                 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
335                         else
336                                 echo " Configured with http proxy"
337                         fi
338                 else
339                         ECS_HTTP_PROXY_CONFIG_PORT=0
340                         ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
341                         echo " Configured without http proxy"
342                 fi
343                 export ECS_HTTP_PROXY_CONFIG_PORT
344                 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
345
346                 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
347
348                 envsubst < $2 > $dest_file
349
350                 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
351
352                 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
353         fi
354         echo ""
355         return 0
356 }
357
358 # Stop the ecs
359 # args: -
360 # args: -
361 # (Function for test scripts)
362 stop_ecs() {
363         echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD
364
365         if [ $RUNMODE == "KUBE" ]; then
366
367                 __check_prestarted_image "ECS"
368                 if [ $? -eq 0 ]; then
369                         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
370                         res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
371                         __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
372                         return 0
373                 fi
374
375                 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
376                 echo "  Deleting the replica set - a new will be started when the app is started"
377                 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS")
378                 if [ $? -ne 0 ]; then
379                         echo -e $RED" Could not delete replica set "$RED
380                         ((RES_CONF_FAIL++))
381                         return 1
382                 fi
383         else
384                 docker stop $ECS_APP_NAME &> ./tmp/.dockererr
385                 if [ $? -ne 0 ]; then
386                         __print_err "Could not stop $ECS_APP_NAME" $@
387                         cat ./tmp/.dockererr
388                         ((RES_CONF_FAIL++))
389                         return 1
390                 fi
391         fi
392         echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
393         echo ""
394         return 0
395 }
396
397 # Start a previously stopped ecs
398 # args: -
399 # (Function for test scripts)
400 start_stopped_ecs() {
401         echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD
402
403         if [ $RUNMODE == "KUBE" ]; then
404
405                 __check_prestarted_image "ECS"
406                 if [ $? -eq 0 ]; then
407                         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
408                         res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
409                         __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
410                         __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
411                         return 0
412                 fi
413
414                 # Tie the PMS to the same worker node it was initially started on
415                 # 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
416                 if [ -z "$__ECS_WORKER_NODE" ]; then
417                         echo -e $RED" No initial worker node found for pod "$RED
418                         ((RES_CONF_FAIL++))
419                         return 1
420                 else
421                         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
422                         echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
423                         tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}')
424                         if [ $? -ne 0 ]; then
425                                 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW
426                         fi
427                         __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
428                 fi
429         else
430                 docker start $ECS_APP_NAME &> ./tmp/.dockererr
431                 if [ $? -ne 0 ]; then
432                         __print_err "Could not start (the stopped) $ECS_APP_NAME" $@
433                         cat ./tmp/.dockererr
434                         ((RES_CONF_FAIL++))
435                         return 1
436                 fi
437         fi
438         __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
439         if [ $? -ne 0 ]; then
440                 return 1
441         fi
442         echo ""
443         return 0
444 }
445
446 # Turn on debug level tracing in ECS
447 # args: -
448 # (Function for test scripts)
449 set_ecs_debug() {
450         echo -e $BOLD"Setting ecs debug logging"$EBOLD
451         curlString="$ECS_PATH$ECS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
452         result=$(__do_curl "$curlString")
453         if [ $? -ne 0 ]; then
454                 __print_err "Could not set debug mode" $@
455                 ((RES_CONF_FAIL++))
456                 return 1
457         fi
458         echo ""
459         return 0
460 }
461
462 # Turn on trace level tracing in ECS
463 # args: -
464 # (Function for test scripts)
465 set_ecs_trace() {
466         echo -e $BOLD"Setting ecs trace logging"$EBOLD
467         curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
468         result=$(__do_curl "$curlString")
469         if [ $? -ne 0 ]; then
470                 __print_err "Could not set trace mode" $@
471                 ((RES_CONF_FAIL++))
472                 return 1
473         fi
474         echo ""
475         return 0
476 }
477
478 # Perform curl retries when making direct call to ECS for the specified http response codes
479 # Speace separated list of http response codes
480 # args: [<response-code>]*
481 use_ecs_retries() {
482         echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
483         ECS_RETRY_CODES=$@
484         echo ""
485         return 0
486 }
487
488 # Check the ecs logs for WARNINGs and ERRORs
489 # args: -
490 # (Function for test scripts)
491 check_ecs_logs() {
492         __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
493 }
494
495
496 # Tests if a variable value in the ECS is equal to a target value and and optional timeout.
497 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
498 # equal to the target or not.
499 # Arg: <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
500 # before setting pass or fail depending on if the variable value becomes equal to the target
501 # value or not.
502 # (Function for test scripts)
503 ecs_equal() {
504         if [ $# -eq 2 ] || [ $# -eq 3 ]; then
505                 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
506         else
507                 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
508         fi
509 }
510
511
512 ##########################################
513 ######### A1-E Enrichment  API ##########
514 ##########################################
515 #Function prefix: ecs_api_a1
516
517 # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
518 # args: <response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
519 # args (flat uri structure): <response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
520 # (Function for test scripts)
521 ecs_api_a1_get_job_ids() {
522         __log_test_start $@
523
524         if [ -z "$FLAT_A1_EI" ]; then
525                 # Valid number of parameters 4,5,6 etc
526         if [ $# -lt 3 ]; then
527                         __print_err "<response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
528                         return 1
529                 fi
530         else
531                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
532                 # Valid number of parameters 4,5,6 etc
533         if [ $# -lt 3 ]; then
534                         __print_err "<response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
535                         return 1
536                 fi
537         fi
538         search=""
539         if [ $3 != "NOWNER" ]; then
540                 search="?owner="$3
541         fi
542
543         if [  -z "$FLAT_A1_EI" ]; then
544                 query="/A1-EI/v1/eitypes/$2/eijobs$search"
545         else
546                 if [ $2 != "NOTYPE" ]; then
547                         if [ -z "$search" ]; then
548                                 search="?eiTypeId="$2
549                         else
550                                 search=$search"&eiTypeId="$2
551                         fi
552                 fi
553                 query="/A1-EI/v1/eijobs$search"
554         fi
555     res="$(__do_curl_to_api ECS GET $query)"
556     status=${res:${#res}-3}
557
558         if [ $status -ne $1 ]; then
559                 __log_test_fail_status_code $1 $status
560                 return 1
561         fi
562
563         if [ $# -gt 3 ]; then
564                 body=${res:0:${#res}-3}
565                 targetJson="["
566
567                 for pid in ${@:4} ; do
568                         if [ "$targetJson" != "[" ]; then
569                                 targetJson=$targetJson","
570                         fi
571                         if [ $pid != "EMPTY" ]; then
572                                 targetJson=$targetJson"\"$pid\""
573                         fi
574                 done
575
576                 targetJson=$targetJson"]"
577                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
578                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
579
580                 if [ $res -ne 0 ]; then
581                         __log_test_fail_body
582                         return 1
583                 fi
584         fi
585
586         __log_test_pass
587         return 0
588 }
589
590 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}
591 # args: <response-code> <type-id> [<schema-file>]
592 # (Function for test scripts)
593 ecs_api_a1_get_type() {
594         __log_test_start $@
595
596     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
597                 __print_err "<response-code> <type-id> [<schema-file>]" $@
598                 return 1
599         fi
600
601         query="/A1-EI/v1/eitypes/$2"
602     res="$(__do_curl_to_api ECS GET $query)"
603     status=${res:${#res}-3}
604
605         if [ $status -ne $1 ]; then
606                 __log_test_fail_status_code $1 $status
607                 return 1
608         fi
609
610         if [ $# -eq 3 ]; then
611                 body=${res:0:${#res}-3}
612                 if [ -f $3 ]; then
613                         schema=$(cat $3)
614                 else
615                         __log_test_fail_general "Schema file "$3", does not exist"
616                         return 1
617                 fi
618                 if [ -z "$FLAT_A1_EI" ]; then
619                         targetJson="{\"eiJobParametersSchema\":$schema}"
620                 else
621                         targetJson=$schema
622                 fi
623                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
624                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
625
626                 if [ $res -ne 0 ]; then
627                         __log_test_fail_body
628                         return 1
629                 fi
630         fi
631
632         __log_test_pass
633         return 0
634 }
635
636 # API Test function: GET /A1-EI/v1/eitypes
637 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
638 # (Function for test scripts)
639 ecs_api_a1_get_type_ids() {
640         __log_test_start $@
641
642     if [ $# -lt 1 ]; then
643                 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
644                 return 1
645         fi
646
647         query="/A1-EI/v1/eitypes"
648     res="$(__do_curl_to_api ECS GET $query)"
649     status=${res:${#res}-3}
650
651         if [ $status -ne $1 ]; then
652                 __log_test_fail_status_code $1 $status
653                 return 1
654         fi
655         if [ $# -gt 1 ]; then
656                 body=${res:0:${#res}-3}
657                 targetJson="["
658                 if [ $2 != "EMPTY" ]; then
659                         for pid in ${@:2} ; do
660                                 if [ "$targetJson" != "[" ]; then
661                                         targetJson=$targetJson","
662                                 fi
663                                 targetJson=$targetJson"\"$pid\""
664                         done
665                 fi
666                 targetJson=$targetJson"]"
667                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
668                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
669
670                 if [ $res -ne 0 ]; then
671                         __log_test_fail_body
672                         return 1
673                 fi
674         fi
675
676         __log_test_pass
677         return 0
678 }
679
680 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
681 # args: <response-code> <type-id> <job-id> [<status>]
682 # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
683 # (Function for test scripts)
684 ecs_api_a1_get_job_status() {
685         __log_test_start $@
686
687         if [ -z "$FLAT_A1_EI" ]; then
688                 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
689                         __print_err "<response-code> <type-id> <job-id> [<status>]" $@
690                         return 1
691                 fi
692
693                 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
694
695                 res="$(__do_curl_to_api ECS GET $query)"
696                 status=${res:${#res}-3}
697
698                 if [ $status -ne $1 ]; then
699                         __log_test_fail_status_code $1 $status
700                         return 1
701                 fi
702                 if [ $# -eq 4 ]; then
703                         body=${res:0:${#res}-3}
704                         targetJson="{\"operationalState\": \"$4\"}"
705                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
706                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
707
708                         if [ $res -ne 0 ]; then
709                                 __log_test_fail_body
710                                 return 1
711                         fi
712                 fi
713         else
714                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
715                 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
716                         __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
717                         return 1
718                 fi
719
720                 query="/A1-EI/v1/eijobs/$2/status"
721
722                 start=$SECONDS
723                 for (( ; ; )); do
724                         res="$(__do_curl_to_api ECS GET $query)"
725                         status=${res:${#res}-3}
726
727                         if [ $# -eq 4 ]; then
728                                 duration=$((SECONDS-start))
729                                 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
730                                 if [ $duration -gt $4 ]; then
731                                         echo ""
732                                         duration=-1  #Last iteration
733                                 fi
734                         else
735                                 duration=-1 #single test, no wait
736                         fi
737
738                         if [ $status -ne $1 ]; then
739                                 if [ $duration -eq -1 ]; then
740                                         __log_test_fail_status_code $1 $status
741                                         return 1
742                                 fi
743                         fi
744                         if [ $# -ge 3 ] && [ $status -eq $1 ]; then
745                                 body=${res:0:${#res}-3}
746                                 targetJson="{\"eiJobStatus\": \"$3\"}"
747                                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
748                                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
749
750                                 if [ $res -ne 0 ]; then
751                                         if [ $duration -eq -1 ]; then
752                                                 __log_test_fail_body
753                                                 return 1
754                                         fi
755                                 else
756                                         duration=-1  #Goto pass
757                                 fi
758                         fi
759                         if [ $duration -eq -1 ]; then
760                                 if [ $# -eq 4 ]; then
761                                         echo ""
762                                 fi
763                                 __log_test_pass
764                                 return 0
765                         else
766                                 sleep 1
767                         fi
768                 done
769         fi
770
771         __log_test_pass
772         return 0
773 }
774
775 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
776 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
777 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
778 # (Function for test scripts)
779 ecs_api_a1_get_job() {
780         __log_test_start $@
781
782         if [  -z "$FLAT_A1_EI" ]; then
783                 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
784                         __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
785                         return 1
786                 fi
787                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
788         else
789                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
790                 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
791                         __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
792                         return 1
793                 fi
794                 query="/A1-EI/v1/eijobs/$2"
795         fi
796     res="$(__do_curl_to_api ECS GET $query)"
797     status=${res:${#res}-3}
798
799         if [ $status -ne $1 ]; then
800                 __log_test_fail_status_code $1 $status
801                 return 1
802         fi
803
804         if [  -z "$FLAT_A1_EI" ]; then
805                 if [ $# -eq 6 ]; then
806                         body=${res:0:${#res}-3}
807
808                         if [ -f $6 ]; then
809                                 jobfile=$(cat $6)
810                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
811                         else
812                                 __log_test_fail_general "Job template file "$6", does not exist"
813                                 return 1
814                         fi
815                         targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
816                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
817                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
818
819                         if [ $res -ne 0 ]; then
820                                 __log_test_fail_body
821                                 return 1
822                         fi
823                 fi
824         else
825                 if [ $# -eq 7 ]; then
826                         body=${res:0:${#res}-3}
827
828                         if [ -f $7 ]; then
829                                 jobfile=$(cat $7)
830                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
831                         else
832                                 __log_test_fail_general "Job template file "$6", does not exist"
833                                 return 1
834                         fi
835                         targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
836                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
837                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
838
839                         if [ $res -ne 0 ]; then
840                                 __log_test_fail_body
841                                 return 1
842                         fi
843                 fi
844         fi
845
846         __log_test_pass
847         return 0
848 }
849
850 # API Test function: DELETE â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
851 # args: <response-code> <type-id> <job-id>
852 # args (flat uri structure): <response-code> <job-id>
853 # (Function for test scripts)
854 ecs_api_a1_delete_job() {
855         __log_test_start $@
856
857         if [  -z "$FLAT_A1_EI" ]; then
858                 if [ $# -ne 3 ]; then
859                         __print_err "<response-code> <type-id> <job-id>" $@
860                         return 1
861                 fi
862
863                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
864         else
865                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
866                 if [ $# -ne 2 ]; then
867                         __print_err "<response-code> <job-id>" $@
868                         return 1
869                 fi
870                 query="/A1-EI/v1/eijobs/$2"
871         fi
872     res="$(__do_curl_to_api ECS DELETE $query)"
873     status=${res:${#res}-3}
874
875         if [ $status -ne $1 ]; then
876                 __log_test_fail_status_code $1 $status
877                 return 1
878         fi
879
880         __log_test_pass
881         return 0
882 }
883
884 # API Test function: PUT â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
885 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
886 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
887 # (Function for test scripts)
888 ecs_api_a1_put_job() {
889         __log_test_start $@
890
891         if [  -z "$FLAT_A1_EI" ]; then
892                 if [ $# -lt 6 ]; then
893                         __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
894                         return 1
895                 fi
896                 if [ -f $6 ]; then
897                         jobfile=$(cat $6)
898                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
899                 else
900                         __log_test_fail_general "Job template file "$6", does not exist"
901                         return 1
902                 fi
903
904                 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
905                 file="./tmp/.p.json"
906                 echo "$inputJson" > $file
907
908                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
909         else
910                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
911                 if [ $# -lt 7 ]; then
912                         __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
913                         return 1
914                 fi
915                 if [ -f $7 ]; then
916                         jobfile=$(cat $7)
917                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
918                 else
919                         __log_test_fail_general "Job template file "$7", does not exist"
920                         return 1
921                 fi
922
923                 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
924                 file="./tmp/.p.json"
925                 echo "$inputJson" > $file
926
927                 query="/A1-EI/v1/eijobs/$2"
928         fi
929
930     res="$(__do_curl_to_api ECS PUT $query $file)"
931     status=${res:${#res}-3}
932
933         if [ $status -ne $1 ]; then
934                 __log_test_fail_status_code $1 $status
935                 return 1
936         fi
937
938         __log_test_pass
939         return 0
940 }
941
942
943 ##########################################
944 ####   Enrichment Data Producer API   ####
945 ##########################################
946 # Function prefix: ecs_api_edp
947
948 # API Test function: GET /ei-producer/v1/eitypes
949 # API Test function: GET /data-producer/v1/info-types
950 # args: <response-code> [ EMPTY | <type-id>+]
951 # (Function for test scripts)
952 ecs_api_edp_get_type_ids() {
953         __log_test_start $@
954
955     if [ $# -lt 1 ]; then
956                 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
957                 return 1
958         fi
959         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
960                 query="/data-producer/v1/info-types"
961         else
962                 query="/ei-producer/v1/eitypes"
963         fi
964     res="$(__do_curl_to_api ECS GET $query)"
965     status=${res:${#res}-3}
966
967         if [ $status -ne $1 ]; then
968                 __log_test_fail_status_code $1 $status
969                 return 1
970         fi
971
972         if [ $# -gt 1 ]; then
973                 body=${res:0:${#res}-3}
974                 targetJson="["
975                 if [ $2 != "EMPTY" ]; then
976                         for pid in ${@:2} ; do
977                                 if [ "$targetJson" != "[" ]; then
978                                         targetJson=$targetJson","
979                                 fi
980                                 targetJson=$targetJson"\"$pid\""
981                         done
982                 fi
983                 targetJson=$targetJson"]"
984                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
985                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
986
987                 if [ $res -ne 0 ]; then
988                         __log_test_fail_body
989                         return 1
990                 fi
991         fi
992
993         __log_test_pass
994         return 0
995 }
996
997 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
998 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
999 # args: <response-code> <producer-id> [<status> [<timeout>]]
1000 # (Function for test scripts)
1001 ecs_api_edp_get_producer_status() {
1002         __log_test_start $@
1003
1004     if [ $# -lt 2 ] || [ $# -gt 4 ]; then
1005                 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
1006                 return 1
1007         fi
1008         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1009                 query="/data-producer/v1/info-producers/$2/status"
1010         else
1011                 query="/ei-producer/v1/eiproducers/$2/status"
1012         fi
1013         start=$SECONDS
1014         for (( ; ; )); do
1015                 res="$(__do_curl_to_api ECS GET $query)"
1016                 status=${res:${#res}-3}
1017
1018                 if [ $# -eq 4 ]; then
1019                         duration=$((SECONDS-start))
1020                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1021                         if [ $duration -gt $4 ]; then
1022                                 echo ""
1023                                 duration=-1  #Last iteration
1024                         fi
1025                 else
1026                         duration=-1 #single test, no wait
1027                 fi
1028
1029                 if [ $status -ne $1 ]; then
1030                         if [ $duration -eq -1 ]; then
1031                                 __log_test_fail_status_code $1 $status
1032                                 return 1
1033                         fi
1034                 fi
1035                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1036                         body=${res:0:${#res}-3}
1037                         targetJson="{\"operational_state\": \"$3\"}"
1038                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
1039                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1040
1041                         if [ $res -ne 0 ]; then
1042                                 if [ $duration -eq -1 ]; then
1043                                         __log_test_fail_body
1044                                         return 1
1045                                 fi
1046                         else
1047                                 duration=-1  #Goto pass
1048                         fi
1049                 fi
1050                 if [ $duration -eq -1 ]; then
1051                         if [ $# -eq 4 ]; then
1052                                 echo ""
1053                         fi
1054                         __log_test_pass
1055                         return 0
1056                 else
1057                         sleep 1
1058                 fi
1059         done
1060 }
1061
1062
1063 # API Test function: GET /ei-producer/v1/eiproducers
1064 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
1065 # (Function for test scripts)
1066 ecs_api_edp_get_producer_ids() {
1067         __log_test_start $@
1068
1069     if [ $# -lt 1 ]; then
1070                 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1071                 return 1
1072         fi
1073
1074         query="/ei-producer/v1/eiproducers"
1075     res="$(__do_curl_to_api ECS GET $query)"
1076     status=${res:${#res}-3}
1077
1078         if [ $status -ne $1 ]; then
1079                 __log_test_fail_status_code $1 $status
1080                 return 1
1081         fi
1082
1083         if [ $# -gt 1 ]; then
1084                 body=${res:0:${#res}-3}
1085                 targetJson="["
1086
1087                 for pid in ${@:2} ; do
1088                         if [ "$targetJson" != "[" ]; then
1089                                 targetJson=$targetJson","
1090                         fi
1091                         if [ $pid != "EMPTY" ]; then
1092                                 targetJson=$targetJson"\"$pid\""
1093                         fi
1094                 done
1095
1096                 targetJson=$targetJson"]"
1097                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1098                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1099
1100                 if [ $res -ne 0 ]; then
1101                         __log_test_fail_body
1102                         return 1
1103                 fi
1104         fi
1105
1106         __log_test_pass
1107         return 0
1108 }
1109
1110 # API Test function: GET /ei-producer/v1/eiproducers
1111 # API Test function: GET /data-producer/v1/info-producers
1112 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1113 # (Function for test scripts)
1114 ecs_api_edp_get_producer_ids_2() {
1115         __log_test_start $@
1116
1117     if [ $# -lt 1 ]; then
1118                 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1119                 return 1
1120         fi
1121     if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1122                 query="/data-producer/v1/info-producers"
1123                 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1124                         query=$query"?info_type_id=$2"
1125                 fi
1126         else
1127                 query="/ei-producer/v1/eiproducers"
1128                 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1129                         query=$query"?ei_type_id=$2"
1130                 fi
1131         fi
1132     res="$(__do_curl_to_api ECS GET $query)"
1133     status=${res:${#res}-3}
1134
1135         if [ $status -ne $1 ]; then
1136                 __log_test_fail_status_code $1 $status
1137                 return 1
1138         fi
1139
1140         if [ $# -gt 2 ]; then
1141                 body=${res:0:${#res}-3}
1142                 targetJson="["
1143
1144                 for pid in ${@:3} ; do
1145                         if [ "$targetJson" != "[" ]; then
1146                                 targetJson=$targetJson","
1147                         fi
1148                         if [ $pid != "EMPTY" ]; then
1149                                 targetJson=$targetJson"\"$pid\""
1150                         fi
1151                 done
1152
1153                 targetJson=$targetJson"]"
1154                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1155                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1156
1157                 if [ $res -ne 0 ]; then
1158                         __log_test_fail_body
1159                         return 1
1160                 fi
1161         fi
1162
1163         __log_test_pass
1164         return 0
1165 }
1166
1167 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1168 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1169 # (Function for test scripts)
1170 ecs_api_edp_get_type() {
1171         __log_test_start $@
1172
1173         paramError=1
1174         if [ $# -eq 2 ]; then
1175                 paramError=0
1176         fi
1177         if [ $# -gt 3 ]; then
1178                 paramError=0
1179         fi
1180     if [ $paramError -ne 0 ]; then
1181                 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1182                 return 1
1183         fi
1184
1185         query="/ei-producer/v1/eitypes/$2"
1186     res="$(__do_curl_to_api ECS GET $query)"
1187     status=${res:${#res}-3}
1188
1189         if [ $status -ne $1 ]; then
1190                 __log_test_fail_status_code $1 $status
1191                 return 1
1192         fi
1193         if [ $# -gt 3 ]; then
1194                 body=${res:0:${#res}-3}
1195
1196                 if [ -f $3 ]; then
1197                         schema=$(cat $3)
1198                 else
1199                         __log_test_fail_general "Job template file "$3", does not exist"
1200                         return 1
1201                 fi
1202
1203                 targetJson=""
1204                 if [ $4 != "EMPTY" ]; then
1205                         for pid in ${@:4} ; do
1206                                 if [ "$targetJson" != "" ]; then
1207                                         targetJson=$targetJson","
1208                                 fi
1209                                 targetJson=$targetJson"\"$pid\""
1210                         done
1211                 fi
1212                 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1213
1214                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1215                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1216
1217                 if [ $res -ne 0 ]; then
1218                         __log_test_fail_body
1219                         return 1
1220                 fi
1221         fi
1222         __log_test_pass
1223         return 0
1224 }
1225
1226 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1227 # API Test function: GET /data-producer/v1/info-types/{infoTypeId}
1228 # args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
1229 # (Function for test scripts)
1230 ecs_api_edp_get_type_2() {
1231         __log_test_start $@
1232
1233         paramError=1
1234         if [ $# -eq 2 ]; then
1235                 paramError=0
1236         fi
1237         if [ $# -eq 3 ]; then
1238                 paramError=0
1239         fi
1240         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1241                 if [ $# -eq 4 ]; then
1242                         paramError=0
1243                 fi
1244         fi
1245     if [ $paramError -ne 0 ]; then
1246                 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
1247                 return 1
1248         fi
1249         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1250                 query="/data-producer/v1/info-types/$2"
1251         else
1252                 query="/ei-producer/v1/eitypes/$2"
1253         fi
1254
1255     res="$(__do_curl_to_api ECS GET $query)"
1256     status=${res:${#res}-3}
1257
1258         if [ $status -ne $1 ]; then
1259                 __log_test_fail_status_code $1 $status
1260                 return 1
1261         fi
1262         if [ $# -ge 3 ]; then
1263                 body=${res:0:${#res}-3}
1264
1265                 if [ -f $3 ]; then
1266                         schema=$(cat $3)
1267                 else
1268                         __log_test_fail_general "Job template file "$3", does not exist"
1269                         return 1
1270                 fi
1271                 info_data=""
1272                 if [ $# -gt 3 ]; then
1273                         if [ -f $4 ]; then
1274                                 info_data=$(cat $4)
1275                         else
1276                                 __log_test_fail_general "Info-data file "$4", does not exist"
1277                                 return 1
1278                         fi
1279                         info_data=",\"info_type_information\":$info_data"
1280                 fi
1281                 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1282                         targetJson="{\"info_job_data_schema\":$schema $info_data}"
1283                 else
1284                         targetJson="{\"ei_job_data_schema\":$schema}"
1285                 fi
1286
1287                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1288                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1289
1290                 if [ $res -ne 0 ]; then
1291                         __log_test_fail_body
1292                         return 1
1293                 fi
1294         fi
1295         __log_test_pass
1296         return 0
1297 }
1298
1299 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1300 # API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
1301 # args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
1302 # (Function for test scripts)
1303 ecs_api_edp_put_type_2() {
1304         __log_test_start $@
1305
1306         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1307                 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1308                         __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1309                         return 1
1310                 fi
1311         else
1312                 if [ $# -ne 3 ]; then
1313                         __print_err "<response-code> <type-id> <job-schema-file>" $@
1314                         return 1
1315                 fi
1316         fi
1317
1318         if [ ! -f $3 ]; then
1319                 __log_test_fail_general "Job schema file "$3", does not exist"
1320                 return 1
1321         fi
1322
1323         info_data=""
1324         if [ $# -gt 3 ]; then
1325                 if [ -f $4 ]; then
1326                         info_data=$(cat $4)
1327                 else
1328                         __log_test_fail_general "Info-data file "$4", does not exist"
1329                         return 1
1330                 fi
1331                 info_data=",\"info_type_information\":$info_data"
1332         fi
1333
1334         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1335                 schema=$(cat $3)
1336                 input_json="{\"info_job_data_schema\":$schema $info_data}"
1337                 file="./tmp/put_type.json"
1338                 echo $input_json > $file
1339
1340                 query="/data-producer/v1/info-types/$2"
1341         else
1342                 schema=$(cat $3)
1343                 input_json="{\"ei_job_data_schema\":$schema}"
1344                 file="./tmp/put_type.json"
1345                 echo $input_json > $file
1346
1347                 query="/ei-producer/v1/eitypes/$2"
1348         fi
1349     res="$(__do_curl_to_api ECS PUT $query $file)"
1350     status=${res:${#res}-3}
1351
1352         if [ $status -ne $1 ]; then
1353                 __log_test_fail_status_code $1 $status
1354                 return 1
1355         fi
1356
1357         __log_test_pass
1358         return 0
1359 }
1360
1361 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1362 # API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
1363 # args: (v1_2) <response-code> <type-id>
1364 # (Function for test scripts)
1365 ecs_api_edp_delete_type_2() {
1366         __log_test_start $@
1367
1368     if [ $# -ne 2 ]; then
1369                 __print_err "<response-code> <type-id>" $@
1370                 return 1
1371         fi
1372
1373         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1374                 query="/data-producer/v1/info-types/$2"
1375         else
1376                 query="/ei-producer/v1/eitypes/$2"
1377         fi
1378     res="$(__do_curl_to_api ECS DELETE $query)"
1379     status=${res:${#res}-3}
1380
1381         if [ $status -ne $1 ]; then
1382                 __log_test_fail_status_code $1 $status
1383                 return 1
1384         fi
1385
1386         __log_test_pass
1387         return 0
1388 }
1389
1390 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1391 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1392 # (Function for test scripts)
1393 ecs_api_edp_get_producer() {
1394         __log_test_start $@
1395
1396         #Possible arg count: 2, 5 6, 8, 10 etc
1397         paramError=1
1398         if [ $# -eq 2 ]; then
1399                 paramError=0
1400         fi
1401         if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1402                 paramError=0
1403         fi
1404         variablecount=$(($#-4))
1405         if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1406                 paramError=0
1407         fi
1408
1409     if [ $paramError -ne 0 ]; then
1410                 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1411                 return 1
1412         fi
1413
1414         query="/ei-producer/v1/eiproducers/$2"
1415     res="$(__do_curl_to_api ECS GET $query)"
1416     status=${res:${#res}-3}
1417
1418         if [ $status -ne $1 ]; then
1419                 __log_test_fail_status_code $1 $status
1420                 return 1
1421         fi
1422
1423         if [ $# -gt 2 ]; then
1424                 body=${res:0:${#res}-3}
1425                 targetJson="["
1426                 if [ $# -gt 5 ]; then
1427                         arr=(${@:5})
1428                         for ((i=0; i<$(($#-5)); i=i+2)); do
1429                                 if [ "$targetJson" != "[" ]; then
1430                                         targetJson=$targetJson","
1431                                 fi
1432                                 if [ -f ${arr[$i+1]} ]; then
1433                                         schema=$(cat ${arr[$i+1]})
1434                                 else
1435                                         __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1436                                         return 1
1437                                 fi
1438
1439                                 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1440                         done
1441                 fi
1442                 targetJson=$targetJson"]"
1443                 if [ $# -gt 4 ]; then
1444                         targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1445                 fi
1446                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1447                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1448
1449                 if [ $res -ne 0 ]; then
1450                         __log_test_fail_body
1451                         return 1
1452                 fi
1453         fi
1454
1455         __log_test_pass
1456         return 0
1457 }
1458
1459 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1460 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
1461 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1462 # (Function for test scripts)
1463 ecs_api_edp_get_producer_2() {
1464         __log_test_start $@
1465
1466         #Possible arg count: 2, 5, 6, 7, 8 etc
1467         paramError=1
1468         if [ $# -eq 2 ]; then
1469                 paramError=0
1470         fi
1471         if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1472                 paramError=0
1473         fi
1474         if [ $# -ge 5 ]; then
1475                 paramError=0
1476         fi
1477
1478     if [ $paramError -ne 0 ]; then
1479                 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1480                 return 1
1481         fi
1482         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1483                 query="/data-producer/v1/info-producers/$2"
1484         else
1485                 query="/ei-producer/v1/eiproducers/$2"
1486         fi
1487     res="$(__do_curl_to_api ECS GET $query)"
1488     status=${res:${#res}-3}
1489
1490         if [ $status -ne $1 ]; then
1491                 __log_test_fail_status_code $1 $status
1492                 return 1
1493         fi
1494
1495         if [ $# -gt 2 ]; then
1496                 body=${res:0:${#res}-3}
1497                 targetJson="["
1498                 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1499                         arr=(${@:5})
1500                         for ((i=0; i<$(($#-4)); i=i+1)); do
1501                                 if [ "$targetJson" != "[" ]; then
1502                                         targetJson=$targetJson","
1503                                 fi
1504                                 targetJson=$targetJson"\"${arr[$i]}\""
1505                         done
1506                 fi
1507                 targetJson=$targetJson"]"
1508                 if [ $# -gt 4 ]; then
1509                         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1510                                 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1511                         else
1512                                 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1513                         fi
1514                 fi
1515                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1516                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1517
1518                 if [ $res -ne 0 ]; then
1519                         __log_test_fail_body
1520                         return 1
1521                 fi
1522         fi
1523
1524         __log_test_pass
1525         return 0
1526 }
1527
1528 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1529 # API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
1530 # args: <response-code> <producer-id>
1531 # (Function for test scripts)
1532 ecs_api_edp_delete_producer() {
1533         __log_test_start $@
1534
1535     if [ $# -lt 2 ]; then
1536                 __print_err "<response-code> <producer-id>" $@
1537                 return 1
1538         fi
1539         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1540                 query="/data-producer/v1/info-producers/$2"
1541         else
1542                 query="/ei-producer/v1/eiproducers/$2"
1543         fi
1544     res="$(__do_curl_to_api ECS DELETE $query)"
1545     status=${res:${#res}-3}
1546
1547         if [ $status -ne $1 ]; then
1548                 __log_test_fail_status_code $1 $status
1549                 return 1
1550         fi
1551
1552         __log_test_pass
1553         return 0
1554 }
1555
1556 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1557 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1558 # (Function for test scripts)
1559 ecs_api_edp_put_producer() {
1560         __log_test_start $@
1561
1562         #Valid number of parametrer 5,6,8,10,
1563         paramError=1
1564         if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1565                 paramError=0
1566         elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1567                 paramError=0
1568         fi
1569         if [ $paramError -ne 0 ]; then
1570                 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1571                 return 1
1572         fi
1573
1574         inputJson="["
1575         if [ $# -gt 5 ]; then
1576                 arr=(${@:5})
1577                 for ((i=0; i<$(($#-5)); i=i+2)); do
1578                         if [ "$inputJson" != "[" ]; then
1579                                 inputJson=$inputJson","
1580                         fi
1581                         if [ -f ${arr[$i+1]} ]; then
1582                                 schema=$(cat ${arr[$i+1]})
1583                         else
1584                                 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1585                                 return 1
1586                         fi
1587                         inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1588                 done
1589         fi
1590         inputJson="\"supported_ei_types\":"$inputJson"]"
1591
1592         inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1593
1594         inputJson="{"$inputJson"}"
1595
1596         file="./tmp/.p.json"
1597         echo "$inputJson" > $file
1598         query="/ei-producer/v1/eiproducers/$2"
1599     res="$(__do_curl_to_api ECS PUT $query $file)"
1600     status=${res:${#res}-3}
1601
1602         if [ $status -ne $1 ]; then
1603                 __log_test_fail_status_code $1 $status
1604                 return 1
1605         fi
1606
1607         __log_test_pass
1608         return 0
1609 }
1610
1611 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1612 # API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
1613 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1614 # (Function for test scripts)
1615 ecs_api_edp_put_producer_2() {
1616         __log_test_start $@
1617
1618         #Valid number of parametrer 5,6,8,10,
1619         paramError=1
1620         if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1621                 paramError=0
1622         elif [ $# -ge 5 ]; then
1623                 paramError=0
1624         fi
1625         if [ $paramError -ne 0 ]; then
1626                 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1627                 return 1
1628         fi
1629
1630         inputJson="["
1631         if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1632                 arr=(${@:5})
1633                 for ((i=0; i<$(($#-4)); i=i+1)); do
1634                         if [ "$inputJson" != "[" ]; then
1635                                 inputJson=$inputJson","
1636                         fi
1637                         inputJson=$inputJson"\""${arr[$i]}"\""
1638                 done
1639         fi
1640         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1641                 inputJson="\"supported_info_types\":"$inputJson"]"
1642
1643                 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
1644
1645                 inputJson="{"$inputJson"}"
1646
1647                 file="./tmp/.p.json"
1648                 echo "$inputJson" > $file
1649                 query="/data-producer/v1/info-producers/$2"
1650         else
1651                 inputJson="\"supported_ei_types\":"$inputJson"]"
1652
1653                 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1654
1655                 inputJson="{"$inputJson"}"
1656
1657                 file="./tmp/.p.json"
1658                 echo "$inputJson" > $file
1659                 query="/ei-producer/v1/eiproducers/$2"
1660         fi
1661     res="$(__do_curl_to_api ECS PUT $query $file)"
1662     status=${res:${#res}-3}
1663
1664         if [ $status -ne $1 ]; then
1665                 __log_test_fail_status_code $1 $status
1666                 return 1
1667         fi
1668
1669         __log_test_pass
1670         return 0
1671 }
1672
1673 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1674 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1675 # (Function for test scripts)
1676 ecs_api_edp_get_producer_jobs() {
1677         __log_test_start $@
1678
1679         #Valid number of parameter 2,3,7,11
1680         paramError=1
1681         if [ $# -eq 2 ]; then
1682                 paramError=0
1683         fi
1684         if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1685                 paramError=0
1686         fi
1687         variablecount=$(($#-2))
1688         if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1689                 paramError=0
1690         fi
1691         if [ $paramError -eq 1 ]; then
1692                 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1693                 return 1
1694         fi
1695
1696         query="/ei-producer/v1/eiproducers/$2/eijobs"
1697     res="$(__do_curl_to_api ECS GET $query)"
1698     status=${res:${#res}-3}
1699         if [ $status -ne $1 ]; then
1700                 __log_test_fail_status_code $1 $status
1701                 return 1
1702         fi
1703         if [ $# -gt 2 ]; then
1704                 body=${res:0:${#res}-3}
1705                 targetJson="["
1706                 if [ $# -gt 3 ]; then
1707                         arr=(${@:3})
1708                         for ((i=0; i<$(($#-3)); i=i+5)); do
1709                                 if [ "$targetJson" != "[" ]; then
1710                                         targetJson=$targetJson","
1711                                 fi
1712                                 if [ -f ${arr[$i+4]} ]; then
1713                                         jobfile=$(cat ${arr[$i+4]})
1714                                         jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1715                                 else
1716                                         __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1717                                         return 1
1718                                 fi
1719                                 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}"
1720                         done
1721                 fi
1722                 targetJson=$targetJson"]"
1723
1724                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1725                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1726
1727                 if [ $res -ne 0 ]; then
1728                         __log_test_fail_body
1729                         return 1
1730                 fi
1731         fi
1732
1733         __log_test_pass
1734         return 0
1735 }
1736
1737 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1738 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
1739 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1740 # (Function for test scripts)
1741 ecs_api_edp_get_producer_jobs_2() {
1742         __log_test_start $@
1743
1744         #Valid number of parameter 2,3,7,11
1745         paramError=1
1746         if [ $# -eq 2 ]; then
1747                 paramError=0
1748         fi
1749         if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1750                 paramError=0
1751         fi
1752         variablecount=$(($#-2))
1753         if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1754                 paramError=0
1755         fi
1756         if [ $paramError -eq 1 ]; then
1757                 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1758                 return 1
1759         fi
1760         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1761                 query="/data-producer/v1/info-producers/$2/info-jobs"
1762         else
1763                 query="/ei-producer/v1/eiproducers/$2/eijobs"
1764         fi
1765     res="$(__do_curl_to_api ECS GET $query)"
1766     status=${res:${#res}-3}
1767         if [ $status -ne $1 ]; then
1768                 __log_test_fail_status_code $1 $status
1769                 return 1
1770         fi
1771         if [ $# -gt 2 ]; then
1772                 body=${res:0:${#res}-3}
1773                 targetJson="["
1774                 if [ $# -gt 3 ]; then
1775                         arr=(${@:3})
1776                         for ((i=0; i<$(($#-3)); i=i+5)); do
1777                                 if [ "$targetJson" != "[" ]; then
1778                                         targetJson=$targetJson","
1779                                 fi
1780                                 if [ -f ${arr[$i+4]} ]; then
1781                                         jobfile=$(cat ${arr[$i+4]})
1782                                         jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1783                                 else
1784                                         __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1785                                         return 1
1786                                 fi
1787                                 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1788                                         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\":\"????\"}"
1789                                 else
1790                                         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\":\"????\"}"
1791                                 fi
1792                         done
1793                 fi
1794                 targetJson=$targetJson"]"
1795
1796                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1797                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1798
1799                 if [ $res -ne 0 ]; then
1800                         __log_test_fail_body
1801                         return 1
1802                 fi
1803         fi
1804
1805         __log_test_pass
1806         return 0
1807 }
1808
1809 ##########################################
1810 ####          Service status          ####
1811 ##########################################
1812 # Function prefix: ecs_api_service
1813
1814 # API Test function: GET â€‹/status
1815 # args: <response-code>
1816 # (Function for test scripts)
1817 ecs_api_service_status() {
1818         __log_test_start $@
1819
1820     if [ $# -lt 1 ]; then
1821                 __print_err "<response-code>" $@
1822                 return 1
1823         fi
1824         res="$(__do_curl_to_api ECS GET /status)"
1825     status=${res:${#res}-3}
1826         if [ $status -ne $1 ]; then
1827                 __log_test_fail_status_code $1 $status
1828                 return 1
1829         fi
1830         __log_test_pass
1831         return 0
1832 }
1833
1834 ###########################################
1835 ######### Info data consumer API ##########
1836 ###########################################
1837 #Function prefix: ecs_api_idc
1838
1839
1840 # API Test function: GET /data-consumer/v1/info-types
1841 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
1842 # (Function for test scripts)
1843 ecs_api_idc_get_type_ids() {
1844         __log_test_start $@
1845
1846     if [ $# -lt 1 ]; then
1847                 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1848                 return 1
1849         fi
1850
1851         query="/data-consumer/v1/info-types"
1852     res="$(__do_curl_to_api ECS GET $query)"
1853     status=${res:${#res}-3}
1854
1855         if [ $status -ne $1 ]; then
1856                 __log_test_fail_status_code $1 $status
1857                 return 1
1858         fi
1859         if [ $# -gt 1 ]; then
1860                 body=${res:0:${#res}-3}
1861                 targetJson="["
1862                 if [ $2 != "EMPTY" ]; then
1863                         for pid in ${@:2} ; do
1864                                 if [ "$targetJson" != "[" ]; then
1865                                         targetJson=$targetJson","
1866                                 fi
1867                                 targetJson=$targetJson"\"$pid\""
1868                         done
1869                 fi
1870                 targetJson=$targetJson"]"
1871                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1872                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1873
1874                 if [ $res -ne 0 ]; then
1875                         __log_test_fail_body
1876                         return 1
1877                 fi
1878         fi
1879
1880         __log_test_pass
1881         return 0
1882 }
1883
1884 # API Test function: GET /data-consumer/v1/info-jobs
1885 # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1886 # (Function for test scripts)
1887 ecs_api_idc_get_job_ids() {
1888         __log_test_start $@
1889
1890         # Valid number of parameters 4,5,6 etc
1891         if [ $# -lt 3 ]; then
1892                 __print_err "<response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1893                 return 1
1894         fi
1895         search=""
1896         if [ $3 != "NOWNER" ]; then
1897                 search="?owner="$3
1898         fi
1899
1900         if [ $2 != "NOTYPE" ]; then
1901                 if [ -z "$search" ]; then
1902                         search="?infoTypeId="$2
1903                 else
1904                         search=$search"&infoTypeId="$2
1905                 fi
1906         fi
1907         query="/data-consumer/v1/info-jobs$search"
1908
1909     res="$(__do_curl_to_api ECS GET $query)"
1910     status=${res:${#res}-3}
1911
1912         if [ $status -ne $1 ]; then
1913                 __log_test_fail_status_code $1 $status
1914                 return 1
1915         fi
1916
1917         if [ $# -gt 3 ]; then
1918                 body=${res:0:${#res}-3}
1919                 targetJson="["
1920
1921                 for pid in ${@:4} ; do
1922                         if [ "$targetJson" != "[" ]; then
1923                                 targetJson=$targetJson","
1924                         fi
1925                         if [ $pid != "EMPTY" ]; then
1926                                 targetJson=$targetJson"\"$pid\""
1927                         fi
1928                 done
1929
1930                 targetJson=$targetJson"]"
1931                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1932                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1933
1934                 if [ $res -ne 0 ]; then
1935                         __log_test_fail_body
1936                         return 1
1937                 fi
1938         fi
1939
1940         __log_test_pass
1941         return 0
1942 }
1943
1944 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1945 # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1946 # (Function for test scripts)
1947 ecs_api_idc_get_job() {
1948         __log_test_start $@
1949
1950         if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1951                 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1952                 return 1
1953         fi
1954         query="/data-consumer/v1/info-jobs/$2"
1955     res="$(__do_curl_to_api ECS GET $query)"
1956     status=${res:${#res}-3}
1957
1958         if [ $status -ne $1 ]; then
1959                 __log_test_fail_status_code $1 $status
1960                 return 1
1961         fi
1962
1963         if [ $# -eq 7 ]; then
1964                 body=${res:0:${#res}-3}
1965
1966                 if [ -f $7 ]; then
1967                         jobfile=$(cat $7)
1968                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1969                 else
1970                         __log_test_fail_general "Job template file "$6", does not exist"
1971                         return 1
1972                 fi
1973                 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1974                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1975                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1976
1977                 if [ $res -ne 0 ]; then
1978                         __log_test_fail_body
1979                         return 1
1980                 fi
1981         fi
1982
1983         __log_test_pass
1984         return 0
1985 }
1986
1987
1988 # API Test function: PUT â€‹/data-consumer/v1/info-jobs/{infoJobId}
1989 # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1990 # (Function for test scripts)
1991 ecs_api_idc_put_job() {
1992         __log_test_start $@
1993
1994         if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1995                 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1996                 return 1
1997         fi
1998         if [ -f $7 ]; then
1999                 jobfile=$(cat $7)
2000                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
2001         else
2002                 __log_test_fail_general "Job template file "$7", does not exist"
2003                 return 1
2004         fi
2005
2006         inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
2007         file="./tmp/.p.json"
2008         echo "$inputJson" > $file
2009
2010         query="/data-consumer/v1/info-jobs/$2"
2011
2012         if [ $# -eq 8 ]; then
2013                 if [ $8 == "VALIDATE" ]; then
2014                         query=$query"?typeCheck=true"
2015                 fi
2016         fi
2017
2018     res="$(__do_curl_to_api ECS PUT $query $file)"
2019     status=${res:${#res}-3}
2020
2021         if [ $status -ne $1 ]; then
2022                 __log_test_fail_status_code $1 $status
2023                 return 1
2024         fi
2025
2026         __log_test_pass
2027         return 0
2028 }
2029
2030 # API Test function: DELETE â€‹/data-consumer/v1/info-jobs/{infoJobId}
2031 # args: <response-code> <job-id>
2032 # (Function for test scripts)
2033 ecs_api_idc_delete_job() {
2034         __log_test_start $@
2035
2036         if [ $# -ne 2 ]; then
2037                 __print_err "<response-code> <job-id>" $@
2038                 return 1
2039         fi
2040         query="/data-consumer/v1/info-jobs/$2"
2041     res="$(__do_curl_to_api ECS DELETE $query)"
2042     status=${res:${#res}-3}
2043
2044         if [ $status -ne $1 ]; then
2045                 __log_test_fail_status_code $1 $status
2046                 return 1
2047         fi
2048
2049         __log_test_pass
2050         return 0
2051 }
2052
2053 # API Test function: GET â€‹/data-consumer/v1/info-types/{infoTypeId}
2054 # args: <response-code> <type-id> [<schema-file> [<type-status> <producers-count]]
2055 # (Function for test scripts)
2056 ecs_api_idc_get_type() {
2057         __log_test_start $@
2058
2059     if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2060                 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
2061                 return 1
2062         fi
2063
2064         query="/data-consumer/v1/info-types/$2"
2065     res="$(__do_curl_to_api ECS GET $query)"
2066     status=${res:${#res}-3}
2067
2068         if [ $status -ne $1 ]; then
2069                 __log_test_fail_status_code $1 $status
2070                 return 1
2071         fi
2072
2073         if [ $# -gt 2 ]; then
2074                 body=${res:0:${#res}-3}
2075                 if [ -f $3 ]; then
2076                         schema=$(cat $3)
2077                 else
2078                         __log_test_fail_general "Schema file "$3", does not exist"
2079                         return 1
2080                 fi
2081                 if [ $# -eq 5 ]; then
2082                         targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2083                 else
2084                         targetJson="{\"job_data_schema\":$schema}"
2085                 fi
2086                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2087                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2088
2089                 if [ $res -ne 0 ]; then
2090                         __log_test_fail_body
2091                         return 1
2092                 fi
2093         fi
2094
2095         __log_test_pass
2096         return 0
2097 }
2098
2099 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2100 # This test only status during an optional timeout. No test of the list of producers
2101 # args: <response-code> <job-id> [<status> [<timeout>]]
2102 # (Function for test scripts)
2103 ecs_api_idc_get_job_status() {
2104         __log_test_start $@
2105
2106         if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2107                 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2108                 return 1
2109         fi
2110
2111         query="/data-consumer/v1/info-jobs/$2/status"
2112
2113         start=$SECONDS
2114         for (( ; ; )); do
2115                 res="$(__do_curl_to_api ECS GET $query)"
2116                 status=${res:${#res}-3}
2117
2118                 if [ $# -eq 4 ]; then
2119                         duration=$((SECONDS-start))
2120                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2121                         if [ $duration -gt $4 ]; then
2122                                 echo ""
2123                                 duration=-1  #Last iteration
2124                         fi
2125                 else
2126                         duration=-1 #single test, no wait
2127                 fi
2128
2129                 if [ $status -ne $1 ]; then
2130                         if [ $duration -eq -1 ]; then
2131                                 __log_test_fail_status_code $1 $status
2132                                 return 1
2133                         fi
2134                 fi
2135                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2136                         body=${res:0:${#res}-3}
2137                         targetJson="{\"info_job_status\": \"$3\"}"
2138                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2139                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2140
2141                         if [ $res -ne 0 ]; then
2142                                 if [ $duration -eq -1 ]; then
2143                                         __log_test_fail_body
2144                                         return 1
2145                                 fi
2146                         else
2147                                 duration=-1  #Goto pass
2148                         fi
2149                 fi
2150                 if [ $duration -eq -1 ]; then
2151                         if [ $# -eq 4 ]; then
2152                                 echo ""
2153                         fi
2154                         __log_test_pass
2155                         return 0
2156                 else
2157                         sleep 1
2158                 fi
2159         done
2160
2161         __log_test_pass
2162         return 0
2163 }
2164
2165 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2166 # This function test status and the list of producers with and optional timeout
2167 # args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2168 # (Function for test scripts)
2169 ecs_api_idc_get_job_status2() {
2170
2171         __log_test_start $@
2172         param_error=0
2173         if [ $# -lt 2 ]; then
2174                 param_error=1
2175         fi
2176         args=("$@")
2177         timeout=0
2178         if [ $# -gt 2 ]; then
2179                 if [ $# -lt 4 ]; then
2180                         param_error=1
2181                 fi
2182                 targetJson="{\"info_job_status\": \"$3\""
2183                 if [ "$4" == "EMPTYPROD" ]; then
2184                         targetJson=$targetJson",\"producers\": []}"
2185                         if [ $# -gt 4 ]; then
2186                                 timeout=$5
2187                         fi
2188                 else
2189                         targetJson=$targetJson",\"producers\": ["
2190                         if [ $# -eq $(($4+5)) ]; then
2191                                 idx=$(($4+4))
2192                                 timeout=${args[$idx]}
2193                         fi
2194                         for ((ecs_i = 0 ; ecs_i < $4 ; ecs_i++)); do
2195                                 idx=$(($ecs_i+4))
2196                                 if [ $ecs_i -gt 0 ]; then
2197                                         targetJson=$targetJson","
2198                                 fi
2199                                 targetJson=$targetJson"\""${args[$idx]}"\""
2200                         done
2201                         targetJson=$targetJson"]}"
2202                 fi
2203         fi
2204
2205         if [ $param_error -ne 0 ]; then
2206                 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2207                 return 1
2208         fi
2209
2210         query="/data-consumer/v1/info-jobs/$2/status"
2211
2212         start=$SECONDS
2213         for (( ; ; )); do
2214                 res="$(__do_curl_to_api ECS GET $query)"
2215                 status=${res:${#res}-3}
2216
2217                 if [ $# -gt 2 ]; then
2218                         duration=$((SECONDS-start))
2219                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2220                         if [ $duration -gt $timeout ]; then
2221                                 echo ""
2222                                 duration=-1  #Last iteration
2223                         fi
2224                 else
2225                         duration=-1 #single test, no wait
2226                 fi
2227
2228                 if [ $status -ne $1 ]; then
2229                         if [ $duration -eq -1 ]; then
2230                                 __log_test_fail_status_code $1 $status
2231                                 return 1
2232                         fi
2233                 fi
2234                 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2235                         body=${res:0:${#res}-3}
2236                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2237                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2238
2239                         if [ $res -ne 0 ]; then
2240                                 if [ $duration -eq -1 ]; then
2241                                         __log_test_fail_body
2242                                         return 1
2243                                 fi
2244                         else
2245                                 duration=-1  #Goto pass
2246                         fi
2247                 fi
2248                 if [ $duration -eq -1 ]; then
2249                         if [ $# -eq 4 ]; then
2250                                 echo ""
2251                         fi
2252                         __log_test_pass
2253                         return 0
2254                 else
2255                         sleep 1
2256                 fi
2257         done
2258
2259         __log_test_pass
2260         return 0
2261 }
2262
2263 ##########################################
2264 ####     Type subscriptions           ####
2265 ##########################################
2266
2267 # API Test function: GET /data-consumer/v1/info-type-subscription
2268 # args: <response-code>  <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2269 # (Function for test scripts)
2270 ecs_api_idc_get_subscription_ids() {
2271         __log_test_start $@
2272
2273     if [ $# -lt 3 ]; then
2274                 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2275                 return 1
2276         fi
2277
2278         query="/data-consumer/v1/info-type-subscription"
2279         search=""
2280         if [ $2 != "NOOWNER" ]; then
2281                 search="?owner="$2
2282         fi
2283
2284     res="$(__do_curl_to_api ECS GET $query$search)"
2285     status=${res:${#res}-3}
2286
2287         if [ $status -ne $1 ]; then
2288                 __log_test_fail_status_code $1 $status
2289                 return 1
2290         fi
2291
2292         if [ $# -gt 2 ]; then
2293                 body=${res:0:${#res}-3}
2294                 targetJson="["
2295                 if [ $3 != "EMPTY" ]; then
2296                         for pid in ${@:3} ; do
2297                                 if [ "$targetJson" != "[" ]; then
2298                                         targetJson=$targetJson","
2299                                 fi
2300                                 targetJson=$targetJson"\"$pid\""
2301                         done
2302                 fi
2303                 targetJson=$targetJson"]"
2304                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2305                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2306
2307                 if [ $res -ne 0 ]; then
2308                         __log_test_fail_body
2309                         return 1
2310                 fi
2311         fi
2312
2313         __log_test_pass
2314         return 0
2315 }
2316
2317 # API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2318 # args: <response-code>  <subscription-id> [ <owner-id> <status-uri> ]
2319 # (Function for test scripts)
2320 ecs_api_idc_get_subscription() {
2321         __log_test_start $@
2322
2323     if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2324                 __print_err "<response-code>  <subscription-id> [ <owner-id> <status-uri> ]" $@
2325                 return 1
2326         fi
2327
2328         query="/data-consumer/v1/info-type-subscription/$2"
2329     res="$(__do_curl_to_api ECS GET $query)"
2330     status=${res:${#res}-3}
2331
2332         if [ $status -ne $1 ]; then
2333                 __log_test_fail_status_code $1 $status
2334                 return 1
2335         fi
2336
2337         if [ $# -gt 2 ]; then
2338                 body=${res:0:${#res}-3}
2339                 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2340                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2341                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2342
2343                 if [ $res -ne 0 ]; then
2344                         __log_test_fail_body
2345                         return 1
2346                 fi
2347         fi
2348
2349         __log_test_pass
2350         return 0
2351 }
2352
2353 # API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2354 # args: <response-code>  <subscription-id> <owner-id> <status-uri>
2355 # (Function for test scripts)
2356 ecs_api_idc_put_subscription() {
2357         __log_test_start $@
2358
2359     if [ $# -ne 4 ]; then
2360                 __print_err "<response-code>  <subscription-id> <owner-id> <status-uri>" $@
2361                 return 1
2362         fi
2363
2364         inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2365         file="./tmp/.p.json"
2366         echo "$inputJson" > $file
2367
2368         query="/data-consumer/v1/info-type-subscription/$2"
2369     res="$(__do_curl_to_api ECS PUT $query $file)"
2370     status=${res:${#res}-3}
2371
2372         if [ $status -ne $1 ]; then
2373                 __log_test_fail_status_code $1 $status
2374                 return 1
2375         fi
2376
2377         __log_test_pass
2378         return 0
2379 }
2380
2381 # API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2382 # args: <response-code>  <subscription-id>
2383 # (Function for test scripts)
2384 ecs_api_idc_delete_subscription() {
2385         __log_test_start $@
2386
2387         if [ $# -ne 2 ]; then
2388                 __print_err "<response-code>  <subscription-id> " $@
2389                 return 1
2390         fi
2391
2392         query="/data-consumer/v1/info-type-subscription/$2"
2393     res="$(__do_curl_to_api ECS DELETE $query)"
2394     status=${res:${#res}-3}
2395
2396         if [ $status -ne $1 ]; then
2397                 __log_test_fail_status_code $1 $status
2398                 return 1
2399         fi
2400
2401         __log_test_pass
2402         return 0
2403 }
2404
2405 ##########################################
2406 ####          Reset jobs              ####
2407 ##########################################
2408 # Function prefix: ecs_api_admin
2409
2410 # Admin to remove all jobs
2411 # args: <response-code> [ <type> ]
2412 # (Function for test scripts)
2413
2414 ecs_api_admin_reset() {
2415         __log_test_start $@
2416
2417         if [  -z "$FLAT_A1_EI" ]; then
2418                 query="/A1-EI/v1/eitypes/$2/eijobs"
2419         else
2420                 query="/A1-EI/v1/eijobs"
2421         fi
2422     res="$(__do_curl_to_api ECS GET $query)"
2423     status=${res:${#res}-3}
2424
2425         if [ $status -ne 200 ]; then
2426                 __log_test_fail_status_code $1 $status
2427                 return 1
2428         fi
2429
2430         #Remove brackets and response code
2431         body=${res:1:${#res}-4}
2432         list=$(echo ${body//,/ })
2433         list=$(echo ${list//[/})
2434         list=$(echo ${list//]/})
2435         list=$(echo ${list//\"/})
2436         list=$list" "
2437         for job in $list; do
2438                 if [  -z "$FLAT_A1_EI" ]; then
2439                         echo "Not supported for non-flat EI api"
2440                 else
2441                         query="/A1-EI/v1/eijobs/$job"
2442                         res="$(__do_curl_to_api ECS DELETE $query)"
2443                         status=${res:${#res}-3}
2444                         if [ $status -ne 204 ]; then
2445                                 __log_test_fail_status_code $1 $status
2446                                 return 1
2447                         fi
2448                         echo " Deleted job: "$job
2449                 fi
2450         done
2451
2452         __log_test_pass
2453         return 0
2454 }
2455
2456 ##########################################
2457 ####     Reset jobs and producers     ####
2458 ##########################################
2459
2460
2461 # Admin reset to remove all data in ecs; jobs, producers etc
2462 # NOTE - only works in kubernetes and the pod should not be running
2463 # args: -
2464 # (Function for test scripts)
2465
2466 ecs_kube_pvc_reset() {
2467         __log_test_start $@
2468
2469         pvc_name=$(kubectl get pvc -n nonrtric  --no-headers -o custom-columns=":metadata.name" | grep enrichment)
2470         if [ -z "$pvc_name" ]; then
2471                 pvc_name=enrichmentservice-pvc
2472         fi
2473         echo " Trying to reset pvc: "$pvc_name
2474
2475         __kube_clean_pvc $ECS_APP_NAME nonrtric $pvc_name /var/enrichment-coordinator-service/database
2476
2477         __log_test_pass
2478         return 0
2479 }