import logging


def _get_master_type(configuration):
    """
    Set the master type for lofn to use by reading the SparkConf() dictionary.
    Fallback to standalone if no master is set.

    :param configuration: SparkConf()
    :return: master_type (standalone, yarn)
    """

    master = configuration.get('spark.master')
    if master:
        if 'spark' in master or 'local' in master:
            master_type = 'standalone'
        elif 'yarn' in master:
            master_type = 'yarn'
        else:
            raise ValueError("Not a supported spark master.")
    else:
        logging.warning("No master type set in the spark configuration, "
                        "attempting to run as standalone.")
        master_type = 'standalone'
    return master_type