#!/usr/bin/bash
#############################################################################
#  Copyright (C) 2013-2015 Lawrence Livermore National Security, LLC.
#  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
#  Written by Albert Chu <chu11@llnl.gov>
#  LLNL-CODE-644248
#
#  This file is part of Magpie, scripts for running Hadoop on
#  traditional HPC systems.  For details, see https://github.com/llnl/magpie.
#
#  Magpie is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  Magpie is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with Magpie.  If not, see <http://www.gnu.org/licenses/>.
#############################################################################

# This is used by scripts, don't edit this
#
# This file has common hadoop checks, does not assume anything setup yet

source ${MAGPIE_SCRIPTS_HOME}/magpie/lib/magpie-lib-log

Magpie_hadoop_setup_type_enables_yarn () {
    if [ "${HADOOP_SETUP_TYPE}" == "MR" ] \
        || [ "${HADOOP_SETUP_TYPE}" == "YARN" ]
    then
        return 0
    fi
    return 1
}

Magpie_hadoop_setup_type_enables_hdfs () {
    if [ "${HADOOP_SETUP_TYPE}" == "MR" ] \
        || [ "${HADOOP_SETUP_TYPE}" == "HDFS" ]
    then
        return 0
    fi
    return 1
}

Magpie_hadoop_filesystem_mode_is_hdfs_type () {
    if [ "${HADOOP_FILESYSTEM_MODE}" == "hdfs" ] \
        || [ "${HADOOP_FILESYSTEM_MODE}" == "hdfsoverlustre" ] \
        || [ "${HADOOP_FILESYSTEM_MODE}" == "hdfsovernetworkfs" ]
    then
        return 0
    fi
    return 1
}

Magpie_hadoop_filesystem_mode_is_hdfs_on_network_type () {
    if [ "${HADOOP_FILESYSTEM_MODE}" == "hdfsoverlustre" ] \
        || [ "${HADOOP_FILESYSTEM_MODE}" == "hdfsovernetworkfs" ]
    then
        return 0
    fi
    return 1
}

Magpie_get_networkedhdfspath () {
    if [ "$HADOOP_FILESYSTEM_MODE" == "hdfsoverlustre" ]
    then
        magpie_networkedhdfspath=${HADOOP_HDFSOVERLUSTRE_PATH}
    elif [ "$HADOOP_FILESYSTEM_MODE" == "hdfsovernetworkfs" ]
    then
        magpie_networkedhdfspath=${HADOOP_HDFSOVERNETWORKFS_PATH}
    else
        Magpie_output_internal_error "Magpie_get_networkedhdfspath called without HDFS networked path set used"
    fi

    if [ "${MAGPIE_ONE_TIME_RUN}" == "yes" ]
    then
        magpie_networkedhdfspath="$magpie_networkedhdfspath/${MAGPIE_JOB_NAME}/${MAGPIE_JOB_ID}"
    fi
}

Magpie_get_hdfs_stored_version_path () {
    Magpie_get_networkedhdfspath
    magpie_hdfs_stored_version_path=${magpie_networkedhdfspath}/magpie.hadoop-version
}

Magpie_get_hdfs_stored_nodecount_path () {
    Magpie_get_networkedhdfspath
    magpie_hdfs_stored_nodecount_path=${magpie_networkedhdfspath}/magpie.node-count
}

Magpie_get_hdfs_in_use_path () {
    Magpie_get_networkedhdfspath
    magpie_hdfs_in_use_path=${magpie_networkedhdfspath}/magpie.hdfs_in_use
}
