Skip to content

Commit

Permalink
Merge pull request #2994 from matyasselmeci/pr/5440.5471.excludecaches
Browse files Browse the repository at this point in the history
OSDF namespaces JSON: exclude caches that are down or inactive
  • Loading branch information
matyasselmeci authored Mar 1, 2023
2 parents 8a98eec + 1e64351 commit 31ac99a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/stashcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,38 @@ def _namespace_dict(ns: Namespace):
}

for cache_name, cache_resource_obj in cache_resource_objs.items():
if resource_allows_namespace(cache_resource_obj, ns) and namespace_allows_cache_resource(ns, cache_resource_obj):
if (resource_allows_namespace(cache_resource_obj, ns) and
namespace_allows_cache_resource(ns, cache_resource_obj)):
nsdict["caches"].append(cache_resource_dicts[cache_name])
return nsdict

def _resource_has_downed_cache(r: Resource, t: Topology):
if r.name not in t.present_downtimes_by_resource:
return False
downtimes = t.present_downtimes_by_resource[r.name]
for dt in downtimes:
try:
if XROOTD_CACHE_SERVER in dt.service_names:
return True
except (KeyError, AttributeError):
continue
return False

# End helper functions

resource_groups: List[ResourceGroup] = global_data.get_topology().get_resource_group_list()
topology = global_data.get_topology()
resource_groups: List[ResourceGroup] = topology.get_resource_group_list()
vos_data = global_data.get_vos_data()

cache_resource_objs = {} # type: Dict[str, Resource]
cache_resource_dicts = {} # type: Dict[str, Dict]

for group in resource_groups:
for resource in group.resources:
if _resource_has_cache(resource):
if (_resource_has_cache(resource)
and resource.is_active
and not _resource_has_downed_cache(resource, topology)
):
cache_resource_objs[resource.name] = resource
cache_resource_dicts[resource.name] = _cache_resource_dict(resource)

Expand Down
11 changes: 10 additions & 1 deletion src/webapp/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ def get_tree(self, authorized=False, filters: Filters = None) -> Optional[Ordere

return new_res

@property
def is_active(self):
"""Check if the Resource is active and not disabled"""
return self.data.get("Active", True) and not self.data.get("Disable", False)

@property
def is_ccstar(self):
"""Check if this site is tagged as a CC* Site"""
Expand Down Expand Up @@ -462,7 +467,8 @@ def __init__(self, rg: ResourceGroup, yaml_data: ParsedYaml, common_data: Common
self.created_time = None
if not is_null(yaml_data, "CreatedTime"):
self.created_time = self.parsetime(yaml_data["CreatedTime"])
self.res = rg.resources_by_name[yaml_data["ResourceName"]]
self.res_name = yaml_data["ResourceName"]
self.res = rg.resources_by_name[self.res_name]
self.service_names = yaml_data["Services"]
self.service_ids = [common_data.service_types[x] for x in yaml_data["Services"]]
self.id = yaml_data["ID"]
Expand Down Expand Up @@ -638,6 +644,7 @@ def __init__(self, common_data: CommonData):
self.service_names_by_resource = {} # type: Dict[str, List[str]]
self.downtime_path_by_resource_group = defaultdict(set)
self.downtime_path_by_resource = {}
self.present_downtimes_by_resource = defaultdict(list) # type: defaultdict[str, List[Downtime]]

def add_rg(self, facility_name: str, site_name: str, name: str, parsed_data: ParsedYaml):
try:
Expand Down Expand Up @@ -742,6 +749,8 @@ def add_downtime(self, sitename: str, rgname: str, downtime: ParsedYaml):
log.warning("Invalid or missing data in downtime -- skipping: %r", err)
return
self.downtimes_by_timeframe[dt.timeframe].append(dt)
if dt.timeframe == Timeframe.PRESENT:
self.present_downtimes_by_resource[dt.res_name].append(dt)

def safe_get_resource_by_fqdn(self, fqdn: str) -> Optional[Resource]:
"""Returns the first resource that has the given FQDN or None if no such resource exists."""
Expand Down

0 comments on commit 31ac99a

Please sign in to comment.