-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Add MaxComputeSQLOperator, MaxComputeHook and AlibabaBaseHook to Alibaba Provider #50178
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
28 commits
Select commit
Hold shift + click to select a range
0ba4a0f
Add MaxComputeHook and AlibabaBaseHook
jsjasonseba 70d43aa
Remove unecessary init override
jsjasonseba da57a67
Fix word spelling
jsjasonseba 09256cc
Add type hints and docstrings to MaxComputeHook and AlibabaBaseHook
jsjasonseba 7e0eeb1
Set priority from hints if not explicitly provided
jsjasonseba 21947f9
Add odps to spelling wordlist
jsjasonseba d891967
Add stop_instance method to MaxComputeHook
jsjasonseba 83540fb
Add MaxComputeSQLOperator
jsjasonseba efe142e
Fix docstring
jsjasonseba 4128d6a
Merge branch 'main' into alibaba-provider-maxcompute
jsjasonseba ca2e808
Add maxcompute to wordlist
jsjasonseba a43ed83
Add alibaba test_version_compat.py to overlooked test list
jsjasonseba 313baa8
Add test for MaxComputeLogViewLink
jsjasonseba a35cd64
Simplify fallback logic
jsjasonseba ed6a7a3
Change error logging to use log.exception
jsjasonseba 476165a
Simplify logics
jsjasonseba 6e65471
Make arguments keyword-only
jsjasonseba 31932ad
Create MaxComputeConfigurationException for configuration issues
jsjasonseba 264ece6
Add test for MaxComputeConfigurationException
jsjasonseba 09cfce1
Merge branch 'main' into alibaba-provider-maxcompute
jsjasonseba c996a98
Simplify code
jsjasonseba 9b09cf7
Simplify code
jsjasonseba e89104e
Simplify code
jsjasonseba bdcc1b2
Adjust connection arg name for styling consistency with other hooks
jsjasonseba 16e64df
Adjust connection arg name for styling consistency with other hooks
jsjasonseba cab01e0
Merge branch 'main' into alibaba-provider-maxcompute
jsjasonseba 155f9ee
Refactor code
jsjasonseba 082f69d
Refactor code
jsjasonseba 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
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
21 changes: 21 additions & 0 deletions
21
providers/alibaba/src/airflow/providers/alibaba/cloud/exceptions.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,21 @@ | ||
| # 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 | ||
|
|
||
|
|
||
| class MaxComputeConfigurationException(Exception): | ||
| """Raised when MaxCompute project or endpoint is not configured properly.""" |
99 changes: 99 additions & 0 deletions
99
providers/alibaba/src/airflow/providers/alibaba/cloud/hooks/base_alibaba.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,99 @@ | ||
| # 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 | ||
|
|
||
| from typing import Any, NamedTuple | ||
|
|
||
| from airflow.hooks.base import BaseHook | ||
|
|
||
|
|
||
| class AccessKeyCredentials(NamedTuple): | ||
| """ | ||
| A NamedTuple to store Alibaba Cloud Access Key credentials. | ||
|
|
||
| :param access_key_id: The Access Key ID for Alibaba Cloud authentication. | ||
| :param access_key_secret: The Access Key Secret for Alibaba Cloud authentication. | ||
| """ | ||
|
|
||
| access_key_id: str | ||
| access_key_secret: str | ||
|
|
||
|
|
||
| class AlibabaBaseHook(BaseHook): | ||
| """ | ||
| A base hook for Alibaba Cloud-related hooks. | ||
|
|
||
| This hook provides a common interface for authenticating using Alibaba Cloud credentials. | ||
|
|
||
| Supports Access Key-based authentication. | ||
|
|
||
| :param alibaba_cloud_conn_id: The connection ID to use when fetching connection info. | ||
| """ | ||
|
|
||
| conn_name_attr = "alibabacloud_conn_id" | ||
| default_conn_name = "alibabacloud_default" | ||
| conn_type = "alibaba_cloud" | ||
| hook_name = "Alibaba Cloud" | ||
|
|
||
| def __init__( | ||
| self, | ||
| alibabacloud_conn_id: str = "alibabacloud_default", | ||
| **kwargs, | ||
| ) -> None: | ||
| super().__init__(**kwargs) | ||
| self.alibaba_cloud_conn_id = alibabacloud_conn_id | ||
| self.extras: dict = self.get_connection(self.alibaba_cloud_conn_id).extra_dejson | ||
|
|
||
| @classmethod | ||
| def get_connection_form_widgets(cls) -> dict[str, Any]: | ||
| """Return connection widgets to add to connection form.""" | ||
| from flask_appbuilder.fieldwidgets import BS3PasswordFieldWidget | ||
| from flask_babel import lazy_gettext | ||
| from wtforms import PasswordField | ||
|
|
||
| return { | ||
| "access_key_id": PasswordField(lazy_gettext("Access Key ID"), widget=BS3PasswordFieldWidget()), | ||
| "access_key_secret": PasswordField( | ||
| lazy_gettext("Access Key Secret"), widget=BS3PasswordFieldWidget() | ||
| ), | ||
| } | ||
|
|
||
| @classmethod | ||
| def get_ui_field_behaviour(cls) -> dict[str, Any]: | ||
| """Return custom field behaviour.""" | ||
| return super().get_ui_field_behaviour() | ||
|
|
||
| def _get_field(self, field_name: str, default: Any = None) -> Any: | ||
| """Fetch a field from extras, and returns it.""" | ||
| value = self.extras.get(field_name) | ||
| return value if value is not None else default | ||
|
|
||
| def get_access_key_credential(self) -> AccessKeyCredentials: | ||
| """ | ||
| Fetch Access Key Credential for authentication. | ||
|
|
||
| :return: AccessKeyCredentials object containing access_key_id and access_key_secret. | ||
| """ | ||
| access_key_id = self._get_field("access_key_id", None) | ||
| access_key_secret = self._get_field("access_key_secret", None) | ||
| if not access_key_id: | ||
| raise ValueError("No access_key_id is specified.") | ||
|
|
||
| if not access_key_secret: | ||
| raise ValueError("No access_key_secret is specified.") | ||
|
|
||
| return AccessKeyCredentials(access_key_id, access_key_secret) | ||
Oops, something went wrong.
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.