-
Notifications
You must be signed in to change notification settings - Fork 1
Add list-all-resources endpoint #7
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
base: add-list-resources-endpoint
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,57 @@ GET /api/resources/get-dependent-workloads?id=x86-ubuntu-18.04-img | |
| ] | ||
| ``` | ||
|
|
||
| ### 5. List All Resources by gem5 Version | ||
|
|
||
| **Endpoint**: `GET /api/resources/list-all-resources` | ||
|
|
||
| Retrieve all resources that are compatible with a specific gem5 version. The endpoint performs prefix matching, so a version like `25.0.0.1` will match resources that have `25.0` or `25.0.0` in their `gem5_versions` field. | ||
|
|
||
| **Parameters**: | ||
|
|
||
| - `gem5-version` (required): The gem5 version to match against (e.g., "23.0", "25.0.0.1") | ||
|
|
||
| **Examples**: | ||
|
|
||
| ```bash | ||
| # Get all resources compatible with gem5 version 23.0 | ||
| GET /api/resources/list-all-resources?gem5-version=23.0 | ||
|
|
||
| # Get all resources compatible with gem5 version 25.0.0.1 | ||
| # This will match resources with gem5_versions containing "25", "25.0", "25.0.0", or "25.0.0.1" | ||
| GET /api/resources/list-all-resources?gem5-version=25.0.0.1 | ||
| ``` | ||
|
|
||
| **Response Format**: | ||
|
|
||
| ```json | ||
| [ | ||
| { | ||
| "id": "riscv-ubuntu-20.04-boot", | ||
| "resource_version": "3.0.0", | ||
| "category": "workload", | ||
| "architecture": "RISCV", | ||
| "gem5_versions": ["23.0", "22.1", "22.0"], | ||
| // ... other resource fields | ||
| }, | ||
| { | ||
| "id": "arm-hello64-static", | ||
| "resource_version": "1.0.0", | ||
| "category": "binary", | ||
| "architecture": "ARM", | ||
| "gem5_versions": ["23.0", "22.0"], | ||
| // ... other resource fields | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| **Notes**: | ||
|
|
||
| - Uses prefix matching: a parameter like `25.0.0.1` matches resources with `25.0`, `25.0.0`, or `25.0.0.1` in their `gem5_versions` field | ||
| - Version parameter must have at least `major.minor` format (e.g., `23.0`, not just `23`) | ||
| - Returns all versions of resources that match | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it? Is that what we want? Shouldn't this return the more current compatible version of each resource. E.g., if Resource A version 1 and Resource A version 2 both state compatibility with the specified gem5 version then this function would return Resource A version 2 only. Version 1 has been replaced with something, presumably, better. I can't see a case you'd need an older version over the most current.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, currently we return all versions. |
||
| - Returns an empty list if no resources match the specified gem5 version | ||
|
|
||
| ## Development Setup | ||
|
|
||
| ### Prerequisites | ||
|
|
@@ -216,7 +267,8 @@ gem5-resources-api/ | |
| │ ├── get_resources_by_batch.py | ||
| │ ├── search_resources.py | ||
| │ ├── get_filters.py | ||
| │ └── get_dependent_workloads.py | ||
| │ ├── get_dependent_workloads.py | ||
| │ └── list_all_resources.py | ||
| ├── shared/ # Shared utilities | ||
| │ ├── database.py # Database connection & config | ||
| │ └── utils.py # Common utilities & validation | ||
|
|
@@ -244,6 +296,7 @@ Functions: | |
| search_resources: [GET] http://localhost:7071/api/resources/search | ||
| get_filters: [GET] http://localhost:7071/api/resources/filters | ||
| get_dependent_workloads: [GET] http://localhost:7071/api/resources/get-dependent-workloads | ||
| list_all_resources: [GET] http://localhost:7071/api/resources/list-all-resources | ||
| ``` | ||
|
|
||
| ### Testing | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Copyright (c) 2025 The Regents of the University of California | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| import json | ||
| import logging | ||
|
|
||
| import azure.functions as func | ||
|
|
||
| from shared.database import RESOURCE_FIELDS | ||
| from shared.utils import ( | ||
| create_error_response, | ||
| sanitize_version, | ||
| ) | ||
|
|
||
|
|
||
| def register_function(app, collection): | ||
| """Register the function with the app.""" | ||
|
|
||
| @app.function_name(name="list_all_resources") | ||
| @app.route( | ||
| route="resources/list-all-resources", | ||
| auth_level=func.AuthLevel.ANONYMOUS, | ||
| ) | ||
| def list_all_resources(req: func.HttpRequest) -> func.HttpResponse: | ||
| """ | ||
| Get all resources where a gem5 version in the resource is a prefix | ||
| of the specified version parameter. | ||
| Route: /resources/list-all-resources | ||
| Query Parameters: | ||
| - gem5-version: Required, the gem5 version to match against | ||
| (e.g., "25.0.0.1" will match resources with "25.0") | ||
| """ | ||
| logging.info( | ||
| "Processing request to list all resources by gem5 version" | ||
| ) | ||
| try: | ||
| gem5_version = req.params.get("gem5-version") | ||
|
|
||
| if not gem5_version: | ||
| return create_error_response( | ||
| 400, "'gem5-version' parameter is required" | ||
| ) | ||
|
|
||
| gem5_version = sanitize_version(gem5_version) | ||
|
|
||
| if not gem5_version: | ||
| return create_error_response( | ||
| 400, "Invalid 'gem5-version' parameter format" | ||
| ) | ||
|
|
||
| # Build a list of all possible prefixes from the version | ||
| # Starting from major.minor since gem5 versions always have at | ||
| # least one dot (e.g., "25.0", "23.1") | ||
| # e.g., "25.0.0.1" -> ["25.0", "25.0.0", "25.0.0.1"] | ||
| version_parts = gem5_version.split(".") | ||
| prefixes = [] | ||
| for i in range(2, len(version_parts) + 1): | ||
| prefixes.append(".".join(version_parts[:i])) | ||
|
Comment on lines
+60
to
+67
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have any real reason to search for compatibility with minor and hotfix values? It kind of makes things more complex. Are there any resources that express compatibility beyond the gem5 major versions? This is more me trying to understand. I assume we do this same procedure elsewhere and it'd be too annoying to change at this stage. Just to check my assumptions on how this works: What would it mean for a resource of a particular version to have a stated compatibility of say, 'v24.0.1', with a gem5 version of 'v24.0.2'? I take it this gem5 resource would be seen as incompatible? Also, am I correct in assuming when a resource has one stated compatibility at the granularity of the a major release, and another stated compatibility at the granularity of am minor/hotfix release of that same major (.e.g., ['v24.1' 'v24.1.1'], or ['v24.0', 'v24.0.0.1']), then the major/hotfix compatibility is effectively redundant as the major version compatibility assumes compatibility with all releases within that major release (e.g., ['v24.1' 'v24.1.1'] is equal to ['v24.1'] in practice).
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We dont currently use the functionality but the For your second question, if a particular version to have a stated compatibility of say, 'v24.0.1', then the resource would be incompatible with gem5 version of 'v24.0.2', this would potentially be helpful in case we need to update checkpoint in hot fixes, etc. Yes, if a resource has one stated compatibility at the granularity of the a major release, and another stated compatibility at the granularity of am minor/hotfix release of that same major (.e.g., ['v24.1' 'v24.1.1'], or ['v24.0', 'v24.0.0.1']), then the major/hotfix compatibility is effectively redundant as the major version compatibility assumes compatibility with all releases within that major release (e.g., ['v24.1' 'v24.1.1'] is equal to ['v24.1'] in practice). |
||
|
|
||
| # If only one part provided (e.g., "25"), return error | ||
| if not prefixes: | ||
| return create_error_response( | ||
| 400, | ||
| "Invalid 'gem5-version' parameter: must have at least " | ||
| "major.minor format (e.g., '23.0')", | ||
Harshil2107 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| # Query for resources where any gem5_version matches one of | ||
| # the prefixes | ||
| query = {"gem5_versions": {"$in": prefixes}} | ||
|
|
||
| resources = list(collection.find(query, RESOURCE_FIELDS)) | ||
|
|
||
| return func.HttpResponse( | ||
| body=json.dumps(resources), | ||
| status_code=200, | ||
| headers={"Content-Type": "application/json"}, | ||
| ) | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| except Exception as e: | ||
| logging.error(f"Error listing resources by gem5 version: {str(e)}") | ||
| return create_error_response(500, "Internal server error") | ||
Uh oh!
There was an error while loading. Please reload this page.