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