Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 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. |
Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 16 | |
| 17 | if ! [ "$(command -v jq)" ]; then |
| 18 | echo "Error: jq is not installed." |
| 19 | echo "use: sudo apt install jq" |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 23 | dir=$( dirname $0 ) |
| 24 | IS_PRIMARY_CLUSTER=$( $dir/sdnc.isPrimaryCluster ) |
Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 25 | |
| 26 | case $IS_PRIMARY_CLUSTER in |
| 27 | true) |
| 28 | MEMBER_NUMBER=1 |
| 29 | ;; |
| 30 | false) |
| 31 | MEMBER_NUMBER=4 |
| 32 | ;; |
| 33 | *) |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 34 | echo "Error: isPrimaryCluster not defined in $dir/../../../values.yaml." |
Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 35 | exit 1 |
| 36 | ;; |
| 37 | esac |
| 38 | |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 39 | USERNAME=admin |
| 40 | PASSWORD=admin |
| 41 | |
Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 42 | for pod_number in {0..2} |
| 43 | do |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 44 | |
toshrajbhardwaj | 72b5f0f | 2018-09-13 02:45:22 +0000 | [diff] [blame] | 45 | 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 Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 46 | |
| 47 | if [ $? -ne 0 ]; then |
Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 48 | continue |
| 49 | fi |
| 50 | |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 51 | status=$( echo -E "$response" | jq -r ".status" ) |
| 52 | if [ "$status" != "200" ]; then |
| 53 | continue |
| 54 | fi |
Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 55 | |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 56 | voting=$( echo -E "$response" | jq -r ".value.Voting" ) |
| 57 | case $voting in |
Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 58 | 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 |
| 71 | done |
| 72 | |
| 73 | echo "Error: Voting status could not be determined." |
| 74 | exit 1 |