Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Jakub Latusek | e0e8ca7 | 2020-10-21 13:36:29 +0200 | [diff] [blame] | 2 | {{/* |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 3 | |
| 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 | */}} |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 18 | |
| 19 | # query ODL cluster state |
| 20 | USERNAME="{{.Values.odl.jolokia.username}}" |
| 21 | PASSWORD="{{.Values.odl.jolokia.password}}" |
| 22 | |
| 23 | count=${SDNC_ODL_COUNT:-1} |
| 24 | memberStart=0 |
| 25 | if [ "${SDNC_IS_PRIMARY_CLUSTER:-true}" != "true" ];then |
| 26 | memberStart=$(( $memberStart + $count )) |
| 27 | fi |
| 28 | |
| 29 | for instance in $(seq $count);do |
| 30 | shard=member-$(( $memberStart + $instance ))-shard-default-config |
| 31 | mbean=Category=Shards,name=$shard,type=DistributedConfigDatastore |
Krzysztof Opasiak | 137d7cc | 2020-01-24 23:49:11 +0100 | [diff] [blame] | 32 | url=http://{{ include "common.release" . }}-sdnc-$(( $instance-1 )).sdnc-cluster.{{.Release.Namespace}}:8181/jolokia/read/org.opendaylight.controller:$mbean |
Mohammadreza Pasandideh | b642ee5 | 2018-06-19 15:19:53 -0400 | [diff] [blame] | 33 | |
| 34 | response=$( curl -s -u $USERNAME:$PASSWORD $url ) |
| 35 | rc=$? |
| 36 | if [ $rc -ne 0 ];then |
| 37 | # failed to contact SDN-C instance - try another |
| 38 | continue |
| 39 | fi |
| 40 | status=$( echo -E "$response" | jq -r ".status" ) |
| 41 | if [ "$status" != "200" ];then |
| 42 | # query failed, try another instance |
| 43 | continue |
| 44 | fi |
| 45 | |
| 46 | voting=$( echo -E "$response" | jq -r ".value.Voting" ) |
| 47 | case $voting in |
| 48 | true) |
| 49 | echo "active" |
| 50 | exit 0 |
| 51 | ;; |
| 52 | false) |
| 53 | echo "standby" |
| 54 | exit 0 |
| 55 | ;; |
| 56 | *) |
| 57 | echo "Error: Voting status could not be determined." |
| 58 | exit 1 |
| 59 | ;; |
| 60 | esac |
| 61 | done |
| 62 | echo "Error: Voting status could not be determined." |
| 63 | exit 1 |