Skip to content

Commit

Permalink
Merge pull request opensciencegrid#3900 from matyasselmeci/pr/product…
Browse files Browse the repository at this point in the history
…ion-in-namespaces-json.SOFTWARE-5862

Add "production" boolean to resources in namespaces JSON (SOFTWARE-5862)
  • Loading branch information
matyasselmeci authored May 17, 2024
2 parents 4dfa76b + 793fdb0 commit 76200bf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ Each cache in the list contains the following attributes:
- `endpoint`: The `<HOST>:<PORT>` of the public (`xrootd@stash-cache`) service
- `auth_endpoint`: The `<HOST>:<PORT>` of the authenticated (`xrootd@stash-cache-auth`) service
- `resource`: The resource name of the cache.
- `production`: true if the resource is in "production" (as opposed to ITB)

The JSON also contains an attribute `namespaces` that is a list of namespaces with the following attributes:
- `path` is the path of the namespace
Expand Down Expand Up @@ -553,11 +554,13 @@ The final result looks like
{
"auth_endpoint": "osg-gftp.pace.gatech.edu:8443",
"endpoint": "osg-gftp.pace.gatech.edu:8000",
"production": true,
"resource": "Georgia_Tech_PACE_GridFTP"
},
{
"auth_endpoint": "osg-gftp2.pace.gatech.edu:8443",
"endpoint": "osg-gftp2.pace.gatech.edu:8000",
"production": true,
"resource": "Georgia_Tech_PACE_GridFTP2"
}
],
Expand All @@ -567,6 +570,7 @@ The final result looks like
{
"auth_endpoint": "rds-cache.sdsc.edu:8443",
"endpoint": "rds-cache.sdsc.edu:8000",
"production": true,
"resource": "RDS_AUTH_OSDF_CACHE"
}
],
Expand Down
12 changes: 11 additions & 1 deletion src/stashcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,17 @@ def _service_resource_dict(
if not is_null(svc, "Details", "auth_endpoint_override"):
auth_endpoint = svc["Details"]["auth_endpoint_override"]
break
return {"endpoint": endpoint, "auth_endpoint": auth_endpoint, "resource": r.name}
production = None
try:
production = bool(r.rg.production)
except AttributeError:
pass
return {
"endpoint": endpoint,
"auth_endpoint": auth_endpoint,
"resource": r.name,
"production": production,
}

def _cache_resource_dict(r: Resource):
return _service_resource_dict(r=r, service_name=XROOTD_CACHE_SERVER, auth_port_default=8443, unauth_port_default=8000)
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,8 @@ class TestEndpointContent:
},
'Tags': ['CC*']
}
mock_resource = Resource("AMNH-ARES", mock_resource_information, global_data.get_topology().common_data)
mock_resource = Resource("AMNH-ARES", mock_resource_information, global_data.get_topology().common_data,
mock_resource_group)

mock_facility.add_site(mock_site)
mock_site.add_resource_group(mock_resource_group)
Expand Down
2 changes: 2 additions & 0 deletions src/tests/test_stashcache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from configparser import ConfigParser
import copy

import flask
import pytest
import re
Expand Down Expand Up @@ -279,6 +280,7 @@ def validate_cache_schema(cc):
assert HOST_PORT_RE.match(cc["auth_endpoint"])
assert HOST_PORT_RE.match(cc["endpoint"])
assert cc["resource"] and isinstance(cc["resource"], str)
assert "production" in cc and isinstance(cc["production"], (type(None), bool))

@staticmethod
def validate_namespace_schema(ns):
Expand Down
11 changes: 6 additions & 5 deletions src/webapp/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def is_ccstar(self):
return self._is_ccstar

class Resource(object):
def __init__(self, name: str, yaml_data: ParsedYaml, common_data: CommonData):
def __init__(self, name: str, yaml_data: ParsedYaml, common_data: CommonData, rg: "ResourceGroup"):
self.name = name
self.service_types = common_data.service_types
self.common_data = common_data
Expand All @@ -124,6 +124,7 @@ def __init__(self, name: str, yaml_data: ParsedYaml, common_data: CommonData):
raise ValueError(f"Resource {name} does not have an FQDN")
self.fqdn = self.data["FQDN"]
self.id = self.data["ID"]
self.rg = rg

def get_stashcache_files(self, global_data, legacy):
"""Gets a resources Cache files as a dictionary"""
Expand Down Expand Up @@ -378,14 +379,14 @@ def __init__(self, name: str, yaml_data: ParsedYaml, site: Site, common_data: Co
self.support_center = OrderedDict([("ID", scid), ("Name", scname)])

self.resources_by_name = {}
for name, res in yaml_data["Resources"].items():
for res_name, res in yaml_data["Resources"].items():
try:
if not isinstance(res, dict):
raise TypeError("expecting a dict")
res_obj = Resource(name, ParsedYaml(res), self.common_data)
self.resources_by_name[name] = res_obj
res_obj = Resource(res_name, ParsedYaml(res), self.common_data, rg=self)
self.resources_by_name[res_name] = res_obj
except (AttributeError, KeyError, TypeError, ValueError) as err:
log.exception("Error with resource %s: %r", name, err)
log.exception("Error with resource %s: %r", res_name, err)
continue

self.data = yaml_data
Expand Down

0 comments on commit 76200bf

Please sign in to comment.