guillaume.lambert | 0daad99 | 2021-12-08 10:14:09 +0100 | [diff] [blame^] | 1 | #!/bin/sh |
Jakub Latusek | e0e8ca7 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 2 | {{/* |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 3 | |
| 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 Latusek | e0e8ca7 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 17 | */}} |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 18 | |
| 19 | LOGFILE="/app/geo.log" |
| 20 | enableDebugLogging=true |
| 21 | message_router=message-router:3904 |
| 22 | topic={{.Values.config.messageRouterTopic}} |
| 23 | KEYWORD_success="success" |
| 24 | KEYWORD_failure="failure" |
| 25 | SITE_NAME="sdnc01" |
| 26 | if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then |
| 27 | SITE_NAME="sdnc02" |
| 28 | fi |
| 29 | |
| 30 | APP_BIN=/app/bin |
| 31 | |
| 32 | debugLog(){ |
guillaume.lambert | 0daad99 | 2021-12-08 10:14:09 +0100 | [diff] [blame^] | 33 | if [ "$enableDebugLogging" = true ]; then |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 34 | if [ $# -eq 0 ]; then |
| 35 | echo "" >> $LOGFILE |
| 36 | else |
| 37 | echo $( date ) $@ >> $LOGFILE |
| 38 | fi |
| 39 | fi |
| 40 | } |
| 41 | |
| 42 | EXC_SIMPLE_FAILOVER=`${APP_BIN}/switchVoting.sh` |
| 43 | |
guillaume.lambert | 0daad99 | 2021-12-08 10:14:09 +0100 | [diff] [blame^] | 44 | if [ "$EXC_SIMPLE_FAILOVER" = "success" ]; then |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 45 | debugLog "Simple failover success. SDNC failover completed." |
| 46 | else |
| 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 |
| 86 | fi |
| 87 | |
| 88 | echo $KEYWORD_success |