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