Neha Jain | de45c68 | 2018-04-05 11:51:29 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | OOM_HOME=${OOM_HOME:-$HOME} |
| 4 | |
| 5 | if ! [ "$(command -v jq)" ]; then |
| 6 | echo "Error: jq is not installed." |
| 7 | echo "use: sudo apt install jq" |
| 8 | exit 1 |
| 9 | fi |
| 10 | |
| 11 | IS_PRIMARY_CLUSTER=`./sdnc.isPrimaryCluster` |
| 12 | |
| 13 | case $IS_PRIMARY_CLUSTER in |
| 14 | true) |
| 15 | MEMBER_NUMBER=1 |
| 16 | ;; |
| 17 | false) |
| 18 | MEMBER_NUMBER=4 |
| 19 | ;; |
| 20 | *) |
| 21 | echo "Error: isPrimaryODLCluster not defined in ${OOM_HOME}/oom/kubernetes/sdnc/values.yaml." |
| 22 | exit 1 |
| 23 | ;; |
| 24 | esac |
| 25 | |
| 26 | for pod_number in {0..2} |
| 27 | do |
| 28 | curl "http://localhost:3026$((${pod_number} + 1))" > /dev/null 2>&1 |
| 29 | if [ "$?" = "7" ]; then |
| 30 | continue |
| 31 | fi |
| 32 | |
| 33 | VOTING_RESULT=`curl -u admin:admin -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 2>/dev/null | jq '.value.Voting'` |
| 34 | |
| 35 | case $VOTING_RESULT in |
| 36 | true) |
| 37 | echo "active" |
| 38 | exit 0 |
| 39 | ;; |
| 40 | false) |
| 41 | echo "standby" |
| 42 | exit 0 |
| 43 | ;; |
| 44 | *) |
| 45 | echo "Error: Voting status could not be determined." |
| 46 | exit 1 |
| 47 | ;; |
| 48 | esac |
| 49 | done |
| 50 | |
| 51 | echo "Error: Voting status could not be determined." |
| 52 | exit 1 |