Merge "Adaptation of test env to helm chart"
[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 "$KUBE_NONRTRIC_NAMESPACE"-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         if [ $RUNMODE == "KUBE" ]; then
81                 kubectl  logs -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE --tail=-1 > $1$2_ecs.log 2>&1
82         else
83                 docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1
84         fi
85 }
86
87 # Initial setup of protocol, host and ports
88 # This function is called for apps managed by the test script.
89 # args: -
90 __ECS_initial_setup() {
91         use_ecs_rest_http
92 }
93
94 #######################################################
95
96
97 # Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
98 ECS_RETRY_CODES=""
99
100 #Save first worker node the pod is started on
101 __ECS_WORKER_NODE=""
102
103 ###########################
104 ### ECS functions
105 ###########################
106
107 # All calls to ECS will be directed to the ECS REST interface from now on
108 # args: -
109 # (Function for test scripts)
110 use_ecs_rest_http() {
111         __ecs_set_protocoll "http" $ECS_INTERNAL_PORT $ECS_EXTERNAL_PORT
112 }
113
114 # All calls to ECS will be directed to the ECS REST interface from now on
115 # args: -
116 # (Function for test scripts)
117 use_ecs_rest_https() {
118         __ecs_set_protocoll "https" $ECS_INTERNAL_SECURE_PORT $ECS_EXTERNAL_SECURE_PORT
119 }
120
121 # All calls to ECS will be directed to the ECS dmaap interface over http from now on
122 # args: -
123 # (Function for test scripts)
124 use_ecs_dmaap_http() {
125         echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
126         echo -e $RED" - NOT SUPPORTED - "$ERED
127         echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
128         ECS_ADAPTER_TYPE="MR-HTTP"
129         echo ""
130 }
131
132 # Setup paths to svc/container for internal and external access
133 # args: <protocol> <internal-port> <external-port>
134 __ecs_set_protocoll() {
135         echo -e $BOLD"$ECS_DISPLAY_NAME protocol setting"$EBOLD
136         echo -e " Using $BOLD http $EBOLD towards $ECS_DISPLAY_NAME"
137
138         ## Access to ECS
139
140         ECS_SERVICE_PATH=$1"://"$ECS_APP_NAME":"$2  # docker access, container->container and script->container via proxy
141         if [ $RUNMODE == "KUBE" ]; then
142                 ECS_SERVICE_PATH=$1"://"$ECS_APP_NAME.$KUBE_NONRTRIC_NAMESPACE":"$3 # kube access, pod->svc and script->svc via proxy
143         fi
144
145         # ECS_ADAPTER used for switching between REST and DMAAP (only REST supported currently)
146         ECS_ADAPTER_TYPE="REST"
147         ECS_ADAPTER=$ECS_SERVICE_PATH
148
149         echo ""
150 }
151
152 # Export env vars for config files, docker compose and kube resources
153 # args: PROXY|NOPROXY
154 __ecs_export_vars() {
155                 export ECS_APP_NAME
156                 export ECS_APP_NAME_ALIAS
157                 export KUBE_NONRTRIC_NAMESPACE
158                 export ECS_IMAGE
159                 export ECS_INTERNAL_PORT
160                 export ECS_INTERNAL_SECURE_PORT
161                 export ECS_EXTERNAL_PORT
162                 export ECS_EXTERNAL_SECURE_PORT
163                 export ECS_CONFIG_MOUNT_PATH
164                 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
165                 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
166                 export ECS_CONTAINER_MNT_DIR
167                 export ECS_HOST_MNT_DIR
168                 export ECS_CONFIG_FILE
169                 export DOCKER_SIM_NWNAME
170                 export ECS_DISPLAY_NAME
171
172
173                 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
174                 export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc"
175                 #Create a unique path for the pv each time to prevent a previous volume to be reused
176                 export ECS_PV_PATH="ecsdata-"$(date +%s)
177
178                 if [ $1 == "PROXY" ]; then
179                         export ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT  #Set if proxy is started
180                         export ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
181                         if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
182                                 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
183                         else
184                                 echo " Configured with http proxy"
185                         fi
186                 else
187                         export ECS_HTTP_PROXY_CONFIG_PORT=0
188                         export ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
189                         echo " Configured without http proxy"
190                 fi
191 }
192
193
194 # Start the ECS
195 # args: PROXY|NOPROXY <config-file>
196 # (Function for test scripts)
197 start_ecs() {
198
199         echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
200
201         if [ $RUNMODE == "KUBE" ]; then
202
203                 # Check if app shall be fully managed by the test script
204                 __check_included_image "ECS"
205                 retcode_i=$?
206
207                 # Check if app shall only be used by the testscipt
208                 __check_prestarted_image "ECS"
209                 retcode_p=$?
210
211                 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
212                         echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
213                         echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
214                         exit
215                 fi
216                 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
217                         echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
218                         echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
219                         exit
220                 fi
221
222
223                 if [ $retcode_p -eq 0 ]; then
224                         echo -e " Using existing $ECS_APP_NAME deployment and service"
225                         echo " Setting ECS replicas=1"
226                         res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
227                         __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
228                 fi
229
230                 # Check if app shall be fully managed by the test script
231                 if [ $retcode_i -eq 0 ]; then
232                         echo -e " Creating $ECS_APP_NAME app and expose service"
233
234                         #Check if nonrtric namespace exists, if not create it
235                         __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
236
237                         __ecs_export_vars $1
238
239                         # Create config map for config
240                         datafile=$PWD/tmp/$ECS_CONFIG_FILE
241                         cp $2 $datafile
242                         output_yaml=$PWD/tmp/ecs_cfc.yaml
243                         __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
244
245                         # Create pv
246                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
247                         output_yaml=$PWD/tmp/ecs_pv.yaml
248                         __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
249
250                         # Create pvc
251                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
252                         output_yaml=$PWD/tmp/ecs_pvc.yaml
253                         __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
254
255                         # Create service
256                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
257                         output_yaml=$PWD/tmp/ecs_svc.yaml
258                         __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
259
260                         # Create app
261                         input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
262                         output_yaml=$PWD/tmp/ecs_app.yaml
263                         __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
264                 fi
265
266                 # 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
267                 # 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
268
269                 # 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
270                 if [ $retcode_i -eq 0 ]; then
271                         __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
272                         if [ -z "$__ECS_WORKER_NODE" ]; then
273                                 echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW
274                         fi
275                 else
276                         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
277                 fi
278
279
280                 __check_service_start $ECS_APP_NAME $ECS_SERVICE_PATH$ECS_ALIVE_URL
281
282         else
283                 __check_included_image 'ECS'
284                 if [ $? -eq 1 ]; then
285                         echo -e $RED"The ECS app is not included in this test script"$ERED
286                         echo -e $RED"ECS will not be started"$ERED
287                         exit 1
288                 fi
289
290                 curdir=$PWD
291                 cd $SIM_GROUP
292                 cd ecs
293                 cd $ECS_HOST_MNT_DIR
294                 #cd ..
295                 if [ -d db ]; then
296                         if [ "$(ls -A $DIR)" ]; then
297                                 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
298                                 rm -rf db/*  &> /dev/null
299                                 if [ $? -ne 0 ]; then
300                                         echo -e $RED" Cannot remove database files in: $PWD"$ERED
301                                         exit 1
302                                 fi
303                         fi
304                 else
305                         echo " No files in mounted dir or dir does not exists"
306                 fi
307
308                 cd $curdir
309
310                 __ecs_export_vars $1
311
312                 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
313
314                 envsubst < $2 > $dest_file
315
316                 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
317
318                 __check_service_start $ECS_APP_NAME $ECS_SERVICE_PATH$ECS_ALIVE_URL
319         fi
320         echo ""
321         return 0
322 }
323
324 # Stop the ecs
325 # args: -
326 # args: -
327 # (Function for test scripts)
328 stop_ecs() {
329         echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD
330
331         if [ $RUNMODE == "KUBE" ]; then
332
333                 __check_prestarted_image "ECS"
334                 if [ $? -eq 0 ]; then
335                         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
336                         res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
337                         __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
338                         return 0
339                 fi
340
341                 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
342                 echo "  Deleting the replica set - a new will be started when the app is started"
343                 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS")
344                 if [ $? -ne 0 ]; then
345                         echo -e $RED" Could not delete replica set "$RED
346                         ((RES_CONF_FAIL++))
347                         return 1
348                 fi
349         else
350                 docker stop $ECS_APP_NAME &> ./tmp/.dockererr
351                 if [ $? -ne 0 ]; then
352                         __print_err "Could not stop $ECS_APP_NAME" $@
353                         cat ./tmp/.dockererr
354                         ((RES_CONF_FAIL++))
355                         return 1
356                 fi
357         fi
358         echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
359         echo ""
360         return 0
361 }
362
363 # Start a previously stopped ecs
364 # args: -
365 # (Function for test scripts)
366 start_stopped_ecs() {
367         echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD
368
369         if [ $RUNMODE == "KUBE" ]; then
370
371                 __check_prestarted_image "ECS"
372                 if [ $? -eq 0 ]; then
373                         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
374                         res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
375                         __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
376                         __check_service_start $ECS_APP_NAME $ECS_SERVICE_PATH$ECS_ALIVE_URL
377                         return 0
378                 fi
379
380                 # Tie the PMS to the same worker node it was initially started on
381                 # 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
382                 if [ -z "$__ECS_WORKER_NODE" ]; then
383                         echo -e $RED" No initial worker node found for pod "$RED
384                         ((RES_CONF_FAIL++))
385                         return 1
386                 else
387                         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
388                         echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
389                         tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}')
390                         if [ $? -ne 0 ]; then
391                                 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW
392                         fi
393                         __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
394                 fi
395         else
396                 docker start $ECS_APP_NAME &> ./tmp/.dockererr
397                 if [ $? -ne 0 ]; then
398                         __print_err "Could not start (the stopped) $ECS_APP_NAME" $@
399                         cat ./tmp/.dockererr
400                         ((RES_CONF_FAIL++))
401                         return 1
402                 fi
403         fi
404         __check_service_start $ECS_APP_NAME $ECS_SERVICE_PATH$ECS_ALIVE_URL
405         if [ $? -ne 0 ]; then
406                 return 1
407         fi
408         echo ""
409         return 0
410 }
411
412 # Turn on debug level tracing in ECS
413 # args: -
414 # (Function for test scripts)
415 set_ecs_debug() {
416         echo -e $BOLD"Setting ecs debug logging"$EBOLD
417         curlString="$ECS_SERVICE_PATH$ECS_ACTUATOR -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
418         result=$(__do_curl "$curlString")
419         if [ $? -ne 0 ]; then
420                 __print_err "Could not set debug mode" $@
421                 ((RES_CONF_FAIL++))
422                 return 1
423         fi
424         echo ""
425         return 0
426 }
427
428 # Turn on trace level tracing in ECS
429 # args: -
430 # (Function for test scripts)
431 set_ecs_trace() {
432         echo -e $BOLD"Setting ecs trace logging"$EBOLD
433         curlString="$ECS_SERVICE_PATH/actuator/loggers/org.oransc.enrichment -X POST  -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
434         result=$(__do_curl "$curlString")
435         if [ $? -ne 0 ]; then
436                 __print_err "Could not set trace mode" $@
437                 ((RES_CONF_FAIL++))
438                 return 1
439         fi
440         echo ""
441         return 0
442 }
443
444 # Perform curl retries when making direct call to ECS for the specified http response codes
445 # Speace separated list of http response codes
446 # args: [<response-code>]*
447 use_ecs_retries() {
448         echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
449         ECS_RETRY_CODES=$@
450         echo ""
451         return 0
452 }
453
454 # Check the ecs logs for WARNINGs and ERRORs
455 # args: -
456 # (Function for test scripts)
457 check_ecs_logs() {
458         __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
459 }
460
461
462 # Tests if a variable value in the ECS is equal to a target value and and optional timeout.
463 # Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
464 # equal to the target or not.
465 # Arg: <variable-name> <target-value> <timeout-in-sec>  - This test waits up to the timeout seconds
466 # before setting pass or fail depending on if the variable value becomes equal to the target
467 # value or not.
468 # (Function for test scripts)
469 ecs_equal() {
470         if [ $# -eq 2 ] || [ $# -eq 3 ]; then
471                 __var_test ECS "$ECS_SERVICE_PATH/" $1 "=" $2 $3
472         else
473                 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
474         fi
475 }
476
477
478 ##########################################
479 ######### A1-E Enrichment  API ##########
480 ##########################################
481 #Function prefix: ecs_api_a1
482
483 # API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
484 # args: <response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
485 # args (flat uri structure): <response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
486 # (Function for test scripts)
487 ecs_api_a1_get_job_ids() {
488         __log_test_start $@
489
490         if [ -z "$FLAT_A1_EI" ]; then
491                 # Valid number of parameters 4,5,6 etc
492         if [ $# -lt 3 ]; then
493                         __print_err "<response-code> <type-id>  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
494                         return 1
495                 fi
496         else
497                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
498                 # Valid number of parameters 4,5,6 etc
499         if [ $# -lt 3 ]; then
500                         __print_err "<response-code> <type-id>|NOTYPE  <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
501                         return 1
502                 fi
503         fi
504         search=""
505         if [ $3 != "NOWNER" ]; then
506                 search="?owner="$3
507         fi
508
509         if [  -z "$FLAT_A1_EI" ]; then
510                 query="/A1-EI/v1/eitypes/$2/eijobs$search"
511         else
512                 if [ $2 != "NOTYPE" ]; then
513                         if [ -z "$search" ]; then
514                                 search="?eiTypeId="$2
515                         else
516                                 search=$search"&eiTypeId="$2
517                         fi
518                 fi
519                 query="/A1-EI/v1/eijobs$search"
520         fi
521     res="$(__do_curl_to_api ECS GET $query)"
522     status=${res:${#res}-3}
523
524         if [ $status -ne $1 ]; then
525                 __log_test_fail_status_code $1 $status
526                 return 1
527         fi
528
529         if [ $# -gt 3 ]; then
530                 body=${res:0:${#res}-3}
531                 targetJson="["
532
533                 for pid in ${@:4} ; do
534                         if [ "$targetJson" != "[" ]; then
535                                 targetJson=$targetJson","
536                         fi
537                         if [ $pid != "EMPTY" ]; then
538                                 targetJson=$targetJson"\"$pid\""
539                         fi
540                 done
541
542                 targetJson=$targetJson"]"
543                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
544                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
545
546                 if [ $res -ne 0 ]; then
547                         __log_test_fail_body
548                         return 1
549                 fi
550         fi
551
552         __log_test_pass
553         return 0
554 }
555
556 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}
557 # args: <response-code> <type-id> [<schema-file>]
558 # (Function for test scripts)
559 ecs_api_a1_get_type() {
560         __log_test_start $@
561
562     if [ $# -lt 2 ] || [ $# -gt 3 ]; then
563                 __print_err "<response-code> <type-id> [<schema-file>]" $@
564                 return 1
565         fi
566
567         query="/A1-EI/v1/eitypes/$2"
568     res="$(__do_curl_to_api ECS GET $query)"
569     status=${res:${#res}-3}
570
571         if [ $status -ne $1 ]; then
572                 __log_test_fail_status_code $1 $status
573                 return 1
574         fi
575
576         if [ $# -eq 3 ]; then
577                 body=${res:0:${#res}-3}
578                 if [ -f $3 ]; then
579                         schema=$(cat $3)
580                 else
581                         __log_test_fail_general "Schema file "$3", does not exist"
582                         return 1
583                 fi
584                 if [ -z "$FLAT_A1_EI" ]; then
585                         targetJson="{\"eiJobParametersSchema\":$schema}"
586                 else
587                         targetJson=$schema
588                 fi
589                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
590                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
591
592                 if [ $res -ne 0 ]; then
593                         __log_test_fail_body
594                         return 1
595                 fi
596         fi
597
598         __log_test_pass
599         return 0
600 }
601
602 # API Test function: GET /A1-EI/v1/eitypes
603 # args: <response-code> [ (EMPTY | [<type-id>]+) ]
604 # (Function for test scripts)
605 ecs_api_a1_get_type_ids() {
606         __log_test_start $@
607
608     if [ $# -lt 1 ]; then
609                 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
610                 return 1
611         fi
612
613         query="/A1-EI/v1/eitypes"
614     res="$(__do_curl_to_api ECS GET $query)"
615     status=${res:${#res}-3}
616
617         if [ $status -ne $1 ]; then
618                 __log_test_fail_status_code $1 $status
619                 return 1
620         fi
621         if [ $# -gt 1 ]; then
622                 body=${res:0:${#res}-3}
623                 targetJson="["
624                 if [ $2 != "EMPTY" ]; then
625                         for pid in ${@:2} ; do
626                                 if [ "$targetJson" != "[" ]; then
627                                         targetJson=$targetJson","
628                                 fi
629                                 targetJson=$targetJson"\"$pid\""
630                         done
631                 fi
632                 targetJson=$targetJson"]"
633                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
634                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
635
636                 if [ $res -ne 0 ]; then
637                         __log_test_fail_body
638                         return 1
639                 fi
640         fi
641
642         __log_test_pass
643         return 0
644 }
645
646 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
647 # args: <response-code> <type-id> <job-id> [<status>]
648 # args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
649 # (Function for test scripts)
650 ecs_api_a1_get_job_status() {
651         __log_test_start $@
652
653         if [ -z "$FLAT_A1_EI" ]; then
654                 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
655                         __print_err "<response-code> <type-id> <job-id> [<status>]" $@
656                         return 1
657                 fi
658
659                 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
660
661                 res="$(__do_curl_to_api ECS GET $query)"
662                 status=${res:${#res}-3}
663
664                 if [ $status -ne $1 ]; then
665                         __log_test_fail_status_code $1 $status
666                         return 1
667                 fi
668                 if [ $# -eq 4 ]; then
669                         body=${res:0:${#res}-3}
670                         targetJson="{\"operationalState\": \"$4\"}"
671                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
672                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
673
674                         if [ $res -ne 0 ]; then
675                                 __log_test_fail_body
676                                 return 1
677                         fi
678                 fi
679         else
680                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
681                 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
682                         __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
683                         return 1
684                 fi
685
686                 query="/A1-EI/v1/eijobs/$2/status"
687
688                 start=$SECONDS
689                 for (( ; ; )); do
690                         res="$(__do_curl_to_api ECS GET $query)"
691                         status=${res:${#res}-3}
692
693                         if [ $# -eq 4 ]; then
694                                 duration=$((SECONDS-start))
695                                 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
696                                 if [ $duration -gt $4 ]; then
697                                         echo ""
698                                         duration=-1  #Last iteration
699                                 fi
700                         else
701                                 duration=-1 #single test, no wait
702                         fi
703
704                         if [ $status -ne $1 ]; then
705                                 if [ $duration -eq -1 ]; then
706                                         __log_test_fail_status_code $1 $status
707                                         return 1
708                                 fi
709                         fi
710                         if [ $# -ge 3 ] && [ $status -eq $1 ]; then
711                                 body=${res:0:${#res}-3}
712                                 targetJson="{\"eiJobStatus\": \"$3\"}"
713                                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
714                                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
715
716                                 if [ $res -ne 0 ]; then
717                                         if [ $duration -eq -1 ]; then
718                                                 __log_test_fail_body
719                                                 return 1
720                                         fi
721                                 else
722                                         duration=-1  #Goto pass
723                                 fi
724                         fi
725                         if [ $duration -eq -1 ]; then
726                                 if [ $# -eq 4 ]; then
727                                         echo ""
728                                 fi
729                                 __log_test_pass
730                                 return 0
731                         else
732                                 sleep 1
733                         fi
734                 done
735         fi
736
737         __log_test_pass
738         return 0
739 }
740
741 # API Test function: GET â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
742 # args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
743 # args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
744 # (Function for test scripts)
745 ecs_api_a1_get_job() {
746         __log_test_start $@
747
748         if [  -z "$FLAT_A1_EI" ]; then
749                 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
750                         __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
751                         return 1
752                 fi
753                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
754         else
755                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
756                 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
757                         __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
758                         return 1
759                 fi
760                 query="/A1-EI/v1/eijobs/$2"
761         fi
762     res="$(__do_curl_to_api ECS GET $query)"
763     status=${res:${#res}-3}
764
765         if [ $status -ne $1 ]; then
766                 __log_test_fail_status_code $1 $status
767                 return 1
768         fi
769
770         if [  -z "$FLAT_A1_EI" ]; then
771                 if [ $# -eq 6 ]; then
772                         body=${res:0:${#res}-3}
773
774                         if [ -f $6 ]; then
775                                 jobfile=$(cat $6)
776                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
777                         else
778                                 __log_test_fail_general "Job template file "$6", does not exist"
779                                 return 1
780                         fi
781                         targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
782                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
783                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
784
785                         if [ $res -ne 0 ]; then
786                                 __log_test_fail_body
787                                 return 1
788                         fi
789                 fi
790         else
791                 if [ $# -eq 7 ]; then
792                         body=${res:0:${#res}-3}
793
794                         if [ -f $7 ]; then
795                                 jobfile=$(cat $7)
796                                 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
797                         else
798                                 __log_test_fail_general "Job template file "$6", does not exist"
799                                 return 1
800                         fi
801                         targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
802                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
803                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
804
805                         if [ $res -ne 0 ]; then
806                                 __log_test_fail_body
807                                 return 1
808                         fi
809                 fi
810         fi
811
812         __log_test_pass
813         return 0
814 }
815
816 # API Test function: DELETE â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
817 # args: <response-code> <type-id> <job-id>
818 # args (flat uri structure): <response-code> <job-id>
819 # (Function for test scripts)
820 ecs_api_a1_delete_job() {
821         __log_test_start $@
822
823         if [  -z "$FLAT_A1_EI" ]; then
824                 if [ $# -ne 3 ]; then
825                         __print_err "<response-code> <type-id> <job-id>" $@
826                         return 1
827                 fi
828
829                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
830         else
831                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
832                 if [ $# -ne 2 ]; then
833                         __print_err "<response-code> <job-id>" $@
834                         return 1
835                 fi
836                 query="/A1-EI/v1/eijobs/$2"
837         fi
838     res="$(__do_curl_to_api ECS DELETE $query)"
839     status=${res:${#res}-3}
840
841         if [ $status -ne $1 ]; then
842                 __log_test_fail_status_code $1 $status
843                 return 1
844         fi
845
846         __log_test_pass
847         return 0
848 }
849
850 # API Test function: PUT â€‹/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
851 # args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
852 # args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
853 # (Function for test scripts)
854 ecs_api_a1_put_job() {
855         __log_test_start $@
856
857         if [  -z "$FLAT_A1_EI" ]; then
858                 if [ $# -lt 6 ]; then
859                         __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
860                         return 1
861                 fi
862                 if [ -f $6 ]; then
863                         jobfile=$(cat $6)
864                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
865                 else
866                         __log_test_fail_general "Job template file "$6", does not exist"
867                         return 1
868                 fi
869
870                 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
871                 file="./tmp/.p.json"
872                 echo "$inputJson" > $file
873
874                 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
875         else
876                 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
877                 if [ $# -lt 7 ]; then
878                         __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
879                         return 1
880                 fi
881                 if [ -f $7 ]; then
882                         jobfile=$(cat $7)
883                         jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
884                 else
885                         __log_test_fail_general "Job template file "$7", does not exist"
886                         return 1
887                 fi
888
889                 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
890                 file="./tmp/.p.json"
891                 echo "$inputJson" > $file
892
893                 query="/A1-EI/v1/eijobs/$2"
894         fi
895
896     res="$(__do_curl_to_api ECS PUT $query $file)"
897     status=${res:${#res}-3}
898
899         if [ $status -ne $1 ]; then
900                 __log_test_fail_status_code $1 $status
901                 return 1
902         fi
903
904         __log_test_pass
905         return 0
906 }
907
908
909 ##########################################
910 ####   Enrichment Data Producer API   ####
911 ##########################################
912 # Function prefix: ecs_api_edp
913
914 # API Test function: GET /ei-producer/v1/eitypes
915 # API Test function: GET /data-producer/v1/info-types
916 # args: <response-code> [ EMPTY | <type-id>+]
917 # (Function for test scripts)
918 ecs_api_edp_get_type_ids() {
919         __log_test_start $@
920
921     if [ $# -lt 1 ]; then
922                 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
923                 return 1
924         fi
925         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
926                 query="/data-producer/v1/info-types"
927         else
928                 query="/ei-producer/v1/eitypes"
929         fi
930     res="$(__do_curl_to_api ECS GET $query)"
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         if [ $# -gt 1 ]; then
939                 body=${res:0:${#res}-3}
940                 targetJson="["
941                 if [ $2 != "EMPTY" ]; then
942                         for pid in ${@:2} ; do
943                                 if [ "$targetJson" != "[" ]; then
944                                         targetJson=$targetJson","
945                                 fi
946                                 targetJson=$targetJson"\"$pid\""
947                         done
948                 fi
949                 targetJson=$targetJson"]"
950                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
951                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
952
953                 if [ $res -ne 0 ]; then
954                         __log_test_fail_body
955                         return 1
956                 fi
957         fi
958
959         __log_test_pass
960         return 0
961 }
962
963 # API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
964 # API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
965 # args: <response-code> <producer-id> [<status> [<timeout>]]
966 # (Function for test scripts)
967 ecs_api_edp_get_producer_status() {
968         __log_test_start $@
969
970     if [ $# -lt 2 ] || [ $# -gt 4 ]; then
971                 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
972                 return 1
973         fi
974         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
975                 query="/data-producer/v1/info-producers/$2/status"
976         else
977                 query="/ei-producer/v1/eiproducers/$2/status"
978         fi
979         start=$SECONDS
980         for (( ; ; )); do
981                 res="$(__do_curl_to_api ECS GET $query)"
982                 status=${res:${#res}-3}
983
984                 if [ $# -eq 4 ]; then
985                         duration=$((SECONDS-start))
986                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
987                         if [ $duration -gt $4 ]; then
988                                 echo ""
989                                 duration=-1  #Last iteration
990                         fi
991                 else
992                         duration=-1 #single test, no wait
993                 fi
994
995                 if [ $status -ne $1 ]; then
996                         if [ $duration -eq -1 ]; then
997                                 __log_test_fail_status_code $1 $status
998                                 return 1
999                         fi
1000                 fi
1001                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1002                         body=${res:0:${#res}-3}
1003                         targetJson="{\"operational_state\": \"$3\"}"
1004                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
1005                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1006
1007                         if [ $res -ne 0 ]; then
1008                                 if [ $duration -eq -1 ]; then
1009                                         __log_test_fail_body
1010                                         return 1
1011                                 fi
1012                         else
1013                                 duration=-1  #Goto pass
1014                         fi
1015                 fi
1016                 if [ $duration -eq -1 ]; then
1017                         if [ $# -eq 4 ]; then
1018                                 echo ""
1019                         fi
1020                         __log_test_pass
1021                         return 0
1022                 else
1023                         sleep 1
1024                 fi
1025         done
1026 }
1027
1028
1029 # API Test function: GET /ei-producer/v1/eiproducers
1030 # args (v1_1): <response-code> [ EMPTY | <producer-id>+]
1031 # (Function for test scripts)
1032 ecs_api_edp_get_producer_ids() {
1033         __log_test_start $@
1034
1035     if [ $# -lt 1 ]; then
1036                 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
1037                 return 1
1038         fi
1039
1040         query="/ei-producer/v1/eiproducers"
1041     res="$(__do_curl_to_api ECS GET $query)"
1042     status=${res:${#res}-3}
1043
1044         if [ $status -ne $1 ]; then
1045                 __log_test_fail_status_code $1 $status
1046                 return 1
1047         fi
1048
1049         if [ $# -gt 1 ]; then
1050                 body=${res:0:${#res}-3}
1051                 targetJson="["
1052
1053                 for pid in ${@:2} ; do
1054                         if [ "$targetJson" != "[" ]; then
1055                                 targetJson=$targetJson","
1056                         fi
1057                         if [ $pid != "EMPTY" ]; then
1058                                 targetJson=$targetJson"\"$pid\""
1059                         fi
1060                 done
1061
1062                 targetJson=$targetJson"]"
1063                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1064                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1065
1066                 if [ $res -ne 0 ]; then
1067                         __log_test_fail_body
1068                         return 1
1069                 fi
1070         fi
1071
1072         __log_test_pass
1073         return 0
1074 }
1075
1076 # API Test function: GET /ei-producer/v1/eiproducers
1077 # API Test function: GET /data-producer/v1/info-producers
1078 # args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1079 # (Function for test scripts)
1080 ecs_api_edp_get_producer_ids_2() {
1081         __log_test_start $@
1082
1083     if [ $# -lt 1 ]; then
1084                 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1085                 return 1
1086         fi
1087     if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1088                 query="/data-producer/v1/info-producers"
1089                 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1090                         query=$query"?info_type_id=$2"
1091                 fi
1092         else
1093                 query="/ei-producer/v1/eiproducers"
1094                 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1095                         query=$query"?ei_type_id=$2"
1096                 fi
1097         fi
1098     res="$(__do_curl_to_api ECS GET $query)"
1099     status=${res:${#res}-3}
1100
1101         if [ $status -ne $1 ]; then
1102                 __log_test_fail_status_code $1 $status
1103                 return 1
1104         fi
1105
1106         if [ $# -gt 2 ]; then
1107                 body=${res:0:${#res}-3}
1108                 targetJson="["
1109
1110                 for pid in ${@:3} ; do
1111                         if [ "$targetJson" != "[" ]; then
1112                                 targetJson=$targetJson","
1113                         fi
1114                         if [ $pid != "EMPTY" ]; then
1115                                 targetJson=$targetJson"\"$pid\""
1116                         fi
1117                 done
1118
1119                 targetJson=$targetJson"]"
1120                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1121                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1122
1123                 if [ $res -ne 0 ]; then
1124                         __log_test_fail_body
1125                         return 1
1126                 fi
1127         fi
1128
1129         __log_test_pass
1130         return 0
1131 }
1132
1133 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1134 # args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
1135 # (Function for test scripts)
1136 ecs_api_edp_get_type() {
1137         __log_test_start $@
1138
1139         paramError=1
1140         if [ $# -eq 2 ]; then
1141                 paramError=0
1142         fi
1143         if [ $# -gt 3 ]; then
1144                 paramError=0
1145         fi
1146     if [ $paramError -ne 0 ]; then
1147                 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
1148                 return 1
1149         fi
1150
1151         query="/ei-producer/v1/eitypes/$2"
1152     res="$(__do_curl_to_api ECS GET $query)"
1153     status=${res:${#res}-3}
1154
1155         if [ $status -ne $1 ]; then
1156                 __log_test_fail_status_code $1 $status
1157                 return 1
1158         fi
1159         if [ $# -gt 3 ]; then
1160                 body=${res:0:${#res}-3}
1161
1162                 if [ -f $3 ]; then
1163                         schema=$(cat $3)
1164                 else
1165                         __log_test_fail_general "Job template file "$3", does not exist"
1166                         return 1
1167                 fi
1168
1169                 targetJson=""
1170                 if [ $4 != "EMPTY" ]; then
1171                         for pid in ${@:4} ; do
1172                                 if [ "$targetJson" != "" ]; then
1173                                         targetJson=$targetJson","
1174                                 fi
1175                                 targetJson=$targetJson"\"$pid\""
1176                         done
1177                 fi
1178                 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1179
1180                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1181                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1182
1183                 if [ $res -ne 0 ]; then
1184                         __log_test_fail_body
1185                         return 1
1186                 fi
1187         fi
1188         __log_test_pass
1189         return 0
1190 }
1191
1192 # API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
1193 # API Test function: GET /data-producer/v1/info-types/{infoTypeId}
1194 # args: (v1_2) <response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]
1195 # (Function for test scripts)
1196 ecs_api_edp_get_type_2() {
1197         __log_test_start $@
1198
1199         paramError=1
1200         if [ $# -eq 2 ]; then
1201                 paramError=0
1202         fi
1203         if [ $# -eq 3 ]; then
1204                 paramError=0
1205         fi
1206         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1207                 if [ $# -eq 4 ]; then
1208                         paramError=0
1209                 fi
1210         fi
1211     if [ $paramError -ne 0 ]; then
1212                 __print_err "<response-code> <type-id> [<job-schema-file> [ <info-type-info> ]]" $@
1213                 return 1
1214         fi
1215         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1216                 query="/data-producer/v1/info-types/$2"
1217         else
1218                 query="/ei-producer/v1/eitypes/$2"
1219         fi
1220
1221     res="$(__do_curl_to_api ECS GET $query)"
1222     status=${res:${#res}-3}
1223
1224         if [ $status -ne $1 ]; then
1225                 __log_test_fail_status_code $1 $status
1226                 return 1
1227         fi
1228         if [ $# -ge 3 ]; then
1229                 body=${res:0:${#res}-3}
1230
1231                 if [ -f $3 ]; then
1232                         schema=$(cat $3)
1233                 else
1234                         __log_test_fail_general "Job template file "$3", does not exist"
1235                         return 1
1236                 fi
1237                 info_data=""
1238                 if [ $# -gt 3 ]; then
1239                         if [ -f $4 ]; then
1240                                 info_data=$(cat $4)
1241                         else
1242                                 __log_test_fail_general "Info-data file "$4", does not exist"
1243                                 return 1
1244                         fi
1245                         info_data=",\"info_type_information\":$info_data"
1246                 fi
1247                 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1248                         targetJson="{\"info_job_data_schema\":$schema $info_data}"
1249                 else
1250                         targetJson="{\"ei_job_data_schema\":$schema}"
1251                 fi
1252
1253                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1254                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1255
1256                 if [ $res -ne 0 ]; then
1257                         __log_test_fail_body
1258                         return 1
1259                 fi
1260         fi
1261         __log_test_pass
1262         return 0
1263 }
1264
1265 # API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
1266 # API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
1267 # args: (v1_2) <response-code> <type-id> <job-schema-file> [ <info-type-info> ]
1268 # (Function for test scripts)
1269 ecs_api_edp_put_type_2() {
1270         __log_test_start $@
1271
1272         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPE-INFO"* ]]; then
1273                 if [ $# -lt 3 ] || [ $# -gt 4 ]; then
1274                         __print_err "<response-code> <type-id> <job-schema-file> [ <info-type-info> ]" $@
1275                         return 1
1276                 fi
1277         else
1278                 if [ $# -ne 3 ]; then
1279                         __print_err "<response-code> <type-id> <job-schema-file>" $@
1280                         return 1
1281                 fi
1282         fi
1283
1284         if [ ! -f $3 ]; then
1285                 __log_test_fail_general "Job schema file "$3", does not exist"
1286                 return 1
1287         fi
1288
1289         info_data=""
1290         if [ $# -gt 3 ]; then
1291                 if [ -f $4 ]; then
1292                         info_data=$(cat $4)
1293                 else
1294                         __log_test_fail_general "Info-data file "$4", does not exist"
1295                         return 1
1296                 fi
1297                 info_data=",\"info_type_information\":$info_data"
1298         fi
1299
1300         if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1301                 schema=$(cat $3)
1302                 input_json="{\"info_job_data_schema\":$schema $info_data}"
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> [<type-status> <producers-count]]
2021 # (Function for test scripts)
2022 ecs_api_idc_get_type() {
2023         __log_test_start $@
2024
2025     if [ $# -lt 2 ] || [ $# -gt 5 ]; then
2026                 __print_err "<response-code> <type-id> [<schema-file> [<type-status> <producers-count]]" $@
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 [ $# -gt 2 ]; 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                 if [ $# -eq 5 ]; then
2048                         targetJson="{\"job_data_schema\":$schema, \"type_status\":\"$4\", \"no_of_producers\":$5}"
2049                 else
2050                         targetJson="{\"job_data_schema\":$schema}"
2051                 fi
2052                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2053                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2054
2055                 if [ $res -ne 0 ]; then
2056                         __log_test_fail_body
2057                         return 1
2058                 fi
2059         fi
2060
2061         __log_test_pass
2062         return 0
2063 }
2064
2065 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2066 # This test only status during an optional timeout. No test of the list of producers
2067 # args: <response-code> <job-id> [<status> [<timeout>]]
2068 # (Function for test scripts)
2069 ecs_api_idc_get_job_status() {
2070         __log_test_start $@
2071
2072         if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2073                 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2074                 return 1
2075         fi
2076
2077         query="/data-consumer/v1/info-jobs/$2/status"
2078
2079         start=$SECONDS
2080         for (( ; ; )); do
2081                 res="$(__do_curl_to_api ECS GET $query)"
2082                 status=${res:${#res}-3}
2083
2084                 if [ $# -eq 4 ]; then
2085                         duration=$((SECONDS-start))
2086                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2087                         if [ $duration -gt $4 ]; then
2088                                 echo ""
2089                                 duration=-1  #Last iteration
2090                         fi
2091                 else
2092                         duration=-1 #single test, no wait
2093                 fi
2094
2095                 if [ $status -ne $1 ]; then
2096                         if [ $duration -eq -1 ]; then
2097                                 __log_test_fail_status_code $1 $status
2098                                 return 1
2099                         fi
2100                 fi
2101                 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2102                         body=${res:0:${#res}-3}
2103                         targetJson="{\"info_job_status\": \"$3\"}"
2104                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2105                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2106
2107                         if [ $res -ne 0 ]; then
2108                                 if [ $duration -eq -1 ]; then
2109                                         __log_test_fail_body
2110                                         return 1
2111                                 fi
2112                         else
2113                                 duration=-1  #Goto pass
2114                         fi
2115                 fi
2116                 if [ $duration -eq -1 ]; then
2117                         if [ $# -eq 4 ]; then
2118                                 echo ""
2119                         fi
2120                         __log_test_pass
2121                         return 0
2122                 else
2123                         sleep 1
2124                 fi
2125         done
2126
2127         __log_test_pass
2128         return 0
2129 }
2130
2131 # API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2132 # This function test status and the list of producers with and optional timeout
2133 # args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2134 # (Function for test scripts)
2135 ecs_api_idc_get_job_status2() {
2136
2137         __log_test_start $@
2138         param_error=0
2139         if [ $# -lt 2 ]; then
2140                 param_error=1
2141         fi
2142         args=("$@")
2143         timeout=0
2144         if [ $# -gt 2 ]; then
2145                 if [ $# -lt 4 ]; then
2146                         param_error=1
2147                 fi
2148                 targetJson="{\"info_job_status\": \"$3\""
2149                 if [ "$4" == "EMPTYPROD" ]; then
2150                         targetJson=$targetJson",\"producers\": []}"
2151                         if [ $# -gt 4 ]; then
2152                                 timeout=$5
2153                         fi
2154                 else
2155                         targetJson=$targetJson",\"producers\": ["
2156                         if [ $# -eq $(($4+5)) ]; then
2157                                 idx=$(($4+4))
2158                                 timeout=${args[$idx]}
2159                         fi
2160                         for ((ecs_i = 0 ; ecs_i < $4 ; ecs_i++)); do
2161                                 idx=$(($ecs_i+4))
2162                                 if [ $ecs_i -gt 0 ]; then
2163                                         targetJson=$targetJson","
2164                                 fi
2165                                 targetJson=$targetJson"\""${args[$idx]}"\""
2166                         done
2167                         targetJson=$targetJson"]}"
2168                 fi
2169         fi
2170
2171         if [ $param_error -ne 0 ]; then
2172                 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2173                 return 1
2174         fi
2175
2176         query="/data-consumer/v1/info-jobs/$2/status"
2177
2178         start=$SECONDS
2179         for (( ; ; )); do
2180                 res="$(__do_curl_to_api ECS GET $query)"
2181                 status=${res:${#res}-3}
2182
2183                 if [ $# -gt 2 ]; then
2184                         duration=$((SECONDS-start))
2185                         echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2186                         if [ $duration -gt $timeout ]; then
2187                                 echo ""
2188                                 duration=-1  #Last iteration
2189                         fi
2190                 else
2191                         duration=-1 #single test, no wait
2192                 fi
2193
2194                 if [ $status -ne $1 ]; then
2195                         if [ $duration -eq -1 ]; then
2196                                 __log_test_fail_status_code $1 $status
2197                                 return 1
2198                         fi
2199                 fi
2200                 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2201                         body=${res:0:${#res}-3}
2202                         echo " TARGET JSON: $targetJson" >> $HTTPLOG
2203                         res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2204
2205                         if [ $res -ne 0 ]; then
2206                                 if [ $duration -eq -1 ]; then
2207                                         __log_test_fail_body
2208                                         return 1
2209                                 fi
2210                         else
2211                                 duration=-1  #Goto pass
2212                         fi
2213                 fi
2214                 if [ $duration -eq -1 ]; then
2215                         if [ $# -eq 4 ]; then
2216                                 echo ""
2217                         fi
2218                         __log_test_pass
2219                         return 0
2220                 else
2221                         sleep 1
2222                 fi
2223         done
2224
2225         __log_test_pass
2226         return 0
2227 }
2228
2229 ##########################################
2230 ####     Type subscriptions           ####
2231 ##########################################
2232
2233 # API Test function: GET /data-consumer/v1/info-type-subscription
2234 # args: <response-code>  <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]
2235 # (Function for test scripts)
2236 ecs_api_idc_get_subscription_ids() {
2237         __log_test_start $@
2238
2239     if [ $# -lt 3 ]; then
2240                 __print_err "<response-code> <owner-id>|NOOWNER [ EMPTY | <subscription-id>+]" $@
2241                 return 1
2242         fi
2243
2244         query="/data-consumer/v1/info-type-subscription"
2245         search=""
2246         if [ $2 != "NOOWNER" ]; then
2247                 search="?owner="$2
2248         fi
2249
2250     res="$(__do_curl_to_api ECS GET $query$search)"
2251     status=${res:${#res}-3}
2252
2253         if [ $status -ne $1 ]; then
2254                 __log_test_fail_status_code $1 $status
2255                 return 1
2256         fi
2257
2258         if [ $# -gt 2 ]; then
2259                 body=${res:0:${#res}-3}
2260                 targetJson="["
2261                 if [ $3 != "EMPTY" ]; then
2262                         for pid in ${@:3} ; do
2263                                 if [ "$targetJson" != "[" ]; then
2264                                         targetJson=$targetJson","
2265                                 fi
2266                                 targetJson=$targetJson"\"$pid\""
2267                         done
2268                 fi
2269                 targetJson=$targetJson"]"
2270                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2271                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2272
2273                 if [ $res -ne 0 ]; then
2274                         __log_test_fail_body
2275                         return 1
2276                 fi
2277         fi
2278
2279         __log_test_pass
2280         return 0
2281 }
2282
2283 # API Test function: GET /data-consumer/v1/info-type-subscription/{subscriptionId}
2284 # args: <response-code>  <subscription-id> [ <owner-id> <status-uri> ]
2285 # (Function for test scripts)
2286 ecs_api_idc_get_subscription() {
2287         __log_test_start $@
2288
2289     if [ $# -ne 2 ] && [ $# -ne 4 ]; then
2290                 __print_err "<response-code>  <subscription-id> [ <owner-id> <status-uri> ]" $@
2291                 return 1
2292         fi
2293
2294         query="/data-consumer/v1/info-type-subscription/$2"
2295     res="$(__do_curl_to_api ECS GET $query)"
2296     status=${res:${#res}-3}
2297
2298         if [ $status -ne $1 ]; then
2299                 __log_test_fail_status_code $1 $status
2300                 return 1
2301         fi
2302
2303         if [ $# -gt 2 ]; then
2304                 body=${res:0:${#res}-3}
2305                 targetJson="{\"owner\":\"$3\",\"status_result_uri\":\"$4\"}"
2306                 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2307                 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2308
2309                 if [ $res -ne 0 ]; then
2310                         __log_test_fail_body
2311                         return 1
2312                 fi
2313         fi
2314
2315         __log_test_pass
2316         return 0
2317 }
2318
2319 # API Test function: PUT /data-consumer/v1/info-type-subscription/{subscriptionId}
2320 # args: <response-code>  <subscription-id> <owner-id> <status-uri>
2321 # (Function for test scripts)
2322 ecs_api_idc_put_subscription() {
2323         __log_test_start $@
2324
2325     if [ $# -ne 4 ]; then
2326                 __print_err "<response-code>  <subscription-id> <owner-id> <status-uri>" $@
2327                 return 1
2328         fi
2329
2330         inputJson="{\"owner\": \"$3\",\"status_result_uri\": \"$4\"}"
2331         file="./tmp/.p.json"
2332         echo "$inputJson" > $file
2333
2334         query="/data-consumer/v1/info-type-subscription/$2"
2335     res="$(__do_curl_to_api ECS PUT $query $file)"
2336     status=${res:${#res}-3}
2337
2338         if [ $status -ne $1 ]; then
2339                 __log_test_fail_status_code $1 $status
2340                 return 1
2341         fi
2342
2343         __log_test_pass
2344         return 0
2345 }
2346
2347 # API Test function: DELETE /data-consumer/v1/info-type-subscription/{subscriptionId}
2348 # args: <response-code>  <subscription-id>
2349 # (Function for test scripts)
2350 ecs_api_idc_delete_subscription() {
2351         __log_test_start $@
2352
2353         if [ $# -ne 2 ]; then
2354                 __print_err "<response-code>  <subscription-id> " $@
2355                 return 1
2356         fi
2357
2358         query="/data-consumer/v1/info-type-subscription/$2"
2359     res="$(__do_curl_to_api ECS DELETE $query)"
2360     status=${res:${#res}-3}
2361
2362         if [ $status -ne $1 ]; then
2363                 __log_test_fail_status_code $1 $status
2364                 return 1
2365         fi
2366
2367         __log_test_pass
2368         return 0
2369 }
2370
2371 ##########################################
2372 ####          Reset jobs              ####
2373 ##########################################
2374 # Function prefix: ecs_api_admin
2375
2376 # Admin to remove all jobs
2377 # args: <response-code> [ <type> ]
2378 # (Function for test scripts)
2379
2380 ecs_api_admin_reset() {
2381         __log_test_start $@
2382
2383         if [  -z "$FLAT_A1_EI" ]; then
2384                 query="/A1-EI/v1/eitypes/$2/eijobs"
2385         else
2386                 query="/A1-EI/v1/eijobs"
2387         fi
2388     res="$(__do_curl_to_api ECS GET $query)"
2389     status=${res:${#res}-3}
2390
2391         if [ $status -ne 200 ]; then
2392                 __log_test_fail_status_code $1 $status
2393                 return 1
2394         fi
2395
2396         #Remove brackets and response code
2397         body=${res:1:${#res}-4}
2398         list=$(echo ${body//,/ })
2399         list=$(echo ${list//[/})
2400         list=$(echo ${list//]/})
2401         list=$(echo ${list//\"/})
2402         list=$list" "
2403         for job in $list; do
2404                 if [  -z "$FLAT_A1_EI" ]; then
2405                         echo "Not supported for non-flat EI api"
2406                 else
2407                         query="/A1-EI/v1/eijobs/$job"
2408                         res="$(__do_curl_to_api ECS DELETE $query)"
2409                         status=${res:${#res}-3}
2410                         if [ $status -ne 204 ]; then
2411                                 __log_test_fail_status_code $1 $status
2412                                 return 1
2413                         fi
2414                         echo " Deleted job: "$job
2415                 fi
2416         done
2417
2418         __log_test_pass
2419         return 0
2420 }
2421
2422 ##########################################
2423 ####     Reset jobs and producers     ####
2424 ##########################################
2425
2426
2427 # Admin reset to remove all data in ecs; jobs, producers etc
2428 # NOTE - only works in kubernetes and the pod should not be running
2429 # args: -
2430 # (Function for test scripts)
2431
2432 ecs_kube_pvc_reset() {
2433         __log_test_start $@
2434
2435         pvc_name=$(kubectl get pvc -n $KUBE_NONRTRIC_NAMESPACE  --no-headers -o custom-columns=":metadata.name" | grep enrichment)
2436         if [ -z "$pvc_name" ]; then
2437                 pvc_name=enrichmentservice-pvc
2438         fi
2439         echo " Trying to reset pvc: "$pvc_name
2440
2441         __kube_clean_pvc $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE $pvc_name $ECS_CONTAINER_MNT_DIR
2442
2443         __log_test_pass
2444         return 0
2445 }