Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Incorporated PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Kartik Ganesh <[email protected]>
  • Loading branch information
kartg committed Jan 24, 2024
1 parent 917f273 commit aaf3761
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions FetchMigration/python/index_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ def doc_count(indices: set, endpoint: EndpointInfo) -> IndexDocCount:
def __fetch_templates(endpoint: EndpointInfo, path: str, root_key: str, factory) -> set:
url: str = endpoint.add_path(path)
# raises RuntimeError in case of any request errors
resp = __send_get_request(url, endpoint)
result = set()
if root_key in resp.json():
for template in resp.json()[root_key]:
result.add(factory(template))
return result
try:
resp = __send_get_request(url, endpoint)
result = set()
if root_key in resp.json():
for template in resp.json()[root_key]:
result.add(factory(template))
return result
except RuntimeError as e:
# Chain the underlying exception as a cause
raise RuntimeError("Failed to fetch template metadata from cluster endpoint") from e


def fetch_all_component_templates(endpoint: EndpointInfo) -> set[ComponentTemplateInfo]:
Expand All @@ -131,7 +135,7 @@ def fetch_all_component_templates(endpoint: EndpointInfo) -> set[ComponentTempla
return __fetch_templates(endpoint, __COMPONENT_TEMPLATES_PATH, __COMPONENT_TEMPLATE_LIST_KEY,
lambda t: ComponentTemplateInfo(t))
except RuntimeError as e:
raise RuntimeError(f"Failed to fetch component template metadata from cluster endpoint: {e!s}")
raise RuntimeError("Failed to fetch component template metadata") from e


def fetch_all_index_templates(endpoint: EndpointInfo) -> set[IndexTemplateInfo]:
Expand All @@ -140,7 +144,7 @@ def fetch_all_index_templates(endpoint: EndpointInfo) -> set[IndexTemplateInfo]:
return __fetch_templates(endpoint, __INDEX_TEMPLATES_PATH, __INDEX_TEMPLATE_LIST_KEY,
lambda t: IndexTemplateInfo(t))
except RuntimeError as e:
raise RuntimeError(f"Failed to fetch index template metadata from cluster endpoint: {e!s}")
raise RuntimeError("Failed to fetch index template metadata") from e


def __create_templates(templates: set[ComponentTemplateInfo], endpoint: EndpointInfo, template_path: str) -> dict:
Expand Down

0 comments on commit aaf3761

Please sign in to comment.