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/02/28 12:09:25 UTC

[GitHub] gglanzani commented on a change in pull request #4708: [AIRFLOW-3888] HA for metastore connection

gglanzani commented on a change in pull request #4708: [AIRFLOW-3888] HA for metastore connection
URL: https://github.com/apache/airflow/pull/4708#discussion_r261141196
 
 

 ##########
 File path: airflow/hooks/hive_hooks.py
 ##########
 @@ -514,20 +520,37 @@ def get_metastore_client(self):
 
             def sasl_factory():
                 sasl_client = sasl.Client()
-                sasl_client.setAttr("host", ms.host)
+                sasl_client.setAttr("host", valid_conn.host)
                 sasl_client.setAttr("service", kerberos_service_name)
                 sasl_client.init()
                 return sasl_client
 
             from thrift_sasl import TSaslClientTransport
-            transport = TSaslClientTransport(sasl_factory, "GSSAPI", socket)
+            transport = TSaslClientTransport(sasl_factory, "GSSAPI", conn_socket)
         else:
-            transport = TTransport.TBufferedTransport(socket)
+            transport = TTransport.TBufferedTransport(conn_socket)
 
         protocol = TBinaryProtocol.TBinaryProtocol(transport)
 
         return hmsclient.HMSClient(iprot=protocol)
 
+    def _find_valid_server(self):
+        result = 1
+        conns = self.get_connections(self.conn_id)
+        for conn in conns:
+            host_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            self.log.info("Trying to connect to %s:%s", conn.host, conn.port)
+            try:
+                result = host_socket.connect_ex((conn.host, conn.port))
+                host_socket.close()
 
 Review comment:
   We can rewrite the try like this
   ```python
   if host_socket.connect_ex((conn.host, conn.port)) == 0:
       self.log.info("Connected to %s:%s", conn.host, conn.port)
       host_socket.close()
       return conn
   ```
   
   and avoid the `break`, the `results` and `valid_conn` variable, etc.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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