Updated tests for changed job status msg
[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> ]
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 [ $paramError -ne 0 ]; then
1241                 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1242                 return 1
1243         fi
1244         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1245                 query="/data-producer/v1/info-types/$2"
1246         else
1247                 query="/ei-producer/v1/eitypes/$2"
1248         fi
1249
1250     res="$(__do_curl_to_api ECS GET $query)"
1251     status=${res:${#res}-3}
1252
1253         if [ $status -ne $1 ]; then
1254                 __log_test_fail_status_code $1 $status
1255                 return 1
1256         fi
1257         if [ $# -eq 3 ]; then
1258                 body=${res:0:${#res}-3}
1259
1260                 if [ -f $3 ]; then
1261                         schema=$(cat $3)
1262                 else
1263                         __log_test_fail_general "Job template file "$3", does not exist"
1264                         return 1
1265                 fi
1266                 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1267                         targetJson="{\"info_job_data_schema\":$schema}"
1268                 else
1269                         targetJson="{\"ei_job_data_schema\":$schema}"
1270                 fi
1271
1272                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1273                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1274
1275                 if [ $res -ne 0 ]; then
1276                         __log_test_fail_body
1277                         return 1
1278                 fi
1279         fi
1280         __log_test_pass
1281         return 0
1282 }
1283
1284 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1285 # API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
1286 # args: (v1_2) <response-code> <type-id> <job-schema-file>
1287 # (Function for test scripts)
1288 ecs_api_edp_put_type_2() {
1289         __log_test_start $@
1290
1291     if [ $# -ne 3 ]; then
1292                 __print_err "<response-code> <type-id> <job-schema-file>" $@
1293                 return 1
1294         fi
1295
1296         if [ ! -f $3 ]; then
1297                 __log_test_fail_general "Job schema file "$3", does not exist"
1298                 return 1
1299         fi
1300         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1301                 schema=$(cat $3)
1302                 input_json="{\"info_job_data_schema\":$schema}"
1303                 file="./tmp/put_type.json"
1304                 echo $input_json > $file
1305
1306                 query="/data-producer/v1/info-types/$2"
1307         else
1308                 schema=$(cat $3)
1309                 input_json="{\"ei_job_data_schema\":$schema}"
1310                 file="./tmp/put_type.json"
1311                 echo $input_json > $file
1312
1313                 query="/ei-producer/v1/eitypes/$2"
1314         fi
1315     res="$(__do_curl_to_api ECS PUT $query $file)"
1316     status=${res:${#res}-3}
1317
1318         if [ $status -ne $1 ]; then
1319                 __log_test_fail_status_code $1 $status
1320                 return 1
1321         fi
1322
1323         __log_test_pass
1324         return 0
1325 }
1326
1327 # API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
1328 # API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
1329 # args: (v1_2) <response-code> <type-id>
1330 # (Function for test scripts)
1331 ecs_api_edp_delete_type_2() {
1332         __log_test_start $@
1333
1334     if [ $# -ne 2 ]; then
1335                 __print_err "<response-code> <type-id>" $@
1336                 return 1
1337         fi
1338
1339         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1340                 query="/data-producer/v1/info-types/$2"
1341         else
1342                 query="/ei-producer/v1/eitypes/$2"
1343         fi
1344     res="$(__do_curl_to_api ECS DELETE $query)"
1345     status=${res:${#res}-3}
1346
1347         if [ $status -ne $1 ]; then
1348                 __log_test_fail_status_code $1 $status
1349                 return 1
1350         fi
1351
1352         __log_test_pass
1353         return 0
1354 }
1355
1356 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1357 # args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
1358 # (Function for test scripts)
1359 ecs_api_edp_get_producer() {
1360         __log_test_start $@
1361
1362         #Possible arg count: 2, 5 6, 8, 10 etc
1363         paramError=1
1364         if [ $# -eq 2 ]; then
1365                 paramError=0
1366         fi
1367         if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1368                 paramError=0
1369         fi
1370         variablecount=$(($#-4))
1371         if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1372                 paramError=0
1373         fi
1374
1375     if [ $paramError -ne 0 ]; then
1376                 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
1377                 return 1
1378         fi
1379
1380         query="/ei-producer/v1/eiproducers/$2"
1381     res="$(__do_curl_to_api ECS GET $query)"
1382     status=${res:${#res}-3}
1383
1384         if [ $status -ne $1 ]; then
1385                 __log_test_fail_status_code $1 $status
1386                 return 1
1387         fi
1388
1389         if [ $# -gt 2 ]; then
1390                 body=${res:0:${#res}-3}
1391                 targetJson="["
1392                 if [ $# -gt 5 ]; then
1393                         arr=(${@:5})
1394                         for ((i=0; i<$(($#-5)); i=i+2)); do
1395                                 if [ "$targetJson" != "[" ]; then
1396                                         targetJson=$targetJson","
1397                                 fi
1398                                 if [ -f ${arr[$i+1]} ]; then
1399                                         schema=$(cat ${arr[$i+1]})
1400                                 else
1401                                         __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1402                                         return 1
1403                                 fi
1404
1405                                 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1406                         done
1407                 fi
1408                 targetJson=$targetJson"]"
1409                 if [ $# -gt 4 ]; then
1410                         targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1411                 fi
1412                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1413                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1414
1415                 if [ $res -ne 0 ]; then
1416                         __log_test_fail_body
1417                         return 1
1418                 fi
1419         fi
1420
1421         __log_test_pass
1422         return 0
1423 }
1424
1425 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
1426 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
1427 # args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1428 # (Function for test scripts)
1429 ecs_api_edp_get_producer_2() {
1430         __log_test_start $@
1431
1432         #Possible arg count: 2, 5, 6, 7, 8 etc
1433         paramError=1
1434         if [ $# -eq 2 ]; then
1435                 paramError=0
1436         fi
1437         if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1438                 paramError=0
1439         fi
1440         if [ $# -ge 5 ]; then
1441                 paramError=0
1442         fi
1443
1444     if [ $paramError -ne 0 ]; then
1445                 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1446                 return 1
1447         fi
1448         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1449                 query="/data-producer/v1/info-producers/$2"
1450         else
1451                 query="/ei-producer/v1/eiproducers/$2"
1452         fi
1453     res="$(__do_curl_to_api ECS GET $query)"
1454     status=${res:${#res}-3}
1455
1456         if [ $status -ne $1 ]; then
1457                 __log_test_fail_status_code $1 $status
1458                 return 1
1459         fi
1460
1461         if [ $# -gt 2 ]; then
1462                 body=${res:0:${#res}-3}
1463                 targetJson="["
1464                 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1465                         arr=(${@:5})
1466                         for ((i=0; i<$(($#-4)); i=i+1)); do
1467                                 if [ "$targetJson" != "[" ]; then
1468                                         targetJson=$targetJson","
1469                                 fi
1470                                 targetJson=$targetJson"\"${arr[$i]}\""
1471                         done
1472                 fi
1473                 targetJson=$targetJson"]"
1474                 if [ $# -gt 4 ]; then
1475                         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1476                                 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1477                         else
1478                                 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1479                         fi
1480                 fi
1481                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1482                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1483
1484                 if [ $res -ne 0 ]; then
1485                         __log_test_fail_body
1486                         return 1
1487                 fi
1488         fi
1489
1490         __log_test_pass
1491         return 0
1492 }
1493
1494 # API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
1495 # API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
1496 # args: <response-code> <producer-id>
1497 # (Function for test scripts)
1498 ecs_api_edp_delete_producer() {
1499         __log_test_start $@
1500
1501     if [ $# -lt 2 ]; then
1502                 __print_err "<response-code> <producer-id>" $@
1503                 return 1
1504         fi
1505         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1506                 query="/data-producer/v1/info-producers/$2"
1507         else
1508                 query="/ei-producer/v1/eiproducers/$2"
1509         fi
1510     res="$(__do_curl_to_api ECS DELETE $query)"
1511     status=${res:${#res}-3}
1512
1513         if [ $status -ne $1 ]; then
1514                 __log_test_fail_status_code $1 $status
1515                 return 1
1516         fi
1517
1518         __log_test_pass
1519         return 0
1520 }
1521
1522 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1523 # args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
1524 # (Function for test scripts)
1525 ecs_api_edp_put_producer() {
1526         __log_test_start $@
1527
1528         #Valid number of parametrer 5,6,8,10,
1529         paramError=1
1530         if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1531                 paramError=0
1532         elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
1533                 paramError=0
1534         fi
1535         if [ $paramError -ne 0 ]; then
1536                 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
1537                 return 1
1538         fi
1539
1540         inputJson="["
1541         if [ $# -gt 5 ]; then
1542                 arr=(${@:5})
1543                 for ((i=0; i<$(($#-5)); i=i+2)); do
1544                         if [ "$inputJson" != "[" ]; then
1545                                 inputJson=$inputJson","
1546                         fi
1547                         if [ -f ${arr[$i+1]} ]; then
1548                                 schema=$(cat ${arr[$i+1]})
1549                         else
1550                                 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
1551                                 return 1
1552                         fi
1553                         inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1554                 done
1555         fi
1556         inputJson="\"supported_ei_types\":"$inputJson"]"
1557
1558         inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1559
1560         inputJson="{"$inputJson"}"
1561
1562         file="./tmp/.p.json"
1563         echo "$inputJson" > $file
1564         query="/ei-producer/v1/eiproducers/$2"
1565     res="$(__do_curl_to_api ECS PUT $query $file)"
1566     status=${res:${#res}-3}
1567
1568         if [ $status -ne $1 ]; then
1569                 __log_test_fail_status_code $1 $status
1570                 return 1
1571         fi
1572
1573         __log_test_pass
1574         return 0
1575 }
1576
1577 # API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
1578 # API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
1579 # args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1580 # (Function for test scripts)
1581 ecs_api_edp_put_producer_2() {
1582         __log_test_start $@
1583
1584         #Valid number of parametrer 5,6,8,10,
1585         paramError=1
1586         if  [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1587                 paramError=0
1588         elif [ $# -ge 5 ]; then
1589                 paramError=0
1590         fi
1591         if [ $paramError -ne 0 ]; then
1592                 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1593                 return 1
1594         fi
1595
1596         inputJson="["
1597         if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1598                 arr=(${@:5})
1599                 for ((i=0; i<$(($#-4)); i=i+1)); do
1600                         if [ "$inputJson" != "[" ]; then
1601                                 inputJson=$inputJson","
1602                         fi
1603                         inputJson=$inputJson"\""${arr[$i]}"\""
1604                 done
1605         fi
1606         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1607                 inputJson="\"supported_info_types\":"$inputJson"]"
1608
1609                 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
1610
1611                 inputJson="{"$inputJson"}"
1612
1613                 file="./tmp/.p.json"
1614                 echo "$inputJson" > $file
1615                 query="/data-producer/v1/info-producers/$2"
1616         else
1617                 inputJson="\"supported_ei_types\":"$inputJson"]"
1618
1619                 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1620
1621                 inputJson="{"$inputJson"}"
1622
1623                 file="./tmp/.p.json"
1624                 echo "$inputJson" > $file
1625                 query="/ei-producer/v1/eiproducers/$2"
1626         fi
1627     res="$(__do_curl_to_api ECS PUT $query $file)"
1628     status=${res:${#res}-3}
1629
1630         if [ $status -ne $1 ]; then
1631                 __log_test_fail_status_code $1 $status
1632                 return 1
1633         fi
1634
1635         __log_test_pass
1636         return 0
1637 }
1638
1639 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1640 # args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1641 # (Function for test scripts)
1642 ecs_api_edp_get_producer_jobs() {
1643         __log_test_start $@
1644
1645         #Valid number of parameter 2,3,7,11
1646         paramError=1
1647         if [ $# -eq 2 ]; then
1648                 paramError=0
1649         fi
1650         if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1651                 paramError=0
1652         fi
1653         variablecount=$(($#-2))
1654         if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1655                 paramError=0
1656         fi
1657         if [ $paramError -eq 1 ]; then
1658                 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1659                 return 1
1660         fi
1661
1662         query="/ei-producer/v1/eiproducers/$2/eijobs"
1663     res="$(__do_curl_to_api ECS GET $query)"
1664     status=${res:${#res}-3}
1665         if [ $status -ne $1 ]; then
1666                 __log_test_fail_status_code $1 $status
1667                 return 1
1668         fi
1669         if [ $# -gt 2 ]; then
1670                 body=${res:0:${#res}-3}
1671                 targetJson="["
1672                 if [ $# -gt 3 ]; then
1673                         arr=(${@:3})
1674                         for ((i=0; i<$(($#-3)); i=i+5)); do
1675                                 if [ "$targetJson" != "[" ]; then
1676                                         targetJson=$targetJson","
1677                                 fi
1678                                 if [ -f ${arr[$i+4]} ]; then
1679                                         jobfile=$(cat ${arr[$i+4]})
1680                                         jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1681                                 else
1682                                         __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1683                                         return 1
1684                                 fi
1685                                 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}"
1686                         done
1687                 fi
1688                 targetJson=$targetJson"]"
1689
1690                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1691                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1692
1693                 if [ $res -ne 0 ]; then
1694                         __log_test_fail_body
1695                         return 1
1696                 fi
1697         fi
1698
1699         __log_test_pass
1700         return 0
1701 }
1702
1703 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
1704 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
1705 # args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1706 # (Function for test scripts)
1707 ecs_api_edp_get_producer_jobs_2() {
1708         __log_test_start $@
1709
1710         #Valid number of parameter 2,3,7,11
1711         paramError=1
1712         if [ $# -eq 2 ]; then
1713                 paramError=0
1714         fi
1715         if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1716                 paramError=0
1717         fi
1718         variablecount=$(($#-2))
1719         if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1720                 paramError=0
1721         fi
1722         if [ $paramError -eq 1 ]; then
1723                 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1724                 return 1
1725         fi
1726         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1727                 query="/data-producer/v1/info-producers/$2/info-jobs"
1728         else
1729                 query="/ei-producer/v1/eiproducers/$2/eijobs"
1730         fi
1731     res="$(__do_curl_to_api ECS GET $query)"
1732     status=${res:${#res}-3}
1733         if [ $status -ne $1 ]; then
1734                 __log_test_fail_status_code $1 $status
1735                 return 1
1736         fi
1737         if [ $# -gt 2 ]; then
1738                 body=${res:0:${#res}-3}
1739                 targetJson="["
1740                 if [ $# -gt 3 ]; then
1741                         arr=(${@:3})
1742                         for ((i=0; i<$(($#-3)); i=i+5)); do
1743                                 if [ "$targetJson" != "[" ]; then
1744                                         targetJson=$targetJson","
1745                                 fi
1746                                 if [ -f ${arr[$i+4]} ]; then
1747                                         jobfile=$(cat ${arr[$i+4]})
1748                                         jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1749                                 else
1750                                         __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
1751                                         return 1
1752                                 fi
1753                                 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1754                                         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\":\"????\"}"
1755                                 else
1756                                         targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1757                                 fi
1758                         done
1759                 fi
1760                 targetJson=$targetJson"]"
1761
1762                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1763                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1764
1765                 if [ $res -ne 0 ]; then
1766                         __log_test_fail_body
1767                         return 1
1768                 fi
1769         fi
1770
1771         __log_test_pass
1772         return 0
1773 }
1774
1775 ##########################################
1776 ####          Service status          ####
1777 ##########################################
1778 # Function prefix: ecs_api_service
1779
1780 # API Test function: GET â€‹/status
1781 # args: <response-code>
1782 # (Function for test scripts)
1783 ecs_api_service_status() {
1784         __log_test_start $@
1785
1786     if [ $# -lt 1 ]; then
1787                 __print_err "<response-code>" $@
1788                 return 1
1789         fi
1790         res="$(__do_curl_to_api ECS GET /status)"
1791     status=${res:${#res}-3}
1792         if [ $status -ne $1 ]; then
1793                 __log_test_fail_status_code $1 $status
1794                 return 1
1795         fi
1796         __log_test_pass
1797         return 0
1798 }
1799
1800 ###########################################
1801 ######### Info data consumer API ##########
1802 ###########################################
1803 #Function prefix: ecs_api_idc
1804
1805
1806 # API Test function: GET /data-consumer/v1/info-types
1807 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
1808 # (Function for test scripts)
1809 ecs_api_idc_get_type_ids() {
1810         __log_test_start $@
1811
1812     if [ $# -lt 1 ]; then
1813                 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1814                 return 1
1815         fi
1816
1817         query="/data-consumer/v1/info-types"
1818     res="$(__do_curl_to_api ECS GET $query)"
1819     status=${res:${#res}-3}
1820
1821         if [ $status -ne $1 ]; then
1822                 __log_test_fail_status_code $1 $status
1823                 return 1
1824         fi
1825         if [ $# -gt 1 ]; then
1826                 body=${res:0:${#res}-3}
1827                 targetJson="["
1828                 if [ $2 != "EMPTY" ]; then
1829                         for pid in ${@:2} ; do
1830                                 if [ "$targetJson" != "[" ]; then
1831                                         targetJson=$targetJson","
1832                                 fi
1833                                 targetJson=$targetJson"\"$pid\""
1834                         done
1835                 fi
1836                 targetJson=$targetJson"]"
1837                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1838                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1839
1840                 if [ $res -ne 0 ]; then
1841                         __log_test_fail_body
1842                         return 1
1843                 fi
1844         fi
1845
1846         __log_test_pass
1847         return 0
1848 }
1849
1850 # API Test function: GET /data-consumer/v1/info-jobs
1851 # args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1852 # (Function for test scripts)
1853 ecs_api_idc_get_job_ids() {
1854         __log_test_start $@
1855
1856         # Valid number of parameters 4,5,6 etc
1857         if [ $# -lt 3 ]; then
1858                 __print_err "<response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1859                 return 1
1860         fi
1861         search=""
1862         if [ $3 != "NOWNER" ]; then
1863                 search="?owner="$3
1864         fi
1865
1866         if [ $2 != "NOTYPE" ]; then
1867                 if [ -z "$search" ]; then
1868                         search="?infoTypeId="$2
1869                 else
1870                         search=$search"&infoTypeId="$2
1871                 fi
1872         fi
1873         query="/data-consumer/v1/info-jobs$search"
1874
1875     res="$(__do_curl_to_api ECS GET $query)"
1876     status=${res:${#res}-3}
1877
1878         if [ $status -ne $1 ]; then
1879                 __log_test_fail_status_code $1 $status
1880                 return 1
1881         fi
1882
1883         if [ $# -gt 3 ]; then
1884                 body=${res:0:${#res}-3}
1885                 targetJson="["
1886
1887                 for pid in ${@:4} ; do
1888                         if [ "$targetJson" != "[" ]; then
1889                                 targetJson=$targetJson","
1890                         fi
1891                         if [ $pid != "EMPTY" ]; then
1892                                 targetJson=$targetJson"\"$pid\""
1893                         fi
1894                 done
1895
1896                 targetJson=$targetJson"]"
1897                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1898                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1899
1900                 if [ $res -ne 0 ]; then
1901                         __log_test_fail_body
1902                         return 1
1903                 fi
1904         fi
1905
1906         __log_test_pass
1907         return 0
1908 }
1909
1910 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1911 # args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1912 # (Function for test scripts)
1913 ecs_api_idc_get_job() {
1914         __log_test_start $@
1915
1916         if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1917                 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1918                 return 1
1919         fi
1920         query="/data-consumer/v1/info-jobs/$2"
1921     res="$(__do_curl_to_api ECS GET $query)"
1922     status=${res:${#res}-3}
1923
1924         if [ $status -ne $1 ]; then
1925                 __log_test_fail_status_code $1 $status
1926                 return 1
1927         fi
1928
1929         if [ $# -eq 7 ]; then
1930                 body=${res:0:${#res}-3}
1931
1932                 if [ -f $7 ]; then
1933                         jobfile=$(cat $7)
1934                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1935                 else
1936                         __log_test_fail_general "Job template file "$6", does not exist"
1937                         return 1
1938                 fi
1939                 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1940                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1941                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1942
1943                 if [ $res -ne 0 ]; then
1944                         __log_test_fail_body
1945                         return 1
1946                 fi
1947         fi
1948
1949         __log_test_pass
1950         return 0
1951 }
1952
1953
1954 # API Test function: PUT â€‹/data-consumer/v1/info-jobs/{infoJobId}
1955 # args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1956 # (Function for test scripts)
1957 ecs_api_idc_put_job() {
1958         __log_test_start $@
1959
1960         if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1961                 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1962                 return 1
1963         fi
1964         if [ -f $7 ]; then
1965                 jobfile=$(cat $7)
1966                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1967         else
1968                 __log_test_fail_general "Job template file "$7", does not exist"
1969                 return 1
1970         fi
1971
1972         inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
1973         file="./tmp/.p.json"
1974         echo "$inputJson" > $file
1975
1976         query="/data-consumer/v1/info-jobs/$2"
1977
1978         if [ $# -eq 8 ]; then
1979                 if [ $8 == "VALIDATE" ]; then
1980                         query=$query"?typeCheck=true"
1981                 fi
1982         fi
1983
1984     res="$(__do_curl_to_api ECS PUT $query $file)"
1985     status=${res:${#res}-3}
1986
1987         if [ $status -ne $1 ]; then
1988                 __log_test_fail_status_code $1 $status
1989                 return 1
1990         fi
1991
1992         __log_test_pass
1993         return 0
1994 }
1995
1996 # API Test function: DELETE â€‹/data-consumer/v1/info-jobs/{infoJobId}
1997 # args: <response-code> <job-id>
1998 # (Function for test scripts)
1999 ecs_api_idc_delete_job() {
2000         __log_test_start $@
2001
2002         if [ $# -ne 2 ]; then
2003                 __print_err "<response-code> <job-id>" $@
2004                 return 1
2005         fi
2006         query="/data-consumer/v1/info-jobs/$2"
2007     res="$(__do_curl_to_api ECS DELETE $query)"
2008     status=${res:${#res}-3}
2009
2010         if [ $status -ne $1 ]; then
2011                 __log_test_fail_status_code $1 $status
2012                 return 1
2013         fi
2014
2015         __log_test_pass
2016         return 0
2017 }
2018
2019 # API Test function: GET â€‹/data-consumer/v1/info-types/{infoTypeId}
2020 # args: <response-code> <type-id> [<schema-file>]
2021 # (Function for test scripts)
2022 ecs_api_idc_get_type() {
2023         __log_test_start $@
2024
2025     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2026                 __print_err "<response-code> <type-id> [<schema-file>]" $@
2027                 return 1
2028         fi
2029
2030         query="/data-consumer/v1/info-types/$2"
2031     res="$(__do_curl_to_api ECS GET $query)"
2032     status=${res:${#res}-3}
2033
2034         if [ $status -ne $1 ]; then
2035                 __log_test_fail_status_code $1 $status
2036                 return 1
2037         fi
2038
2039         if [ $# -eq 3 ]; then
2040                 body=${res:0:${#res}-3}
2041                 if [ -f $3 ]; then
2042                         schema=$(cat $3)
2043                 else
2044                         __log_test_fail_general "Schema file "$3", does not exist"
2045                         return 1
2046                 fi
2047                 targetJson="{\"job_data_schema\":$schema}"
2048                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2049                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2050
2051                 if [ $res -ne 0 ]; then
2052                         __log_test_fail_body
2053                         return 1
2054                 fi
2055         fi
2056
2057         __log_test_pass
2058         return 0
2059 }
2060
2061 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2062 # This test only status during an optional timeout. No test of the list of producers
2063 # args: <response-code> <job-id> [<status> [<timeout>]]
2064 # (Function for test scripts)
2065 ecs_api_idc_get_job_status() {
2066         __log_test_start $@
2067
2068         if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2069                 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2070                 return 1
2071         fi
2072
2073         query="/data-consumer/v1/info-jobs/$2/status"
2074
2075         start=$SECONDS
2076         for (( ; ; )); do
2077                 res="$(__do_curl_to_api ECS GET $query)"
2078                 status=${res:${#res}-3}
2079
2080                 if [ $# -eq 4 ]; then
2081                         duration=$((SECONDS-start))
2082                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2083                         if [ $duration -gt $4 ]; then
2084                                 echo ""
2085                                 duration=-1  #Last iteration
2086                         fi
2087                 else
2088                         duration=-1 #single test, no wait
2089                 fi
2090
2091                 if [ $status -ne $1 ]; then
2092                         if [ $duration -eq -1 ]; then
2093                                 __log_test_fail_status_code $1 $status
2094                                 return 1
2095                         fi
2096                 fi
2097                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2098                         body=${res:0:${#res}-3}
2099                         targetJson="{\"info_job_status\": \"$3\"}"
2100                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2101                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2102
2103                         if [ $res -ne 0 ]; then
2104                                 if [ $duration -eq -1 ]; then
2105                                         __log_test_fail_body
2106                                         return 1
2107                                 fi
2108                         else
2109                                 duration=-1  #Goto pass
2110                         fi
2111                 fi
2112                 if [ $duration -eq -1 ]; then
2113                         if [ $# -eq 4 ]; then
2114                                 echo ""
2115                         fi
2116                         __log_test_pass
2117                         return 0
2118                 else
2119                         sleep 1
2120                 fi
2121         done
2122
2123         __log_test_pass
2124         return 0
2125 }
2126
2127 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2128 # This function test status and the list of producers with and optional timeout
2129 # args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2130 # (Function for test scripts)
2131 ecs_api_idc_get_job_status2() {
2132
2133         __log_test_start $@
2134         param_error=0
2135         if [ $# -lt 2 ]; then
2136                 param_error=1
2137         fi
2138         args=("$@")
2139         timeout=0
2140         if [ $# -gt 2 ]; then
2141                 if [ $# -lt 4 ]; then
2142                         param_error=1
2143                 fi
2144                 targetJson="{\"info_job_status\": \"$3\""
2145                 if [ "$4" == "EMPTYPROD" ]; then
2146                         targetJson=$targetJson",\"producers\": []}"
2147                         if [ $# -gt 4 ]; then
2148                                 timeout=$5
2149                         fi
2150                 else
2151                         targetJson=$targetJson",\"producers\": ["
2152                         if [ $# -eq $(($4+5)) ]; then
2153                                 idx=$(($4+4))
2154                                 timeout=${args[$idx]}
2155                         fi
2156                         for ((ecs_i = 0 ; ecs_i < $4 ; ecs_i++)); do
2157                                 idx=$(($ecs_i+4))
2158                                 if [ $ecs_i -gt 0 ]; then
2159                                         targetJson=$targetJson","
2160                                 fi
2161                                 targetJson=$targetJson"\""${args[$idx]}"\""
2162                         done
2163                         targetJson=$targetJson"]}"
2164                 fi
2165         fi
2166
2167         if [ $param_error -ne 0 ]; then
2168                 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2169                 return 1
2170         fi
2171
2172         query="/data-consumer/v1/info-jobs/$2/status"
2173
2174         start=$SECONDS
2175         for (( ; ; )); do
2176                 res="$(__do_curl_to_api ECS GET $query)"
2177                 status=${res:${#res}-3}
2178
2179                 if [ $# -gt 2 ]; then
2180                         duration=$((SECONDS-start))
2181                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2182                         if [ $duration -gt $timeout ]; then
2183                                 echo ""
2184                                 duration=-1  #Last iteration
2185                         fi
2186                 else
2187                         duration=-1 #single test, no wait
2188                 fi
2189
2190                 if [ $status -ne $1 ]; then
2191                         if [ $duration -eq -1 ]; then
2192                                 __log_test_fail_status_code $1 $status
2193                                 return 1
2194                         fi
2195                 fi
2196                 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2197                         body=${res:0:${#res}-3}
2198                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2199                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2200
2201                         if [ $res -ne 0 ]; then
2202                                 if [ $duration -eq -1 ]; then
2203                                         __log_test_fail_body
2204                                         return 1
2205                                 fi
2206                         else
2207                                 duration=-1  #Goto pass
2208                         fi
2209                 fi
2210                 if [ $duration -eq -1 ]; then
2211                         if [ $# -eq 4 ]; then
2212                                 echo ""
2213                         fi
2214                         __log_test_pass
2215                         return 0
2216                 else
2217                         sleep 1
2218                 fi
2219         done
2220
2221         __log_test_pass
2222         return 0
2223 }
2224
2225 ##########################################
2226 ####          Reset jobs              ####
2227 ##########################################
2228 # Function prefix: ecs_api_admin
2229
2230 # Admin to remove all jobs
2231 # args: <response-code> [ <type> ]
2232 # (Function for test scripts)
2233
2234 ecs_api_admin_reset() {
2235         __log_test_start $@
2236
2237         if [  -z "$FLAT_A1_EI" ]; then
2238                 query="/A1-EI/v1/eitypes/$2/eijobs"
2239         else
2240                 query="/A1-EI/v1/eijobs"
2241         fi
2242     res="$(__do_curl_to_api ECS GET $query)"
2243     status=${res:${#res}-3}
2244
2245         if [ $status -ne 200 ]; then
2246                 __log_test_fail_status_code $1 $status
2247                 return 1
2248         fi
2249
2250         #Remove brackets and response code
2251         body=${res:1:${#res}-4}
2252         list=$(echo ${body//,/ })
2253         list=$(echo ${list//[/})
2254         list=$(echo ${list//]/})
2255         list=$(echo ${list//\"/})
2256         list=$list" "
2257         for job in $list; do
2258                 if [  -z "$FLAT_A1_EI" ]; then
2259                         echo "Not supported for non-flat EI api"
2260                 else
2261                         query="/A1-EI/v1/eijobs/$job"
2262                         res="$(__do_curl_to_api ECS DELETE $query)"
2263                         status=${res:${#res}-3}
2264                         if [ $status -ne 204 ]; then
2265                                 __log_test_fail_status_code $1 $status
2266                                 return 1
2267                         fi
2268                         echo " Deleted job: "$job
2269                 fi
2270         done
2271
2272         __log_test_pass
2273         return 0
2274 }
2275
2276 ##########################################
2277 ####     Reset jobs and producers     ####
2278 ##########################################
2279
2280
2281 # Admin reset to remove all data in ecs; jobs, producers etc
2282 # NOTE - only works in kubernetes and the pod should not be running
2283 # args: -
2284 # (Function for test scripts)
2285
2286 ecs_kube_pvc_reset() {
2287         __log_test_start $@
2288
2289         pvc_name=$(kubectl get pvc -n nonrtric  --no-headers -o custom-columns=":metadata.name" | grep enrichment)
2290         if [ -z "$pvc_name" ]; then
2291                 pvc_name=enrichmentservice-pvc
2292         fi
2293         echo " Trying to reset pvc: "$pvc_name
2294
2295         __kube_clean_pvc $ECS_APP_NAME nonrtric $pvc_name /var/enrichment-coordinator-service/database
2296
2297         __log_test_pass
2298         return 0
2299 }