SDNC ODL cluster POC
[sdnc/oam.git] / installation / sdnc / src / main / scripts / startODL.sh
1 #!/bin/bash
2
3 ###
4 # ============LICENSE_START=======================================================
5 # openECOMP : SDN-C
6 # ================================================================================
7 # Copyright (C) 2017 AT&T Intellectual Property. All rights
8 #                                                       reserved.
9 # ================================================================================
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
13 #
14 #      http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 # ============LICENSE_END=========================================================
22 ###
23
24 function enable_odl_cluster(){
25   if [ -z $SDNC_REPLICAS ]; then
26      echo "SDNC_REPLICAS is not configured in Env field"
27      exit
28   fi
29
30   echo "Installing Opendaylight cluster features"
31   ${ODL_HOME}/bin/client -u karaf feature:install odl-mdsal-clustering
32   ${ODL_HOME}/bin/client -u karaf feature:install odl-jolokia
33
34   echo "Update cluster information statically"
35   hm=$(hostname)
36   echo "Get current Hostname ${hm}"
37
38   node=($(echo ${hm} | tr '-' '\n'))
39   node_name=${node[0]}
40   node_index=${node[1]}
41   node_list="${node_name}-0.sdnhost-cluster.onap-sdnc.svc.cluster.local";
42
43   for ((i=1;i<${SDNC_REPLICAS};i++));
44   do
45     node_list="${node_list} ${node_name}-$i.sdnhost-cluster.onap-sdnc.svc.cluster.local"
46   done
47
48   /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
49 }
50
51
52 # Install SDN-C platform components if not already installed and start container
53
54 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
55 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
56 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
57 SLEEP_TIME=${SLEEP_TIME:-120}
58 MYSQL_PASSWD=${MYSQL_PASSWD:-openECOMP1.0}
59 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
60
61 #
62 # Wait for database
63 #
64 echo "Waiting for mysql"
65 until mysql -h dbhost -u root -p${MYSQL_PASSWD} mysql &> /dev/null
66 do
67   printf "."
68   sleep 1
69 done
70 echo -e "\nmysql ready"
71
72 if [ ! -f ${SDNC_HOME}/.installed ]
73 then
74         echo "Installing SDN-C database"
75         ${SDNC_HOME}/bin/installSdncDb.sh
76         echo "Installing SDN-C keyStore"
77         ${SDNC_HOME}/bin/addSdncKeyStore.sh
78         echo "Starting OpenDaylight"
79         ${ODL_HOME}/bin/start
80         echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize"
81         sleep ${SLEEP_TIME}
82         echo "Installing SDN-C platform features"
83         ${SDNC_HOME}/bin/installFeatures.sh
84         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
85         then
86                 echo "Installing directed graphs"
87                 ${SDNC_HOME}/svclogic/bin/install.sh
88         fi
89
90         if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
91
92         echo "Restarting OpenDaylight"
93         ${ODL_HOME}/bin/stop
94         echo "Installed at `date`" > ${SDNC_HOME}/.installed
95 fi
96
97 exec ${ODL_HOME}/bin/karaf