You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/10/02 16:18:18 UTC

[GitHub] [airflow] Tagar commented on a change in pull request #6090: [AIRFLOW-5470] Add Apache Livy REST operator

Tagar commented on a change in pull request #6090: [AIRFLOW-5470] Add Apache Livy REST operator
URL: https://github.com/apache/airflow/pull/6090#discussion_r330639113
 
 

 ##########
 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)
 
 Review comment:
   We use http**s**-backed Livy instance. 
   Would be great to make https/http schema configurable 

----------------------------------------------------------------
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