blob: 48db5744dec49a29c9f26d9c944f86673d28fe2e [file] [log] [blame]
Neha Jainde45c682018-04-05 11:51:29 -04001#!/bin/bash
2
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04003# 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.
Neha Jainde45c682018-04-05 11:51:29 -040016
17if ! [ "$(command -v jq)" ]; then
18 echo "Error: jq is not installed."
19 echo "use: sudo apt install jq"
20 exit 1
21fi
22
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040023dir=$( dirname $0 )
24IS_PRIMARY_CLUSTER=$( $dir/sdnc.isPrimaryCluster )
Neha Jainde45c682018-04-05 11:51:29 -040025
26case $IS_PRIMARY_CLUSTER in
27true)
28 MEMBER_NUMBER=1
29 ;;
30false)
31 MEMBER_NUMBER=4
32 ;;
33*)
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040034 echo "Error: isPrimaryCluster not defined in $dir/../../../values.yaml."
Neha Jainde45c682018-04-05 11:51:29 -040035 exit 1
36 ;;
37esac
38
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040039USERNAME=admin
40PASSWORD=admin
41
Neha Jainde45c682018-04-05 11:51:29 -040042for pod_number in {0..2}
43do
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040044
jmac7e131f32018-09-07 20:23:53 +000045 response=`curl -s -u $USERNAME:$PASSWORD -H "Content-Type: application/json" -H "Accept: application/json" -X GET http://localhost:3046$((${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 -040046
47 if [ $? -ne 0 ]; then
Neha Jainde45c682018-04-05 11:51:29 -040048 continue
49 fi
50
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040051 status=$( echo -E "$response" | jq -r ".status" )
52 if [ "$status" != "200" ]; then
53 continue
54 fi
Neha Jainde45c682018-04-05 11:51:29 -040055
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040056 voting=$( echo -E "$response" | jq -r ".value.Voting" )
57 case $voting in
Neha Jainde45c682018-04-05 11:51:29 -040058 true)
59 echo "active"
60 exit 0
61 ;;
62 false)
63 echo "standby"
64 exit 0
65 ;;
66 *)
67 echo "Error: Voting status could not be determined."
68 exit 1
69 ;;
70 esac
71done
72
73echo "Error: Voting status could not be determined."
74exit 1