aboutsummaryrefslogtreecommitdiffstats
path: root/csit/scripts/sdnr/sdnr-launch.sh
blob: 39ca8081353b3444b7e2443690234989a45c0f46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
#
#  ============LICENSE_START=======================================================
#  ONAP : ccsdk feature sdnr wt
#  ================================================================================
#  Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
#  All rights reserved.
#  ================================================================================
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#  ============LICENSE_END=========================================================
#
docker version
docker-compose version
# update installed docker compose version
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
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
which docker-compose
docker version
docker-compose version

if [[ -z $WORKSPACE ]]; then
    CUR_PATH="`dirname \"$0\"`"              # relative path
    CUR_PATH="`( cd \"$CUR_PATH\" && pwd )`"  # absolutized and normalized
    if [ -z "$CUR_PATH" ] ; then
        echo "Permission error!"
        exit 1
    fi

    # define location of workpsace based on where the current script is
    WORKSPACE=$(cd $CUR_PATH/../../ && pwd)
fi

if [[ -z $SCRIPTS ]]; then
    SCRIPTS=$(cd $WORKSPACE/scripts && pwd)
fi

HOST_IP=$(ip route get 8.8.8.8 | awk '/8.8.8.8/ {print $7}')
SDNC_WEB_PORT=${SDNC_WEB_PORT:-8282}
SDNC_PORT=${SDNC_PORT:-8181}

env_file="--env-file ${SCRIPTS}/sdnr/docker-compose/.env"
echo $env_file

# Define sdnrdb type
# default: ESDB
# alternative: MARIADB
SDNRDB_TYPE="${SDNRDB_TYPE:-ESDB}"
if [[ "$SDNRDB_TYPE" == "ESDB" ]]; then
  sdnrdb_compose_file="docker-compose-sdnrdb-elasticsearch.yaml"
else
  sdnrdb_compose_file="docker-compose-sdnrdb-mariadb.yaml"
fi
docker ps -a

# Call function with port like:
# check_for_ready_state 1234
# export SDNC_READY_RETRY_PERIOD and SDNC_READY_TIMEOUT to overwrite default values
function check_for_ready_state() {
  sdnc_port=${1}
  SDNC_READY_RETRY_PERIOD=${SDNC_READY_RETRY_PERIOD:-15}
  SDNC_READY_TIMEOUT=${SDNC_READY_TIMEOUT:-450}
  max_retry=$(expr $SDNC_READY_TIMEOUT / $SDNC_READY_RETRY_PERIOD)
  for ((i=1; i<=$max_retry; i++)); do
    wait_time=$(expr $i \* $SDNC_READY_RETRY_PERIOD)
    echo "[INFO] SDNC/R container not yet ready after: $wait_time seconds, Timeout: $SDNC_READY_TIMEOUT seconds"
    curl -sS -m 1 -k -D - ${HTTPS_PREFIX}${HOST_IP}:${sdnc_port}/ready | grep 200 && break
    if [ $i == $max_retry ]; then
        echo "[ERROR] SDNC/R container not ready after ${SDNC_READY_TIMEOUT} seconds!"
        export SDNC_READY_STATE_TIME_OUT=true
        return
    fi
    echo sleep ${SDNC_READY_RETRY_PERIOD}
    sleep ${SDNC_READY_RETRY_PERIOD}
  done
  echo "[INFO] SDNC/R container ready after: $wait_time seconds"
}

function onap_dependent_components_launch() {
    docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-onap-addons.yaml pull
    docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-onap-addons.yaml up -d
}
function netconfserver_simulator_launch() {
    docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-netconfserver-simulator.yaml pull
    docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-netconfserver-simulator.yaml up -d
}

function nts_manager_launch() {
    # starts all ntsim managers defined in the csv file
    ${SCRIPTS}/sdnr/docker-compose/nts-manager-launch.sh $1
}

function nts_networkfunctions_launch() {
    # starts all ntsim networkfucntions defined in the csv file
    ${SCRIPTS}/sdnr/docker-compose/nts-networkfunctions-launch.sh $1
}


function sdnr_launch() {
    #if [ -n "${CALLHOME}" ] ; then
      #sdnrwtbootfeatures="-e SDNRWT_BOOTFEATURES=odl-netconf-callhome-ssh,sdnr-wt-feature-aggregator "
      #callhomeport="-p ${CALL_HOME_PORT}:6666 "
    #fi
    if [ "$SDNR_CLUSTER_MODE" == "true" ]; then
        sdnr_launch_cluster $1
    else
        sdnr_launch_single_node $1
    fi
}


function sdnr_launch_single_node() {

    # Use locally build sdnr .. no need to pull
    #docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
    #                         -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
    #                         pull
    docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
                             -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
                             up -d
    check_for_ready_state ${SDNC_PORT}
}

function sdnr_web_launch() {
    # Use locally build sdnr, sdnc-web .. no need to pull
    #docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
    #                         -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr-web.override.yaml \
    #                         -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
    #                         pull
    docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr.yaml \
                             -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose-single-sdnr-web.override.yaml \
                             -f ${WORKSPACE}/scripts/sdnr/docker-compose/$sdnrdb_compose_file \
                             up -d
    check_for_ready_state ${SDNC_WEB_PORT}
}

function sdnr_launch_cluster() {
    # source ${SCRIPTS}/sdnr/sdnrEnv_Cluster.sh
    SDNRDM="false"
    [[ -n "$1" ]]  && SDNRDM="true" && echo "SDNRDM arg detected - running in headless mode"
    echo "SDNR being launched in Cluster mode"
    #docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose/cluster-sdnr.yaml pull
    docker-compose $env_file -f ${WORKSPACE}/scripts/sdnr/docker-compose/docker-compose/cluster-sdnr.yaml up -d
    check_for_ready_state ${SDNC_WEB_PORT}
}