2022-10-04 00:15:18 +05:30
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.
import warnings
2023-11-06 13:08:19 -05:00
from typing import Any
2022-10-04 00:15:18 +05:30
from . . plugins . alerting import AlertingClient
2023-06-28 22:56:00 +02:00
from . . plugins . index_management import IndexManagementClient
2024-03-22 16:40:18 -04:00
from . . plugins . knn import KnnClient
2024-06-17 15:33:14 -07:00
from . . plugins . ml import MlClient
2024-04-17 16:22:14 -07:00
from . . plugins . notifications import NotificationsClient
2024-08-14 18:25:01 -04:00
from . . plugins . observability import ObservabilityClient
from . . plugins . ppl import PplClient
from . . plugins . query import QueryClient
2024-05-15 09:55:45 -07:00
from . . plugins . rollups import RollupsClient
2024-08-14 18:25:01 -04:00
from . . plugins . sql import SqlClient
2024-05-22 08:30:08 -07:00
from . . plugins . transforms import TransformsClient
2023-11-06 13:08:19 -05:00
from . client import Client
2022-10-04 00:15:18 +05:30
from . utils import NamespacedClient
class PluginsClient ( NamespacedClient ) :
2023-11-06 13:08:19 -05:00
alerting : Any
index_management : Any
def __init__ ( self , client : Client ) - > None :
2024-07-20 23:19:20 +03:00
super ( ) . __init__ ( client )
2024-08-14 18:25:01 -04:00
2022-10-04 00:15:18 +05:30
self . alerting = AlertingClient ( client )
2023-06-28 22:56:00 +02:00
self . index_management = IndexManagementClient ( client )
2024-08-14 18:25:01 -04:00
self . knn = KnnClient ( client )
self . ml = MlClient ( client )
self . notifications = NotificationsClient ( client )
self . observability = ObservabilityClient ( client )
self . ppl = PplClient ( client )
self . query = QueryClient ( client )
self . rollups = RollupsClient ( client )
self . sql = SqlClient ( client )
self . transforms = TransformsClient ( client )
2022-10-04 00:15:18 +05:30
self . _dynamic_lookup ( client )
2023-11-06 13:08:19 -05:00
def _dynamic_lookup ( self , client : Any ) - > None :
2022-10-04 00:15:18 +05:30
# Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742
plugins = [
# "query_workbench",
# "reporting",
# "notebooks",
" alerting " ,
# "anomaly_detection",
# "trace_analytics",
2023-06-28 22:56:00 +02:00
" index_management " ,
2022-10-04 00:15:18 +05:30
]
for plugin in plugins :
if not hasattr ( client , plugin ) :
setattr ( client , plugin , getattr ( self , plugin ) )
else :
warnings . warn (
2023-10-26 12:30:23 -04:00
f " Cannot load ` { plugin } ` directly to { self . client . __class__ . __name__ } as it already exists. Use ` { self . client . __class__ . __name__ } .plugin. { plugin } ` instead. " ,
2022-10-04 00:15:18 +05:30
category = RuntimeWarning ,
stacklevel = 2 ,
)