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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
20 # This is a script that contains container/service managemnt functions for Http Proxy
22 ## Access to Http Proxy Receiver
23 # Host name may be changed if app started by kube
24 # Direct access from script
25 HTTP_PROXY_HTTPX="http"
26 HTTP_PROXY_HOST_NAME=$LOCALHOST_NAME
27 HTTP_PROXY_PATH=$HTTP_PROXY_HTTPX"://"$HTTP_PROXY_HOST_NAME":"$HTTP_PROXY_WEB_EXTERNAL_PORT
29 #########################
30 ### Http Proxy functions
31 #########################
33 # Start the Http Proxy in the simulator group
35 # (Function for test scripts)
38 echo -e $BOLD"Starting $HTTP_PROXY_DISPLAY_NAME"$EBOLD
40 if [ $RUNMODE == "KUBE" ]; then
42 # Check if app shall be fully managed by the test script
43 __check_included_image "HTTPPROXY"
46 # Check if app shall only be used by the testscipt
47 __check_prestarted_image "HTTPPROXY"
50 if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
51 echo -e $RED"The $HTTP_PROXY_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
52 echo -e $RED"The $HTTP_PROXY_APP_NAME will not be started"$ERED
55 if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
56 echo -e $RED"The $HTTP_PROXY_APP_NAME app is included both as managed and prestarted in this test script"$ERED
57 echo -e $RED"The $HTTP_PROXY_APP_NAME will not be started"$ERED
61 # Check if app shall be used - not managed - by the test script
62 if [ $retcode_p -eq 0 ]; then
63 echo -e " Using existing $HTTP_PROXY_APP_NAME deployment and service"
64 echo " Setting HTTPPROXY replicas=1"
65 __kube_scale deployment $HTTP_PROXY_APP_NAME $KUBE_SIM_NAMESPACE 1
68 if [ $retcode_i -eq 0 ]; then
69 echo -e " Creating $HTTP_PROXY_APP_NAME deployment and service"
70 export HTTP_PROXY_APP_NAME
71 export HTTP_PROXY_WEB_EXTERNAL_PORT
72 export HTTP_PROXY_WEB_INTERNAL_PORT
73 export HTTP_PROXY_EXTERNAL_PORT
74 export HTTP_PROXY_INTERNAL_PORT
75 export KUBE_SIM_NAMESPACE
76 export HTTP_PROXY_IMAGE
78 __kube_create_namespace $KUBE_SIM_NAMESPACE
81 input_yaml=$SIM_GROUP"/"$HTTP_PROXY_COMPOSE_DIR"/"svc.yaml
82 output_yaml=$PWD/tmp/proxy_svc.yaml
83 __kube_create_instance service $HTTP_PROXY_APP_NAME $input_yaml $output_yaml
86 input_yaml=$SIM_GROUP"/"$HTTP_PROXY_COMPOSE_DIR"/"app.yaml
87 output_yaml=$PWD/tmp/proxy_app.yaml
88 __kube_create_instance app $HTTP_PROXY_APP_NAME $input_yaml $output_yaml
92 echo " Retrieving host and ports for service..."
93 HTTP_PROXY_HOST_NAME=$(__kube_get_service_host $HTTP_PROXY_APP_NAME $KUBE_SIM_NAMESPACE)
94 HTTP_PROXY_WEB_EXTERNAL_PORT=$(__kube_get_service_port $HTTP_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "web")
95 HTTP_PROXY_EXTERNAL_PORT=$(__kube_get_service_port $HTTP_PROXY_APP_NAME $KUBE_SIM_NAMESPACE "http")
97 HTTP_PROXY_PATH=$HTTP_PROXY_HTTPX"://"$HTTP_PROXY_HOST_NAME":"$HTTP_PROXY_WEB_EXTERNAL_PORT
98 HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_EXTERNAL_PORT
99 HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_APP_NAME"."$KUBE_SIM_NAMESPACE
101 echo " Host IP, http port: $HTTP_PROXY_HOST_NAME $HTTP_PROXY_WEB_EXTERNAL_PORT"
103 __check_service_start $HTTP_PROXY_APP_NAME $HTTP_PROXY_PATH$HTTP_PROXY_ALIVE_URL
106 # Check if docker app shall be fully managed by the test script
107 __check_included_image 'HTTPPROXY'
108 if [ $? -eq 1 ]; then
109 echo -e $RED"The Http Proxy app is not included in this test script"$ERED
110 echo -e $RED"The Http Proxy will not be started"$ERED
114 export HTTP_PROXY_APP_NAME
115 export HTTP_PROXY_WEB_EXTERNAL_PORT
116 export HTTP_PROXY_WEB_INTERNAL_PORT
117 export DOCKER_SIM_NWNAME
119 __start_container $HTTP_PROXY_COMPOSE_DIR NODOCKERARGS 1 $HTTP_PROXY_APP_NAME
121 __check_service_start $HTTP_PROXY_APP_NAME $HTTP_PROXY_PATH$HTTP_PROXY_ALIVE_URL
123 HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_INTERNAL_PORT
124 HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_APP_NAME