Hadoop/hdfs command wrapper

       As Hadoop command has been deprecated this module will default
       to use hdfs command and fall back to hadoop if it is not found

       In order to prevent random execution the module name is checked

       Follows hadoop command template:
          hadoop module -command args
       E.g.: hadoop dfs -ls /

def _hadoop_cmd(module, command, *args):
    '''
       Hadoop/hdfs command wrapper

       As Hadoop command has been deprecated this module will default
       to use hdfs command and fall back to hadoop if it is not found

       In order to prevent random execution the module name is checked

       Follows hadoop command template:
          hadoop module -command args
       E.g.: hadoop dfs -ls /
    '''
    tool = 'hadoop'
    if salt.utils.path.which('hdfs'):
        tool = 'hdfs'

    out = None
    if module and command:
        if module in __authorized_modules__:
            mappings = {'tool': tool, 'module': module, 'command': command, 'args': ' '.join(args)}
            cmd = '{tool} {module} -{command} {args}'.format(**mappings)
            out = __salt__['cmd.run'](cmd, python_shell=False)
        else:
            return 'Error: Unknown module'
    else:
        return 'Error: Module and command not defined'
    return out