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

Ordering/selection for display purposes of Resources attached to Allocation #334

Closed
payerle opened this issue Nov 10, 2021 · 3 comments
Closed

Comments

@payerle
Copy link
Contributor

payerle commented Nov 10, 2021

If one has an allocation with multiple resources attached, there currently does not appear to be any way to control which Resource is used as the "parent" Resource or the ordering of the Resources for display purposes.

E.g., when listing the Allocations for a Project (ie the $WEBROOT/project/$PROJECT_ID page), the allocations will be shown with a Resource name and type, but this can be any of the Resources attached to the Allocation and it does not appear easy to control. It looks to me like this is controlled by Allocation.get_parent_resource, which seems to order the Resources by 'name' (from the Resource Meta subclass) and then filter out any which are not allocatable.
This means that the only means to control which Resource is picked up by the parent is by carefully choosing Resource names so that the desired Resource to be used is always alphabetically first, which is onerous.
(It also means that for the abnormal case wherein an Allocation has multiple Resources attached and none of the Resources are allocatable, exceptions will be raised in the web pages whenever trying to display that Allocation. While this admittedly is a problematic situation for other reasons, it should not cause exceptions to be raised just to display things)
Also, the get_resources_as_string appears to order things somewhat differently (i.e. is uses order_by '-is_allocatable', so allocatable
Resources come first, but any ordering among Resources with the same allocatability is up to the DB???), so that the first Resource in the get_resources_as_string() list is not necessarily the get_parent_resource().

Ideally, there would be some way to associate a priority to each Resource so one could force ResourceA to always come before/ be preferred as the get_parent_resource over ResourceB whenever both are in the list of Resources for an Allocation. The natural way would be with a ResourceAttribute, but I am not sure if the overhead of doing attribute lookups that frequently would be worthwhile.

As a simpler first step, I propose that a new setting ALLOCATION_RESOURCE_ORDERING be added, and that this value be used by both get_parent_resource() and get_resources_as_string() for ordering the Resources attached to an Allocation. The default value can be [ '-is_allocatable', 'name' ] which would mostly reproduce the existing behavior (it would make the two methods consistent, and because they previously were not necessarily consistent, there will some existing behavior which is not reproduced). It also will handle the admittedly abnormal case wherein an Allocation has multiple Resources attached which are all non-allocatable. A PR is forthcoming.

@dsajdak
Copy link
Contributor

dsajdak commented Nov 10, 2021

I agree with the problems detailed in this issue. It's been an annoyance that I have not yet bothered to document so I appreciate this! It would be convenient to be able to select the order displayed and not just count on alphabetical order.

@payerle
Copy link
Contributor Author

payerle commented Nov 11, 2021 via email

@aebruno
Copy link
Member

aebruno commented Jan 11, 2022

Fixed in #335

@aebruno aebruno closed this as completed Jan 11, 2022
@dsajdak dsajdak added this to Completed in Version 1.1.0 Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Version 1.1.0
Completed
Development

No branches or pull requests

3 participants