blob: ed7aefc0cf5307416f135452aec83b5462e230e0 [file] [log] [blame]
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04001#!/bin/sh
Jakub Latusekd4e96f42020-10-21 13:36:29 +02002{{/*
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04003
4# Copyright © 2018 Amdocs
Mukul2b4e7532018-08-03 10:41:29 +00005# Modifications Copyright © 2018 AT&T
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -04006#
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.
Jakub Latusekd4e96f42020-10-21 13:36:29 +020018*/}}
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040019
20# query ODL cluster state
21USERNAME="{{.Values.odl.jolokia.username}}"
22PASSWORD="{{.Values.odl.jolokia.password}}"
23
24count=${SDNC_ODL_COUNT:-1}
25siteId=0
26if [ "$SDNC_IS_PRIMARY_CLUSTER" = "false" ];then
27 siteId=1
28fi
29
30for instance in $(seq $count);do
31 shard=member-$(( $siteId*$count + $instance ))-shard-default-config
32 mbean=Category=Shards,name=$shard,type=DistributedConfigDatastore
Krzysztof Opasiak137d7cc2020-01-24 23:49:11 +010033 url=http://{{ include "common.release" . }}-sdnc-$(( $instance-1 )).sdnc-cluster.{{.Release.Namespace}}:8181/jolokia/read/org.opendaylight.controller:$mbean
Mohammadreza Pasandidehb642ee52018-06-19 15:19:53 -040034
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
58done
59
60# ODL cluster is not healthy
61exit 2