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/05/12 19:23:29 UTC
[GitHub] [airflow] ferruzzi opened a new pull request, #23681: Update the DMS Sample DAG and Docs
ferruzzi opened a new pull request, #23681:
URL: https://github.com/apache/airflow/pull/23681
Cleans up the existing sample DAG and docs for the DMS operators.
Part of a project to standardize AWS sample dags and docs in preparation for adding System Testing.
Related: https://github.com/apache/airflow/pull/21523
Related: https://github.com/apache/airflow/pull/21475
Related: https://github.com/apache/airflow/pull/21828
Related: https://github.com/apache/airflow/pull/21920
etc...
--
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] eladkal commented on a diff in pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
eladkal commented on code in PR #23681:
URL: https://github.com/apache/airflow/pull/23681#discussion_r876253773
##########
airflow/providers/amazon/aws/example_dags/example_dms.py:
##########
@@ -0,0 +1,347 @@
+#
+# 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.
+"""
+Note: DMS requires you to configure specific IAM roles/permissions. For more information, see
+https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole
+"""
+
+import json
+import os
+from datetime import datetime
+
+import boto3
+from sqlalchemy import Column, MetaData, String, Table, create_engine
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.operators.python import get_current_context
+from airflow.providers.amazon.aws.operators.dms import (
+ DmsCreateTaskOperator,
+ DmsDeleteTaskOperator,
+ DmsDescribeTasksOperator,
+ DmsStartTaskOperator,
+ DmsStopTaskOperator,
+)
+from airflow.providers.amazon.aws.sensors.dms import DmsTaskBaseSensor, DmsTaskCompletedSensor
+
+S3_BUCKET = os.getenv('S3_BUCKET', 's3_bucket_name')
+ROLE_ARN = os.getenv('ROLE_ARN', 'arn:aws:iam::1234567890:role/s3_target_endpoint_role')
+
+# The project name will be used as a prefix for various entity names.
+# Use either PascalCase or camelCase. While some names require kebab-case
+# and others require snake_case, they all accept mixedCase strings.
+PROJECT_NAME = 'DmsDemo'
+
+# Config values for setting up the "Source" database.
+RDS_ENGINE = 'postgres'
+RDS_PROTOCOL = 'postgresql'
+RDS_USERNAME = 'username'
+# NEVER store your production password in plaintext in a DAG like this.
+# Use Airflow Secrets or a secret manager for this in production.
+RDS_PASSWORD = 'rds_password'
+
+# Config values for RDS.
+RDS_INSTANCE_NAME = f'{PROJECT_NAME}-instance'
+RDS_DB_NAME = f'{PROJECT_NAME}_source_database'
+
+# Config values for DMS.
+DMS_REPLICATION_INSTANCE_NAME = f'{PROJECT_NAME}-replication-instance'
+DMS_REPLICATION_TASK_ID = f'{PROJECT_NAME}-replication-task'
+SOURCE_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-source-endpoint'
+TARGET_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-target-endpoint'
+
+# Sample data.
+TABLE_NAME = f'{PROJECT_NAME}-table'
+TABLE_HEADERS = ['apache_project', 'release_year']
+SAMPLE_DATA = [
+ ('Airflow', '2015'),
+ ('OpenOffice', '2012'),
+ ('Subversion', '2000'),
+ ('NiFi', '2006'),
+]
+TABLE_DEFINITION = {
+ 'TableCount': '1',
+ 'Tables': [
+ {
+ 'TableName': TABLE_NAME,
+ 'TableColumns': [
+ {
+ 'ColumnName': TABLE_HEADERS[0],
+ 'ColumnType': 'STRING',
+ 'ColumnNullable': 'false',
+ 'ColumnIsPk': 'true',
+ },
+ {"ColumnName": TABLE_HEADERS[1], "ColumnType": 'STRING', "ColumnLength": "4"},
+ ],
+ 'TableColumnsTotal': '2',
+ }
+ ],
+}
+TABLE_MAPPINGS = {
+ 'rules': [
+ {
+ 'rule-type': 'selection',
+ 'rule-id': '1',
+ 'rule-name': '1',
+ 'object-locator': {
+ 'schema-name': 'public',
+ 'table-name': TABLE_NAME,
+ },
+ 'rule-action': 'include',
+ }
+ ]
+}
+
+
+def _create_rds_instance():
+ print('Creating RDS Instance.')
+
+ rds_client = boto3.client('rds')
+ rds_client.create_db_instance(
+ DBName=RDS_DB_NAME,
+ DBInstanceIdentifier=RDS_INSTANCE_NAME,
+ AllocatedStorage=20,
+ DBInstanceClass='db.t3.micro',
+ Engine=RDS_ENGINE,
+ MasterUsername=RDS_USERNAME,
+ MasterUserPassword=RDS_PASSWORD,
Review Comment:
I suggest to create a followup issue and point also to handle the example dag here after auch operators are added
--
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] github-actions[bot] commented on pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #23681:
URL: https://github.com/apache/airflow/pull/23681#issuecomment-1130407157
The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.
--
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] eladkal commented on a diff in pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
eladkal commented on code in PR #23681:
URL: https://github.com/apache/airflow/pull/23681#discussion_r875778372
##########
airflow/providers/amazon/aws/example_dags/example_dms.py:
##########
@@ -0,0 +1,347 @@
+#
+# 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.
+"""
+Note: DMS requires you to configure specific IAM roles/permissions. For more information, see
+https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole
+"""
+
+import json
+import os
+from datetime import datetime
+
+import boto3
+from sqlalchemy import Column, MetaData, String, Table, create_engine
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.operators.python import get_current_context
+from airflow.providers.amazon.aws.operators.dms import (
+ DmsCreateTaskOperator,
+ DmsDeleteTaskOperator,
+ DmsDescribeTasksOperator,
+ DmsStartTaskOperator,
+ DmsStopTaskOperator,
+)
+from airflow.providers.amazon.aws.sensors.dms import DmsTaskBaseSensor, DmsTaskCompletedSensor
+
+S3_BUCKET = os.getenv('S3_BUCKET', 's3_bucket_name')
+ROLE_ARN = os.getenv('ROLE_ARN', 'arn:aws:iam::1234567890:role/s3_target_endpoint_role')
+
+# The project name will be used as a prefix for various entity names.
+# Use either PascalCase or camelCase. While some names require kebab-case
+# and others require snake_case, they all accept mixedCase strings.
+PROJECT_NAME = 'DmsDemo'
+
+# Config values for setting up the "Source" database.
+RDS_ENGINE = 'postgres'
+RDS_PROTOCOL = 'postgresql'
+RDS_USERNAME = 'username'
+# NEVER store your production password in plaintext in a DAG like this.
+# Use Airflow Secrets or a secret manager for this in production.
+RDS_PASSWORD = 'rds_password'
+
+# Config values for RDS.
+RDS_INSTANCE_NAME = f'{PROJECT_NAME}-instance'
+RDS_DB_NAME = f'{PROJECT_NAME}_source_database'
+
+# Config values for DMS.
+DMS_REPLICATION_INSTANCE_NAME = f'{PROJECT_NAME}-replication-instance'
+DMS_REPLICATION_TASK_ID = f'{PROJECT_NAME}-replication-task'
+SOURCE_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-source-endpoint'
+TARGET_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-target-endpoint'
+
+# Sample data.
+TABLE_NAME = f'{PROJECT_NAME}-table'
+TABLE_HEADERS = ['apache_project', 'release_year']
+SAMPLE_DATA = [
+ ('Airflow', '2015'),
+ ('OpenOffice', '2012'),
+ ('Subversion', '2000'),
+ ('NiFi', '2006'),
+]
+TABLE_DEFINITION = {
+ 'TableCount': '1',
+ 'Tables': [
+ {
+ 'TableName': TABLE_NAME,
+ 'TableColumns': [
+ {
+ 'ColumnName': TABLE_HEADERS[0],
+ 'ColumnType': 'STRING',
+ 'ColumnNullable': 'false',
+ 'ColumnIsPk': 'true',
+ },
+ {"ColumnName": TABLE_HEADERS[1], "ColumnType": 'STRING', "ColumnLength": "4"},
+ ],
+ 'TableColumnsTotal': '2',
+ }
+ ],
+}
+TABLE_MAPPINGS = {
+ 'rules': [
+ {
+ 'rule-type': 'selection',
+ 'rule-id': '1',
+ 'rule-name': '1',
+ 'object-locator': {
+ 'schema-name': 'public',
+ 'table-name': TABLE_NAME,
+ },
+ 'rule-action': 'include',
+ }
+ ]
+}
+
+
+def _create_rds_instance():
+ print('Creating RDS Instance.')
+
+ rds_client = boto3.client('rds')
+ rds_client.create_db_instance(
+ DBName=RDS_DB_NAME,
+ DBInstanceIdentifier=RDS_INSTANCE_NAME,
+ AllocatedStorage=20,
+ DBInstanceClass='db.t3.micro',
+ Engine=RDS_ENGINE,
+ MasterUsername=RDS_USERNAME,
+ MasterUserPassword=RDS_PASSWORD,
Review Comment:
Example dags should be simple this done feels a little overwhelming it has many code lines that are not really in the essence but more of the setups needed to make the point.
It feels like we should have proper operators for all the "setup" part. Consider adding the needed operators in a separate PR and then adjust this PR with updated code.
This is just an observation - if you feel comfortable with it as is... I'm happy to proceed.
--
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] ferruzzi commented on a diff in pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
ferruzzi commented on code in PR #23681:
URL: https://github.com/apache/airflow/pull/23681#discussion_r873864584
##########
airflow/providers/amazon/aws/example_dags/example_dms.py:
##########
@@ -0,0 +1,347 @@
+#
+# 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.
+"""
+Note: DMS requires you to configure specific IAM roles/permissions. For more information, see
+https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole
+"""
+
+import json
+import os
+from datetime import datetime
+
+import boto3
+from sqlalchemy import Column, MetaData, String, Table, create_engine
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.operators.python import get_current_context
+from airflow.providers.amazon.aws.operators.dms import (
+ DmsCreateTaskOperator,
+ DmsDeleteTaskOperator,
+ DmsDescribeTasksOperator,
+ DmsStartTaskOperator,
+ DmsStopTaskOperator,
+)
+from airflow.providers.amazon.aws.sensors.dms import DmsTaskBaseSensor, DmsTaskCompletedSensor
+
+S3_BUCKET = os.getenv('S3_BUCKET', 's3_bucket_name')
+ROLE_ARN = os.getenv('ROLE_ARN', 'arn:aws:iam::1234567890:role/s3_target_endpoint_role')
+
+# The project name will be used as a prefix for various entity names.
+# Use either PascalCase or camelCase. While some names require kebab-case
+# and others require snake_case, they all accept mixedCase strings.
+PROJECT_NAME = 'DmsDemo'
+
+# Config values for setting up the "Source" database.
+RDS_ENGINE = 'postgres'
+RDS_PROTOCOL = 'postgresql'
+RDS_USERNAME = 'username'
+# NEVER store your production password in plaintext in a DAG like this.
+# Use Airflow Secrets or a secret manager for this in production.
+RDS_PASSWORD = 'rds_password'
+
+# Config values for RDS.
+RDS_INSTANCE_NAME = f'{PROJECT_NAME}-instance'
+RDS_DB_NAME = f'{PROJECT_NAME}_source_database'
+
+# Config values for DMS.
+DMS_REPLICATION_INSTANCE_NAME = f'{PROJECT_NAME}-replication-instance'
+DMS_REPLICATION_TASK_ID = f'{PROJECT_NAME}-replication-task'
+SOURCE_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-source-endpoint'
+TARGET_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-target-endpoint'
+
+# Sample data.
+TABLE_NAME = f'{PROJECT_NAME}-table'
+TABLE_HEADERS = ['apache_project', 'release_year']
+SAMPLE_DATA = [
+ ('Airflow', '2015'),
+ ('OpenOffice', '2012'),
+ ('Subversion', '2000'),
+ ('NiFi', '2006'),
+]
+TABLE_DEFINITION = {
+ 'TableCount': '1',
+ 'Tables': [
+ {
+ 'TableName': TABLE_NAME,
+ 'TableColumns': [
+ {
+ 'ColumnName': TABLE_HEADERS[0],
+ 'ColumnType': 'STRING',
+ 'ColumnNullable': 'false',
+ 'ColumnIsPk': 'true',
+ },
+ {"ColumnName": TABLE_HEADERS[1], "ColumnType": 'STRING', "ColumnLength": "4"},
+ ],
+ 'TableColumnsTotal': '2',
+ }
+ ],
+}
+TABLE_MAPPINGS = {
+ 'rules': [
+ {
+ 'rule-type': 'selection',
+ 'rule-id': '1',
+ 'rule-name': '1',
+ 'object-locator': {
+ 'schema-name': 'public',
+ 'table-name': TABLE_NAME,
+ },
+ 'rule-action': 'include',
+ }
+ ]
+}
+
+
+def _create_rds_instance():
+ print('Creating RDS Instance.')
+
+ rds_client = boto3.client('rds')
+ rds_client.create_db_instance(
+ DBName=RDS_DB_NAME,
+ DBInstanceIdentifier=RDS_INSTANCE_NAME,
+ AllocatedStorage=20,
+ DBInstanceClass='db.t3.micro',
+ Engine=RDS_ENGINE,
+ MasterUsername=RDS_USERNAME,
+ MasterUserPassword=RDS_PASSWORD,
Review Comment:
Nope, not that I can tell. There is Create/Copy/Delete Snapshot, Start/Cancel Export, and Create/Delete Event Subscription.
--
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] eladkal commented on a diff in pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
eladkal commented on code in PR #23681:
URL: https://github.com/apache/airflow/pull/23681#discussion_r875778372
##########
airflow/providers/amazon/aws/example_dags/example_dms.py:
##########
@@ -0,0 +1,347 @@
+#
+# 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.
+"""
+Note: DMS requires you to configure specific IAM roles/permissions. For more information, see
+https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole
+"""
+
+import json
+import os
+from datetime import datetime
+
+import boto3
+from sqlalchemy import Column, MetaData, String, Table, create_engine
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.operators.python import get_current_context
+from airflow.providers.amazon.aws.operators.dms import (
+ DmsCreateTaskOperator,
+ DmsDeleteTaskOperator,
+ DmsDescribeTasksOperator,
+ DmsStartTaskOperator,
+ DmsStopTaskOperator,
+)
+from airflow.providers.amazon.aws.sensors.dms import DmsTaskBaseSensor, DmsTaskCompletedSensor
+
+S3_BUCKET = os.getenv('S3_BUCKET', 's3_bucket_name')
+ROLE_ARN = os.getenv('ROLE_ARN', 'arn:aws:iam::1234567890:role/s3_target_endpoint_role')
+
+# The project name will be used as a prefix for various entity names.
+# Use either PascalCase or camelCase. While some names require kebab-case
+# and others require snake_case, they all accept mixedCase strings.
+PROJECT_NAME = 'DmsDemo'
+
+# Config values for setting up the "Source" database.
+RDS_ENGINE = 'postgres'
+RDS_PROTOCOL = 'postgresql'
+RDS_USERNAME = 'username'
+# NEVER store your production password in plaintext in a DAG like this.
+# Use Airflow Secrets or a secret manager for this in production.
+RDS_PASSWORD = 'rds_password'
+
+# Config values for RDS.
+RDS_INSTANCE_NAME = f'{PROJECT_NAME}-instance'
+RDS_DB_NAME = f'{PROJECT_NAME}_source_database'
+
+# Config values for DMS.
+DMS_REPLICATION_INSTANCE_NAME = f'{PROJECT_NAME}-replication-instance'
+DMS_REPLICATION_TASK_ID = f'{PROJECT_NAME}-replication-task'
+SOURCE_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-source-endpoint'
+TARGET_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-target-endpoint'
+
+# Sample data.
+TABLE_NAME = f'{PROJECT_NAME}-table'
+TABLE_HEADERS = ['apache_project', 'release_year']
+SAMPLE_DATA = [
+ ('Airflow', '2015'),
+ ('OpenOffice', '2012'),
+ ('Subversion', '2000'),
+ ('NiFi', '2006'),
+]
+TABLE_DEFINITION = {
+ 'TableCount': '1',
+ 'Tables': [
+ {
+ 'TableName': TABLE_NAME,
+ 'TableColumns': [
+ {
+ 'ColumnName': TABLE_HEADERS[0],
+ 'ColumnType': 'STRING',
+ 'ColumnNullable': 'false',
+ 'ColumnIsPk': 'true',
+ },
+ {"ColumnName": TABLE_HEADERS[1], "ColumnType": 'STRING', "ColumnLength": "4"},
+ ],
+ 'TableColumnsTotal': '2',
+ }
+ ],
+}
+TABLE_MAPPINGS = {
+ 'rules': [
+ {
+ 'rule-type': 'selection',
+ 'rule-id': '1',
+ 'rule-name': '1',
+ 'object-locator': {
+ 'schema-name': 'public',
+ 'table-name': TABLE_NAME,
+ },
+ 'rule-action': 'include',
+ }
+ ]
+}
+
+
+def _create_rds_instance():
+ print('Creating RDS Instance.')
+
+ rds_client = boto3.client('rds')
+ rds_client.create_db_instance(
+ DBName=RDS_DB_NAME,
+ DBInstanceIdentifier=RDS_INSTANCE_NAME,
+ AllocatedStorage=20,
+ DBInstanceClass='db.t3.micro',
+ Engine=RDS_ENGINE,
+ MasterUsername=RDS_USERNAME,
+ MasterUserPassword=RDS_PASSWORD,
Review Comment:
Example dags should be simple this done feels a little overwhelming it has many code lines that in fact are not really part of the essence of the example but more of the setups needed to make the point.
It feels like we should have proper operators for all the "setup" part. Consider adding the needed operators in a separate PR and then adjust this PR with updated code.
This is just an observation - if you feel comfortable with it as is... I'm happy to proceed.
--
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] eladkal commented on a diff in pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
eladkal commented on code in PR #23681:
URL: https://github.com/apache/airflow/pull/23681#discussion_r873146612
##########
airflow/providers/amazon/aws/example_dags/example_dms.py:
##########
@@ -0,0 +1,347 @@
+#
+# 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.
+"""
+Note: DMS requires you to configure specific IAM roles/permissions. For more information, see
+https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole
+"""
+
+import json
+import os
+from datetime import datetime
+
+import boto3
+from sqlalchemy import Column, MetaData, String, Table, create_engine
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.operators.python import get_current_context
+from airflow.providers.amazon.aws.operators.dms import (
+ DmsCreateTaskOperator,
+ DmsDeleteTaskOperator,
+ DmsDescribeTasksOperator,
+ DmsStartTaskOperator,
+ DmsStopTaskOperator,
+)
+from airflow.providers.amazon.aws.sensors.dms import DmsTaskBaseSensor, DmsTaskCompletedSensor
+
+S3_BUCKET = os.getenv('S3_BUCKET', 's3_bucket_name')
+ROLE_ARN = os.getenv('ROLE_ARN', 'arn:aws:iam::1234567890:role/s3_target_endpoint_role')
+
+# The project name will be used as a prefix for various entity names.
+# Use either PascalCase or camelCase. While some names require kebab-case
+# and others require snake_case, they all accept mixedCase strings.
+PROJECT_NAME = 'DmsDemo'
+
+# Config values for setting up the "Source" database.
+RDS_ENGINE = 'postgres'
+RDS_PROTOCOL = 'postgresql'
+RDS_USERNAME = 'username'
+# NEVER store your production password in plaintext in a DAG like this.
+# Use Airflow Secrets or a secret manager for this in production.
+RDS_PASSWORD = 'rds_password'
+
+# Config values for RDS.
+RDS_INSTANCE_NAME = f'{PROJECT_NAME}-instance'
+RDS_DB_NAME = f'{PROJECT_NAME}_source_database'
+
+# Config values for DMS.
+DMS_REPLICATION_INSTANCE_NAME = f'{PROJECT_NAME}-replication-instance'
+DMS_REPLICATION_TASK_ID = f'{PROJECT_NAME}-replication-task'
+SOURCE_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-source-endpoint'
+TARGET_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-target-endpoint'
+
+# Sample data.
+TABLE_NAME = f'{PROJECT_NAME}-table'
+TABLE_HEADERS = ['apache_project', 'release_year']
+SAMPLE_DATA = [
+ ('Airflow', '2015'),
+ ('OpenOffice', '2012'),
+ ('Subversion', '2000'),
+ ('NiFi', '2006'),
+]
+TABLE_DEFINITION = {
+ 'TableCount': '1',
+ 'Tables': [
+ {
+ 'TableName': TABLE_NAME,
+ 'TableColumns': [
+ {
+ 'ColumnName': TABLE_HEADERS[0],
+ 'ColumnType': 'STRING',
+ 'ColumnNullable': 'false',
+ 'ColumnIsPk': 'true',
+ },
+ {"ColumnName": TABLE_HEADERS[1], "ColumnType": 'STRING', "ColumnLength": "4"},
+ ],
+ 'TableColumnsTotal': '2',
+ }
+ ],
+}
+TABLE_MAPPINGS = {
+ 'rules': [
+ {
+ 'rule-type': 'selection',
+ 'rule-id': '1',
+ 'rule-name': '1',
+ 'object-locator': {
+ 'schema-name': 'public',
+ 'table-name': TABLE_NAME,
+ },
+ 'rule-action': 'include',
+ }
+ ]
+}
+
+
+def _create_rds_instance():
+ print('Creating RDS Instance.')
+
+ rds_client = boto3.client('rds')
+ rds_client.create_db_instance(
+ DBName=RDS_DB_NAME,
+ DBInstanceIdentifier=RDS_INSTANCE_NAME,
+ AllocatedStorage=20,
+ DBInstanceClass='db.t3.micro',
+ Engine=RDS_ENGINE,
+ MasterUsername=RDS_USERNAME,
+ MasterUserPassword=RDS_PASSWORD,
Review Comment:
Don't we have operator in Rds for this?
--
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] eladkal commented on a diff in pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
eladkal commented on code in PR #23681:
URL: https://github.com/apache/airflow/pull/23681#discussion_r875778372
##########
airflow/providers/amazon/aws/example_dags/example_dms.py:
##########
@@ -0,0 +1,347 @@
+#
+# 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.
+"""
+Note: DMS requires you to configure specific IAM roles/permissions. For more information, see
+https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole
+"""
+
+import json
+import os
+from datetime import datetime
+
+import boto3
+from sqlalchemy import Column, MetaData, String, Table, create_engine
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.operators.python import get_current_context
+from airflow.providers.amazon.aws.operators.dms import (
+ DmsCreateTaskOperator,
+ DmsDeleteTaskOperator,
+ DmsDescribeTasksOperator,
+ DmsStartTaskOperator,
+ DmsStopTaskOperator,
+)
+from airflow.providers.amazon.aws.sensors.dms import DmsTaskBaseSensor, DmsTaskCompletedSensor
+
+S3_BUCKET = os.getenv('S3_BUCKET', 's3_bucket_name')
+ROLE_ARN = os.getenv('ROLE_ARN', 'arn:aws:iam::1234567890:role/s3_target_endpoint_role')
+
+# The project name will be used as a prefix for various entity names.
+# Use either PascalCase or camelCase. While some names require kebab-case
+# and others require snake_case, they all accept mixedCase strings.
+PROJECT_NAME = 'DmsDemo'
+
+# Config values for setting up the "Source" database.
+RDS_ENGINE = 'postgres'
+RDS_PROTOCOL = 'postgresql'
+RDS_USERNAME = 'username'
+# NEVER store your production password in plaintext in a DAG like this.
+# Use Airflow Secrets or a secret manager for this in production.
+RDS_PASSWORD = 'rds_password'
+
+# Config values for RDS.
+RDS_INSTANCE_NAME = f'{PROJECT_NAME}-instance'
+RDS_DB_NAME = f'{PROJECT_NAME}_source_database'
+
+# Config values for DMS.
+DMS_REPLICATION_INSTANCE_NAME = f'{PROJECT_NAME}-replication-instance'
+DMS_REPLICATION_TASK_ID = f'{PROJECT_NAME}-replication-task'
+SOURCE_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-source-endpoint'
+TARGET_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-target-endpoint'
+
+# Sample data.
+TABLE_NAME = f'{PROJECT_NAME}-table'
+TABLE_HEADERS = ['apache_project', 'release_year']
+SAMPLE_DATA = [
+ ('Airflow', '2015'),
+ ('OpenOffice', '2012'),
+ ('Subversion', '2000'),
+ ('NiFi', '2006'),
+]
+TABLE_DEFINITION = {
+ 'TableCount': '1',
+ 'Tables': [
+ {
+ 'TableName': TABLE_NAME,
+ 'TableColumns': [
+ {
+ 'ColumnName': TABLE_HEADERS[0],
+ 'ColumnType': 'STRING',
+ 'ColumnNullable': 'false',
+ 'ColumnIsPk': 'true',
+ },
+ {"ColumnName": TABLE_HEADERS[1], "ColumnType": 'STRING', "ColumnLength": "4"},
+ ],
+ 'TableColumnsTotal': '2',
+ }
+ ],
+}
+TABLE_MAPPINGS = {
+ 'rules': [
+ {
+ 'rule-type': 'selection',
+ 'rule-id': '1',
+ 'rule-name': '1',
+ 'object-locator': {
+ 'schema-name': 'public',
+ 'table-name': TABLE_NAME,
+ },
+ 'rule-action': 'include',
+ }
+ ]
+}
+
+
+def _create_rds_instance():
+ print('Creating RDS Instance.')
+
+ rds_client = boto3.client('rds')
+ rds_client.create_db_instance(
+ DBName=RDS_DB_NAME,
+ DBInstanceIdentifier=RDS_INSTANCE_NAME,
+ AllocatedStorage=20,
+ DBInstanceClass='db.t3.micro',
+ Engine=RDS_ENGINE,
+ MasterUsername=RDS_USERNAME,
+ MasterUserPassword=RDS_PASSWORD,
Review Comment:
Example dags should be simple to comprehend this one feels a little overwhelming it has many code lines that are not really in the essence but more of the setups needed to make the point.
It feels like we should have proper operators for all the "setup" part. Consider adding the needed operators in a separate PR and then adjust this PR with updated code.
This is just an observation - if you feel comfortable with it as is... I'm happy to proceed.
--
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] ferruzzi commented on a diff in pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
ferruzzi commented on code in PR #23681:
URL: https://github.com/apache/airflow/pull/23681#discussion_r876190155
##########
airflow/providers/amazon/aws/example_dags/example_dms.py:
##########
@@ -0,0 +1,347 @@
+#
+# 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.
+"""
+Note: DMS requires you to configure specific IAM roles/permissions. For more information, see
+https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Security.html#CHAP_Security.APIRole
+"""
+
+import json
+import os
+from datetime import datetime
+
+import boto3
+from sqlalchemy import Column, MetaData, String, Table, create_engine
+
+from airflow import DAG
+from airflow.decorators import task
+from airflow.models.baseoperator import chain
+from airflow.operators.python import get_current_context
+from airflow.providers.amazon.aws.operators.dms import (
+ DmsCreateTaskOperator,
+ DmsDeleteTaskOperator,
+ DmsDescribeTasksOperator,
+ DmsStartTaskOperator,
+ DmsStopTaskOperator,
+)
+from airflow.providers.amazon.aws.sensors.dms import DmsTaskBaseSensor, DmsTaskCompletedSensor
+
+S3_BUCKET = os.getenv('S3_BUCKET', 's3_bucket_name')
+ROLE_ARN = os.getenv('ROLE_ARN', 'arn:aws:iam::1234567890:role/s3_target_endpoint_role')
+
+# The project name will be used as a prefix for various entity names.
+# Use either PascalCase or camelCase. While some names require kebab-case
+# and others require snake_case, they all accept mixedCase strings.
+PROJECT_NAME = 'DmsDemo'
+
+# Config values for setting up the "Source" database.
+RDS_ENGINE = 'postgres'
+RDS_PROTOCOL = 'postgresql'
+RDS_USERNAME = 'username'
+# NEVER store your production password in plaintext in a DAG like this.
+# Use Airflow Secrets or a secret manager for this in production.
+RDS_PASSWORD = 'rds_password'
+
+# Config values for RDS.
+RDS_INSTANCE_NAME = f'{PROJECT_NAME}-instance'
+RDS_DB_NAME = f'{PROJECT_NAME}_source_database'
+
+# Config values for DMS.
+DMS_REPLICATION_INSTANCE_NAME = f'{PROJECT_NAME}-replication-instance'
+DMS_REPLICATION_TASK_ID = f'{PROJECT_NAME}-replication-task'
+SOURCE_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-source-endpoint'
+TARGET_ENDPOINT_IDENTIFIER = f'{PROJECT_NAME}-target-endpoint'
+
+# Sample data.
+TABLE_NAME = f'{PROJECT_NAME}-table'
+TABLE_HEADERS = ['apache_project', 'release_year']
+SAMPLE_DATA = [
+ ('Airflow', '2015'),
+ ('OpenOffice', '2012'),
+ ('Subversion', '2000'),
+ ('NiFi', '2006'),
+]
+TABLE_DEFINITION = {
+ 'TableCount': '1',
+ 'Tables': [
+ {
+ 'TableName': TABLE_NAME,
+ 'TableColumns': [
+ {
+ 'ColumnName': TABLE_HEADERS[0],
+ 'ColumnType': 'STRING',
+ 'ColumnNullable': 'false',
+ 'ColumnIsPk': 'true',
+ },
+ {"ColumnName": TABLE_HEADERS[1], "ColumnType": 'STRING', "ColumnLength": "4"},
+ ],
+ 'TableColumnsTotal': '2',
+ }
+ ],
+}
+TABLE_MAPPINGS = {
+ 'rules': [
+ {
+ 'rule-type': 'selection',
+ 'rule-id': '1',
+ 'rule-name': '1',
+ 'object-locator': {
+ 'schema-name': 'public',
+ 'table-name': TABLE_NAME,
+ },
+ 'rule-action': 'include',
+ }
+ ]
+}
+
+
+def _create_rds_instance():
+ print('Creating RDS Instance.')
+
+ rds_client = boto3.client('rds')
+ rds_client.create_db_instance(
+ DBName=RDS_DB_NAME,
+ DBInstanceIdentifier=RDS_INSTANCE_NAME,
+ AllocatedStorage=20,
+ DBInstanceClass='db.t3.micro',
+ Engine=RDS_ENGINE,
+ MasterUsername=RDS_USERNAME,
+ MasterUserPassword=RDS_PASSWORD,
Review Comment:
We can add those new operators, but that shouldn't block documenting the existing stuff. The support code is there because we are transitioning it all over to System Tests which need to be self-sufficient. These can't just be the most basic versions anymore if they are going to be used as end to end tests, they'll need to create and destroy the required resources to actually work.
I can add the new operators to my backlog list, and make updating this part of that task, but I would rather get this merged in and update it later than shelf this until that gets 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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] potiuk merged pull request #23681: Update the DMS Sample DAG and Docs
Posted by GitBox <gi...@apache.org>.
potiuk merged PR #23681:
URL: https://github.com/apache/airflow/pull/23681
--
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