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 | |
| 23 | function enable_odl_cluster(){ |
| 24 | if [ -z $SDNC_REPLICAS ]; then |
| 25 | echo "SDNC_REPLICAS is not configured in Env field" |
| 26 | exit |
| 27 | fi |
| 28 | |
| 29 | echo "Installing Opendaylight cluster features" |
jmac | c74329e | 2018-04-11 21:52:01 +0000 | [diff] [blame] | 30 | ${ODL_HOME}/bin/client feature:install odl-mdsal-clustering |
| 31 | ${ODL_HOME}/bin/client feature:install odl-jolokia |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 32 | |
| 33 | echo "Update cluster information statically" |
| 34 | hm=$(hostname) |
| 35 | echo "Get current Hostname ${hm}" |
| 36 | |
Trevor Tait | 702d105 | 2018-04-20 11:21:09 -0400 | [diff] [blame] | 37 | node=($(echo ${hm} | sed 's/-[0-9]*$//g')) |
| 38 | node_index=($(echo ${hm} | awk -F"-" '{print $NF}')) |
| 39 | member_offset=1 |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 40 | |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 41 | if $GEO_ENABLED; then |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 42 | echo "This is a Geo cluster" |
| 43 | |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 44 | if [ -z $IS_PRIMARY_CLUSTER ] || [ -z $MY_ODL_CLUSTER ] || [ -z $PEER_ODL_CLUSTER ]; then |
| 45 | echo "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field" |
| 46 | return |
| 47 | fi |
| 48 | |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 49 | if $IS_PRIMARY_CLUSTER; then |
| 50 | PRIMARY_NODE=${MY_ODL_CLUSTER} |
| 51 | SECONDARY_NODE=${PEER_ODL_CLUSTER} |
| 52 | else |
| 53 | PRIMARY_NODE=${PEER_ODL_CLUSTER} |
| 54 | SECONDARY_NODE=${MY_ODL_CLUSTER} |
| 55 | member_offset=4 |
| 56 | fi |
| 57 | |
| 58 | node_list="${PRIMARY_NODE} ${SECONDARY_NODE}" |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 59 | |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 60 | /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] | 61 | else |
| 62 | echo "This is a local cluster" |
| 63 | |
| 64 | node_list="${node}-0.{{.Values.service.name}}-cluster.{{.Release.Namespace}}"; |
| 65 | |
| 66 | for ((i=1;i<${SDNC_REPLICAS};i++)); |
| 67 | do |
| 68 | node_list="${node_list} ${node}-$i.{{.Values.service.name}}-cluster.{{.Release.Namespace}}" |
| 69 | done |
| 70 | |
| 71 | /opt/opendaylight/current/bin/configure_cluster.sh $((node_index+1)) ${node_list} |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 72 | fi |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 73 | } |
| 74 | |
jmac | c21cb7d | 2018-04-16 19:54:54 +0000 | [diff] [blame] | 75 | |
| 76 | # Install SDN-C platform components if not already installed and start container |
| 77 | |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 78 | ODL_HOME=${ODL_HOME:-/opt/opendaylight/current} |
| 79 | ODL_ADMIN_PASSWORD=${ODL_ADMIN_PASSWORD:-Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U} |
| 80 | SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc} |
Trevor Tait | 702d105 | 2018-04-20 11:21:09 -0400 | [diff] [blame] | 81 | CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk} |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 82 | SLEEP_TIME=${SLEEP_TIME:-120} |
| 83 | MYSQL_PASSWD=${MYSQL_PASSWD:-{{.Values.config.dbRootPassword}}} |
jmac | bc92d13 | 2018-04-07 03:46:12 +0000 | [diff] [blame] | 84 | MYSQL_HOST=${MYSQL_HOST:-{{.Release.Name}}-{{.Values.mysql.nameOverride}}-0.{{.Values.mysql.service.name}}.{{.Release.Namespace}}} |
Trevor Tait | 567ff1e | 2018-05-01 16:20:54 -0400 | [diff] [blame] | 85 | ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false} |
| 86 | GEO_ENABLED=${GEO_ENABLED:-false} |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 87 | |
| 88 | # |
| 89 | # Wait for database to init properly |
| 90 | # |
| 91 | echo "Waiting for mysql" |
jmac | bc92d13 | 2018-04-07 03:46:12 +0000 | [diff] [blame] | 92 | until mysql -h ${MYSQL_HOST} -u root -p${MYSQL_PASSWD} mysql &> /dev/null |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 93 | do |
| 94 | printf "." |
| 95 | sleep 1 |
| 96 | done |
| 97 | echo -e "\nmysql ready" |
| 98 | |
| 99 | if [ ! -f ${SDNC_HOME}/.installed ] |
| 100 | then |
| 101 | echo "Installing SDNC database" |
| 102 | ${SDNC_HOME}/bin/installSdncDb.sh |
| 103 | echo "Installing SDN-C keyStore" |
| 104 | ${SDNC_HOME}/bin/addSdncKeyStore.sh |
| 105 | echo "Starting OpenDaylight" |
Trevor Tait | 702d105 | 2018-04-20 11:21:09 -0400 | [diff] [blame] | 106 | ${CCSDK_HOME}/bin/installOdlHostKey.sh |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 107 | ${ODL_HOME}/bin/start |
| 108 | echo "Waiting ${SLEEP_TIME} seconds for OpenDaylight to initialize" |
| 109 | sleep ${SLEEP_TIME} |
| 110 | echo "Installing SDN-C platform features" |
| 111 | ${SDNC_HOME}/bin/installFeatures.sh |
| 112 | if [ -x ${SDNC_HOME}/svclogic/bin/install.sh ] |
| 113 | then |
| 114 | echo "Installing directed graphs" |
| 115 | ${SDNC_HOME}/svclogic/bin/install.sh |
| 116 | fi |
| 117 | |
| 118 | if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi |
| 119 | |
| 120 | echo "Restarting OpenDaylight" |
| 121 | ${ODL_HOME}/bin/stop |
jmac | c74329e | 2018-04-11 21:52:01 +0000 | [diff] [blame] | 122 | |
| 123 | echo "Waiting 60 seconds for OpenDaylight stop to complete" |
| 124 | sleep 60 |
| 125 | |
jmac | 065e2ce | 2018-03-29 01:18:02 +0000 | [diff] [blame] | 126 | echo "Installed at `date`" > ${SDNC_HOME}/.installed |
| 127 | fi |
| 128 | |
| 129 | exec ${ODL_HOME}/bin/karaf |
| 130 | |