Skip to content
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

Create external connector and local connector #325

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions opensearch_py_ml/ml_commons/ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,63 @@ def delete_task(self, task_id: str) -> object:
method="DELETE",
url=API_URL,
)

def create_connector(self, connector_payload: dict) -> dict:
"""
This method creates a connector in the OpenSearch cluster using the ml-common plugin's API.

:param connector_payload: Dictionary containing the details of the connector.
:type connector_payload: dict
:return: API response
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors/_create"
return self._client.transport.perform_request(
method="POST",
url=API_URL,
body=connector_payload,
)

def delete_connector(self, connector_id: str) -> dict:
"""
This method deletes a specific connector using its ID.

:param connector_id: ID of the connector to be deleted.
:type connector_id: str
:return: API response
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors/{connector_id}"
return self._client.transport.perform_request(
method="DELETE",
url=API_URL,
)

def list_connectors(self) -> dict:
"""
This method lists all connectors in the OpenSearch cluster.

:return: API response containing a list of connectors.
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors"
return self._client.transport.perform_request(
method="GET",
url=API_URL,
)

def search_connectors(self, search_payload: dict) -> dict:
"""
This method searches for connectors based on specific criteria.

:param search_payload: Dictionary containing search criteria.
:type search_payload: dict
:return: API response containing search results.
:rtype: dict
"""
API_URL = f"{ML_BASE_URI}/connectors/_search"
return self._client.transport.perform_request(
method="POST",
url=API_URL,
body=search_payload,
)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"pandas>=1.5,<3",
"matplotlib>=3.6.0,<4",
"numpy>=1.24.0,<2",
"deprecated",
],
python_requires=">=3.8",
package_data={"opensearch_py_ml": ["py.typed"]},
Expand Down
6 changes: 5 additions & 1 deletion tests/ml_commons/test_ml_commons_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
# GitHub history for details.

import os
import subprocess
import shutil
import time
from json import JSONDecodeError
from os.path import exists
import sys

import pytest
from opensearchpy import OpenSearch, helpers
Expand Down Expand Up @@ -385,7 +387,7 @@ def test_DEPRECATED_integration_model_train_upload_full_cycle():
except: # noqa: E722
raised = True
assert raised == False, "Raised Exception in deleting model"


def test_integration_model_train_register_full_cycle():
# first training the model with small epoch
Expand Down Expand Up @@ -510,6 +512,8 @@ def test_integration_model_train_register_full_cycle():
raised = True
assert raised == False, "Raised Exception in deleting model"




def test_search():
# Search task cases
Expand Down
Loading