airflow.providers.apache.livy.hooks.livy

This module contains the Apache Livy hook.

Module Contents

class airflow.providers.apache.livy.hooks.livy.BatchState[source]

Bases: enum.Enum

Batch session states

NOT_STARTED = not_started[source]
STARTING = starting[source]
RUNNING = running[source]
IDLE = idle[source]
BUSY = busy[source]
SHUTTING_DOWN = shutting_down[source]
ERROR = error[source]
DEAD = dead[source]
KILLED = killed[source]
SUCCESS = success[source]
class airflow.providers.apache.livy.hooks.livy.LivyHook(livy_conn_id: str = default_conn_name, extra_options: Optional[Dict[str, Any]] = None, extra_headers: Optional[Dict[str, Any]] = None)[source]

Bases: airflow.providers.http.hooks.http.HttpHook, airflow.utils.log.logging_mixin.LoggingMixin

Hook for Apache Livy through the REST API.

Parameters
  • livy_conn_id (str) -- reference to a pre-defined Livy Connection.

  • extra_options (Dict[str, Any]) -- A dictionary of options passed to Livy.

  • extra_headers (Dict[str, Any]) -- A dictionary of headers passed to the HTTP request to livy.

See also

For more details refer to the Apache Livy API reference: https://livy.apache.org/docs/latest/rest-api.html

TERMINAL_STATES[source]
conn_name_attr = livy_conn_id[source]
default_conn_name = livy_default[source]
conn_type = livy[source]
hook_name = Apache Livy[source]
get_conn(self, headers: Optional[Dict[str, Any]] = None)[source]

Returns http session for use with requests

Parameters

headers (dict) -- additional headers to be passed through as a dictionary

Returns

requests session

Return type

requests.Session

run_method(self, endpoint: str, method: str = 'GET', data: Optional[Any] = None, headers: Optional[Dict[str, Any]] = None)[source]

Wrapper for HttpHook, allows to change method on the same HttpHook

Parameters
  • method (str) -- http method

  • endpoint (str) -- endpoint

  • data (dict) -- request payload

  • headers (dict) -- headers

Returns

http response

Return type

requests.Response

post_batch(self, *args, **kwargs)[source]

Perform request to submit batch

Returns

batch session id

Return type

int

get_batch(self, session_id: Union[int, str])[source]

Fetch info about the specified batch

Parameters

session_id (int) -- identifier of the batch sessions

Returns

response body

Return type

dict

get_batch_state(self, session_id: Union[int, str])[source]

Fetch the state of the specified batch

Parameters

session_id (Union[int, str]) -- identifier of the batch sessions

Returns

batch state

Return type

BatchState

delete_batch(self, session_id: Union[int, str])[source]

Delete the specified batch

Parameters

session_id (int) -- identifier of the batch sessions

Returns

response body

Return type

dict

static build_post_batch_body(file: str, args: Optional[Sequence[Union[str, int, float]]] = None, class_name: Optional[str] = None, jars: Optional[List[str]] = None, py_files: Optional[List[str]] = None, files: Optional[List[str]] = None, archives: Optional[List[str]] = None, name: Optional[str] = None, driver_memory: Optional[str] = None, driver_cores: Optional[Union[int, str]] = None, executor_memory: Optional[str] = None, executor_cores: Optional[int] = None, num_executors: Optional[Union[int, str]] = None, queue: Optional[str] = None, proxy_user: Optional[str] = None, conf: Optional[Dict[Any, Any]] = None)[source]

Build the post batch request body. For more information about the format refer to .. seealso:: https://livy.apache.org/docs/latest/rest-api.html :param file: Path of the file containing the application to execute (required). :type file: str :param proxy_user: User to impersonate when running the job. :type proxy_user: str :param class_name: Application Java/Spark main class string. :type class_name: str :param args: Command line arguments for the application s. :type args: Sequence[Union[str, int, float]] :param jars: jars to be used in this sessions. :type jars: Sequence[str] :param py_files: Python files to be used in this session. :type py_files: Sequence[str] :param files: files to be used in this session. :type files: Sequence[str] :param driver_memory: Amount of memory to use for the driver process string. :type driver_memory: str :param driver_cores: Number of cores to use for the driver process int. :type driver_cores: Union[str, int] :param executor_memory: Amount of memory to use per executor process string. :type executor_memory: str :param executor_cores: Number of cores to use for each executor int. :type executor_cores: Union[int, str] :param num_executors: Number of executors to launch for this session int. :type num_executors: Union[str, int] :param archives: Archives to be used in this session. :type archives: Sequence[str] :param queue: The name of the YARN queue to which submitted string. :type queue: str :param name: The name of this session string. :type name: str :param conf: Spark configuration properties. :type conf: dict :return: request body :rtype: dict

Was this entry helpful?