Visya commented on a change in pull request #15850: URL: https://github.com/apache/airflow/pull/15850#discussion_r637377348
########## File path: airflow/providers/amazon/aws/hooks/dms.py ########## @@ -0,0 +1,222 @@ +# +# 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. +import json +from typing import Optional + +from airflow.exceptions import AirflowException +from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook + + +class DmsHook(AwsBaseHook): + """Interact with AWS Database Migration Service.""" + + def __init__( + self, + *args, + **kwargs, + ): + kwargs['client_type'] = 'dms' + super().__init__(*args, **kwargs) + + def describe_replication_tasks( + self, + describe_tasks_kwargs: Optional[dict] = None, Review comment: I relied on some of the examples in the aws provider code, for example: https://github.com/apache/airflow/blob/master/airflow/providers/amazon/aws/hooks/glue.py#L64 Would you suggest using kwargs in both hook functions and the operator, something like this? ``` diff diff --git a/airflow/providers/amazon/aws/hooks/dms.py b/airflow/providers/amazon/aws/hooks/dms.py index 92b9f4924..1ead73c7e 100644 --- a/airflow/providers/amazon/aws/hooks/dms.py +++ b/airflow/providers/amazon/aws/hooks/dms.py @@ -105,7 +105,7 @@ class DmsHook(AwsBaseHook): replication_instance_arn: str, migration_type: str, table_mappings: dict, - create_task_kwargs: Optional[dict] = None, + **kwargs, ) -> str: """ Create DMS replication task @@ -122,11 +122,8 @@ class DmsHook(AwsBaseHook): :type table_mappings: dict :param migration_type: Migration type ('full-load'|'cdc'|'full-load-and-cdc'), full-load by default. :type migration_type: str - :param create_task_kwargs: Extra arguments for DMS replication task creation. - :type create_task_kwargs: Optional[dict] :return: Replication task ARN """ - additional_args = create_task_kwargs or {} dms_client = self.get_conn() create_task_response = dms_client.create_replication_task( ReplicationTaskIdentifier=replication_task_id, @@ -135,7 +132,7 @@ class DmsHook(AwsBaseHook): ReplicationInstanceArn=replication_instance_arn, MigrationType=migration_type, TableMappings=json.dumps(table_mappings), - **additional_args, + **kwargs, ) replication_task_arn = create_task_response['ReplicationTask']['ReplicationTaskArn'] diff --git a/airflow/providers/amazon/aws/operators/dms_create_task.py b/airflow/providers/amazon/aws/operators/dms_create_task.py index 22ddcd958..8cd2f327c 100644 --- a/airflow/providers/amazon/aws/operators/dms_create_task.py +++ b/airflow/providers/amazon/aws/operators/dms_create_task.py @@ -43,8 +43,6 @@ class DmsCreateTaskOperator(BaseOperator): :type table_mappings: dict :param migration_type: Migration type ('full-load'|'cdc'|'full-load-and-cdc'), full-load by default. :type migration_type: str - :param create_task_kwargs: Extra arguments for DMS replication task creation. - :type create_task_kwargs: Optional[dict] :param aws_conn_id: The Airflow connection used for AWS credentials. If this is None or empty then the default boto3 behaviour is used. If running Airflow in a distributed manner and aws_conn_id is None or @@ -60,13 +58,9 @@ class DmsCreateTaskOperator(BaseOperator): 'replication_instance_arn', 'table_mappings', 'migration_type', - 'create_task_kwargs', ) template_ext = () - template_fields_renderers = { - "table_mappings": "json", - "create_task_kwargs": "json", - } + template_fields_renderers = {"table_mappings": "json"} @apply_defaults def __init__( @@ -78,7 +72,6 @@ class DmsCreateTaskOperator(BaseOperator): replication_instance_arn: str, table_mappings: dict, migration_type: Optional[str] = 'full-load', - create_task_kwargs: Optional[dict] = None, aws_conn_id: str = 'aws_default', **kwargs, ): @@ -89,7 +82,7 @@ class DmsCreateTaskOperator(BaseOperator): self.replication_instance_arn = replication_instance_arn self.migration_type = migration_type self.table_mappings = table_mappings - self.create_task_kwargs = create_task_kwargs + self.create_task_kwargs = kwargs self.aws_conn_id = aws_conn_id def execute(self, context): @@ -107,7 +100,7 @@ class DmsCreateTaskOperator(BaseOperator): replication_instance_arn=self.replication_instance_arn, migration_type=self.migration_type, table_mappings=self.table_mappings, - create_task_kwargs=self.create_task_kwargs, + **self.create_task_kwargs, ) self.log.info("DMS replication task(%s) is ready.", self.replication_task_id) ``` -- 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. For queries about this service, please contact Infrastructure at: [email protected]
