blob: bc285fb42da9d596150c6b203f14e8f1461d278a [file] [log] [blame]
Neha Jainde45c682018-04-05 11:51:29 -04001#!/bin/bash
Jakub Latuseke0e8ca72020-10-21 13:36:29 +02002{{/*
Neha Jainde45c682018-04-05 11:51:29 -04003
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04004# 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*/}}
Neha Jainde45c682018-04-05 11:51:29 -040018
19if ! [ "$(command -v jq)" ]; then
20 echo "Error: jq is not installed."
21 echo "use: sudo apt install jq"
22 exit 1
23fi
24
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040025dir=$( dirname $0 )
26IS_PRIMARY_CLUSTER=$( $dir/sdnc.isPrimaryCluster )
Neha Jainde45c682018-04-05 11:51:29 -040027
28case $IS_PRIMARY_CLUSTER in
29true)
30 MEMBER_NUMBER=1
31 ;;
32false)
33 MEMBER_NUMBER=4
34 ;;
35*)
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040036 echo "Error: isPrimaryCluster not defined in $dir/../../../values.yaml."
Neha Jainde45c682018-04-05 11:51:29 -040037 exit 1
38 ;;
39esac
40
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040041USERNAME=admin
42PASSWORD=admin
43
Neha Jainde45c682018-04-05 11:51:29 -040044for pod_number in {0..2}
45do
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040046
toshrajbhardwaj72b5f0f2018-09-13 02:45:22 +000047 response=`curl -s -u $USERNAME:$PASSWORD -H "Content-Type: application/json" -H "Accept: application/json" -X GET http://localhost:3026$((${pod_number} + 1))/jolokia/read/org.opendaylight.controller:Category=Shards,name=member-$((${MEMBER_NUMBER} + ${pod_number}))-shard-default-config,type=DistributedConfigDatastore`
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040048
49 if [ $? -ne 0 ]; then
Neha Jainde45c682018-04-05 11:51:29 -040050 continue
51 fi
52
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040053 status=$( echo -E "$response" | jq -r ".status" )
54 if [ "$status" != "200" ]; then
55 continue
56 fi
Neha Jainde45c682018-04-05 11:51:29 -040057
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040058 voting=$( echo -E "$response" | jq -r ".value.Voting" )
59 case $voting in
Neha Jainde45c682018-04-05 11:51:29 -040060 true)
61 echo "active"
62 exit 0
63 ;;
64 false)
65 echo "standby"
66 exit 0
67 ;;
68 *)
69 echo "Error: Voting status could not be determined."
70 exit 1
71 ;;
72 esac
73done
74
75echo "Error: Voting status could not be determined."
76exit 1