#!/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.
################################################################################
################################################################################
################################################################################

#-------------------------------------------------------------------------------
# Load common EnginFrame functions and environment
#-------------------------------------------------------------------------------

. "${EF_ROOT}/plugins/ef/lib/functions"

ef_init_environment "$@"

#-------------------------------------------------------------------------------
# Load common SLURM Plugin functions
#-------------------------------------------------------------------------------

. "${EF_ROOT}/plugins/slurm/bin/functions.lib.sh"

#-------------------------------------------------------------------------------
# Load SLURM Plug-in configuration
#-------------------------------------------------------------------------------

ef_source_conf slurm "ef.slurm.conf"
if [ -d "${SLURM_BINDIR}" ] ; then
   PATH="${SLURM_BINDIR}:${PATH}"
fi

# For backward compatibility, if SLURM_CLUSTER_IDS is not set it will default to ","
# in order to list just one default cluster (default cluster is the cluster without id, with legacy settings)
SLURM_CLUSTER_IDS="${SLURM_CLUSTER_IDS:-,}"

which scontrol >/dev/null 2>&1
if [ $? -ne 0 ] ; then
    ef_error_and_exit 1 "scontrol not found" \
                        "SLURM binary directory is missing"; return
fi

#-------------------------------------------------------------------------------
# Check SLURM is up and store cluster name
#-------------------------------------------------------------------------------
if [ -z "${SLURM_JOB_FORMAT}" ]; then
   ef_error_and_exit 1 "Missing SLURM_JOB_FORMAT configuration parameter" \
                       "EnginFrame SLURM Plugin Error"; return
fi
export SLURM_JOB_FORMAT

# Be sure efadmin is able to collect information of all users jobs
unset SQUEUE_USERS

# ex:ts=4:sw=4:et:ft=sh:
