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 2023/01/03 15:28:16 UTC

[GitHub] [airflow] MrGeorgeOwl commented on a diff in pull request #28690: Add deferrable mode to DataFusionStartPipelineOperator

MrGeorgeOwl commented on code in PR #28690:
URL: https://github.com/apache/airflow/pull/28690#discussion_r1060690144


##########
airflow/providers/google/cloud/hooks/datafusion.py:
##########
@@ -469,3 +477,93 @@ def stop_pipeline(self, pipeline_name: str, instance_url: str, namespace: str =
         self._check_response_status_and_data(
             response, f"Stopping a pipeline failed with code {response.status}"
         )
+
+
+class DataFusionAsyncHook(GoogleBaseAsyncHook):
+    """Class to get async hook for Datafusion Async"""
+
+    sync_hook_class = DataFusionHook
+    scopes = ["https://www.googleapis.com/auth/cloud-platform"]
+
+    @staticmethod
+    def _base_url(instance_url: str, namespace: str) -> str:
+        return os.path.join(instance_url, "v3", "namespaces", quote(namespace), "apps")
+
+    async def _get_link(self, url: str, session):
+        async with Token(scopes=self.scopes) as token:
+            session_aio = AioSession(session)
+            headers = {
+                "Authorization": f"Bearer {await token.get()}",
+            }
+            try:
+                pipeline = await session_aio.get(url=url, headers=headers)
+            except AirflowException:
+                pass  # Because the pipeline may not be visible in system yet
+
+        return pipeline
+
+    async def get_pipeline(
+        self,
+        instance_url: str,
+        namespace: str,
+        pipeline_name: str,
+        pipeline_id: str,
+        session,
+    ):
+        base_url_link = self._base_url(instance_url, namespace)
+        url = os.path.join(

Review Comment:
   Same here, check comment about `urljoin`



##########
airflow/providers/google/cloud/hooks/datafusion.py:
##########
@@ -469,3 +477,93 @@ def stop_pipeline(self, pipeline_name: str, instance_url: str, namespace: str =
         self._check_response_status_and_data(
             response, f"Stopping a pipeline failed with code {response.status}"
         )
+
+
+class DataFusionAsyncHook(GoogleBaseAsyncHook):
+    """Class to get async hook for Datafusion Async"""
+
+    sync_hook_class = DataFusionHook
+    scopes = ["https://www.googleapis.com/auth/cloud-platform"]
+
+    @staticmethod
+    def _base_url(instance_url: str, namespace: str) -> str:
+        return os.path.join(instance_url, "v3", "namespaces", quote(namespace), "apps")

Review Comment:
   It is better to use `urllib.parse.urljoin` function instead of os.path.join. Because the second one is used for file path construction



##########
airflow/providers/google/cloud/links/datafusion.py:
##########
@@ -0,0 +1,131 @@
+#
+# 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 Google Compute Engine links."""
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, ClassVar
+
+from airflow.models import BaseOperatorLink, XCom
+
+if TYPE_CHECKING:
+    from airflow.models import BaseOperator
+    from airflow.models.taskinstance import TaskInstanceKey
+    from airflow.utils.context import Context
+
+
+BASE_LINK = "https://console.cloud.google.com/data-fusion"
+DATAFUSION_INSTANCE_LINK = BASE_LINK + "/locations/{region}/instances/{instance_name}?project={project_id}"
+DATAFUSION_PIPELINES_LINK = "{uri}/cdap/ns/default/pipelines"
+DATAFUSION_PIPELINE_LINK = "{uri}/pipelines/ns/default/view/{pipeline_name}"
+
+
+class BaseGoogleLink(BaseOperatorLink):
+    """
+    Override the base logic to prevent adding 'https://console.cloud.google.com'
+    in front of every link where uri is used
+    """
+
+    name: ClassVar[str]
+    key: ClassVar[str]
+    format_str: ClassVar[str]
+
+    def get_link(
+        self,
+        operator: BaseOperator,
+        *,
+        ti_key: TaskInstanceKey,
+    ) -> str:
+        conf = XCom.get_value(key=self.key, ti_key=ti_key)
+        if not conf:
+            return ""
+        if self.format_str.startswith("http"):
+            print("here")

Review Comment:
   Forget to remove `print` statement



-- 
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-unsubscribe@airflow.apache.org

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