jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 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 | |
Herbert Eiselt | 746fa02 | 2019-04-05 20:01:01 +0200 | [diff] [blame] | 23 | # Append features to karaf boot feature configuration |
| 24 | # $1 additional feature to be added |
| 25 | # $2 repositories to be added (optional) |
| 26 | function 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 |
| 42 | function 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 | |
| 49 | function install_sdnrwt_features() { |
| 50 | addToFeatureBoot "$SDNRWT_BOOTFEATURES" $SDNRWT_REPOSITORY |
| 51 | } |
| 52 | |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 53 | function 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 Eiselt | 746fa02 | 2019-04-05 20:01:01 +0200 | [diff] [blame] | 59 | #Be sure to remove feature odl-netconf-connector-all from list |
| 60 | replaceFeatureBoot "odl-netconf-connector-all," |
| 61 | |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 62 | echo "Installing Opendaylight cluster features" |
Herbert Eiselt | 746fa02 | 2019-04-05 20:01:01 +0200 | [diff] [blame] | 63 | 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) | 1bb05c8 | 2018-07-24 10:10:08 -0400 | [diff] [blame] | 66 | #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering |
| 67 | #${ODL_HOME}/bin/client feature:install odl-jolokia |
Herbert Eiselt | 746fa02 | 2019-04-05 20:01:01 +0200 | [diff] [blame] | 68 | |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 69 | |
| 70 | echo "Update cluster information statically" |
| 71 | hm=$(hostname) |
| 72 | echo "Get current Hostname ${hm}" |
| 73 | |
Trevor Tait | 702d105 | 2018-04-20 11:21:09 -0400 | [diff] [blame] | 74 | node=($(echo ${hm} | sed 's/-[0-9]*$//g')) |
| 75 | node_index=($(echo ${hm} | awk -F"-" '{print $NF}')) |
| 76 | member_offset=1 |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 77 | |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 78 | if $GEO_ENABLED; then |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 79 | echo "This is a Geo cluster" |
| 80 | |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 81 | 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 | |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 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}" |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 96 | |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 97 | /opt/onap/sdnc/bin/configure_geo_cluster.sh $((node_index+member_offset)) ${node_list} |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 98 | 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} |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 109 | fi |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 110 | } |
| 111 | |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 112 | |
| 113 | # Install SDN-C platform components if not already installed and start container |
| 114 | |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 115 | ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} |
DarraghEgan | 78531bf | 2019-05-20 13:24:29 +0000 | [diff] [blame^] | 116 | ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME:-admin} |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 117 | ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U} |
| 118 | SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc} |
DarraghEgan | dbb5b68 | 2019-03-25 18:04:31 +0000 | [diff] [blame] | 119 | SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin} |
Trevor Tait | 702d105 | 2018-04-20 11:21:09 -0400 | [diff] [blame] | 120 | CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk} |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 121 | SLEEP_TIME=${SLEEP_TIME:-120} |
| 122 | MYSQL_PASSWD=${MYSQL_PASSWD:-{{.Values.config.dbRootPassword}}} |
Mahendra Raghuwanshi | b76cb28 | 2019-04-09 10:13:07 +0000 | [diff] [blame] | 123 | MYSQL_HOST=${MYSQL_HOST:-{{.Values.config.dbServiceName}}.{{.Release.Namespace}}} |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 124 | ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false} |
| 125 | GEO_ENABLED=${GEO_ENABLED:-false} |
Timoney, Dan (dt5972) | eaa6a24 | 2018-11-16 17:08:12 -0500 | [diff] [blame] | 126 | DBINIT_DIR=${DBINIT_DIR:-/opt/opendaylight/current/daexim} |
Herbert Eiselt | 746fa02 | 2019-04-05 20:01:01 +0200 | [diff] [blame] | 127 | SDNRWT=${SDNRWT:-false} |
| 128 | SDNRWT_BOOTFEATURES=${SDNRWT_BOOTFEATURES:-sdnr-wt-feature-aggregator} |
DarraghEgan | 78531bf | 2019-05-20 13:24:29 +0000 | [diff] [blame^] | 129 | export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME |
Herbert Eiselt | 746fa02 | 2019-04-05 20:01:01 +0200 | [diff] [blame] | 130 | |
| 131 | echo "Settings:" |
| 132 | echo " ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER" |
| 133 | echo " SDNC_REPLICAS=$SDNC_REPLICAS" |
| 134 | echo " SDNRWT=$SDNRWT" |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 135 | |
| 136 | # |
| 137 | # Wait for database to init properly |
| 138 | # |
| 139 | echo "Waiting for mysql" |
jmac | bc92d13 | 2018-04-07 03:46:12 +0000 | [diff] [blame] | 140 | until mysql -h ${MYSQL_HOST} -u root -p${MYSQL_PASSWD} mysql &> /dev/null |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 141 | do |
| 142 | printf "." |
| 143 | sleep 1 |
| 144 | done |
| 145 | echo -e "\nmysql ready" |
| 146 | |
Timoney, Dan (dt5972) | eaa6a24 | 2018-11-16 17:08:12 -0500 | [diff] [blame] | 147 | if [ ! -d ${DBINIT_DIR} ] |
Timoney, Dan (dt5972) | e156c23 | 2018-11-14 10:34:31 -0500 | [diff] [blame] | 148 | then |
Timoney, Dan (dt5972) | eaa6a24 | 2018-11-16 17:08:12 -0500 | [diff] [blame] | 149 | mkdir -p ${DBINIT_DIR} |
Timoney, Dan (dt5972) | e156c23 | 2018-11-14 10:34:31 -0500 | [diff] [blame] | 150 | fi |
| 151 | |
Timoney, Dan (dt5972) | eaa6a24 | 2018-11-16 17:08:12 -0500 | [diff] [blame] | 152 | if [ ! -f ${DBINIT_DIR}/.installed ] |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 153 | then |
| 154 | echo "Installing SDNC database" |
| 155 | ${SDNC_HOME}/bin/installSdncDb.sh |
Timoney, Dan (dt5972) | 1bb05c8 | 2018-07-24 10:10:08 -0400 | [diff] [blame] | 156 | |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 157 | if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ] |
| 158 | then |
| 159 | echo "Installing directed graphs" |
| 160 | ${SDNC_HOME}/svclogic/bin/install.sh |
| 161 | fi |
| 162 | |
Timoney, Dan (dt5972) | eaa6a24 | 2018-11-16 17:08:12 -0500 | [diff] [blame] | 163 | echo "Installed at `date`" > ${DBINIT_DIR}/.installed |
| 164 | fi |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 165 | |
Timoney, Dan (dt5972) | eaa6a24 | 2018-11-16 17:08:12 -0500 | [diff] [blame] | 166 | if [ ! -f ${SDNC_HOME}/.installed ] |
| 167 | then |
| 168 | echo "Installing SDN-C keyStore" |
| 169 | ${SDNC_HOME}/bin/addSdncKeyStore.sh |
| 170 | |
| 171 | # No longer needed (this was a workaround for bug in Nitrogen) |
| 172 | #${CCSDK_HOME}/bin/installOdlHostKey.sh |
| 173 | |
| 174 | if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi |
| 175 | |
Herbert Eiselt | 746fa02 | 2019-04-05 20:01:01 +0200 | [diff] [blame] | 176 | if $SDNRWT ; then install_sdnrwt_features ; fi |
| 177 | |
Timoney, Dan (dt5972) | eaa6a24 | 2018-11-16 17:08:12 -0500 | [diff] [blame] | 178 | echo "Installed at `date`" > ${SDNC_HOME}/.installed |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 179 | fi |
| 180 | |
DarraghEgan | dbb5b68 | 2019-03-25 18:04:31 +0000 | [diff] [blame] | 181 | cp /opt/opendaylight/current/certs/* /tmp |
| 182 | |
| 183 | nohup python ${SDNC_BIN}/installCerts.py & |
| 184 | |
| 185 | |
jmac | dbbe937 | 2018-07-30 20:18:44 +0000 | [diff] [blame] | 186 | exec ${ODL_HOME}/bin/karaf server |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 187 | |