blob: 2513fc9dd4a365d1b8fd1a7e49cca15fd3949250 [file] [log] [blame]
jmac065e2ce2018-03-29 01:18:02 +00001#!/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
Herbert Eiselt746fa022019-04-05 20:01:01 +020023# Append features to karaf boot feature configuration
24# $1 additional feature to be added
25# $2 repositories to be added (optional)
26function addToFeatureBoot() {
27 CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
28 ORIG=$CFG.orig
29 if [ -n "$2" ] ; then
30 echo "Add repository: $2"
31 mv $CFG $ORIG
32 cat $ORIG | sed -e "\|featuresRepositories|s|$|,$2|" > $CFG
33 fi
34 echo "Add boot feature: $1"
35 mv $CFG $ORIG
36 cat $ORIG | sed -e "\|featuresBoot *=|s|$|,$1|" > $CFG
37}
38
39# Append features to karaf boot feature configuration
40# $1 search pattern
41# $2 replacement
42function replaceFeatureBoot() {
43 CFG=$ODL_HOME/etc/org.apache.karaf.features.cfg
44 ORIG=$CFG.orig
45 echo "Replace boot feature $1 with: $2"
46 sed -i "/featuresBoot/ s/$1/$2/g" $CFG
47}
48
49function install_sdnrwt_features() {
50 addToFeatureBoot "$SDNRWT_BOOTFEATURES" $SDNRWT_REPOSITORY
51}
52
jmac065e2ce2018-03-29 01:18:02 +000053function enable_odl_cluster(){
54 if [ -z $SDNC_REPLICAS ]; then
55 echo "SDNC_REPLICAS is not configured in Env field"
56 exit
57 fi
58
Herbert Eiselt746fa022019-04-05 20:01:01 +020059 #Be sure to remove feature odl-netconf-connector-all from list
60 replaceFeatureBoot "odl-netconf-connector-all,"
61
jmac065e2ce2018-03-29 01:18:02 +000062 echo "Installing Opendaylight cluster features"
Herbert Eiselt746fa022019-04-05 20:01:01 +020063 replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
64 replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
65 addToFeatureBoot odl-jolokia
Timoney, Dan (dt5972)1bb05c82018-07-24 10:10:08 -040066 #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
67 #${ODL_HOME}/bin/client feature:install odl-jolokia
Herbert Eiselt746fa022019-04-05 20:01:01 +020068
jmac065e2ce2018-03-29 01:18:02 +000069
70 echo "Update cluster information statically"
71 hm=$(hostname)
72 echo "Get current Hostname ${hm}"
73
Trevor Tait702d1052018-04-20 11:21:09 -040074 node=($(echo ${hm} | sed 's/-[0-9]*$//g'))
75 node_index=($(echo ${hm} | awk -F"-" '{print $NF}'))
76 member_offset=1
jmac065e2ce2018-03-29 01:18:02 +000077
Trevor Tait567ff1e2018-05-01 16:20:54 -040078 if $GEO_ENABLED; then
jmacc21cb7d2018-04-16 19:54:54 +000079 echo "This is a Geo cluster"
80
Trevor Tait567ff1e2018-05-01 16:20:54 -040081 if [ -z $IS_PRIMARY_CLUSTER ] || [ -z $MY_ODL_CLUSTER ] || [ -z $PEER_ODL_CLUSTER ]; then
82 echo "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field"
83 return
84 fi
85
jmacc21cb7d2018-04-16 19:54:54 +000086 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}"
Trevor Tait567ff1e2018-05-01 16:20:54 -040096
jmacc21cb7d2018-04-16 19:54:54 +000097 /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list}
Trevor Tait567ff1e2018-05-01 16:20:54 -040098 else
99 echo "This is a local cluster"
100
101 node_list="${node}-0.{{.Values.service.name}}-cluster.{{.Release.Namespace}}";
102
103 for ((i=1;i<${SDNC_REPLICAS};i++));
104 do
105 node_list="${node_list} ${node}-$i.{{.Values.service.name}}-cluster.{{.Release.Namespace}}"
106 done
107
108 /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list}
jmacc21cb7d2018-04-16 19:54:54 +0000109 fi
jmac065e2ce2018-03-29 01:18:02 +0000110}
111
jmacc21cb7d2018-04-16 19:54:54 +0000112
113# Install SDN-C platform components if not already installed and start container
114
jmac065e2ce2018-03-29 01:18:02 +0000115ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
116ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U}
117SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
DarraghEgandbb5b682019-03-25 18:04:31 +0000118SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
Trevor Tait702d1052018-04-20 11:21:09 -0400119CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
jmac065e2ce2018-03-29 01:18:02 +0000120SLEEP_TIME=${SLEEP_TIME:-120}
121MYSQL_PASSWD=${MYSQL_PASSWD:-{{.Values.config.dbRootPassword}}}
jmacbc92d132018-04-07 03:46:12 +0000122MYSQL_HOST=${MYSQL_HOST:-{{.Release.Name}}-{{.Values.mysql.nameOverride}}-0.{{.Values.mysql.service.name}}.{{.Release.Namespace}}}
Trevor Tait567ff1e2018-05-01 16:20:54 -0400123ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
124GEO_ENABLED=${GEO_ENABLED:-false}
Timoney, Dan (dt5972)eaa6a242018-11-16 17:08:12 -0500125DBINIT_DIR=${DBINIT_DIR:-/opt/opendaylight/current/daexim}
Herbert Eiselt746fa022019-04-05 20:01:01 +0200126SDNRWT=${SDNRWT:-false}
127SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator}
128
129echo "Settings:"
130echo " ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
131echo " SDNC_REPLICAS=$SDNC_REPLICAS"
132echo " SDNRWT=$SDNRWT"
jmac065e2ce2018-03-29 01:18:02 +0000133
134#
135# Wait for database to init properly
136#
137echo "Waiting for mysql"
jmacbc92d132018-04-07 03:46:12 +0000138until mysql -h ${MYSQL_HOST} -u root -p${MYSQL_PASSWD} mysql &> /dev/null
jmac065e2ce2018-03-29 01:18:02 +0000139do
140 printf "."
141 sleep 1
142done
143echo -e "\nmysql ready"
144
Timoney, Dan (dt5972)eaa6a242018-11-16 17:08:12 -0500145if [ ! -d ${DBINIT_DIR} ]
Timoney, Dan (dt5972)e156c232018-11-14 10:34:31 -0500146then
Timoney, Dan (dt5972)eaa6a242018-11-16 17:08:12 -0500147 mkdir -p ${DBINIT_DIR}
Timoney, Dan (dt5972)e156c232018-11-14 10:34:31 -0500148fi
149
Timoney, Dan (dt5972)eaa6a242018-11-16 17:08:12 -0500150if [ ! -f ${DBINIT_DIR}/.installed ]
jmac065e2ce2018-03-29 01:18:02 +0000151then
152 echo "Installing SDNC database"
153 ${SDNC_HOME}/bin/installSdncDb.sh
Timoney, Dan (dt5972)1bb05c82018-07-24 10:10:08 -0400154
jmac065e2ce2018-03-29 01:18:02 +0000155 if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ]
156 then
157 echo "Installing directed graphs"
158 ${SDNC_HOME}/svclogic/bin/install.sh
159 fi
160
Timoney, Dan (dt5972)eaa6a242018-11-16 17:08:12 -0500161 echo "Installed at `date`" > ${DBINIT_DIR}/.installed
162fi
jmac065e2ce2018-03-29 01:18:02 +0000163
Timoney, Dan (dt5972)eaa6a242018-11-16 17:08:12 -0500164if [ ! -f ${SDNC_HOME}/.installed ]
165then
166 echo "Installing SDN-C keyStore"
167 ${SDNC_HOME}/bin/addSdncKeyStore.sh
168
169 # No longer needed (this was a workaround for bug in Nitrogen)
170 #${CCSDK_HOME}/bin/installOdlHostKey.sh
171
172 if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
173
Herbert Eiselt746fa022019-04-05 20:01:01 +0200174 if $SDNRWT ; then install_sdnrwt_features ; fi
175
Timoney, Dan (dt5972)eaa6a242018-11-16 17:08:12 -0500176 echo "Installed at `date`" > ${SDNC_HOME}/.installed
jmac065e2ce2018-03-29 01:18:02 +0000177fi
178
DarraghEgandbb5b682019-03-25 18:04:31 +0000179cp /opt/opendaylight/current/certs/* /tmp
180
181nohup python ${SDNC_BIN}/installCerts.py &
182
183
jmacdbbe9372018-07-30 20:18:44 +0000184exec ${ODL_HOME}/bin/karaf server
jmac065e2ce2018-03-29 01:18:02 +0000185