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