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 2022/03/06 07:12:04 UTC

[GitHub] [airflow] abhinavraj23 opened a new pull request #22022: feat: add an operator to run a transfer job

abhinavraj23 opened a new pull request #22022:
URL: https://github.com/apache/airflow/pull/22022


   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   Add an operator in google storage transfer service  to directly run a pre-configured transfer job. The storage transfer service provides the API for this use case, here the [link](https://cloud.google.com/storage-transfer/docs/reference/rest/v1/transferJobs/run) to the API. Corresponding to this API the `cloud_transfer_service` hook has been changed and an operator has been added.
   
   closes: #22019 
   
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/main/UPDATING.md).
   


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



[GitHub] [airflow] boring-cyborg[bot] commented on pull request #22022: feat: add an operator to run a transfer job

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #22022:
URL: https://github.com/apache/airflow/pull/22022#issuecomment-1059909167


   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (flake8, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, itโ€™s a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
   Apache Airflow is a community-driven project and together we are making it better ๐Ÿš€.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


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



[GitHub] [airflow] potiuk commented on pull request #22022: feat: add an operator to run a transfer job

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #22022:
URL: https://github.com/apache/airflow/pull/22022#issuecomment-1061174989


   You also need to add some tests (and fix static check and test 


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



[GitHub] [airflow] mik-laj commented on a change in pull request #22022: feat: add an operator to run a transfer job

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #22022:
URL: https://github.com/apache/airflow/pull/22022#discussion_r820260905



##########
File path: airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py
##########
@@ -326,6 +326,64 @@ def execute(self, context: 'Context') -> dict:
         return hook.update_transfer_job(job_name=self.job_name, body=self.body)
 
 
+class CloudDataTransferServiceRunJobOperator(BaseOperator):
+    """
+    Runs a transfer job in Google Storage Transfer Service.
+
+    :param job_name: (Required) Name of the transfer job.
+    :param gcp_conn_id: The connection ID used to connect to Google Cloud.
+    :param api_version: API version used (e.g. v1).
+    :param google_impersonation_chain: Optional Google service account to impersonate using
+        short-term credentials, or chained list of accounts required to get the access_token
+        of the last account in the list, which will be impersonated in the request.
+        If set as a string, the account must grant the originating account
+        the Service Account Token Creator IAM role.
+        If set as a sequence, the identities from the list must grant
+        Service Account Token Creator IAM role to the directly preceding identity, with first
+        account from the list granting this role to the originating account (templated).
+    """
+
+    # [START gcp_transfer_job_run_template_fields]
+    template_fields: Sequence[str] = (
+        "job_name",
+        "gcp_conn_id",
+        "api_version",
+        "google_impersonation_chain",
+    )
+    # [END gcp_transfer_job_run_template_fields]
+
+    def __init__(
+        self,
+        *,
+        job_name: str,
+        project_id: str,
+        gcp_conn_id: str = "google_cloud_default",
+        api_version: str = "v1",
+        google_impersonation_chain: Optional[Union[str, Sequence[str]]] = None,
+        **kwargs,
+    ) -> None:
+        self.job_name = job_name
+        self.project_id = project_id
+        self.gcp_conn_id = gcp_conn_id
+        self.api_version = api_version
+        self.google_impersonation_chain = google_impersonation_chain
+        self.body = {PROJECT_ID: project_id}

Review comment:
       Can you add fallback to default_project_id from connection? To do it, you should use     `@GoogleBaseHook.fallback_to_default_project_id` decorator.




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



[GitHub] [airflow] abhinavraj23 commented on a change in pull request #22022: feat: add an operator to run a transfer job

Posted by GitBox <gi...@apache.org>.
abhinavraj23 commented on a change in pull request #22022:
URL: https://github.com/apache/airflow/pull/22022#discussion_r820458718



##########
File path: airflow/providers/google/cloud/operators/cloud_storage_transfer_service.py
##########
@@ -326,6 +326,64 @@ def execute(self, context: 'Context') -> dict:
         return hook.update_transfer_job(job_name=self.job_name, body=self.body)
 
 
+class CloudDataTransferServiceRunJobOperator(BaseOperator):
+    """
+    Runs a transfer job in Google Storage Transfer Service.
+
+    :param job_name: (Required) Name of the transfer job.
+    :param gcp_conn_id: The connection ID used to connect to Google Cloud.
+    :param api_version: API version used (e.g. v1).
+    :param google_impersonation_chain: Optional Google service account to impersonate using
+        short-term credentials, or chained list of accounts required to get the access_token
+        of the last account in the list, which will be impersonated in the request.
+        If set as a string, the account must grant the originating account
+        the Service Account Token Creator IAM role.
+        If set as a sequence, the identities from the list must grant
+        Service Account Token Creator IAM role to the directly preceding identity, with first
+        account from the list granting this role to the originating account (templated).
+    """
+
+    # [START gcp_transfer_job_run_template_fields]
+    template_fields: Sequence[str] = (
+        "job_name",
+        "gcp_conn_id",
+        "api_version",
+        "google_impersonation_chain",
+    )
+    # [END gcp_transfer_job_run_template_fields]
+
+    def __init__(
+        self,
+        *,
+        job_name: str,
+        project_id: str,
+        gcp_conn_id: str = "google_cloud_default",
+        api_version: str = "v1",
+        google_impersonation_chain: Optional[Union[str, Sequence[str]]] = None,
+        **kwargs,
+    ) -> None:
+        self.job_name = job_name
+        self.project_id = project_id
+        self.gcp_conn_id = gcp_conn_id
+        self.api_version = api_version
+        self.google_impersonation_chain = google_impersonation_chain
+        self.body = {PROJECT_ID: project_id}

Review comment:
       Sure @mik-laj, have made the change




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