blob: d328d04241690f91e552844520f0c024e1e2367d [file] [log] [blame]
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04001#!/bin/sh
2
3# Copyright © 2018 Amdocs
Mukul2b4e7532018-08-03 10:41:29 +00004# Modifications Copyright © 2018 AT&T
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04005#
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# query ODL cluster state
19USERNAME="{{.Values.odl.jolokia.username}}"
20PASSWORD="{{.Values.odl.jolokia.password}}"
21
22count=${SDNC_ODL_COUNT:-1}
23siteId=0
24if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then
25 siteId=1
26fi
27
28for instance in $(seq $count);do
29 shard=member-$(( $siteId*$count + $instance ))-shard-default-config
30 mbean=Category=Shards,name=$shard,type=DistributedConfigDatastore
31 url=http://{{.Release.Name}}-sdnc-$(( $instance-1 )).sdnc-cluster.{{.Release.Namespace}}:8181/jolokia/read/org.opendaylight.controller:$mbean
32
33 response=$( curl -s -u $USERNAME:$PASSWORD $url )
34 rc=$?
35 if [ $rc -ne 0 ];then
36 # failed to contact SDN-C instance - try another
37 echo "Unable to connect to $shard [rc=$?]"
38 continue
39 fi
40
41 status=$( echo "$response" | jq -r ".status" )
42 if [ "$status" != "200" ];then
43 # query failed, try another instance
44 echo "$shard query failed [http-status=$status]"
45 continue
46 fi
47
48 raftState=$( echo "$response" | jq -r ".value.RaftState" )
49 if [ "$raftState" = "Leader" -o "$raftState" = "Follower" ];then
50 # cluster has a leader and is healthy
51 echo "$shard is healthy [RaftState=$raftState]"
52 exit 0
53 else
54 echo "$shard is not healthy [RaftState=$raftState]"
55 fi
56done
57
58# ODL cluster is not healthy
59exit 2