Merge "Add Common Helm Chart "mariadb-galera""
[oom.git] / kubernetes / sdnc / resources / config / bin / startODL.sh
1 #!/bin/bash
2
3 ###
4 # ============LICENSE_START=======================================================
5 # SDNC
6 # ================================================================================
7 # Copyright (C) 2017 AT&T Intellectual Property. 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
23 function enable_odl_cluster(){
24   if [ -z $SDNC_REPLICAS ]; then
25      echo "SDNC_REPLICAS is not configured in Env field"
26      exit
27   fi
28
29   echo "Installing Opendaylight cluster features"
30   ${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
31   ${ODL_HOME}/bin/client feature:install odl-jolokia
32
33   echo "Update cluster information statically"
34   hm=$(hostname)
35   echo "Get current Hostname ${hm}"
36
37   node=($(echo ${hm} | tr '-' '\n'))
38   node_name=${node[0]}
39   node_index=${node[1]}
40
41   if [ -z $PEER_ODL_CLUSTER ]; then
42     echo "This is a local cluster"
43     node_list="${node_name}-0.{{.Values.service.name}}-cluster.{{.Release.Namespace}}";
44
45     for ((i=1;i<${SDNC_REPLICAS};i++));
46     do
47       node_list="${node_list} ${node_name}-$i.{{.Values.service.name}}-cluster.{{.Release.Namespace}}"
48     done
49     /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
50   else
51     echo "This is a Geo cluster"
52
53     if $IS_PRIMARY_CLUSTER; then
54        PRIMARY_NODE=${MY_ODL_CLUSTER}
55        SECONDARY_NODE=${PEER_ODL_CLUSTER}
56     else
57        PRIMARY_NODE=${PEER_ODL_CLUSTER}
58        SECONDARY_NODE=${MY_ODL_CLUSTER}
59        member_offset=4
60     fi
61
62     node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
63     /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
64   fi
65 }
66
67
68 # Install SDN-C platform components if not already installed and start container
69
70 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
71 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
72 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
73 SLEEP_TIME=${SLEEP_TIME:-120}
74 MYSQL_PASSWD=${MYSQL_PASSWD:-{{.Values.config.dbRootPassword}}}
75 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
76 MYSQL_HOST=${MYSQL_HOST:-{{.Release.Name}}-{{.Values.mysql.nameOverride}}-0.{{.Values.mysql.service.name}}.{{.Release.Namespace}}}
77 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
78 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
79
80 #
81 # Wait for database to init properly
82 #
83 echo "Waiting for mysql"
84 until mysql -h ${MYSQL_HOST} -u root -p${MYSQL_PASSWD} mysql &> /dev/null
85 do
86   printf "."
87   sleep 1
88 done
89 echo -e "\nmysql ready"
90
91 if [ ! -f ${SDNC_HOME}/.installed ]
92 then
93         echo "Installing SDNC database"
94         ${SDNC_HOME}/bin/installSdncDb.sh
95         echo "Installing SDN-C keyStore"
96         ${SDNC_HOME}/bin/addSdncKeyStore.sh
97         echo "Starting OpenDaylight"
98         ${ODL_HOME}/bin/start
99         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
100         sleep ${SLEEP_TIME}
101         echo "Installing SDN-C platform features"
102         ${SDNC_HOME}/bin/installFeatures.sh
103         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
104         then
105                 echo "Installing directed graphs"
106                 ${SDNC_HOME}/svclogic/bin/install.sh
107         fi
108
109         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
110
111         echo "Restarting OpenDaylight"
112         ${ODL_HOME}/bin/stop
113
114         echo "Waiting 60 seconds for OpenDaylight stop to complete"
115         sleep 60
116
117         echo "Installed at `date`" > ${SDNC_HOME}/.installed
118 fi
119
120 exec ${ODL_HOME}/bin/karaf
121