Merge "Drop CDS tables only if they exist"
[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   mv $ODL_HOME/etc/org.apache.karaf.features.cfg $ODL_HOME/etc/org.apache.karaf.features.cfg.orig
32   cat $ODL_HOME/etc/org.apache.karaf.features.cfg.orig | sed -e "\|featuresBoot=config|s|$|,odl-mdsal-clustering,odl-jolokia|" > $ODL_HOME/etc/org.apache.karaf.features.cfg
33   #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
34   #${ODL_HOME}/bin/client feature:install odl-jolokia
35
36   echo "Update cluster information statically"
37   hm=$(hostname)
38   echo "Get current Hostname ${hm}"
39
40   node=($(echo ${hm} | tr '-' '\n'))
41   node_name=${node[0]}
42   node_index=${node[1]}
43
44   if [ -z $PEER_ODL_CLUSTER ]; then
45     echo "This is a local cluster"
46     node_list="${node_name}-0.sdnhost-cluster.onap.svc.cluster.local";
47
48     for ((i=1;i<${SDNC_REPLICAS};i++));
49     do
50       node_list="${node_list} ${node_name}-$i.sdnhost-cluster.onap.svc.cluster.local"
51     done
52     /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
53   else
54     echo "This is a Geo cluster"
55
56     if $IS_PRIMARY_CLUSTER; then
57        PRIMARY_NODE=${MY_ODL_CLUSTER}
58        SECONDARY_NODE=${PEER_ODL_CLUSTER}
59     else
60        PRIMARY_NODE=${PEER_ODL_CLUSTER}
61        SECONDARY_NODE=${MY_ODL_CLUSTER}
62        member_offset=4
63     fi
64
65     node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
66     /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
67   fi
68 }
69
70
71 # Install SDN-C platform components if not already installed and start container
72
73 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
74 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
75 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
76 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
77 SLEEP_TIME=${SLEEP_TIME:-120}
78 MYSQL_PASSWD=${MYSQL_PASSWD:-openECOMP1.0}
79 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
80 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
81 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
82 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
83
84 #
85 # Wait for database
86 #
87 echo "Waiting for mysql"
88 until mysql -h dbhost -u root -p${MYSQL_PASSWD} mysql &> /dev/null
89 do
90   printf "."
91   sleep 1
92 done
93 echo -e "\nmysql ready"
94
95 if [ ! -d ${INSTALLED_DIR} ]
96 then
97     mkdir -p ${INSTALLED_DIR}
98 fi
99
100 if [ ! -f ${INSTALLED_DIR}/.installed ]
101 then
102         echo "Installing SDN-C database"
103         ${SDNC_HOME}/bin/installSdncDb.sh
104         echo "Installing SDN-C keyStore"
105         ${SDNC_HOME}/bin/addSdncKeyStore.sh
106
107         #${CCSDK_HOME}/bin/installOdlHostKey.sh
108
109         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
110         then
111                 echo "Installing directed graphs"
112                 ${SDNC_HOME}/svclogic/bin/install.sh
113         fi
114
115     if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
116
117         echo "Installed at `date`" > ${INSTALLED_DIR}/.installed
118 fi
119
120 exec ${ODL_HOME}/bin/karaf server