Merge "[UUI] Service Mesh Compliance for UUI"
[oom.git] / kubernetes / consul / resources / config / consul-agent-config / scripts / sdnc-cluster-health.sh
1 #!/bin/sh
2 {{/*
3
4 # Copyright © 2018 Amdocs
5 # Modifications Copyright © 2018 AT&T
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #       http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 */}}
19
20 # query ODL cluster state
21 USERNAME="{{.Values.odl.jolokia.username}}"
22 PASSWORD="{{.Values.odl.jolokia.password}}"
23
24 count=${SDNC_ODL_COUNT:-1}
25 siteId=0
26 if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then
27   siteId=1
28 fi
29
30 for instance in $(seq $count);do
31   shard=member-$(( $siteId*$count + $instance ))-shard-default-config
32   mbean=Category=Shards,name=$shard,type=DistributedConfigDatastore
33   url=http://{{ include "common.release" . }}-sdnc-$(( $instance-1 )).sdnc-cluster.{{.Release.Namespace}}:8181/jolokia/read/org.opendaylight.controller:$mbean
34
35   response=$( curl -s -u $USERNAME:$PASSWORD $url )
36   rc=$?
37   if [ $rc -ne 0 ];then
38     # failed to contact SDN-C instance - try another
39     echo "Unable to connect to $shard [rc=$?]"
40     continue
41   fi
42
43   status=$( echo "$response" | jq -r ".status" )
44   if [ "$status" != "200" ];then
45     # query failed, try another instance
46     echo "$shard query failed [http-status=$status]"
47     continue
48   fi
49
50   raftState=$( echo "$response" | jq -r ".value.RaftState" )
51   if [ "$raftState" = "Leader" -o "$raftState" = "Follower" ];then
52     # cluster has a leader and is healthy
53     echo "$shard is healthy [RaftState=$raftState]"
54     exit 0
55   else
56     echo "$shard is not healthy [RaftState=$raftState]"
57   fi
58 done
59
60 # ODL cluster is not healthy
61 exit 2