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