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