Skip to content

Commit 92637a8

Browse files
committed
shfmt
1 parent dc8aba2 commit 92637a8

File tree

1 file changed

+34
-72
lines changed

1 file changed

+34
-72
lines changed

pipeline/test/services/service-cluster/testOpensearch.sh

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -95,87 +95,49 @@ check_opensearch_cluster_health() {
9595
}
9696

9797
check_opensearch_snapshots_status() {
98-
echo -ne "Checking opensearch snapshots status ... "
99-
no_error=true
100-
debug_msg=""
101-
repo_name=$(yq4 -e '.opensearch.snapshot.repository' "${config['config_file_sc']}")
102-
repo_exists_status=$(curl -sk -u admin:"${adminPassword}" -X GET "https://opensearch.${opsDomain}/_snapshot/${repo_name}" | jq "select(.error)")
103-
if [[ -z "$repo_exists_status" ]]; then
104-
snapshots=$(curl -sk -u admin:"${adminPassword}" -X GET "https://opensearch.${opsDomain}/_cat/snapshots/${repo_name}")
105-
error=$(echo "$snapshots" | jq '.error' 2>/dev/null || true)
106-
failed=$(echo "$snapshots" | grep 'FAILED' || true)
107-
partial=$(echo "$snapshots" | grep 'PARTIAL' || true)
108-
109-
if [[ "$error" != "" ]] && [[ "$error" != "null" ]]; then
110-
no_error=false
111-
debug_msg+="[ERROR] Error in snapshots output: \n $error\n"
112-
else
113-
if [[ "$failed" != "" ]]; then
114-
no_error=false
115-
debug_msg+="[ERROR] We found some failed snapshots: \n $failed\n"
116-
fi
117-
118-
if [[ "$partial" != "" ]]; then
119-
no_error=false
120-
debug_msg+="[WARNING] We found some partial snapshots: \n $partial\n"
121-
fi
122-
123-
IFS=$'\n' readarray -t data < <(awk '{ print $1 " " $2 " " $3}' <<<"$snapshots")
124-
IFS=" " read -ra last_snapshot <<<"${data[-1]}"
125-
126-
127-
if [[ "${#last_snapshot[@]}" -gt 0 ]]; then
128-
now_epoch=$(date +%s)
129-
last_snapshot_epoch=${last_snapshot[2]}
130-
((diff = now_epoch - last_snapshot_epoch))
131-
132-
if [[ $diff -gt 86400 ]]; then
133-
no_error=false
134-
debug_msg+="[ERROR] The latest snapshot has not been created within the past 24 hours, with status: ${last_snapshot[1]}\n"
135-
else
136-
debug_msg+="[WARNING] The latest snapshot has been created within the past 24 hours, with status: ${last_snapshot[1]}\n"
137-
fi
138-
else
139-
no_error=false
140-
debug_msg+="[ERROR] No snapshots found, if this is a brand new cluster this can safely be ignored\n"
141-
fi
142-
fi
98+
echo -ne "Checking opensearch snapshots status ... "
99+
no_error=true
100+
debug_msg=""
101+
repo_name=$(yq4 -e '.opensearch.snapshot.repository' "${config['config_file_sc']}")
102+
repo_exists_status=$(curl -sk -u admin:"${adminPassword}" -X GET "https://opensearch.${opsDomain}/_snapshot/${repo_name}" | jq "select(.error)")
103+
if [[ -z "$repo_exists_status" ]]; then
104+
snapshots=$(curl -sk -u admin:"${adminPassword}" -X GET "https://opensearch.${opsDomain}/_cat/snapshots/${repo_name}")
105+
error=$(echo "$snapshots" | jq '.error' 2>/dev/null || true)
106+
failed=$(echo "$snapshots" | grep 'FAILED' || true)
107+
partial=$(echo "$snapshots" | grep 'PARTIAL' || true)
108+
109+
if [[ "$error" != "" ]] && [[ "$error" != "null" ]]; then
110+
no_error=false
111+
debug_msg+="[ERROR] Error in snapshots output: \n $error\n"
143112
else
113+
if [[ "$failed" != "" ]]; then
144114
no_error=false
145-
debug_msg+="[ERROR] Error in snapshots output: \n $error\n"
146-
else
147-
if [[ "$failed" != "" ]]; then
148-
no_error=false
149-
debug_msg+="[ERROR] We found some failed snapshots: \n $failed\n"
150-
fi
115+
debug_msg+="[ERROR] We found some failed snapshots: \n $failed\n"
116+
fi
151117

152-
if [[ "$partial" != "" ]]; then
153-
no_error=false
154-
debug_msg+="[WARNING] We found some partial snapshots: \n $partial\n"
155-
fi
118+
if [[ "$partial" != "" ]]; then
119+
no_error=false
120+
debug_msg+="[WARNING] We found some partial snapshots: \n $partial\n"
121+
fi
156122

157-
IFS=$'\n' readarray -t data < <(awk '{ print $1 " " $2 " " $3}' <<<"$snapshots")
158-
IFS=" " read -ra last_snapshot <<<"${data[-1]}"
123+
IFS=$'\n' readarray -t data < <(awk '{ print $1 " " $2 " " $3}' <<<"$snapshots")
124+
IFS=" " read -ra last_snapshot <<<"${data[-1]}"
159125

160-
if [[ "${#last_snapshot[@]}" -gt 0 ]]; then
161-
now_epoch=$(date +%s)
162-
last_snapshot_epoch=${last_snapshot[2]}
163-
((diff = now_epoch - last_snapshot_epoch))
126+
if [[ "${#last_snapshot[@]}" -gt 0 ]]; then
127+
now_epoch=$(date +%s)
128+
last_snapshot_epoch=${last_snapshot[2]}
129+
((diff = now_epoch - last_snapshot_epoch))
164130

165-
if [[ $diff -gt 86400 ]]; then
166-
no_error=false
167-
debug_msg+="[ERROR] The latest snapshot has not been created within the past 24 hours, with status: ${last_snapshot[1]}\n"
168-
else
169-
debug_msg+="[WARNING] The latest snapshot has been created within the past 24 hours, with status: ${last_snapshot[1]}\n"
170-
fi
171-
else
131+
if [[ $diff -gt 86400 ]]; then
172132
no_error=false
173-
debug_msg+="[ERROR] No snapshots found, if this is a brand new cluster this can safely be ignored\n"
133+
debug_msg+="[ERROR] The latest snapshot has not been created within the past 24 hours, with status: ${last_snapshot[1]}\n"
134+
else
135+
debug_msg+="[WARNING] The latest snapshot has been created within the past 24 hours, with status: ${last_snapshot[1]}\n"
174136
fi
137+
else
138+
no_error=false
139+
debug_msg+="[ERROR] No snapshots found, if this is a brand new cluster this can safely be ignored\n"
175140
fi
176-
else
177-
no_error=false
178-
debug_msg+="[ERROR] opensearch-backup cronjob doesn't exist\n"
179141
fi
180142
else
181143
no_error=false

0 commit comments

Comments
 (0)