airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [airflow] lucacavazzana commented on a change in pull request #6090: [AIRFLOW-5470] Add Apache Livy REST operator
Date Wed, 09 Oct 2019 14:50:35 GMT
lucacavazzana commented on a change in pull request #6090: [AIRFLOW-5470] Add Apache Livy REST
operator
URL: https://github.com/apache/airflow/pull/6090#discussion_r333059474
 
 

 ##########
 File path: airflow/contrib/hooks/livy_hook.py
 ##########
 @@ -0,0 +1,297 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+This module contains the Apache Livy hook.
+"""
+
+import re
+from enum import Enum
+import json
+import requests
+
+from airflow.exceptions import AirflowException
+from airflow.hooks.base_hook import BaseHook
+from airflow.utils.log.logging_mixin import LoggingMixin
+
+
+class BatchState(Enum):
+    """
+    Batch session states
+    """
+    NOT_STARTED = 'not_started'
+    STARTING = 'starting'
+    RUNNING = 'running'
+    IDLE = 'idle'
+    BUSY = 'busy'
+    SHUTTING_DOWN = 'shutting_down'
+    ERROR = 'error'
+    DEAD = 'dead'
+    KILLED = 'killed'
+    SUCCESS = 'success'
+
+
+TERMINAL_STATES = {
+    BatchState.SUCCESS,
+    BatchState.DEAD,
+    BatchState.KILLED,
+    BatchState.ERROR,
+}
+
+
+class LivyHook(BaseHook, LoggingMixin):
+    """
+    Hook for Apache Livy through the REST API.
+
+    For more information about the API refer to
+    https://livy.apache.org/docs/latest/rest-api.html
+
+    :param livy_conn_id: reference to a pre-defined Livy Connection.
+    :type livy_conn_id: str
+    """
+    def __init__(self, livy_conn_id='livy_default'):
+        super(LivyHook, self).__init__(livy_conn_id)
+        self._livy_conn_id = livy_conn_id
+        self._build_base_url()
+
+    def _build_base_url(self):
+        """
+        Build connection URL
+        """
+        params = self.get_connection(self._livy_conn_id)
+
+        base_url = params.host
+
+        if not base_url:
+            raise AirflowException("Missing Livy endpoint hostname")
+
+        if '://' not in base_url:
+            base_url = '{}://{}'.format('http', base_url)
+        if not re.search(r':\d+$', base_url):
+            base_url = '{}:{}'.format(base_url, str(params.port or 8998))
+
+        self._base_url = base_url
+
+    def get_conn(self):
+        pass
+
+    def post_batch(self, *args, **kwargs):
+        """
+        Perform request to submit batch
+        """
+
+        batch_submit_body = json.dumps(LivyHook.build_post_batch_body(*args, **kwargs))
+        headers = {'Content-Type': 'application/json'}
 
 Review comment:
   the value of the header must be configurable.
   Since after the update it will inherit from HttpHook it will be configurable through the
_Extra_ argument in the connection

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message