blob: 5ad1b98e67a9262813b928e65c5a4f624ae0c8c8 [file] [log] [blame]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001#!/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
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010020# This is a script that contains container/service management functions and test functions for ECS
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +020021
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010022################ Test engine functions ################
23
24# Create the image var used during the test
25# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
26# <image-tag-suffix> is present only for images with staging, snapshot,release tags
27__ECS_imagesetup() {
28 __check_and_create_image_var ECS "ECS_IMAGE" "ECS_IMAGE_BASE" "ECS_IMAGE_TAG" $1 "$ECS_DISPLAY_NAME"
29}
30
31# Pull image from remote repo or use locally built image
32# arg: <pull-policy-override> <pull-policy-original>
33# <pull-policy-override> Shall be used for images allowing overriding. For example use a local image when test is started to use released images
34# <pull-policy-original> Shall be used for images that does not allow overriding
35# Both var may contain: 'remote', 'remote-remove' or 'local'
36__ECS_imagepull() {
BjornMagnussonXA483ee332021-04-08 01:35:24 +020037 __check_and_pull_image $1 "$ECS_DISPLAY_NAME" $ECS_APP_NAME ECS_IMAGE
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010038}
39
40# Build image (only for simulator or interfaces stubs owned by the test environment)
41# arg: <image-tag-suffix> (selects staging, snapshot, release etc)
42# <image-tag-suffix> is present only for images with staging, snapshot,release tags
43__ECS_imagebuild() {
44 echo -e $RED" Image for app ECS shall never be built"$ERED
45}
46
47# Generate a string for each included image using the app display name and a docker images format string
BjornMagnussonXA483ee332021-04-08 01:35:24 +020048# If a custom image repo is used then also the source image from the local repo is listed
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010049# arg: <docker-images-format-string> <file-to-append>
50__ECS_image_data() {
51 echo -e "$ECS_DISPLAY_NAME\t$(docker images --format $1 $ECS_IMAGE)" >> $2
BjornMagnussonXA483ee332021-04-08 01:35:24 +020052 if [ ! -z "$ECS_IMAGE_SOURCE" ]; then
53 echo -e "-- source image --\t$(docker images --format $1 $ECS_IMAGE_SOURCE)" >> $2
54 fi
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +010055}
56
57# Scale kubernetes resources to zero
58# All resources shall be ordered to be scaled to 0, if relevant. If not relevant to scale, then do no action.
59# This function is called for apps fully managed by the test script
60__ECS_kube_scale_zero() {
61 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
62}
63
64# Scale kubernetes resources to zero and wait until this has been accomplished, if relevant. If not relevant to scale, then do no action.
65# This function is called for prestarted apps not managed by the test script.
66__ECS_kube_scale_zero_and_wait() {
67 __kube_scale_and_wait_all_resources $KUBE_NONRTRIC_NAMESPACE app nonrtric-enrichmentservice
68}
69
70# Delete all kube resouces for the app
71# This function is called for apps managed by the test script.
72__ECS_kube_delete_all() {
73 __kube_delete_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
74}
75
76# Store docker logs
77# This function is called for apps managed by the test script.
78# args: <log-dir> <file-prexix>
79__ECS_store_docker_logs() {
80 docker logs $ECS_APP_NAME > $1$2_ecs.log 2>&1
81}
82#######################################################
83
84
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +010085## Access to ECS
86# Host name may be changed if app started by kube
87# Direct access
88ECS_HTTPX="http"
89ECS_HOST_NAME=$LOCALHOST_NAME
90ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
91
92# ECS_ADAPTER used for switch between REST and DMAAP (only REST supported currently)
93ECS_ADAPTER_TYPE="REST"
94ECS_ADAPTER=$ECS_PATH
95
96# Make curl retries towards ECS for http response codes set in this env var, space separated list of codes
97ECS_RETRY_CODES=""
98
BjornMagnussonXAa69cd902021-04-22 23:46:10 +020099#Save first worker node the pod is started on
100__ECS_WORKER_NODE=""
101
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100102###########################
103### ECS functions
104###########################
105
106# All calls to ECS will be directed to the ECS REST interface from now on
107# args: -
108# (Function for test scripts)
109use_ecs_rest_http() {
110 echo -e $BOLD"ECS protocol setting"$EBOLD
111 echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards ECS"
112 ECS_HTTPX="http"
113 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
114
115 ECS_ADAPTER_TYPE="REST"
116 ECS_ADAPTER=$ECS_PATH
117 echo ""
118}
119
120# All calls to ECS will be directed to the ECS REST interface from now on
121# args: -
122# (Function for test scripts)
123use_ecs_rest_https() {
124 echo -e $BOLD"ECS protocol setting"$EBOLD
125 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
126 ECS_HTTPX="https"
127 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
128
129 ECS_ADAPTER_TYPE="REST"
130 ECS_ADAPTER=$ECS_PATH
131 echo ""
132}
133
134# All calls to ECS will be directed to the ECS dmaap interface over http from now on
135# args: -
136# (Function for test scripts)
137use_ecs_dmaap_http() {
138 echo -e $BOLD"ECS dmaap protocol setting"$EBOLD
139 echo -e $RED" - NOT SUPPORTED - "$ERED
140 echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards ECS"
141 ECS_ADAPTER_TYPE="MR-HTTP"
142 echo ""
143}
144
145# All calls to ECS will be directed to the ECS dmaap interface over https from now on
146# args: -
147# (Function for test scripts)
148use_ecs_dmaap_https() {
149 echo -e $BOLD"RICSIM protocol setting"$EBOLD
150 echo -e $RED" - NOT SUPPORTED - "$ERED
151 echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards ECS"
152 ECS_ADAPTER_TYPE="MR-HTTPS"
153 echo ""
154}
155
156# Start the ECS
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100157# args: PROXY|NOPROXY <config-file>
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100158# (Function for test scripts)
159start_ecs() {
160
161 echo -e $BOLD"Starting $ECS_DISPLAY_NAME"$EBOLD
162
163 if [ $RUNMODE == "KUBE" ]; then
164
165 # Check if app shall be fully managed by the test script
166 __check_included_image "ECS"
167 retcode_i=$?
168
169 # Check if app shall only be used by the testscipt
170 __check_prestarted_image "ECS"
171 retcode_p=$?
172
173 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
174 echo -e $RED"The $ECS_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
175 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
176 exit
177 fi
178 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
179 echo -e $RED"The $ECS_APP_NAME app is included both as managed and prestarted in this test script"$ERED
180 echo -e $RED"The $ECS_APP_NAME will not be started"$ERED
181 exit
182 fi
183
184
185 if [ $retcode_p -eq 0 ]; then
186 echo -e " Using existing $ECS_APP_NAME deployment and service"
187 echo " Setting ECS replicas=1"
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200188 res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
189 __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100190 fi
191
192 # Check if app shall be fully managed by the test script
193 if [ $retcode_i -eq 0 ]; then
194 echo -e " Creating $ECS_APP_NAME app and expose service"
195
196 #Check if nonrtric namespace exists, if not create it
197 __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
198
199 export ECS_APP_NAME
200 export KUBE_NONRTRIC_NAMESPACE
201 export ECS_IMAGE
202 export ECS_INTERNAL_PORT
203 export ECS_INTERNAL_SECURE_PORT
204 export ECS_EXTERNAL_PORT
205 export ECS_EXTERNAL_SECURE_PORT
206 export ECS_CONFIG_MOUNT_PATH
207 export ECS_CONFIG_CONFIGMAP_NAME=$ECS_APP_NAME"-config"
208 export ECS_DATA_CONFIGMAP_NAME=$ECS_APP_NAME"-data"
209 export ECS_CONTAINER_MNT_DIR
210
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100211 export ECS_DATA_PV_NAME=$ECS_APP_NAME"-pv"
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200212 export ECS_DATA_PVC_NAME=$ECS_APP_NAME"-pvc"
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100213 #Create a unique path for the pv each time to prevent a previous volume to be reused
214 export ECS_PV_PATH="ecsdata-"$(date +%s)
215
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100216 if [ $1 == "PROXY" ]; then
217 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
218 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
219 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
220 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
221 else
222 echo " Configured with http proxy"
223 fi
224 else
225 ECS_HTTP_PROXY_CONFIG_PORT=0
226 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
227 echo " Configured without http proxy"
228 fi
229 export ECS_HTTP_PROXY_CONFIG_PORT
230 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
231
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100232 # Create config map for config
233 datafile=$PWD/tmp/$ECS_CONFIG_FILE
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100234 cp $2 $datafile
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100235 output_yaml=$PWD/tmp/ecs_cfc.yaml
236 __kube_create_configmap $ECS_CONFIG_CONFIGMAP_NAME $KUBE_NONRTRIC_NAMESPACE autotest ECS $datafile $output_yaml
237
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100238 # Create pv
239 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pv.yaml
240 output_yaml=$PWD/tmp/ecs_pv.yaml
241 __kube_create_instance pv $ECS_APP_NAME $input_yaml $output_yaml
242
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100243 # Create pvc
244 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"pvc.yaml
245 output_yaml=$PWD/tmp/ecs_pvc.yaml
246 __kube_create_instance pvc $ECS_APP_NAME $input_yaml $output_yaml
247
248 # Create service
249 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"svc.yaml
250 output_yaml=$PWD/tmp/ecs_svc.yaml
251 __kube_create_instance service $ECS_APP_NAME $input_yaml $output_yaml
252
253 # Create app
254 input_yaml=$SIM_GROUP"/"$ECS_COMPOSE_DIR"/"app.yaml
255 output_yaml=$PWD/tmp/ecs_app.yaml
256 __kube_create_instance app $ECS_APP_NAME $input_yaml $output_yaml
257 fi
258
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200259 # Tie the ECS to a worker node so that ECS will always be scheduled to the same worker node if the ECS pod is restarted
260 # A PVC of type hostPath is mounted to ECS, for persistent storage, so the ECS must always be on the node which mounted the volume
261
262 # Keep the initial worker node in case the pod need to be "restarted" - must be made to the same node due to a volume mounted on the host
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200263 if [ $retcode_i -eq 0 ]; then
264 __ECS_WORKER_NODE=$(kubectl get pod -l "autotest=ECS" -n $KUBE_NONRTRIC_NAMESPACE -o jsonpath='{.items[*].spec.nodeName}')
265 if [ -z "$__ECS_WORKER_NODE" ]; then
266 echo -e $YELLOW" Cannot find worker node for pod for $ECS_APP_NAME, persistency may not work"$EYELLOW
267 fi
268 else
269 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200270 fi
271
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100272 echo " Retrieving host and ports for service..."
273 ECS_HOST_NAME=$(__kube_get_service_host $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
274 ECS_EXTERNAL_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "http")
275 ECS_EXTERNAL_SECURE_PORT=$(__kube_get_service_port $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE "https")
276
277 echo " Host IP, http port, https port: $ECS_HOST_NAME $ECS_EXTERNAL_PORT $ECS_EXTERNAL_SECURE_PORT"
278
279 if [ $ECS_HTTPX == "http" ]; then
280 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_PORT
281 else
282 ECS_PATH=$ECS_HTTPX"://"$ECS_HOST_NAME":"$ECS_EXTERNAL_SECURE_PORT
283 fi
284
285 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
286
287 if [ $ECS_ADAPTER_TYPE == "REST" ]; then
288 ECS_ADAPTER=$ECS_PATH
289 fi
290 else
291 __check_included_image 'ECS'
292 if [ $? -eq 1 ]; then
293 echo -e $RED"The ECS app is not included in this test script"$ERED
294 echo -e $RED"ECS will not be started"$ERED
295 exit 1
296 fi
297
298 curdir=$PWD
299 cd $SIM_GROUP
300 cd ecs
301 cd $ECS_HOST_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100302 #cd ..
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100303 if [ -d db ]; then
304 if [ "$(ls -A $DIR)" ]; then
305 echo -e $BOLD" Cleaning files in mounted dir: $PWD/db"$EBOLD
306 rm -rf db/* &> /dev/null
307 if [ $? -ne 0 ]; then
308 echo -e $RED" Cannot remove database files in: $PWD"$ERED
309 exit 1
310 fi
311 fi
312 else
313 echo " No files in mounted dir or dir does not exists"
314 fi
315 cd $curdir
316
317 export ECS_APP_NAME
318 export ECS_APP_NAME_ALIAS
319 export ECS_HOST_MNT_DIR
320 export ECS_CONTAINER_MNT_DIR
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100321 export ECS_CONFIG_MOUNT_PATH
322 export ECS_CONFIG_FILE
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100323 export ECS_INTERNAL_PORT
324 export ECS_EXTERNAL_PORT
325 export ECS_INTERNAL_SECURE_PORT
326 export ECS_EXTERNAL_SECURE_PORT
327 export DOCKER_SIM_NWNAME
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100328 export ECS_DISPLAY_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100329
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100330 if [ $1 == "PROXY" ]; then
331 ECS_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
332 ECS_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
333 if [ $ECS_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$ECS_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
334 echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
335 else
336 echo " Configured with http proxy"
337 fi
338 else
339 ECS_HTTP_PROXY_CONFIG_PORT=0
340 ECS_HTTP_PROXY_CONFIG_HOST_NAME=""
341 echo " Configured without http proxy"
342 fi
343 export ECS_HTTP_PROXY_CONFIG_PORT
344 export ECS_HTTP_PROXY_CONFIG_HOST_NAME
345
346 dest_file=$SIM_GROUP/$ECS_COMPOSE_DIR/$ECS_HOST_MNT_DIR/$ECS_CONFIG_FILE
347
348 envsubst < $2 > $dest_file
349
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100350 __start_container $ECS_COMPOSE_DIR "" NODOCKERARGS 1 $ECS_APP_NAME
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100351
352 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
353 fi
354 echo ""
355 return 0
356}
357
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200358# Stop the ecs
359# args: -
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100360# args: -
361# (Function for test scripts)
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200362stop_ecs() {
363 echo -e $BOLD"Stopping $ECS_DISPLAY_NAME"$EBOLD
364
365 if [ $RUNMODE == "KUBE" ]; then
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200366
367 __check_prestarted_image "ECS"
368 if [ $? -eq 0 ]; then
369 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200370 res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
371 __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200372 return 0
373 fi
374
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200375 __kube_scale_all_resources $KUBE_NONRTRIC_NAMESPACE autotest ECS
376 echo " Deleting the replica set - a new will be started when the app is started"
377 tmp=$(kubectl delete rs -n $KUBE_NONRTRIC_NAMESPACE -l "autotest=ECS")
378 if [ $? -ne 0 ]; then
379 echo -e $RED" Could not delete replica set "$RED
380 ((RES_CONF_FAIL++))
381 return 1
382 fi
383 else
384 docker stop $ECS_APP_NAME &> ./tmp/.dockererr
385 if [ $? -ne 0 ]; then
386 __print_err "Could not stop $ECS_APP_NAME" $@
387 cat ./tmp/.dockererr
388 ((RES_CONF_FAIL++))
389 return 1
390 fi
391 fi
392 echo -e $BOLD$GREEN"Stopped"$EGREEN$EBOLD
393 echo ""
394 return 0
395}
396
397# Start a previously stopped ecs
398# args: -
399# (Function for test scripts)
400start_stopped_ecs() {
401 echo -e $BOLD"Starting (the previously stopped) $ECS_DISPLAY_NAME"$EBOLD
402
403 if [ $RUNMODE == "KUBE" ]; then
404
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200405 __check_prestarted_image "ECS"
406 if [ $? -eq 0 ]; then
407 echo -e $YELLOW" Persistency may not work for app $ECS_APP_NAME in multi-worker node config when running it as a prestarted app"$EYELLOW
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +0200408 res_type=$(__kube_get_resource_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE)
409 __kube_scale $res_type $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
BjornMagnussonXAa5491572021-05-04 09:21:24 +0200410 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
411 return 0
412 fi
413
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200414 # Tie the PMS to the same worker node it was initially started on
415 # A PVC of type hostPath is mounted to PMS, for persistent storage, so the PMS must always be on the node which mounted the volume
416 if [ -z "$__ECS_WORKER_NODE" ]; then
417 echo -e $RED" No initial worker node found for pod "$RED
418 ((RES_CONF_FAIL++))
419 return 1
420 else
421 echo -e $BOLD" Setting nodeSelector kubernetes.io/hostname=$__ECS_WORKER_NODE to deployment for $ECS_APP_NAME. Pod will always run on this worker node: $__PA_WORKER_NODE"$BOLD
422 echo -e $BOLD" The mounted volume is mounted as hostPath and only available on that worker node."$BOLD
423 tmp=$(kubectl patch deployment $ECS_APP_NAME -n $KUBE_NONRTRIC_NAMESPACE --patch '{"spec": {"template": {"spec": {"nodeSelector": {"kubernetes.io/hostname": "'$__ECS_WORKER_NODE'"}}}}}')
424 if [ $? -ne 0 ]; then
425 echo -e $YELLOW" Cannot set nodeSelector to deployment for $ECS_APP_NAME, persistency may not work"$EYELLOW
426 fi
427 __kube_scale deployment $ECS_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
428 fi
BjornMagnussonXAa69cd902021-04-22 23:46:10 +0200429 else
430 docker start $ECS_APP_NAME &> ./tmp/.dockererr
431 if [ $? -ne 0 ]; then
432 __print_err "Could not start (the stopped) $ECS_APP_NAME" $@
433 cat ./tmp/.dockererr
434 ((RES_CONF_FAIL++))
435 return 1
436 fi
437 fi
438 __check_service_start $ECS_APP_NAME $ECS_PATH$ECS_ALIVE_URL
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100439 if [ $? -ne 0 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100440 return 1
441 fi
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100442 echo ""
443 return 0
444}
445
446# Turn on debug level tracing in ECS
447# args: -
448# (Function for test scripts)
449set_ecs_debug() {
450 echo -e $BOLD"Setting ecs debug logging"$EBOLD
451 curlString="$ECS_PATH$ECS_ACTUATOR -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"debug\"}"
452 result=$(__do_curl "$curlString")
453 if [ $? -ne 0 ]; then
454 __print_err "Could not set debug mode" $@
455 ((RES_CONF_FAIL++))
456 return 1
457 fi
458 echo ""
459 return 0
460}
461
462# Turn on trace level tracing in ECS
463# args: -
464# (Function for test scripts)
465set_ecs_trace() {
466 echo -e $BOLD"Setting ecs trace logging"$EBOLD
467 curlString="$ECS_PATH/actuator/loggers/org.oransc.enrichment -X POST -H Content-Type:application/json -d {\"configuredLevel\":\"trace\"}"
468 result=$(__do_curl "$curlString")
469 if [ $? -ne 0 ]; then
470 __print_err "Could not set trace mode" $@
471 ((RES_CONF_FAIL++))
472 return 1
473 fi
474 echo ""
475 return 0
476}
477
478# Perform curl retries when making direct call to ECS for the specified http response codes
479# Speace separated list of http response codes
480# args: [<response-code>]*
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100481use_ecs_retries() {
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100482 echo -e $BOLD"Do curl retries to the ECS REST inteface for these response codes:$@"$EBOLD
BjornMagnussonXAc963b732021-01-20 14:24:13 +0100483 ECS_RETRY_CODES=$@
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100484 echo ""
485 return 0
486}
487
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100488# Check the ecs logs for WARNINGs and ERRORs
489# args: -
490# (Function for test scripts)
491check_ecs_logs() {
492 __check_container_logs "ECS" $ECS_APP_NAME $ECS_LOGPATH WARN ERR
493}
494
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200495
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100496# Tests if a variable value in the ECS is equal to a target value and and optional timeout.
497# Arg: <variable-name> <target-value> - This test set pass or fail depending on if the variable is
498# equal to the target or not.
499# Arg: <variable-name> <target-value> <timeout-in-sec> - This test waits up to the timeout seconds
500# before setting pass or fail depending on if the variable value becomes equal to the target
501# value or not.
502# (Function for test scripts)
503ecs_equal() {
504 if [ $# -eq 2 ] || [ $# -eq 3 ]; then
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +0100505 __var_test ECS "$ECS_PATH/" $1 "=" $2 $3
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100506 else
507 __print_err "Wrong args to ecs_equal, needs two or three args: <sim-param> <target-value> [ timeout ]" $@
508 fi
509}
510
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200511
512##########################################
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100513######### A1-E Enrichment API ##########
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200514##########################################
515#Function prefix: ecs_api_a1
516
517# API Test function: GET /A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200518# args: <response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100519# args (flat uri structure): <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200520# (Function for test scripts)
521ecs_api_a1_get_job_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100522 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200523
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100524 if [ -z "$FLAT_A1_EI" ]; then
525 # Valid number of parameters 4,5,6 etc
526 if [ $# -lt 3 ]; then
527 __print_err "<response-code> <type-id> <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
528 return 1
529 fi
530 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100531 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100532 # Valid number of parameters 4,5,6 etc
533 if [ $# -lt 3 ]; then
534 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
535 return 1
536 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200537 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100538 search=""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200539 if [ $3 != "NOWNER" ]; then
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100540 search="?owner="$3
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200541 fi
542
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100543 if [ -z "$FLAT_A1_EI" ]; then
544 query="/A1-EI/v1/eitypes/$2/eijobs$search"
545 else
546 if [ $2 != "NOTYPE" ]; then
547 if [ -z "$search" ]; then
548 search="?eiTypeId="$2
549 else
550 search=$search"&eiTypeId="$2
551 fi
552 fi
553 query="/A1-EI/v1/eijobs$search"
554 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200555 res="$(__do_curl_to_api ECS GET $query)"
556 status=${res:${#res}-3}
557
558 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100559 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200560 return 1
561 fi
562
563 if [ $# -gt 3 ]; then
564 body=${res:0:${#res}-3}
565 targetJson="["
566
567 for pid in ${@:4} ; do
568 if [ "$targetJson" != "[" ]; then
569 targetJson=$targetJson","
570 fi
571 if [ $pid != "EMPTY" ]; then
572 targetJson=$targetJson"\"$pid\""
573 fi
574 done
575
576 targetJson=$targetJson"]"
577 echo " TARGET JSON: $targetJson" >> $HTTPLOG
578 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
579
580 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100581 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200582 return 1
583 fi
584 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200585
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100586 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200587 return 0
588}
589
590# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200591# args: <response-code> <type-id> [<schema-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200592# (Function for test scripts)
593ecs_api_a1_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100594 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200595
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200596 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
597 __print_err "<response-code> <type-id> [<schema-file>]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200598 return 1
599 fi
600
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200601 query="/A1-EI/v1/eitypes/$2"
602 res="$(__do_curl_to_api ECS GET $query)"
603 status=${res:${#res}-3}
604
605 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100606 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200607 return 1
608 fi
609
610 if [ $# -eq 3 ]; then
611 body=${res:0:${#res}-3}
612 if [ -f $3 ]; then
613 schema=$(cat $3)
614 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100615 __log_test_fail_general "Schema file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200616 return 1
617 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100618 if [ -z "$FLAT_A1_EI" ]; then
619 targetJson="{\"eiJobParametersSchema\":$schema}"
620 else
621 targetJson=$schema
622 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200623 echo " TARGET JSON: $targetJson" >> $HTTPLOG
624 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
625
626 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100627 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200628 return 1
629 fi
630 fi
631
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100632 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200633 return 0
634}
635
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200636# API Test function: GET /A1-EI/v1/eitypes
637# args: <response-code> [ (EMPTY | [<type-id>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200638# (Function for test scripts)
639ecs_api_a1_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100640 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200641
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200642 if [ $# -lt 1 ]; then
643 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200644 return 1
645 fi
646
647 query="/A1-EI/v1/eitypes"
648 res="$(__do_curl_to_api ECS GET $query)"
649 status=${res:${#res}-3}
650
651 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100652 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200653 return 1
654 fi
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200655 if [ $# -gt 1 ]; then
656 body=${res:0:${#res}-3}
657 targetJson="["
658 if [ $2 != "EMPTY" ]; then
659 for pid in ${@:2} ; do
660 if [ "$targetJson" != "[" ]; then
661 targetJson=$targetJson","
662 fi
663 targetJson=$targetJson"\"$pid\""
664 done
665 fi
666 targetJson=$targetJson"]"
667 echo " TARGET JSON: $targetJson" >> $HTTPLOG
668 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200669
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200670 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100671 __log_test_fail_body
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +0200672 return 1
673 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200674 fi
675
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100676 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200677 return 0
678}
679
680# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}​/status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200681# args: <response-code> <type-id> <job-id> [<status>]
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100682# args (flat uri structure): <response-code> <job-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200683# (Function for test scripts)
684ecs_api_a1_get_job_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100685 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200686
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100687 if [ -z "$FLAT_A1_EI" ]; then
688 if [ $# -ne 3 ] && [ $# -ne 4 ]; then
689 __print_err "<response-code> <type-id> <job-id> [<status>]" $@
690 return 1
691 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200692
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100693 query="/A1-EI/v1/eitypes/$2/eijobs/$3/status"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200694
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100695 res="$(__do_curl_to_api ECS GET $query)"
696 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200697
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100698 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100699 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200700 return 1
701 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100702 if [ $# -eq 4 ]; then
703 body=${res:0:${#res}-3}
704 targetJson="{\"operationalState\": \"$4\"}"
705 echo " TARGET JSON: $targetJson" >> $HTTPLOG
706 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
707
708 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100709 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100710 return 1
711 fi
712 fi
713 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100714 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100715 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
716 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100717 return 1
718 fi
719
720 query="/A1-EI/v1/eijobs/$2/status"
721
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100722 start=$SECONDS
723 for (( ; ; )); do
724 res="$(__do_curl_to_api ECS GET $query)"
725 status=${res:${#res}-3}
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100726
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100727 if [ $# -eq 4 ]; then
728 duration=$((SECONDS-start))
729 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
730 if [ $duration -gt $4 ]; then
731 echo ""
732 duration=-1 #Last iteration
733 fi
734 else
735 duration=-1 #single test, no wait
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100736 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +0100737
738 if [ $status -ne $1 ]; then
739 if [ $duration -eq -1 ]; then
740 __log_test_fail_status_code $1 $status
741 return 1
742 fi
743 fi
744 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
745 body=${res:0:${#res}-3}
746 targetJson="{\"eiJobStatus\": \"$3\"}"
747 echo " TARGET JSON: $targetJson" >> $HTTPLOG
748 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
749
750 if [ $res -ne 0 ]; then
751 if [ $duration -eq -1 ]; then
752 __log_test_fail_body
753 return 1
754 fi
755 else
756 duration=-1 #Goto pass
757 fi
758 fi
759 if [ $duration -eq -1 ]; then
760 if [ $# -eq 4 ]; then
761 echo ""
762 fi
763 __log_test_pass
764 return 0
765 else
766 sleep 1
767 fi
768 done
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200769 fi
770
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100771 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200772 return 0
773}
774
775# API Test function: GET ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200776# args: <response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100777# args (flat uri structure): <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200778# (Function for test scripts)
779ecs_api_a1_get_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100780 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200781
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100782 if [ -z "$FLAT_A1_EI" ]; then
783 if [ $# -ne 3 ] && [ $# -ne 6 ]; then
784 __print_err "<response-code> <type-id> <job-id> [<target-url> <owner-id> <template-job-file>]" $@
785 return 1
786 fi
787 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
788 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100789 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100790 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
791 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
792 return 1
793 fi
794 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200795 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200796 res="$(__do_curl_to_api ECS GET $query)"
797 status=${res:${#res}-3}
798
799 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100800 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200801 return 1
802 fi
803
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100804 if [ -z "$FLAT_A1_EI" ]; then
805 if [ $# -eq 6 ]; then
806 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200807
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100808 if [ -f $6 ]; then
809 jobfile=$(cat $6)
810 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
811 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200812 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100813 return 1
814 fi
815 targetJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
816 echo " TARGET JSON: $targetJson" >> $HTTPLOG
817 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
818
819 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100820 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100821 return 1
822 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200823 fi
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100824 else
825 if [ $# -eq 7 ]; then
826 body=${res:0:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200827
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100828 if [ -f $7 ]; then
829 jobfile=$(cat $7)
830 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
831 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200832 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100833 return 1
834 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100835 targetJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100836 echo " TARGET JSON: $targetJson" >> $HTTPLOG
837 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
838
839 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100840 __log_test_fail_body
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100841 return 1
842 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200843 fi
844 fi
845
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100846 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200847 return 0
848}
849
850# API Test function: DELETE ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200851# args: <response-code> <type-id> <job-id>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100852# args (flat uri structure): <response-code> <job-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200853# (Function for test scripts)
854ecs_api_a1_delete_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100855 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200856
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100857 if [ -z "$FLAT_A1_EI" ]; then
858 if [ $# -ne 3 ]; then
859 __print_err "<response-code> <type-id> <job-id>" $@
860 return 1
861 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200862
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100863 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
864 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100865 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100866 if [ $# -ne 2 ]; then
867 __print_err "<response-code> <job-id>" $@
868 return 1
869 fi
870 query="/A1-EI/v1/eijobs/$2"
871 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200872 res="$(__do_curl_to_api ECS DELETE $query)"
873 status=${res:${#res}-3}
874
875 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100876 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200877 return 1
878 fi
879
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100880 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200881 return 0
882}
883
884# API Test function: PUT ​/A1-EI​/v1​/eitypes​/{eiTypeId}​/eijobs​/{eiJobId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200885# args: <response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100886# args (flat uri structure): <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200887# (Function for test scripts)
888ecs_api_a1_put_job() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100889 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200890
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100891 if [ -z "$FLAT_A1_EI" ]; then
892 if [ $# -lt 6 ]; then
893 __print_err "<response-code> <type-id> <job-id> <target-url> <owner-id> <template-job-file>" $@
894 return 1
895 fi
896 if [ -f $6 ]; then
897 jobfile=$(cat $6)
898 jobfile=$(echo "$jobfile" | sed "s/XXXX/$3/g")
899 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200900 __log_test_fail_general "Job template file "$6", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100901 return 1
902 fi
903
904 inputJson="{\"targetUri\": \"$4\",\"jobOwner\": \"$5\",\"jobParameters\": $jobfile}"
905 file="./tmp/.p.json"
906 echo "$inputJson" > $file
907
908 query="/A1-EI/v1/eitypes/$2/eijobs/$3"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200909 else
BjornMagnussonXAbe9a07f2021-02-25 10:51:46 +0100910 echo -e $YELLOW"INTERFACE - FLAT URI STRUCTURE"$EYELLOW
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100911 if [ $# -lt 7 ]; then
912 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file>" $@
913 return 1
914 fi
915 if [ -f $7 ]; then
916 jobfile=$(cat $7)
917 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
918 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +0200919 __log_test_fail_general "Job template file "$7", does not exist"
BjornMagnussonXA4207b832020-11-03 09:52:49 +0100920 return 1
921 fi
922
923 inputJson="{\"eiTypeId\": \"$3\", \"jobResultUri\": \"$4\",\"jobOwner\": \"$5\",\"jobStatusNotificationUri\": \"$6\",\"jobDefinition\": $jobfile}"
924 file="./tmp/.p.json"
925 echo "$inputJson" > $file
926
927 query="/A1-EI/v1/eijobs/$2"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200928 fi
929
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200930 res="$(__do_curl_to_api ECS PUT $query $file)"
931 status=${res:${#res}-3}
932
933 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100934 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200935 return 1
936 fi
937
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100938 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200939 return 0
940}
941
942
943##########################################
944#### Enrichment Data Producer API ####
945##########################################
946# Function prefix: ecs_api_edp
947
948# API Test function: GET /ei-producer/v1/eitypes
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200949# API Test function: GET /data-producer/v1/info-types
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200950# args: <response-code> [ EMPTY | <type-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200951# (Function for test scripts)
952ecs_api_edp_get_type_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100953 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200954
955 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200956 __print_err "<response-code> [ EMPTY | <type-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200957 return 1
958 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200959 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
960 query="/data-producer/v1/info-types"
961 else
962 query="/ei-producer/v1/eitypes"
963 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200964 res="$(__do_curl_to_api ECS GET $query)"
965 status=${res:${#res}-3}
966
967 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100968 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200969 return 1
970 fi
971
972 if [ $# -gt 1 ]; then
973 body=${res:0:${#res}-3}
974 targetJson="["
975 if [ $2 != "EMPTY" ]; then
976 for pid in ${@:2} ; do
977 if [ "$targetJson" != "[" ]; then
978 targetJson=$targetJson","
979 fi
980 targetJson=$targetJson"\"$pid\""
981 done
982 fi
983 targetJson=$targetJson"]"
984 echo " TARGET JSON: $targetJson" >> $HTTPLOG
985 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
986
987 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100988 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +0200989 return 1
990 fi
991 fi
992
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100993 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +0200994 return 0
995}
996
997# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/status
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +0200998# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/status
BjornMagnussonXA7b36db62020-11-23 10:57:57 +0100999# args: <response-code> <producer-id> [<status> [<timeout>]]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001000# (Function for test scripts)
1001ecs_api_edp_get_producer_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001002 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001003
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001004 if [ $# -lt 2 ] || [ $# -gt 4 ]; then
1005 __print_err "<response-code> <producer-id> [<status> [<timeout>]]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001006 return 1
1007 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001008 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1009 query="/data-producer/v1/info-producers/$2/status"
1010 else
1011 query="/ei-producer/v1/eiproducers/$2/status"
1012 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001013 start=$SECONDS
1014 for (( ; ; )); do
1015 res="$(__do_curl_to_api ECS GET $query)"
1016 status=${res:${#res}-3}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001017
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001018 if [ $# -eq 4 ]; then
1019 duration=$((SECONDS-start))
1020 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
1021 if [ $duration -gt $4 ]; then
1022 echo ""
1023 duration=-1 #Last iteration
1024 fi
1025 else
1026 duration=-1 #single test, no wait
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001027 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001028
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001029 if [ $status -ne $1 ]; then
1030 if [ $duration -eq -1 ]; then
1031 __log_test_fail_status_code $1 $status
1032 return 1
1033 fi
1034 fi
1035 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
1036 body=${res:0:${#res}-3}
1037 targetJson="{\"operational_state\": \"$3\"}"
1038 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1039 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1040
1041 if [ $res -ne 0 ]; then
1042 if [ $duration -eq -1 ]; then
1043 __log_test_fail_body
1044 return 1
1045 fi
1046 else
1047 duration=-1 #Goto pass
1048 fi
1049 fi
1050 if [ $duration -eq -1 ]; then
1051 if [ $# -eq 4 ]; then
1052 echo ""
1053 fi
1054 __log_test_pass
1055 return 0
1056 else
1057 sleep 1
1058 fi
1059 done
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001060}
1061
1062
1063# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001064# args (v1_1): <response-code> [ EMPTY | <producer-id>+]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001065# (Function for test scripts)
1066ecs_api_edp_get_producer_ids() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001067 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001068
1069 if [ $# -lt 1 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001070 __print_err "<response-code> [ EMPTY | <producer-id>+]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001071 return 1
1072 fi
1073
1074 query="/ei-producer/v1/eiproducers"
1075 res="$(__do_curl_to_api ECS GET $query)"
1076 status=${res:${#res}-3}
1077
1078 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001079 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001080 return 1
1081 fi
1082
1083 if [ $# -gt 1 ]; then
1084 body=${res:0:${#res}-3}
1085 targetJson="["
1086
1087 for pid in ${@:2} ; do
1088 if [ "$targetJson" != "[" ]; then
1089 targetJson=$targetJson","
1090 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001091 if [ $pid != "EMPTY" ]; then
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001092 targetJson=$targetJson"\"$pid\""
1093 fi
1094 done
1095
1096 targetJson=$targetJson"]"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001097 echo " TARGET JSON: $targetJson" >> $HTTPLOG
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001098 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1099
1100 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001101 __log_test_fail_body
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001102 return 1
1103 fi
1104 fi
1105
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001106 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001107 return 0
1108}
1109
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001110# API Test function: GET /ei-producer/v1/eiproducers
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001111# API Test function: GET /data-producer/v1/info-producers
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001112# args (v1_2): <response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]
1113# (Function for test scripts)
1114ecs_api_edp_get_producer_ids_2() {
1115 __log_test_start $@
1116
1117 if [ $# -lt 1 ]; then
1118 __print_err "<response-code> [ ( NOTYPE | <type-id> ) [ EMPTY | <producer-id>+] ]" $@
1119 return 1
1120 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001121 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1122 query="/data-producer/v1/info-producers"
1123 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1124 query=$query"?info_type_id=$2"
1125 fi
1126 else
1127 query="/ei-producer/v1/eiproducers"
1128 if [ $# -gt 1 ] && [ $2 != "NOTYPE" ]; then
1129 query=$query"?ei_type_id=$2"
1130 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001131 fi
1132 res="$(__do_curl_to_api ECS GET $query)"
1133 status=${res:${#res}-3}
1134
1135 if [ $status -ne $1 ]; then
1136 __log_test_fail_status_code $1 $status
1137 return 1
1138 fi
1139
1140 if [ $# -gt 2 ]; then
1141 body=${res:0:${#res}-3}
1142 targetJson="["
1143
1144 for pid in ${@:3} ; do
1145 if [ "$targetJson" != "[" ]; then
1146 targetJson=$targetJson","
1147 fi
1148 if [ $pid != "EMPTY" ]; then
1149 targetJson=$targetJson"\"$pid\""
1150 fi
1151 done
1152
1153 targetJson=$targetJson"]"
1154 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1155 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1156
1157 if [ $res -ne 0 ]; then
1158 __log_test_fail_body
1159 return 1
1160 fi
1161 fi
1162
1163 __log_test_pass
1164 return 0
1165}
1166
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001167# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001168# args: (v1_1) <response-code> <type-id> [<job-schema-file> (EMPTY | [<producer-id>]+)]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001169# (Function for test scripts)
1170ecs_api_edp_get_type() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001171 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001172
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001173 paramError=1
1174 if [ $# -eq 2 ]; then
1175 paramError=0
1176 fi
1177 if [ $# -gt 3 ]; then
1178 paramError=0
1179 fi
1180 if [ $paramError -ne 0 ]; then
BjornMagnussonXA39ad50e2020-10-22 09:55:25 +02001181 __print_err "<response-code> <type-id> [<job-schema-file> 'EMPTY' | ([<producer-id>]+)]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001182 return 1
1183 fi
1184
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001185 query="/ei-producer/v1/eitypes/$2"
1186 res="$(__do_curl_to_api ECS GET $query)"
1187 status=${res:${#res}-3}
1188
1189 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001190 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001191 return 1
1192 fi
1193 if [ $# -gt 3 ]; then
1194 body=${res:0:${#res}-3}
1195
1196 if [ -f $3 ]; then
1197 schema=$(cat $3)
1198 else
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001199 __log_test_fail_general "Job template file "$3", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001200 return 1
1201 fi
1202
1203 targetJson=""
1204 if [ $4 != "EMPTY" ]; then
1205 for pid in ${@:4} ; do
1206 if [ "$targetJson" != "" ]; then
1207 targetJson=$targetJson","
1208 fi
1209 targetJson=$targetJson"\"$pid\""
1210 done
1211 fi
1212 targetJson="{\"ei_job_data_schema\":$schema, \"ei_producer_ids\": [$targetJson]}"
1213
1214 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1215 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1216
1217 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001218 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001219 return 1
1220 fi
1221 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001222 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001223 return 0
1224}
1225
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001226# API Test function: GET /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001227# API Test function: GET /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001228# args: (v1_2) <response-code> <type-id> [<job-schema-file> ]
1229# (Function for test scripts)
1230ecs_api_edp_get_type_2() {
1231 __log_test_start $@
1232
1233 paramError=1
1234 if [ $# -eq 2 ]; then
1235 paramError=0
1236 fi
1237 if [ $# -eq 3 ]; then
1238 paramError=0
1239 fi
1240 if [ $paramError -ne 0 ]; then
1241 __print_err "<response-code> <type-id> [<job-schema-file> ]" $@
1242 return 1
1243 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001244 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1245 query="/data-producer/v1/info-types/$2"
1246 else
1247 query="/ei-producer/v1/eitypes/$2"
1248 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001249
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001250 res="$(__do_curl_to_api ECS GET $query)"
1251 status=${res:${#res}-3}
1252
1253 if [ $status -ne $1 ]; then
1254 __log_test_fail_status_code $1 $status
1255 return 1
1256 fi
1257 if [ $# -eq 3 ]; then
1258 body=${res:0:${#res}-3}
1259
1260 if [ -f $3 ]; then
1261 schema=$(cat $3)
1262 else
1263 __log_test_fail_general "Job template file "$3", does not exist"
1264 return 1
1265 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001266 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1267 targetJson="{\"info_job_data_schema\":$schema}"
1268 else
1269 targetJson="{\"ei_job_data_schema\":$schema}"
1270 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001271
1272 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1273 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1274
1275 if [ $res -ne 0 ]; then
1276 __log_test_fail_body
1277 return 1
1278 fi
1279 fi
1280 __log_test_pass
1281 return 0
1282}
1283
1284# API Test function: PUT /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001285# API Test function: PUT /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001286# args: (v1_2) <response-code> <type-id> <job-schema-file>
1287# (Function for test scripts)
1288ecs_api_edp_put_type_2() {
1289 __log_test_start $@
1290
1291 if [ $# -ne 3 ]; then
1292 __print_err "<response-code> <type-id> <job-schema-file>" $@
1293 return 1
1294 fi
1295
1296 if [ ! -f $3 ]; then
1297 __log_test_fail_general "Job schema file "$3", does not exist"
1298 return 1
1299 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001300 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1301 schema=$(cat $3)
1302 input_json="{\"info_job_data_schema\":$schema}"
1303 file="./tmp/put_type.json"
1304 echo $input_json > $file
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001305
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001306 query="/data-producer/v1/info-types/$2"
1307 else
1308 schema=$(cat $3)
1309 input_json="{\"ei_job_data_schema\":$schema}"
1310 file="./tmp/put_type.json"
1311 echo $input_json > $file
1312
1313 query="/ei-producer/v1/eitypes/$2"
1314 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001315 res="$(__do_curl_to_api ECS PUT $query $file)"
1316 status=${res:${#res}-3}
1317
1318 if [ $status -ne $1 ]; then
1319 __log_test_fail_status_code $1 $status
1320 return 1
1321 fi
1322
1323 __log_test_pass
1324 return 0
1325}
1326
1327# API Test function: DELETE /ei-producer/v1/eitypes/{eiTypeId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001328# API Test function: DELETE /data-producer/v1/info-types/{infoTypeId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001329# args: (v1_2) <response-code> <type-id>
1330# (Function for test scripts)
1331ecs_api_edp_delete_type_2() {
1332 __log_test_start $@
1333
1334 if [ $# -ne 2 ]; then
1335 __print_err "<response-code> <type-id>" $@
1336 return 1
1337 fi
1338
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001339 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1340 query="/data-producer/v1/info-types/$2"
1341 else
1342 query="/ei-producer/v1/eitypes/$2"
1343 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001344 res="$(__do_curl_to_api ECS DELETE $query)"
1345 status=${res:${#res}-3}
1346
1347 if [ $status -ne $1 ]; then
1348 __log_test_fail_status_code $1 $status
1349 return 1
1350 fi
1351
1352 __log_test_pass
1353 return 0
1354}
1355
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001356# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001357# args: (v1_1) <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | [<type-id> <schema-file>]+) ]
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001358# (Function for test scripts)
1359ecs_api_edp_get_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001360 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001361
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001362 #Possible arg count: 2, 5 6, 8, 10 etc
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001363 paramError=1
1364 if [ $# -eq 2 ]; then
1365 paramError=0
1366 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001367 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001368 paramError=0
1369 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001370 variablecount=$(($#-4))
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001371 if [ $# -gt 5 ] && [ $(($variablecount%2)) -eq 0 ]; then
1372 paramError=0
1373 fi
1374
1375 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001376 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (NOID | [<type-id> <schema-file>]+) ]" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001377 return 1
1378 fi
1379
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001380 query="/ei-producer/v1/eiproducers/$2"
1381 res="$(__do_curl_to_api ECS GET $query)"
1382 status=${res:${#res}-3}
1383
1384 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001385 __log_test_fail_status_code $1 $status
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001386 return 1
1387 fi
1388
1389 if [ $# -gt 2 ]; then
1390 body=${res:0:${#res}-3}
1391 targetJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001392 if [ $# -gt 5 ]; then
1393 arr=(${@:5})
1394 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001395 if [ "$targetJson" != "[" ]; then
1396 targetJson=$targetJson","
1397 fi
1398 if [ -f ${arr[$i+1]} ]; then
1399 schema=$(cat ${arr[$i+1]})
1400 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001401 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001402 return 1
1403 fi
1404
1405 targetJson=$targetJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1406 done
1407 fi
1408 targetJson=$targetJson"]"
1409 if [ $# -gt 4 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001410 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001411 fi
1412 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1413 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1414
1415 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001416 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001417 return 1
1418 fi
1419 fi
1420
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001421 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001422 return 0
1423}
1424
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001425# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001426# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001427# args (v1_2): <response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]
1428# (Function for test scripts)
1429ecs_api_edp_get_producer_2() {
1430 __log_test_start $@
1431
1432 #Possible arg count: 2, 5, 6, 7, 8 etc
1433 paramError=1
1434 if [ $# -eq 2 ]; then
1435 paramError=0
1436 fi
1437 if [ $# -eq 5 ] && [ "$5" == "EMPTY" ]; then
1438 paramError=0
1439 fi
1440 if [ $# -ge 5 ]; then
1441 paramError=0
1442 fi
1443
1444 if [ $paramError -ne 0 ]; then
1445 __print_err "<response-code> <producer-id> [<job-callback> <supervision-callback> (EMPTY | <type-id>+) ]" $@
1446 return 1
1447 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001448 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1449 query="/data-producer/v1/info-producers/$2"
1450 else
1451 query="/ei-producer/v1/eiproducers/$2"
1452 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001453 res="$(__do_curl_to_api ECS GET $query)"
1454 status=${res:${#res}-3}
1455
1456 if [ $status -ne $1 ]; then
1457 __log_test_fail_status_code $1 $status
1458 return 1
1459 fi
1460
1461 if [ $# -gt 2 ]; then
1462 body=${res:0:${#res}-3}
1463 targetJson="["
1464 if [ $# -gt 4 ] && [ "$5" != "EMPTY" ]; then
1465 arr=(${@:5})
1466 for ((i=0; i<$(($#-4)); i=i+1)); do
1467 if [ "$targetJson" != "[" ]; then
1468 targetJson=$targetJson","
1469 fi
1470 targetJson=$targetJson"\"${arr[$i]}\""
1471 done
1472 fi
1473 targetJson=$targetJson"]"
1474 if [ $# -gt 4 ]; then
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001475 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1476 targetJson="{\"supported_info_types\":$targetJson,\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\"}"
1477 else
1478 targetJson="{\"supported_ei_types\":$targetJson,\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\"}"
1479 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001480 fi
1481 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1482 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1483
1484 if [ $res -ne 0 ]; then
1485 __log_test_fail_body
1486 return 1
1487 fi
1488 fi
1489
1490 __log_test_pass
1491 return 0
1492}
1493
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001494# API Test function: DELETE /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001495# API Test function: DELETE /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001496# args: <response-code> <producer-id>
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001497# (Function for test scripts)
1498ecs_api_edp_delete_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001499 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001500
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001501 if [ $# -lt 2 ]; then
1502 __print_err "<response-code> <producer-id>" $@
1503 return 1
1504 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001505 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1506 query="/data-producer/v1/info-producers/$2"
1507 else
1508 query="/ei-producer/v1/eiproducers/$2"
1509 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001510 res="$(__do_curl_to_api ECS DELETE $query)"
1511 status=${res:${#res}-3}
1512
1513 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001514 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001515 return 1
1516 fi
1517
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001518 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001519 return 0
1520}
1521
1522# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001523# args: (v1_1) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001524# (Function for test scripts)
1525ecs_api_edp_put_producer() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001526 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001527
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001528 #Valid number of parametrer 5,6,8,10,
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001529 paramError=1
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001530 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001531 paramError=0
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001532 elif [ $# -gt 5 ] && [ $(($#%2)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001533 paramError=0
1534 fi
1535 if [ $paramError -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001536 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id> <schema-file>]+" $@
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001537 return 1
1538 fi
1539
1540 inputJson="["
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001541 if [ $# -gt 5 ]; then
1542 arr=(${@:5})
1543 for ((i=0; i<$(($#-5)); i=i+2)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001544 if [ "$inputJson" != "[" ]; then
1545 inputJson=$inputJson","
1546 fi
1547 if [ -f ${arr[$i+1]} ]; then
1548 schema=$(cat ${arr[$i+1]})
1549 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001550 __log_test_fail_general "Schema file "${arr[$i+1]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001551 return 1
1552 fi
1553 inputJson=$inputJson"{\"ei_type_identity\":\"${arr[$i]}\",\"ei_job_data_schema\":$schema}"
1554 done
1555 fi
1556 inputJson="\"supported_ei_types\":"$inputJson"]"
1557
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001558 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001559
1560 inputJson="{"$inputJson"}"
1561
1562 file="./tmp/.p.json"
1563 echo "$inputJson" > $file
1564 query="/ei-producer/v1/eiproducers/$2"
1565 res="$(__do_curl_to_api ECS PUT $query $file)"
1566 status=${res:${#res}-3}
1567
1568 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001569 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001570 return 1
1571 fi
1572
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001573 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001574 return 0
1575}
1576
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001577# API Test function: PUT /ei-producer/v1/eiproducers/{eiProducerId}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001578# API Test function: PUT /data-producer/v1/info-producers/{infoProducerId}
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001579# args: (v1_2) <response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]
1580# (Function for test scripts)
1581ecs_api_edp_put_producer_2() {
1582 __log_test_start $@
1583
1584 #Valid number of parametrer 5,6,8,10,
1585 paramError=1
1586 if [ $# -eq 5 ] && [ "$5" == "NOTYPE" ]; then
1587 paramError=0
1588 elif [ $# -ge 5 ]; then
1589 paramError=0
1590 fi
1591 if [ $paramError -ne 0 ]; then
1592 __print_err "<response-code> <producer-id> <job-callback> <supervision-callback> NOTYPE|[<type-id>+]" $@
1593 return 1
1594 fi
1595
1596 inputJson="["
1597 if [ $# -gt 4 ] && [ "$5" != "NOTYPE" ]; then
1598 arr=(${@:5})
1599 for ((i=0; i<$(($#-4)); i=i+1)); do
1600 if [ "$inputJson" != "[" ]; then
1601 inputJson=$inputJson","
1602 fi
1603 inputJson=$inputJson"\""${arr[$i]}"\""
1604 done
1605 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001606 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1607 inputJson="\"supported_info_types\":"$inputJson"]"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001608
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001609 inputJson=$inputJson",\"info_job_callback_url\": \"$3\",\"info_producer_supervision_callback_url\": \"$4\""
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001610
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001611 inputJson="{"$inputJson"}"
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001612
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001613 file="./tmp/.p.json"
1614 echo "$inputJson" > $file
1615 query="/data-producer/v1/info-producers/$2"
1616 else
1617 inputJson="\"supported_ei_types\":"$inputJson"]"
1618
1619 inputJson=$inputJson",\"ei_job_callback_url\": \"$3\",\"ei_producer_supervision_callback_url\": \"$4\""
1620
1621 inputJson="{"$inputJson"}"
1622
1623 file="./tmp/.p.json"
1624 echo "$inputJson" > $file
1625 query="/ei-producer/v1/eiproducers/$2"
1626 fi
BjornMagnussonXA27db02f2021-01-19 08:13:00 +01001627 res="$(__do_curl_to_api ECS PUT $query $file)"
1628 status=${res:${#res}-3}
1629
1630 if [ $status -ne $1 ]; then
1631 __log_test_fail_status_code $1 $status
1632 return 1
1633 fi
1634
1635 __log_test_pass
1636 return 0
1637}
1638
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001639# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001640# args: (V1-1) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001641# (Function for test scripts)
1642ecs_api_edp_get_producer_jobs() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001643 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001644
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001645 #Valid number of parameter 2,3,7,11
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001646 paramError=1
1647 if [ $# -eq 2 ]; then
1648 paramError=0
1649 fi
1650 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1651 paramError=0
1652 fi
1653 variablecount=$(($#-2))
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001654 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001655 paramError=0
1656 fi
1657 if [ $paramError -eq 1 ]; then
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001658 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001659 return 1
1660 fi
1661
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001662 query="/ei-producer/v1/eiproducers/$2/eijobs"
1663 res="$(__do_curl_to_api ECS GET $query)"
1664 status=${res:${#res}-3}
1665 if [ $status -ne $1 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001666 __log_test_fail_status_code $1 $status
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001667 return 1
1668 fi
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001669 if [ $# -gt 2 ]; then
1670 body=${res:0:${#res}-3}
1671 targetJson="["
1672 if [ $# -gt 3 ]; then
1673 arr=(${@:3})
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001674 for ((i=0; i<$(($#-3)); i=i+5)); do
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001675 if [ "$targetJson" != "[" ]; then
1676 targetJson=$targetJson","
1677 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001678 if [ -f ${arr[$i+4]} ]; then
1679 jobfile=$(cat ${arr[$i+4]})
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001680 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1681 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001682 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001683 return 1
1684 fi
BjornMagnussonXA2138b632020-11-30 21:17:32 +01001685 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}"
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001686 done
1687 fi
1688 targetJson=$targetJson"]"
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001689
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001690 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1691 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001692
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001693 if [ $res -ne 0 ]; then
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001694 __log_test_fail_body
BjornMagnussonXAf38e1e82020-10-11 23:05:02 +02001695 return 1
1696 fi
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001697 fi
1698
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001699 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001700 return 0
1701}
1702
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001703# API Test function: GET /ei-producer/v1/eiproducers/{eiProducerId}/eijobs
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001704# API Test function: GET /data-producer/v1/info-producers/{infoProducerId}/info-jobs
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001705# args: (V1-2) <response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)
1706# (Function for test scripts)
1707ecs_api_edp_get_producer_jobs_2() {
1708 __log_test_start $@
1709
1710 #Valid number of parameter 2,3,7,11
1711 paramError=1
1712 if [ $# -eq 2 ]; then
1713 paramError=0
1714 fi
1715 if [ $# -eq 3 ] && [ "$3" == "EMPTY" ]; then
1716 paramError=0
1717 fi
1718 variablecount=$(($#-2))
1719 if [ $# -gt 3 ] && [ $(($variablecount%5)) -eq 0 ]; then
1720 paramError=0
1721 fi
1722 if [ $paramError -eq 1 ]; then
1723 __print_err "<response-code> <producer-id> (EMPTY | [<job-id> <type-id> <target-url> <job-owner> <template-job-file>]+)" $@
1724 return 1
1725 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001726 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1727 query="/data-producer/v1/info-producers/$2/info-jobs"
1728 else
1729 query="/ei-producer/v1/eiproducers/$2/eijobs"
1730 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001731 res="$(__do_curl_to_api ECS GET $query)"
1732 status=${res:${#res}-3}
1733 if [ $status -ne $1 ]; then
1734 __log_test_fail_status_code $1 $status
1735 return 1
1736 fi
1737 if [ $# -gt 2 ]; then
1738 body=${res:0:${#res}-3}
1739 targetJson="["
1740 if [ $# -gt 3 ]; then
1741 arr=(${@:3})
1742 for ((i=0; i<$(($#-3)); i=i+5)); do
1743 if [ "$targetJson" != "[" ]; then
1744 targetJson=$targetJson","
1745 fi
1746 if [ -f ${arr[$i+4]} ]; then
1747 jobfile=$(cat ${arr[$i+4]})
1748 jobfile=$(echo "$jobfile" | sed "s/XXXX/${arr[$i]}/g")
1749 else
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001750 __log_test_fail_general "Job template file "${arr[$i+4]}", does not exist"
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001751 return 1
1752 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001753 if [[ "$ECS_FEATURE_LEVEL" == *"INFO-TYPES"* ]]; then
1754 targetJson=$targetJson"{\"info_job_identity\":\"${arr[$i]}\",\"info_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"info_job_data\":$jobfile, \"last_updated\":\"????\"}"
1755 else
1756 targetJson=$targetJson"{\"ei_job_identity\":\"${arr[$i]}\",\"ei_type_identity\":\"${arr[$i+1]}\",\"target_uri\":\"${arr[$i+2]}\",\"owner\":\"${arr[$i+3]}\",\"ei_job_data\":$jobfile, \"last_updated\":\"????\"}"
1757 fi
BjornMagnussonXAc963b732021-01-20 14:24:13 +01001758 done
1759 fi
1760 targetJson=$targetJson"]"
1761
1762 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1763 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1764
1765 if [ $res -ne 0 ]; then
1766 __log_test_fail_body
1767 return 1
1768 fi
1769 fi
1770
1771 __log_test_pass
1772 return 0
1773}
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001774
1775##########################################
1776#### Service status ####
1777##########################################
1778# Function prefix: ecs_api_service
1779
1780# API Test function: GET ​/status
1781# args: <response-code>
1782# (Function for test scripts)
1783ecs_api_service_status() {
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001784 __log_test_start $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001785
1786 if [ $# -lt 1 ]; then
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001787 __print_err "<response-code>" $@
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001788 return 1
1789 fi
BjornMagnussonXA7b36db62020-11-23 10:57:57 +01001790 res="$(__do_curl_to_api ECS GET /status)"
1791 status=${res:${#res}-3}
1792 if [ $status -ne $1 ]; then
1793 __log_test_fail_status_code $1 $status
1794 return 1
1795 fi
1796 __log_test_pass
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02001797 return 0
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01001798}
1799
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001800###########################################
1801######### Info data consumer API ##########
1802###########################################
1803#Function prefix: ecs_api_idc
1804
1805
1806# API Test function: GET /data-consumer/v1/info-types
1807# args: <response-code> [ (EMPTY | [<type-id>]+) ]
1808# (Function for test scripts)
1809ecs_api_idc_get_type_ids() {
1810 __log_test_start $@
1811
1812 if [ $# -lt 1 ]; then
1813 __print_err "<response-code> [ (EMPTY | [<type-id>]+) ]" $@
1814 return 1
1815 fi
1816
1817 query="/data-consumer/v1/info-types"
1818 res="$(__do_curl_to_api ECS GET $query)"
1819 status=${res:${#res}-3}
1820
1821 if [ $status -ne $1 ]; then
1822 __log_test_fail_status_code $1 $status
1823 return 1
1824 fi
1825 if [ $# -gt 1 ]; then
1826 body=${res:0:${#res}-3}
1827 targetJson="["
1828 if [ $2 != "EMPTY" ]; then
1829 for pid in ${@:2} ; do
1830 if [ "$targetJson" != "[" ]; then
1831 targetJson=$targetJson","
1832 fi
1833 targetJson=$targetJson"\"$pid\""
1834 done
1835 fi
1836 targetJson=$targetJson"]"
1837 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1838 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1839
1840 if [ $res -ne 0 ]; then
1841 __log_test_fail_body
1842 return 1
1843 fi
1844 fi
1845
1846 __log_test_pass
1847 return 0
1848}
1849
1850# API Test function: GET /data-consumer/v1/info-jobs
1851# args: <response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]
1852# (Function for test scripts)
1853ecs_api_idc_get_job_ids() {
1854 __log_test_start $@
1855
1856 # Valid number of parameters 4,5,6 etc
1857 if [ $# -lt 3 ]; then
1858 __print_err "<response-code> <type-id>|NOTYPE <owner-id>|NOOWNER [ EMPTY | <job-id>+ ]" $@
1859 return 1
1860 fi
1861 search=""
1862 if [ $3 != "NOWNER" ]; then
1863 search="?owner="$3
1864 fi
1865
1866 if [ $2 != "NOTYPE" ]; then
1867 if [ -z "$search" ]; then
1868 search="?infoTypeId="$2
1869 else
1870 search=$search"&infoTypeId="$2
1871 fi
1872 fi
1873 query="/data-consumer/v1/info-jobs$search"
1874
1875 res="$(__do_curl_to_api ECS GET $query)"
1876 status=${res:${#res}-3}
1877
1878 if [ $status -ne $1 ]; then
1879 __log_test_fail_status_code $1 $status
1880 return 1
1881 fi
1882
1883 if [ $# -gt 3 ]; then
1884 body=${res:0:${#res}-3}
1885 targetJson="["
1886
1887 for pid in ${@:4} ; do
1888 if [ "$targetJson" != "[" ]; then
1889 targetJson=$targetJson","
1890 fi
1891 if [ $pid != "EMPTY" ]; then
1892 targetJson=$targetJson"\"$pid\""
1893 fi
1894 done
1895
1896 targetJson=$targetJson"]"
1897 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1898 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1899
1900 if [ $res -ne 0 ]; then
1901 __log_test_fail_body
1902 return 1
1903 fi
1904 fi
1905
1906 __log_test_pass
1907 return 0
1908}
1909
1910# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}
1911# args: <response-code> <job-id> [<type-id> <target-url> <owner-id> <template-job-file>]
1912# (Function for test scripts)
1913ecs_api_idc_get_job() {
1914 __log_test_start $@
1915
1916 if [ $# -ne 2 ] && [ $# -ne 7 ]; then
1917 __print_err "<response-code> <job-id> [<type-id> <target-url> <owner-id> <notification-url> <template-job-file>]" $@
1918 return 1
1919 fi
1920 query="/data-consumer/v1/info-jobs/$2"
1921 res="$(__do_curl_to_api ECS GET $query)"
1922 status=${res:${#res}-3}
1923
1924 if [ $status -ne $1 ]; then
1925 __log_test_fail_status_code $1 $status
1926 return 1
1927 fi
1928
1929 if [ $# -eq 7 ]; then
1930 body=${res:0:${#res}-3}
1931
1932 if [ -f $7 ]; then
1933 jobfile=$(cat $7)
1934 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1935 else
1936 __log_test_fail_general "Job template file "$6", does not exist"
1937 return 1
1938 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001939 targetJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001940 echo " TARGET JSON: $targetJson" >> $HTTPLOG
1941 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
1942
1943 if [ $res -ne 0 ]; then
1944 __log_test_fail_body
1945 return 1
1946 fi
1947 fi
1948
1949 __log_test_pass
1950 return 0
1951}
1952
1953
1954# API Test function: PUT ​/data-consumer/v1/info-jobs/{infoJobId}
1955# args: <response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]
1956# (Function for test scripts)
1957ecs_api_idc_put_job() {
1958 __log_test_start $@
1959
1960 if [ $# -lt 7 ] || [ $# -gt 8 ]; then
1961 __print_err "<response-code> <job-id> <type-id> <target-url> <owner-id> <notification-url> <template-job-file> [ VALIDATE ]" $@
1962 return 1
1963 fi
1964 if [ -f $7 ]; then
1965 jobfile=$(cat $7)
1966 jobfile=$(echo "$jobfile" | sed "s/XXXX/$2/g")
1967 else
1968 __log_test_fail_general "Job template file "$7", does not exist"
1969 return 1
1970 fi
1971
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02001972 inputJson="{\"info_type_id\": \"$3\", \"job_result_uri\": \"$4\",\"job_owner\": \"$5\",\"status_notification_uri\": \"$6\",\"job_definition\": $jobfile}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02001973 file="./tmp/.p.json"
1974 echo "$inputJson" > $file
1975
1976 query="/data-consumer/v1/info-jobs/$2"
1977
1978 if [ $# -eq 8 ]; then
1979 if [ $8 == "VALIDATE" ]; then
1980 query=$query"?typeCheck=true"
1981 fi
1982 fi
1983
1984 res="$(__do_curl_to_api ECS PUT $query $file)"
1985 status=${res:${#res}-3}
1986
1987 if [ $status -ne $1 ]; then
1988 __log_test_fail_status_code $1 $status
1989 return 1
1990 fi
1991
1992 __log_test_pass
1993 return 0
1994}
1995
1996# API Test function: DELETE ​/data-consumer/v1/info-jobs/{infoJobId}
1997# args: <response-code> <job-id>
1998# (Function for test scripts)
1999ecs_api_idc_delete_job() {
2000 __log_test_start $@
2001
2002 if [ $# -ne 2 ]; then
2003 __print_err "<response-code> <job-id>" $@
2004 return 1
2005 fi
2006 query="/data-consumer/v1/info-jobs/$2"
2007 res="$(__do_curl_to_api ECS DELETE $query)"
2008 status=${res:${#res}-3}
2009
2010 if [ $status -ne $1 ]; then
2011 __log_test_fail_status_code $1 $status
2012 return 1
2013 fi
2014
2015 __log_test_pass
2016 return 0
2017}
2018
2019# API Test function: GET ​/data-consumer/v1/info-types/{infoTypeId}
2020# args: <response-code> <type-id> [<schema-file>]
2021# (Function for test scripts)
2022ecs_api_idc_get_type() {
2023 __log_test_start $@
2024
2025 if [ $# -lt 2 ] || [ $# -gt 3 ]; then
2026 __print_err "<response-code> <type-id> [<schema-file>]" $@
2027 return 1
2028 fi
2029
2030 query="/data-consumer/v1/info-types/$2"
2031 res="$(__do_curl_to_api ECS GET $query)"
2032 status=${res:${#res}-3}
2033
2034 if [ $status -ne $1 ]; then
2035 __log_test_fail_status_code $1 $status
2036 return 1
2037 fi
2038
2039 if [ $# -eq 3 ]; then
2040 body=${res:0:${#res}-3}
2041 if [ -f $3 ]; then
2042 schema=$(cat $3)
2043 else
2044 __log_test_fail_general "Schema file "$3", does not exist"
2045 return 1
2046 fi
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002047 targetJson="{\"job_data_schema\":$schema}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002048 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2049 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2050
2051 if [ $res -ne 0 ]; then
2052 __log_test_fail_body
2053 return 1
2054 fi
2055 fi
2056
2057 __log_test_pass
2058 return 0
2059}
2060
2061# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002062# This test only status during an optional timeout. No test of the list of producers
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002063# args: <response-code> <job-id> [<status> [<timeout>]]
2064# (Function for test scripts)
2065ecs_api_idc_get_job_status() {
2066 __log_test_start $@
2067
2068 if [ $# -lt 2 ] && [ $# -gt 4 ]; then
2069 __print_err "<response-code> <job-id> [<status> [<timeout>]]" $@
2070 return 1
2071 fi
2072
2073 query="/data-consumer/v1/info-jobs/$2/status"
2074
2075 start=$SECONDS
2076 for (( ; ; )); do
2077 res="$(__do_curl_to_api ECS GET $query)"
2078 status=${res:${#res}-3}
2079
2080 if [ $# -eq 4 ]; then
2081 duration=$((SECONDS-start))
2082 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2083 if [ $duration -gt $4 ]; then
2084 echo ""
2085 duration=-1 #Last iteration
2086 fi
2087 else
2088 duration=-1 #single test, no wait
2089 fi
2090
2091 if [ $status -ne $1 ]; then
2092 if [ $duration -eq -1 ]; then
2093 __log_test_fail_status_code $1 $status
2094 return 1
2095 fi
2096 fi
2097 if [ $# -ge 3 ] && [ $status -eq $1 ]; then
2098 body=${res:0:${#res}-3}
BjornMagnussonXAce4b14c2021-05-11 15:40:03 +02002099 targetJson="{\"info_job_status\": \"$3\"}"
BjornMagnussonXA9d8fafb2021-05-10 11:11:49 +02002100 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2101 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2102
2103 if [ $res -ne 0 ]; then
2104 if [ $duration -eq -1 ]; then
2105 __log_test_fail_body
2106 return 1
2107 fi
2108 else
2109 duration=-1 #Goto pass
2110 fi
2111 fi
2112 if [ $duration -eq -1 ]; then
2113 if [ $# -eq 4 ]; then
2114 echo ""
2115 fi
2116 __log_test_pass
2117 return 0
2118 else
2119 sleep 1
2120 fi
2121 done
2122
2123 __log_test_pass
2124 return 0
2125}
2126
BjornMagnussonXAe45cd2c2021-06-18 09:00:49 +02002127# API Test function: GET /data-consumer/v1/info-jobs/{infoJobId}/status
2128# This function test status and the list of producers with and optional timeout
2129# args: <response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]
2130# (Function for test scripts)
2131ecs_api_idc_get_job_status2() {
2132
2133 __log_test_start $@
2134 param_error=0
2135 if [ $# -lt 2 ]; then
2136 param_error=1
2137 fi
2138 args=("$@")
2139 timeout=0
2140 if [ $# -gt 2 ]; then
2141 if [ $# -lt 4 ]; then
2142 param_error=1
2143 fi
2144 targetJson="{\"info_job_status\": \"$3\""
2145 if [ "$4" == "EMPTYPROD" ]; then
2146 targetJson=$targetJson",\"producers\": []}"
2147 if [ $# -gt 4 ]; then
2148 timeout=$5
2149 fi
2150 else
2151 targetJson=$targetJson",\"producers\": ["
2152 if [ $# -eq $(($4+5)) ]; then
2153 idx=$(($4+4))
2154 timeout=${args[$idx]}
2155 fi
2156 for ((ecs_i = 0 ; ecs_i < $4 ; ecs_i++)); do
2157 idx=$(($ecs_i+4))
2158 if [ $ecs_i -gt 0 ]; then
2159 targetJson=$targetJson","
2160 fi
2161 targetJson=$targetJson"\""${args[$idx]}"\""
2162 done
2163 targetJson=$targetJson"]}"
2164 fi
2165 fi
2166
2167 if [ $param_error -ne 0 ]; then
2168 __print_err "<response-code> <job-id> [<status> EMPTYPROD|( <prod-count> <producer-id>+ ) [<timeout>]]" $@
2169 return 1
2170 fi
2171
2172 query="/data-consumer/v1/info-jobs/$2/status"
2173
2174 start=$SECONDS
2175 for (( ; ; )); do
2176 res="$(__do_curl_to_api ECS GET $query)"
2177 status=${res:${#res}-3}
2178
2179 if [ $# -gt 2 ]; then
2180 duration=$((SECONDS-start))
2181 echo -ne " Response=${status} after ${duration} seconds, waiting for ${3} ${SAMELINE}"
2182 if [ $duration -gt $timeout ]; then
2183 echo ""
2184 duration=-1 #Last iteration
2185 fi
2186 else
2187 duration=-1 #single test, no wait
2188 fi
2189
2190 if [ $status -ne $1 ]; then
2191 if [ $duration -eq -1 ]; then
2192 __log_test_fail_status_code $1 $status
2193 return 1
2194 fi
2195 fi
2196 if [ $# -gt 2 ] && [ $status -eq $1 ]; then
2197 body=${res:0:${#res}-3}
2198 echo " TARGET JSON: $targetJson" >> $HTTPLOG
2199 res=$(python3 ../common/compare_json.py "$targetJson" "$body")
2200
2201 if [ $res -ne 0 ]; then
2202 if [ $duration -eq -1 ]; then
2203 __log_test_fail_body
2204 return 1
2205 fi
2206 else
2207 duration=-1 #Goto pass
2208 fi
2209 fi
2210 if [ $duration -eq -1 ]; then
2211 if [ $# -eq 4 ]; then
2212 echo ""
2213 fi
2214 __log_test_pass
2215 return 0
2216 else
2217 sleep 1
2218 fi
2219 done
2220
2221 __log_test_pass
2222 return 0
2223}
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002224
2225##########################################
2226#### Reset jobs ####
2227##########################################
2228# Function prefix: ecs_api_admin
2229
2230# Admin to remove all jobs
BjornMagnussonXA366e36a2021-01-27 11:48:56 +01002231# args: <response-code> [ <type> ]
BjornMagnussonXAe0b665e2021-01-08 22:19:18 +01002232# (Function for test scripts)
2233
2234ecs_api_admin_reset() {
2235 __log_test_start $@
2236
2237 if [ -z "$FLAT_A1_EI" ]; then
2238 query="/A1-EI/v1/eitypes/$2/eijobs"
2239 else
2240 query="/A1-EI/v1/eijobs"
2241 fi
2242 res="$(__do_curl_to_api ECS GET $query)"
2243 status=${res:${#res}-3}
2244
2245 if [ $status -ne 200 ]; then
2246 __log_test_fail_status_code $1 $status
2247 return 1
2248 fi
2249
2250 #Remove brackets and response code
2251 body=${res:1:${#res}-4}
2252 list=$(echo ${body//,/ })
2253 list=$(echo ${list//[/})
2254 list=$(echo ${list//]/})
2255 list=$(echo ${list//\"/})
2256 list=$list" "
2257 for job in $list; do
2258 if [ -z "$FLAT_A1_EI" ]; then
2259 echo "Not supported for non-flat EI api"
2260 else
2261 query="/A1-EI/v1/eijobs/$job"
2262 res="$(__do_curl_to_api ECS DELETE $query)"
2263 status=${res:${#res}-3}
2264 if [ $status -ne 204 ]; then
2265 __log_test_fail_status_code $1 $status
2266 return 1
2267 fi
2268 echo " Deleted job: "$job
2269 fi
2270 done
2271
2272 __log_test_pass
2273 return 0
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002274}
2275
2276##########################################
2277#### Reset jobs and producers ####
2278##########################################
2279
2280
2281# Admin reset to remove all data in ecs; jobs, producers etc
2282# NOTE - only works in kubernetes and the pod should not be running
2283# args: -
2284# (Function for test scripts)
2285
2286ecs_kube_pvc_reset() {
2287 __log_test_start $@
2288
BjornMagnussonXA6f9c2b22021-06-11 16:31:40 +02002289 pvc_name=$(kubectl get pvc -n nonrtric --no-headers -o custom-columns=":metadata.name" | grep enrichment)
2290 if [ -z "$pvc_name" ]; then
2291 pvc_name=enrichmentservice-pvc
2292 fi
2293 echo " Trying to reset pvc: "$pvc_name
2294
2295 __kube_clean_pvc $ECS_APP_NAME nonrtric $pvc_name /var/enrichment-coordinator-service/database
BjornMagnussonXAa5491572021-05-04 09:21:24 +02002296
2297 __log_test_pass
2298 return 0
BjornMagnussonXAbf3700b2020-10-05 08:39:40 +02002299}