From 12128584d99499eeddc8e8396103da1e749ebcca Mon Sep 17 00:00:00 2001 From: i318829 Date: Tue, 16 Nov 2021 10:07:12 +0530 Subject: [PATCH 1/2] Business Blueprint API Support. --- sap/aibus/dar/client/model_manager_client.py | 24 +++++++++++++++++ .../dar/client/model_manager_constants.py | 27 +++++++++++++++++++ .../dar/client/test_model_manager_client.py | 24 +++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/sap/aibus/dar/client/model_manager_client.py b/sap/aibus/dar/client/model_manager_client.py index 580691e..b2324fc 100644 --- a/sap/aibus/dar/client/model_manager_client.py +++ b/sap/aibus/dar/client/model_manager_client.py @@ -617,3 +617,27 @@ def is_deployment_failed(deployment_resource: dict): DeploymentStatus.STOPPED.value, DeploymentStatus.FAILED.value, ] + + def read_business_blueprint_template_collection(self) -> dict: + """ + Reads the collection of BusinessBlueprint Template. + :return: BusinessBlueprint collection as dict + """ + response = self.session.get_from_endpoint( + ModelManagerPaths.ENDPOINT_BUSINESS_BLUEPRINT_TEMPLATE_COLLECTION + ) + return response.json() + + def read_business_blueprint_template_by_id( + self, business_blueprint_id: str + ) -> dict: + """ + Reads the BusinessBlueprintTemplate with the given *business_blueprint_id*. + :param business_blueprint_id: ID of the BusinessBlueprint to be retrieved + :return: a single BusinessBlueprintTemplate as dict + """ + endpoint = ModelManagerPaths.format_business_blueprint_endpoint_by_id( + business_blueprint_id + ) + response = self.session.get_from_endpoint(endpoint) + return response.json() diff --git a/sap/aibus/dar/client/model_manager_constants.py b/sap/aibus/dar/client/model_manager_constants.py index e34b795..07b5062 100644 --- a/sap/aibus/dar/client/model_manager_constants.py +++ b/sap/aibus/dar/client/model_manager_constants.py @@ -64,6 +64,11 @@ class ModelManagerPaths: #: Path for the Deployment collection ENDPOINT_DEPLOYMENT_COLLECTION = "/model-manager/api/v3/deployments" + #: Path for the BusinessBlueprint collection + ENDPOINT_BUSINESS_BLUEPRINT_TEMPLATE_COLLECTION = ( + "/model-manager/api/v3/businessBlueprints" + ) + @classmethod def format_model_templates_endpoint_by_id(cls, model_template_id: str) -> str: # How can I fix the formatting of the doctest below without introducing a lot @@ -128,3 +133,25 @@ def format_deployment_endpoint_by_id(cls, deployment_id: str): :return: endpoint, to be used as URL component """ return cls.ENDPOINT_DEPLOYMENT_COLLECTION + "/" + deployment_id + + @classmethod + def format_business_blueprint_endpoint_by_id( + cls, business_blueprint_id: str + ) -> str: + """ + Returns the path of a BusinessBlueprintTemplate with given identifier. + + .. doctest:: + + >>> ModelManagerPaths.format_business_blueprint_endpoint_by_id(\ +'4788254b-0bad-4757-a67f-92d5b55f322d') + '/model-manager/api/v3/businessBlueprints/4788254b-0bad-4757-a67f-92d5b55f322d' + + :param business_blueprint_id: identifier of BusinessBlueprintTemplate + :return: endpoint, to be used as URL component + """ + return ( + cls.ENDPOINT_BUSINESS_BLUEPRINT_TEMPLATE_COLLECTION + + "/" + + business_blueprint_id + ) diff --git a/tests/sap/aibus/dar/client/test_model_manager_client.py b/tests/sap/aibus/dar/client/test_model_manager_client.py index 5672ffa..50343f6 100644 --- a/tests/sap/aibus/dar/client/test_model_manager_client.py +++ b/tests/sap/aibus/dar/client/test_model_manager_client.py @@ -954,3 +954,27 @@ def test_deployment_exists_and_is_unhealthy( assert mock_create.call_args_list == [call(model_name)] assert response == mock_create.return_value + + +class TestModelManagerClientBusinessBlueprintTemplate: + def test_read_model_template_collection(self, model_manager_client): + response = model_manager_client.read_business_blueprint_template_collection() + assert_get_response_is_json(model_manager_client, response) + expected_endpoint = "/model-manager/api/v3/businessBlueprints" + assert_get_from_endpoint_called_with_endpoint( + model_manager_client, expected_endpoint + ) + + def test_read_model_template_by_id(self, model_manager_client): + business_blueprint_id = "4788254b-0bad-4757-a67f-92d5b55f322d" + + response = model_manager_client.read_business_blueprint_template_by_id( + "4788254b-0bad-4757-a67f-92d5b55f322d" + ) + assert_get_response_is_json(model_manager_client, response) + expected_endpoint = "/model-manager/api/v3/businessBlueprints/{}".format( + business_blueprint_id + ) + assert_get_from_endpoint_called_with_endpoint( + model_manager_client, expected_endpoint + ) From eac7b1dbe71f199ddabee98b8b9478371add100d Mon Sep 17 00:00:00 2001 From: i318829 Date: Tue, 16 Nov 2021 12:16:15 +0530 Subject: [PATCH 2/2] Updating version and change.log --- CHANGELOG.md | 13 ++++++++++++- version.txt | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 728b947..4f7bd7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.9.1] + +### Added + +* Support for Business Blueprint API. [#118] + * This feature is **not supported** in DAR service yet, it is added for internal testing purposes. + * `read_business_blueprint_template_collection` method to list business blueprint templates collection. + * `read_business_blueprint_template_by_id` method to fetch information of a specific business blueprint template for the given business_blueprint_id + +[#118]: https://github.com/SAP/data-attribute-recommendation-python-sdk/pull/118 ## [0.9.0] @@ -215,7 +225,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * First public release -[Unreleased]: https://github.com/SAP/data-attribute-recommendation-python-sdk/compare/rel/0.9.0...HEAD +[Unreleased]: https://github.com/SAP/data-attribute-recommendation-python-sdk/compare/rel/0.9.1...HEAD +[0.9.1]: https://github.com/SAP/data-attribute-recommendation-python-sdk/compare/rel/0.9.0...rel/0.9.1 [0.9.0]: https://github.com/SAP/data-attribute-recommendation-python-sdk/compare/rel/0.8.2...rel/0.9.0 [0.8.2]: https://github.com/SAP/data-attribute-recommendation-python-sdk/compare/rel/0.8.1...rel/0.8.2 [0.8.1]: https://github.com/SAP/data-attribute-recommendation-python-sdk/compare/rel/0.8.0...rel/0.8.1 diff --git a/version.txt b/version.txt index ac39a10..f374f66 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.9.0 +0.9.1