Fix root pom version definition
[sdnc/oam.git] / csit / scripts / sdnr / sdnr-launch.sh
1 #!/bin/bash
2 #
3 #  ============LICENSE_START=======================================================
4 #  ONAP : ccsdk feature sdnr wt
5 #  ================================================================================
6 #  Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 #  All rights reserved.
8 #  ================================================================================
9 #  Licensed under the Apache License, Version 2.0 (the "License");
10 #  you may not use this file except in compliance with the License.
11 #  You may obtain a copy of the License at
12 #
13 #      http://www.apache.org/licenses/LICENSE-2.0
14 #
15 #  Unless required by applicable law or agreed to in writing, software
16 #  distributed under the License is distributed on an "AS IS" BASIS,
17 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 #  See the License for the specific language governing permissions and
19 #  limitations under the License.
20 #  ============LICENSE_END=========================================================
21 #
22 docker version
23 docker-compose version
24 # update installed docker compose version
25 sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
26 sudo chmod +x /usr/local/bin/docker-compose
27 sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
28 which docker-compose
29 docker version
30 docker-compose version
31
32 if [[ -z $WORKSPACE ]]; then
33     CUR_PATH="`dirname \"$0\"`"              # relative path
34     CUR_PATH="`( cd \"$CUR_PATH\" && pwd )`"  # absolutized and normalized
35     if [ -z "$CUR_PATH" ] ; then
36         echo "Permission error!"
37         exit 1
38     fi
39
40     # define location of workpsace based on where the current script is
41     WORKSPACE=$(cd $CUR_PATH/../../ && pwd)
42 fi
43
44 if [[ -z $SCRIPTS ]]; then
45     SCRIPTS=$(cd $WORKSPACE/scripts && pwd)
46 fi
47
48 HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $7}')
49 SDNC_WEB_PORT=${SDNC_WEB_PORT:-8282}
50
51 env_file="--env-file ${SCRIPTS}/sdnr/docker-compose/.env"
52 echo $env_file
53
54 # Define sdnrdb type
55 # default: ESDB
56 # alternative: MARIADB
57 SDNRDB_TYPE="${SDNRDB_TYPE:-ESDB}"
58 if [[ "$SDNRDB_TYPE" == "ESDB" ]]; then
59   sdnrdb_compose_file="docker-compose-sdnrdb-elasticsearch.yaml"
60 else
61   sdnrdb_compose_file="docker-compose-sdnrdb-mariadb.yaml"
62 fi
63 docker ps -a
64
65 function onap_dependent_components_launch() {
66     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-onap-addons.yaml pull
67     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-onap-addons.yaml up -d
68 }
69 function netconfserver_simulator_launch() {
70     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-netconfserver-simulator.yaml pull
71     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-netconfserver-simulator.yaml up -d
72 }
73
74 function nts_manager_launch() {
75     # starts all ntsim managers defined in the csv file
76     ${SCRIPTS}/sdnr/docker-compose/nts-manager-launch.sh $1
77 }
78
79 function nts_networkfunctions_launch() {
80     # starts all ntsim networkfucntions defined in the csv file
81     ${SCRIPTS}/sdnr/docker-compose/nts-networkfunctions-launch.sh $1
82 }
83
84
85 function sdnr_launch() {
86     #if [ -n "${CALLHOME}" ] ; then
87       #sdnrwtbootfeatures="-e SDNRWT_BOOTFEATURES=odl-netconf-callhome-ssh,sdnr-wt-feature-aggregator "
88       #callhomeport="-p ${CALL_HOME_PORT}:6666 "
89     #fi
90     if [ $SDNR_CLUSTER_MODE == "true" ]; then
91         sdnr_launch_cluster $1
92     else
93         sdnr_launch_single_node $1
94     fi
95     cd $WORKSPACE
96     ./getAllInfo.sh -c sdnr -kp
97 }
98
99
100 function sdnr_launch_single_node() {
101
102     # Use locally build sdnr .. no need to pull
103     #docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
104     #                         -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
105     #                         pull
106     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
107                              pull
108     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
109                              -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
110                              up -d
111          for i in {1..50}; do
112              curl -sS -m 1 -D - ${HOST_IP}:8181/ready | grep 200 && break
113              echo sleep $i
114              sleep $i
115              if [ $i == 50 ]; then
116                 echo "[ERROR] SDNC/R container not ready"
117                 docker ps -a
118                 docker logs sdnr
119                 # exit 1
120              fi
121          done
122 }
123
124 function sdnr_web_launch() {
125     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
126                              -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr-web.override.yaml \
127                              -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
128                              pull
129     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
130                              -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr-web.override.yaml \
131                              -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
132                              up -d
133          for i in {1..50}; do
134              curl -sS -m 1 -D - ${HOST_IP}:${SDNC_WEB_PORT}/ready | grep 200 && break
135              echo sleep $i
136              sleep $i
137     done
138 }
139
140 function sdnr_launch_cluster() {
141     # source ${SCRIPTS}/sdnr/sdnrEnv_Cluster.sh
142     SDNRDM="false"
143     [[ -n "$1" ]]  && SDNRDM="true" && echo "SDNRDM arg detected - running in headless mode"
144     echo "SDNR being launched in Cluster mode"
145     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose/cluster-sdnr.yaml pull
146     docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose/cluster-sdnr.yaml up -d
147     # Wait for initialization of docker services. At the moment its the master SDNR node
148          HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $7}')
149          for i in {1..50}; do
150              curl -sS -m 1 -D - ${HOST_IP}:${ODLUXPORT}/ready | grep 200 && break
151              echo sleep $i
152              sleep $i
153          done
154 }