wojsamjan commented on a change in pull request #18945:
URL: https://github.com/apache/airflow/pull/18945#discussion_r728882220



##########
File path: airflow/providers/google/cloud/hooks/dataproc_metastore.py
##########
@@ -0,0 +1,673 @@
+#
+# 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 a Google Cloud Dataproc Metastore hook."""
+
+from time import sleep
+from typing import Dict, Optional, Sequence, Tuple, Union
+
+from google.api_core.operation import Operation
+from google.api_core.retry import Retry, exponential_sleep_generator
+from google.cloud.metastore_v1 import DataprocMetastoreClient
+from google.cloud.metastore_v1.types import Backup, MetadataImport, Service
+from google.cloud.metastore_v1.types.metastore import DatabaseDumpSpec, Restore
+from google.protobuf.field_mask_pb2 import FieldMask
+
+from airflow.exceptions import AirflowException
+from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
+
+
+class DataprocMetastoreHook(GoogleBaseHook):
+    """Hook for Google Cloud Dataproc Metastore APIs."""
+
+    def get_dataproc_metastore_client(self, region: Optional[str] = None) -> 
DataprocMetastoreClient:
+        """Returns DataprocMetastoreClient."""
+        client_options = None
+        if region and region != 'global':
+            client_options = {'api_endpoint': 
f'{region}-metastore.googleapis.com:443'}
+
+        return DataprocMetastoreClient(
+            credentials=self._get_credentials(), client_info=self.client_info, 
client_options=client_options
+        )
+
+    def wait_for_operation(self, operation: Operation):
+        """Waits for long-lasting operation to complete."""
+        for time_to_wait in exponential_sleep_generator(initial=10, 
maximum=120):
+            sleep(time_to_wait)
+            if operation.done():
+                break

Review comment:
       @mik-laj  As I understand after the change I will have to pass timeout 
every time to the Hook´s wait_for_operation so both 
https://github.com/googleapis/python-api-core/blob/main/google/api_core/future/polling.py#L116
 & 
https://github.com/googleapis/python-api-core/blob/main/google/api_core/future/polling.py#L141
 could call 
https://github.com/googleapis/python-api-core/blob/main/google/api_core/future/polling.py#L106
 with timeout passed for Retry´s deadline, right?




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

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to