-
Notifications
You must be signed in to change notification settings - Fork 17.4k
Firehose and kinesis hook in independent file #56276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6c29099
move firehose class
xchwan 02058f4
add Kinesishook
xchwan bfa97c8
rename test_kinesis to test_firehose
xchwan f6e80fc
add test_kinesis
xchwan c02e41a
modify deprecate wapper
xchwan e2bc830
fix provider yaml and file check
xchwan adc618e
modify reStructuredText
xchwan 7f427b3
add return type
xchwan c7082c7
Merge branch 'main' into kinesis_hook_modified
xchwan 3ec8983
Merge branch 'main' into kinesis_hook_modified
xchwan e70432a
Merge branch 'main' into kinesis_hook_modified
xchwan f1f1206
Merge branch 'main' into kinesis_hook_modified
xchwan ef27c1e
Merge branch 'main' into kinesis_hook_modified
xchwan 818d92c
remove warp boto3 API methods
xchwan 43c40b9
Merge branch 'main' into kinesis_hook_modified
xchwan 1a1b013
Merge branch 'main' into kinesis_hook_modified
xchwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
providers/amazon/src/airflow/providers/amazon/aws/hooks/firehose.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # | ||
| # 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 AWS Firehose hook.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterable | ||
|
|
||
| from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook | ||
|
|
||
|
|
||
| class FirehoseHook(AwsBaseHook): | ||
| """ | ||
| Interact with Amazon Kinesis Firehose. | ||
|
|
||
| Provide thick wrapper around :external+boto3:py:class:`boto3.client("firehose") <Firehose.Client>`. | ||
|
|
||
| :param delivery_stream: Name of the delivery stream | ||
|
|
||
| Additional arguments (such as ``aws_conn_id``) may be specified and | ||
| are passed down to the underlying AwsBaseHook. | ||
|
|
||
| .. seealso:: | ||
| - :class:`airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook` | ||
| """ | ||
|
|
||
| def __init__(self, delivery_stream: str, *args, **kwargs) -> None: | ||
| self.delivery_stream = delivery_stream | ||
| kwargs["client_type"] = "firehose" | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| def put_records(self, records: Iterable) -> dict: | ||
| """ | ||
| Write batch records to Kinesis Firehose. | ||
|
|
||
| .. seealso:: | ||
| - :external+boto3:py:meth:`Firehose.Client.put_record_batch` | ||
|
|
||
| :param records: list of records | ||
| """ | ||
| return self.get_conn().put_record_batch(DeliveryStreamName=self.delivery_stream, Records=records) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
providers/amazon/tests/unit/amazon/aws/hooks/test_firehose.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # | ||
| # 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. | ||
| from __future__ import annotations | ||
|
|
||
| import uuid | ||
|
|
||
| import boto3 | ||
| from moto import mock_aws | ||
|
|
||
| from airflow.providers.amazon.aws.hooks.firehose import FirehoseHook | ||
|
|
||
|
|
||
| @mock_aws | ||
| class TestFirehoseHook: | ||
| def test_get_conn_returns_a_boto3_connection(self): | ||
| hook = FirehoseHook( | ||
| aws_conn_id="aws_default", delivery_stream="test_airflow", region_name="us-east-1" | ||
| ) | ||
| assert hook.get_conn() is not None | ||
|
|
||
| def test_insert_batch_records_kinesis_firehose(self): | ||
| boto3.client("s3").create_bucket(Bucket="kinesis-test") | ||
| hook = FirehoseHook( | ||
| aws_conn_id="aws_default", delivery_stream="test_airflow", region_name="us-east-1" | ||
| ) | ||
|
|
||
| response = hook.get_conn().create_delivery_stream( | ||
| DeliveryStreamName="test_airflow", | ||
| S3DestinationConfiguration={ | ||
| "RoleARN": "arn:aws:iam::123456789012:role/firehose_delivery_role", | ||
| "BucketARN": "arn:aws:s3:::kinesis-test", | ||
| "Prefix": "airflow/", | ||
| "BufferingHints": {"SizeInMBs": 123, "IntervalInSeconds": 124}, | ||
| "CompressionFormat": "UNCOMPRESSED", | ||
| }, | ||
| ) | ||
|
|
||
| stream_arn = response["DeliveryStreamARN"] | ||
| assert stream_arn == "arn:aws:firehose:us-east-1:123456789012:deliverystream/test_airflow" | ||
|
|
||
| records = [{"Data": str(uuid.uuid4())} for _ in range(100)] | ||
|
|
||
| response = hook.put_records(records) | ||
|
|
||
| assert response["FailedPutCount"] == 0 | ||
| assert response["ResponseMetadata"]["HTTPStatusCode"] == 200 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.