Merge "[CONSUL] Add limits to consul chart."
[oom.git] / kubernetes / sdnc / resources / geo / bin / sdnc.cluster
1 #!/bin/bash
2 {{/*
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.
17 */}}
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
25 dir=$( dirname $0 )
26 IS_PRIMARY_CLUSTER=$( $dir/sdnc.isPrimaryCluster )
27
28 case $IS_PRIMARY_CLUSTER in
29 true)
30    MEMBER_NUMBER=1
31    ;;
32 false)
33    MEMBER_NUMBER=4
34    ;;
35 *)
36   echo "Error: isPrimaryCluster not defined in $dir/../../../values.yaml."
37   exit 1
38   ;;
39 esac
40
41 USERNAME=admin
42 PASSWORD=admin
43
44 for pod_number in {0..2}
45 do
46
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`
48
49    if [ $? -ne 0 ]; then
50       continue
51    fi
52
53    status=$( echo -E "$response" | jq -r ".status" )
54    if [ "$status" != "200" ]; then
55       continue
56    fi
57
58    voting=$( echo -E "$response" | jq -r ".value.Voting" )
59    case $voting in
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