#!/bin/bash

################################################################################
# Copyright 2023-2025 by NI SP Software GmbH, All rights reserved.
# Copyright 1999-2023 by Nice, srl., All rights reserved.
#
# This software includes confidential and proprietary information
# of NI SP Software GmbH ("Confidential Information").
# You shall not disclose such Confidential Information
# and shall use it only in accordance with the terms of
# the license agreement you entered into with NI SP Software.
################################################################################
################################################################################

. "${EF_ROOT}/plugins/awsbatch/bin/common"
. "${EF_ROOT}/plugins/awsbatch/bin/aws.utils"

# parse the output of awsbqueues
_ef_awsbqueues_2xml () {
    "${EF_AWK}" \
        -v CLUSTER_ID="${AWSBATCH_CLUSTER_ID}" \
        -v EF_XMLNS_grid="${EF_XMLNS_grid}" \
        -f "${EF_ROOT}/plugins/ef/lib/awk/utils.awk" \
        -f "${EF_ROOT}/plugins/awsbatch/lib/awsbqueues_2xml.awk"
}

_awsbqueues_out="$(call_aws_ef_error awsbqueues --cluster "${AWSBATCH_CLUSTER_ID}" --details 2>&1)"
_exit_code="$?"

if [ "${_exit_code}" != "0" ]; then
    echo "${_awsbqueues_out}"
    exit ${_exit_code}
else
    # print output
    echo "${_awsbqueues_out}" | _ef_awsbqueues_2xml
fi

# vi: ts=4 sw=4 et syntax=sh :
