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

CASMCMS-8941: Break up large CFS component queries to avoid failures #255

Merged
merged 1 commit into from
Mar 8, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.10.6] - 2024-03-07
### Fixed
- Break up large CFS component queries to avoid errors

## [2.10.5] - 2024-03-04
### Fixed
- Corrected minor errors in a couple description fields in API spec (no functional impact)
Expand Down
8 changes: 4 additions & 4 deletions src/bos/operators/filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# MIT License
#
# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP
# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -31,7 +31,7 @@
from bos.common.utils import get_current_time, load_timestamp
from bos.operators.filters.base import BaseFilter, DetailsFilter, IDFilter, LocalFilter
from bos.operators.utils.clients.bos import BOSClient
from bos.operators.utils.clients.cfs import get_components as get_cfs_components
from bos.operators.utils.clients.cfs import get_components_from_id_list as get_cfs_components_from_id_list
from bos.operators.utils.clients.hsm import get_components as get_hsm_components

LOGGER = logging.getLogger('bos.operators.filters.filters')
Expand Down Expand Up @@ -198,8 +198,8 @@ def __init__(self):
super().__init__()

def _filter(self, components: List[dict]) -> List[dict]:
component_ids = ','.join([component['id'] for component in components])
cfs_components = get_cfs_components(ids=component_ids)
component_ids = [component['id'] for component in components]
cfs_components = get_cfs_components_from_id_list(id_list=component_ids)
self.cfs_components_dict = {component['id']: component for component in cfs_components}
matches = LocalFilter._filter(self, components)
# Clear this, so there are no lingering side-effects of running this method.
Expand Down
14 changes: 13 additions & 1 deletion src/bos/operators/utils/clients/cfs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# MIT License
#
# (C) Copyright 2021-2023 Hewlett Packard Enterprise Development LP
# (C) Copyright 2021-2024 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -33,6 +33,7 @@

LOGGER = logging.getLogger('bos.operators.utils.clients.cfs')

GET_BATCH_SIZE = 200
PATCH_BATCH_SIZE = 1000


Expand All @@ -59,6 +60,17 @@ def patch_components(data, session=None):
raise


def get_components_from_id_list(id_list):
session = requests_retry_session()
component_list = []
while id_list:
next_batch = id_list[:GET_BATCH_SIZE]
next_comps = get_components(session=session, ids=','.join(next_batch))
component_list.extend(next_comps)
id_list = id_list[GET_BATCH_SIZE:]
return component_list


def patch_desired_config(node_ids, desired_config, enabled=False, tags=None, clear_state=False):
session = requests_retry_session()
data = []
Expand Down
Loading