#!/bin/bash
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/utils"
assert_resources_exist(){

	# verify DS
	os::cmd::try_until_success "oc -n $LOGGING_NS get ds collector" ${TIMEOUT_MIN}

	# verify ER
	os::cmd::try_until_success "oc -n $LOGGING_NS get elasticsearch elasticsearch" ${TIMEOUT_MIN}

}

assert_kibana_instance_exists() {
	# verify kibana crd
	os::cmd::try_until_success "oc -n $LOGGING_NS get kibana kibana" ${TIMEOUT_MIN}
}

assert_resources_does_not_exist(){
	os::cmd::try_until_failure "oc -n $LOGGING_NS get cronjob curator"
	os::cmd::try_until_failure "oc -n $LOGGING_NS get ds collector"
	os::cmd::try_until_failure "oc -n $LOGGING_NS get elasticsearch elasticsearch"

}

assert_kibana_instance_does_not_exists() {
	os::cmd::try_until_failure "oc -n $LOGGING_NS get kibana kibana"
}

# assert_cl_clf_instance_does_not_exist checking is
# 'oc -n $LOGGING_NS get clusterlogging instance' and 'oc -n $LOGGING_NS get clusterlogforwarder instance'
# both will failure or or times out (60 sec)
# Returns:
#  - 0: success - resources was deleted in given timeout
#  - !0 if clusterlogforwarder or clusterlogging instance still exist after 60 sec
assert_cl_clf_instance_does_not_exist(){
  os::cmd::try_until_failure "oc -n $LOGGING_NS get clusterlogging instance" "$((5 * $minute))"
  local cl_return_code=$?
  os::cmd::try_until_failure "oc -n $LOGGING_NS get clusterlogforwarder instance" "$((5 * $minute))"
  local clf_return_code=$?
  ret_code=0
  if [ ${cl_return_code} -gt 0 ]; then
    os::log::warning "waiting for deleting clusterlogging instance"
    ret_code=${cl_return_code}
  fi
  if [ ${clf_return_code} -gt 0 ]; then
    os::log::warning "waiting for deleting clusterlogforwarder instance"
    ret_code=${clf_return_code}
  fi
  return ${ret_code}
}
