You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ahidalgob (via GitHub)" <gi...@apache.org> on 2023/08/07 18:10:39 UTC

[GitHub] [airflow] ahidalgob commented on a diff in pull request #32846: Adding Support for Google Cloud's Data Pipelines Run Operator

ahidalgob commented on code in PR #32846:
URL: https://github.com/apache/airflow/pull/32846#discussion_r1286230528


##########
airflow/providers/google/cloud/hooks/datapipeline.py:
##########
@@ -0,0 +1,87 @@
+#
+# 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 Data Pipelines Hook."""
+from __future__ import annotations
+
+from googleapiclient.discovery import build
+
+from airflow.providers.google.common.hooks.base_google import (
+    GoogleBaseHook,
+)
+
+DEFAULT_DATAPIPELINE_LOCATION = "us-central1"
+
+
+class DataPipelineHook(GoogleBaseHook):
+    """
+    Hook for Google Data Pipelines.
+    All the methods in the hook where project_id is used must be called with
+    keyword arguments rather than positional.
+    """
+
+    def __init__(
+        self,
+        gcp_conn_id: str = "google_cloud_default",
+        impersonation_chain: str | Sequence[str] | None = None,
+        **kwargs,
+    ) -> None:
+        super().__init__(
+            gcp_conn_id=gcp_conn_id,
+            impersonation_chain=impersonation_chain,
+        )
+
+    def get_conn(self) -> build:
+        """Returns a Google Cloud Data Pipelines service object."""
+        http_authorized = self._authorize()
+        return build("datapipelines", "v1", http=http_authorized, cache_discovery=False)
+
+    @staticmethod
+    def build_parent_name(project_id: str, location: str):
+        return f"projects/{project_id}/locations/{location}"
+
+    @GoogleBaseHook.fallback_to_default_project_id
+    def run_data_pipeline(
+        self,
+        data_pipeline_name: str,
+        project_id: str,
+        location: str = DEFAULT_DATAPIPELINE_LOCATION,
+    ) -> None:
+        """
+        Runs a Data Pipelines Instance using the Data Pipelines API.
+
+        :param data_pipeline_name:  The display name of the pipeline. In example
+            projects/PROJECT_ID/locations/LOCATION_ID/pipelines/PIPELINE_ID it would be the PIPELINE_ID.
+        :param project_id: The ID of the GCP project that owns the job.
+        :param location: The location of the Data Pipelines instance to (example_dags uses uscentral-1).
+
+        Returns the created Job in JSON representation.
+        """
+        parent = self.build_parent_name(project_id, location)
+        service = self.get_conn()
+        self.log.info(dir(service.projects().locations()))

Review Comment:
   I guess this was a debuging log? Please remove



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