blob: e78b7eeee3f3a448d4cbaabbf71f94afa207253a [file] [log] [blame]
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04001#!/bin/bash
2
3# Copyright © 2018 Amdocs
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17LOGFILE="/app/geo.log"
18enableDebugLogging=true
19message_router=message-router:3904
20topic={{.Values.config.messageRouterTopic}}
21KEYWORD_success="success"
22KEYWORD_failure="failure"
23SITE_NAME="sdnc01"
24if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then
25 SITE_NAME="sdnc02"
26fi
27
28APP_BIN=/app/bin
29
30debugLog(){
31 if [ "$enableDebugLogging" == true ]; then
32 if [ $# -eq 0 ]; then
33 echo "" >> $LOGFILE
34 else
35 echo $( date ) $@ >> $LOGFILE
36 fi
37 fi
38}
39
40EXC_SIMPLE_FAILOVER=`${APP_BIN}/switchVoting.sh`
41
42if [ "$EXC_SIMPLE_FAILOVER" == "success" ]; then
43 debugLog "Simple failover success. SDNC failover completed."
44else
45 # Simple failover failed. Trying catastrophic failover ...
46 debugLog "Simple failover failed. Trying catastrophic failover for $SITE_NAME ..."
47
48 # Notify Dmaap before executing catastrophic failover, because all connections will be reset.
49 data="{\
50 \"type\": \"Catastrophic failover\",\
51 \"reason\": \"Simple failover failed\",\
52 \"message_router\": \"$message_router\",\
53 \"topic\": \"$topic\",\
54 \"site\": \"$SITE_NAME\",\
55 \"deployment\": \"{{.Values.config.deployment}}\",\
56 \"timestamp\": \"$(date '+%F %T')\"\
57 }"
58
59 debugLog "$data"
60
61 # notifications to Dmaap
62 curl -H "Content-Type: application/json" -X POST --data "$data" http://$message_router/events/$topic >/dev/null 2>&1
63
64 # We're going to kill prom, so we need to do dnsswitch now
65
66 debugLog "Executing sdnc.dnsswitch"
67
68 /app/bin/sdnc.dnsswitch > /dev/null 2>&1
69 rc=$?
70 if [ $rc -ne 0 ];then
71 debugLog "sdnc.dnsswitch FAILED"
72 echo $KEYWORD_failure
73 exit 0
74 fi
75
76 # Now do catastrophic failure
77
78 debugLog "Catastrophic failover in progress"
79
80 ssh -o StrictHostKeyChecking=no -i /app/config/coredns/master.key root@$SDNC_LOCAL_K8S_CLUSTER_MASTER "su - ubuntu bash -c 'helm upgrade --set sdnc.config.geoEnabled=false dev local/onap --namespace onap; kubectl -n onap delete pods -l app=sdnc'" > /dev/null 2>&1
81
82 # Sleep here so prom can die without us passing control back to ensureSDNCActive
83 sleep 300
84fi
85
86echo $KEYWORD_success