Merge "SDNC oam installer mdsal clustering"
[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 # Append features to karaf boot feature configuration
25 # $1 additional feature to be added
26 # $2 repositories to be added (optional)
27 function addToFeatureBoot() {
28   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
29   ORIG=$CFG.orig
30   if [ -n "$2" ] ; then
31     echo "Add repository: $2"
32     mv $CFG $ORIG
33     cat $ORIG | sed -e "\|featuresRepositories|s|$|,$2|" > $CFG
34   fi
35   echo "Add boot feature: $1"
36   mv $CFG $ORIG
37   cat $ORIG | sed -e "\|featuresBoot *=|s|$|,$1|" > $CFG
38 }
39
40 # Append features to karaf boot feature configuration
41 # $1 search pattern
42 # $2 replacement
43 function replaceFeatureBoot() {
44   CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
45   ORIG=$CFG.orig
46   echo "Replace boot feature $1 with: $2"
47   sed -i "/featuresBoot/ s/$1/$2/g" $CFG
48 }
49
50 function install_sdnrwt_features() {
51   addToFeatureBoot "$SDNRWT_BOOTFEATURES" $SDNRWT_REPOSITORY
52 }
53
54 function enable_odl_cluster(){
55   if [ -z $SDNC_REPLICAS ]; then
56      echo "SDNC_REPLICAS is not configured in Env field"
57      exit
58   fi
59
60   echo "Installing Opendaylight cluster features"
61   replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
62   addToFeatureBoot odl-jolokia
63   #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
64   #${ODL_HOME}/bin/client feature:install odl-jolokia
65
66   echo "Update cluster information statically"
67   hm=$(hostname)
68   echo "Get current Hostname ${hm}"
69
70   node=($(echo ${hm} | tr '-' '\n'))
71   node_name=${node[0]}
72   node_index=${node[1]}
73
74   if [ -z $PEER_ODL_CLUSTER ]; then
75     echo "This is a local cluster"
76     node_list="${node_name}-0.sdnhost-cluster.onap.svc.cluster.local";
77
78     for ((i=1;i<${SDNC_REPLICAS};i++));
79     do
80       node_list="${node_list} ${node_name}-$i.sdnhost-cluster.onap.svc.cluster.local"
81     done
82     /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
83   else
84     echo "This is a Geo cluster"
85
86     if $IS_PRIMARY_CLUSTER; then
87        PRIMARY_NODE=${MY_ODL_CLUSTER}
88        SECONDARY_NODE=${PEER_ODL_CLUSTER}
89     else
90        PRIMARY_NODE=${PEER_ODL_CLUSTER}
91        SECONDARY_NODE=${MY_ODL_CLUSTER}
92        member_offset=4
93     fi
94
95     node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
96     /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
97   fi
98 }
99
100
101 # Install SDN-C platform components if not already installed and start container
102
103 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
104 ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
105 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
106 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
107 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
108 SLEEP_TIME=${SLEEP_TIME:-120}
109 MYSQL_PASSWD=${MYSQL_PASSWD:-openECOMP1.0}
110 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
111 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
112 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
113 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
114 SDNRWT=${SDNRWT:-false}
115 SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
116
117
118 echo "Settings:"
119 echo "  ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
120 echo "  SDNC_REPLICAS=$SDNC_REPLICAS"
121 echo "  SDNRWT=$SDNRWT"
122
123 #
124 # Wait for database
125 #
126 echo "Waiting for mysql"
127 until mysql -h dbhost -u root -p${MYSQL_PASSWD} mysql &> /dev/null
128 do
129   printf "."
130   sleep 1
131 done
132 echo -e "\nmysql ready"
133
134 if [ ! -d ${INSTALLED_DIR} ]
135 then
136     mkdir -p ${INSTALLED_DIR}
137 fi
138
139 if [ ! -f ${INSTALLED_DIR}/.installed ]
140 then
141         echo "Installing SDN-C database"
142         ${SDNC_HOME}/bin/installSdncDb.sh
143         echo "Installing SDN-C keyStore"
144         ${SDNC_HOME}/bin/addSdncKeyStore.sh
145
146         #${CCSDK_HOME}/bin/installOdlHostKey.sh
147
148         if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
149         then
150                 echo "Installing directed graphs"
151                 ${SDNC_HOME}/svclogic/bin/install.sh
152         fi
153
154     if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
155
156         if $SDNRWT ; then install_sdnrwt_features ; fi
157
158         echo "Installed at `date`" > ${INSTALLED_DIR}/.installed
159 fi
160
161 cp /opt/opendaylight/current/certs/* /tmp
162
163 nohup python ${SDNC_BIN}/installCerts.py &
164
165 exec ${ODL_HOME}/bin/karaf server