Skip to content

Commit

Permalink
Add get_resource_status rule and use it in older rules [DHDO-1371]
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlinssen committed Jul 2, 2024
1 parent 659a891 commit 487ada5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
3 changes: 1 addition & 2 deletions datahubirodsruleset/drop_zones/get_active_drop_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def get_active_drop_zone(ctx, token, check_ingest_resource_status, dropzone_type
project_path, ProjectAVUs.RESOURCE.value, "*resource", "", TRUE_AS_STRING
)["arguments"][2]
# Query the resource status
for resc_result in row_iterator("RESC_STATUS", "RESC_NAME = '{}'".format(resource), AS_LIST, ctx.callback):
avu["resourceStatus"] = resc_result[0]
avu["resourceStatus"] = ctx.callback.get_resource_status(resource, "")["arguments"][1]

avu["percentage_ingested"] = get_drop_zone_percentage_ingested(ctx, avu)

Expand Down
17 changes: 3 additions & 14 deletions datahubirodsruleset/projects/get_project_resource_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,24 @@ def get_project_resource_availability(
ingest_resource = ctx.callback.getCollectionAVU(
project_path, ProjectAVUs.INGEST_RESOURCE.value, "", "", TRUE_AS_STRING
)["arguments"][2]
ingest_status = get_resource_status(ctx, ingest_resource)
ingest_status = ctx.callback.get_resource_status(ingest_resource, "")["arguments"][1] != "down"

destination_status = False
if check_destination_resource:
destination_resource = ctx.callback.getCollectionAVU(
project_path, ProjectAVUs.RESOURCE.value, "", "", TRUE_AS_STRING
)["arguments"][2]
destination_status = get_resource_status(ctx, destination_resource)
destination_status = ctx.callback.get_resource_status(destination_resource, "")["arguments"][1] != "down"

archive_status = False
if check_archive_resource:
archive_resource = ctx.callback.getCollectionAVU(
project_path, ProjectAVUs.ARCHIVE_DESTINATION_RESOURCE.value, "", "", TRUE_AS_STRING
)["arguments"][2]
archive_status = get_resource_status(ctx, archive_resource)
archive_status = ctx.callback.get_resource_status(archive_resource, "")["arguments"][1] != "down"

return (
check_ingest_resource is ingest_status
and check_destination_resource is destination_status
and check_archive_resource is archive_status
)


# TODO move to its own file
def get_resource_status(ctx, resource_name):
for result in row_iterator(
"RESC_STATUS",
"RESC_NAME = '{}'".format(resource_name),
AS_LIST,
ctx.callback,
):
return result[0] != "down"
1 change: 1 addition & 0 deletions datahubirodsruleset/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This sub-package contains the rules related to DataHub resources (ingest & destination)"""
# Public rules
from datahubirodsruleset.resources.get_resource_size_for_all_collections import get_resource_size_for_all_collections
from datahubirodsruleset.resources.get_resource_status import get_resource_status

# Private rules
from datahubirodsruleset.resources.get_direct_ingest_resource_host import get_direct_ingest_resource_host
23 changes: 23 additions & 0 deletions datahubirodsruleset/resources/get_resource_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# /rules/tests/run_test.sh -r get_resource_status -a "replRescUM01" -j
from genquery import row_iterator, AS_LIST # pylint: disable=import-error

from datahubirodsruleset.decorator import make, Output


@make(inputs=[0], outputs=[1], handler=Output.STORE)
def get_resource_status(ctx, resource_name):
"""
Queries the resources to get the resource host of the resc that has the directIngestResc AVU
Returns
-------
str:
The direct ingest resource host
"""
for result in row_iterator(
"RESC_STATUS",
"RESC_NAME = '{}'".format(resource_name),
AS_LIST,
ctx.callback,
):
return result[0]

0 comments on commit 487ada5

Please sign in to comment.