blpham commented on code in PR #32846: URL: https://github.com/apache/airflow/pull/32846#discussion_r1286436172
########## tests/system/providers/google/cloud/datapipelines/google-datapipeline.py: ########## @@ -0,0 +1,52 @@ +# +# 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. + +""" +Example Airflow DAG for testing Google DataPipelines Create Data Pipeline Operator. +""" +from __future__ import annotations + +import os +from datetime import datetime + +from airflow import models +from airflow.providers.apache.beam.hooks.beam import BeamRunnerType +from airflow.providers.google.cloud.operators.datapipeline import CreateDataPipelineOperator, RunDataPipelineOperator +from airflow.providers.google.cloud.operators.gcs import GCSCreateBucketOperator, GCSDeleteBucketOperator +from airflow.providers.google.cloud.transfers.gcs_to_local import GCSToLocalFilesystemOperator +from airflow.utils.trigger_rule import TriggerRule + +DAG_ID = "google-datapipeline" +DATA_PIPELINE_NAME = os.environ.get("DATA_PIPELINE_NAME", "example-datapipeline") +GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "example-project") Review Comment: Fixed; changed to "SYSTEM_TESTS_GCP_PROJECT" ########## 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: Done -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
