File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/hadoop.cpython-310.pyc
o
�N�g � @ s^ d Z ddlZg d�Zdd� Zdd� Zdd � Zdd
d�Zddd
�Zdd� Z dd� Z
ddd�ZdS )zw
Support for hadoop
:maintainer: Yann Jouanin <yann.jouanin@intelunix.fr>
:maturity: new
:depends:
:platform: linux
� N)�version�namenode�dfsadmin�dfs�fsc C s$ t jj�d�st jj�d�rdS dS )z:
Check if hadoop is present, then load the module
�hadoop�hdfs)FzPThe hadoop execution module cannot be loaded: hadoop or hdfs binary not in path.)�salt�utils�path�which� r
r
�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/hadoop.py�__virtual__ s r c G sj d}t jj�d�rd}d}| r3|r3| tv r1|| |d�|�d�}djdi |��}td |dd �}|S d
S dS )
aU
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 /
r r N� )�tool�module�command�argsz!{tool} {module} -{command} {args}zcmd.runF)Zpython_shellzError: Unknown modulez%Error: Module and command not definedr
)r r
r r �__authorized_modules__�join�formatZ__salt__)r r r r �outZmappings�cmdr
r
r �_hadoop_cmd s
��r c C s d} t | d��� }|d S )zy
Return version from hadoop version
CLI Example:
.. code-block:: bash
salt '*' hadoop.version
r T� )r �split)r r r
r
r r A s
r c G s | rt d| g|�R � S dS )zp
Execute a command on DFS
CLI Example:
.. code-block:: bash
salt '*' hadoop.dfs ls /
r zError: command must be provided�r )r r r
r
r r P s
r c C s, | dur| dv rt dd| �S dS t dd�S )a+
.. versionadded:: 2019.2.0
Reports basic filesystem information and statistics. Optional flags may be used to filter the list of displayed DataNodes.
arg
[live] [dead] [decommissioning]
CLI Example:
.. code-block:: bash
salt '*' hadoop.dfsadmin -report
N)ZliveZdeadZdecommissioningr �reportzJError: the arg is wrong, it must be in ['live', 'dead', 'decommissioning']r )�argr
r
r �dfsadmin_report` s �
r c C � t dd| �}d}||v rdS dS )z�
Check if a file or directory is present on the distributed FS.
CLI Example:
.. code-block:: bash
salt '*' hadoop.dfs_present /some_random_file
Returns True if the file is present
r �stat�No such file or directoryFTr �r Z
cmd_return�matchr
r
r �dfs_present{ � r&