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