-
Notifications
You must be signed in to change notification settings - Fork 17.3k
Add Open Search Provider #34705
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
Add Open Search Provider #34705
Changes from 36 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
9a18ce6
Create Chime Notifier
cjames23 6e45261
Rename chime notifier test file
cjames23 5df0196
Create open search hook and operators for search, index, and add docu…
cjames23 1cbca1e
Merge branch 'apache:main' into open-search-integrations
cjames23 851c3ab
Fix system test, connection name, missing provider.yaml info and add …
cjames23 4bafbeb
Merge branch 'apache:main' into open-search-integrations
cjames23 e595762
Create opensearch provider and hook as base for amazon open search hook
cjames23 1abf3a5
Create OpenSearch provider to enable AWS OpenSearch functionality see…
cjames23 d698c56
Merge branch 'apache:main' into open-search-provider
cjames23 ec03b37
Remove aws open search files
cjames23 48d9511
Remove reference to opensearch provider
cjames23 94cd468
Fix docs for OpenSearch
cjames23 4fc313e
Merge branch 'main' into open-search-provider
hussein-awala c5f8fd5
Merge branch 'main' into open-search-provider
cjames23 830a49d
Fix type for OpenSearchAddDocumentOperator
cjames23 46dfd29
Merge branch 'main' into open-search-provider
cjames23 fa721c6
Fix ruff errors for documentation, amazon provider linter issue. Add …
cjames23 f3b8d77
Merge branch 'main' into open-search-provider
cjames23 19da2e0
Fix documentation for OpenSearch provider
cjames23 1f92e16
Fix breeze cmds regenerated.
cjames23 09d6969
Fix opensearch example dag spelling error
cjames23 8e45bf3
Merge branch 'main' into open-search-provider
cjames23 0fa59c1
Fix old amazon providers.yaml ref, req 2.5 airflow for open search
cjames23 566da22
Fix open search logo location
cjames23 6855af9
Merge branch 'main' into open-search-provider
cjames23 681ca93
Add open search to bug report. Fix open search example dag.
cjames23 61aca32
Add licenses to inits in open search provider
cjames23 1436960
Merge branch 'main' into open-search-provider
cjames23 1aa8726
Use opensearch base exception class in operators. Fix documentation c…
cjames23 b071121
Update airflow/providers/opensearch/hooks/opensearch.py doc string.
cjames23 5de3a33
Turn connection into cached property in opensearch hook
cjames23 652f674
Merge branch 'main' into open-search-provider
cjames23 fa7266e
Update tests/providers/opensearch/hooks/test_opensearch.py move hook …
cjames23 d191184
Fix misspelling in connection, add dag fixture to tests/providers/ope…
cjames23 4fdfaf3
Merge branch 'main' into open-search-provider
cjames23 7449ba2
Fix formatting of opensearch hook tests
cjames23 858ca52
Merge branch 'main' into open-search-provider
cjames23 0f12c90
Merge branch 'apache:main' into open-search-provider
cjames23 a6f0b1b
Fix output-commands-hast.txt
cjames23 9ae9807
rename OpenSearchHook get_client to client.
cjames23 6ad4533
Merge branch 'main' into open-search-provider
cjames23 c8f731b
Merge branch 'main' into open-search-provider
cjames23 6f40db4
Remove provider.yaml changes from PR
cjames23 88a7d7e
Merge branch 'main' into open-search-provider
cjames23 475232c
Fix OpenSearch provider conf.test client ref
cjames23 b9896ac
Merge branch 'main' into open-search-provider
cjames23 2983447
Merge branch 'main' into open-search-provider
cjames23 dd1a47f
Fix breeze command images
cjames23 36c9393
Fix conftest.py for OpenSearch Provider, change from get_client to cl…
cjames23 afcee3e
Merge branch 'main' into open-search-provider
cjames23 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ body: | |
| - odbc | ||
| - openfaas | ||
| - openlineage | ||
| - opensearch | ||
| - opsgenie | ||
| - oracle | ||
| - pagerduty | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| .. 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 TO CONTRIBUTORS: | ||
| Please, only add notes to the Changelog just below the "Changelog" header when there are some breaking changes | ||
| and you want to add an explanation to the users on how they are supposed to deal with them. | ||
| The changelog is updated and maintained semi-automatically by release manager. | ||
|
|
||
| ``apache-airflow-providers-opensearch`` | ||
|
|
||
| Changelog | ||
| --------- |
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,16 @@ | ||
| # 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 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,16 @@ | ||
| # 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 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,122 @@ | ||
| # | ||
| # 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 json | ||
| from functools import cached_property | ||
| from typing import Any | ||
|
|
||
| from opensearchpy import OpenSearch, RequestsHttpConnection | ||
|
|
||
| from airflow.exceptions import AirflowException | ||
| from airflow.hooks.base import BaseHook | ||
|
|
||
|
|
||
| class OpenSearchHook(BaseHook): | ||
| """ | ||
| Provide a thin wrapper around the OpenSearch client. | ||
|
|
||
| :param: open_search_conn_id: Connection to use with Open Search | ||
| :param: log_query: Whether to log the query used for Open Search | ||
| """ | ||
|
|
||
| conn_name_attr = "opensearch_conn_id" | ||
| default_conn_name = "opensearch_default" | ||
| conn_type = "opensearch" | ||
| hook_name = "OpenSearch Hook" | ||
|
|
||
| def __init__(self, open_search_conn_id: str, log_query: bool, **kwargs: Any): | ||
| super().__init__(**kwargs) | ||
| self.conn_id = open_search_conn_id | ||
| self.log_query = log_query | ||
|
|
||
| self.use_ssl = self.conn.extra_dejson.get("use_ssl", False) | ||
| self.verify_certs = self.conn.extra_dejson.get("verify_certs", False) | ||
| self.__SERVICE = "es" | ||
|
|
||
| @cached_property | ||
| def conn(self): | ||
| return self.get_connection(self.conn_id) | ||
|
|
||
| @cached_property | ||
| def get_client(self) -> OpenSearch: | ||
| """This function is intended for Operators that forward high level client objects.""" | ||
| auth = (self.conn.login, self.conn.password) | ||
| client = OpenSearch( | ||
| hosts=[{"host": self.conn.host, "port": self.conn.port}], | ||
| http_auth=auth, | ||
| use_ssl=self.use_ssl, | ||
| verify_certs=self.verify_certs, | ||
| connection_class=RequestsHttpConnection, | ||
| ) | ||
| return client | ||
|
|
||
| def search(self, query: dict, index_name: str, **kwargs: Any) -> Any: | ||
| """ | ||
| Run a search query against the connected OpenSearch cluster. | ||
|
|
||
| :param: query: The query for the search against OpenSearch. | ||
| :param: index_name: The name of the index to search against | ||
| """ | ||
| if self.log_query: | ||
| self.log.info("Searching %s with Query: %s", index_name, query) | ||
| return self.get_client.search(body=query, index=index_name, **kwargs) | ||
|
|
||
| def index(self, document: dict, index_name: str, doc_id: int, **kwargs: Any) -> Any: | ||
| """ | ||
| Index a document on OpenSearch. | ||
|
|
||
| :param: document: A dictionary representation of the document | ||
| :param: index_name: the name of the index that this document will be associated with | ||
| :param: doc_id: the numerical identifier that will be used to identify the document on the index. | ||
| """ | ||
| return self.get_client.index(index=index_name, id=doc_id, body=document, **kwargs) | ||
|
|
||
| def delete(self, index_name: str, query: dict | None = None, doc_id: int | None = None) -> Any: | ||
| """ | ||
| Delete from an index by either a query or by the document id. | ||
|
|
||
| :param: index_name: the name of the index to delete from | ||
| :param: query: If deleting by query a dict representation of the query to run to | ||
| identify documents to delete. | ||
| :param: doc_id: The identifier of the document to delete. | ||
| """ | ||
| if query is not None: | ||
| if self.log_query: | ||
| self.log.info("Deleting from %s using Query: %s", index_name, query) | ||
| return self.get_client.delete_by_query(index=index_name, body=query) | ||
| elif doc_id is not None: | ||
| return self.get_client.delete(index=index_name, id=doc_id) | ||
| else: | ||
| AirflowException("To delete a document you must include one of either a query or a document id. ") | ||
|
|
||
| @staticmethod | ||
| def get_ui_field_behaviour() -> dict[str, Any]: | ||
| """Returns custom UI field behaviour for Open Search Connection.""" | ||
| return { | ||
| "hidden_fields": ["schema"], | ||
| "relabeling": { | ||
| "extra": "Open Search Configuration", | ||
| }, | ||
| "placeholders": { | ||
| "extra": json.dumps( | ||
| {"use_ssl": True, "verify_certs": True}, | ||
| indent=2, | ||
| ), | ||
| }, | ||
| } | ||
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,16 @@ | ||
| # 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. |
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.