Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/demo_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import uuid

from fastapi import HTTPException
from fastapi.encoders import jsonable_encoder
from pydantic import BaseModel

from .routers.account import facility_adapter as account_adapter
Expand Down Expand Up @@ -520,8 +519,8 @@ async def list_sites(
sites = [s for s in sites if s.last_modified > ms]

o = offset or 0
l = limit or len(sites)
return sites[o : o + l]
page_limit = limit or len(sites)
return sites[o : o + page_limit]

async def get_site(self: "DemoAdapter", site_id: str, modified_since: str | None = None) -> facility_models.Site:
site = next((s for s in self.sites if s.id == site_id), None)
Expand All @@ -547,7 +546,7 @@ async def get_resources(
description: str | None = None,
group: str | None = None,
modified_since: datetime.datetime | None = None,
resource_type: status_models.ResourceType | None = None,
resource_type: status_models.ResourceTypeValue | None = None,
current_status: status_models.Status | None = None,
capability: Capability | None = None,
site_id: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions app/routers/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ...request_context import get_url_prefix
from ...types.base import IRIBaseModel
from ...types.scalars import AllocationUnit
from ...types.scalars import AllocationUnit, AllocationUnitValue


class Project(IRIBaseModel):
Expand Down Expand Up @@ -34,7 +34,7 @@ class AllocationEntry(IRIBaseModel):

allocation: float = Field(..., description="Total allocation amount granted.", example=100000.0) # how much this allocation can spend
usage: float = Field(..., description="Amount of allocation consumed.", example=52342.5) # how much this allocation has spent
unit: AllocationUnit = Field(..., description="Unit of the allocation (e.g., node_hours, bytes).", example="node_hours")
unit: AllocationUnitValue = Field(..., description="DOE IRI URN for the allocation unit.", example=AllocationUnit.node_hours)


class ProjectAllocation(IRIBaseModel):
Expand Down
16 changes: 5 additions & 11 deletions app/routers/filesystem/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
from enum import Enum
from pydantic import Field, AliasChoices, BaseModel


class CompressionType(str, Enum):
"""Defines the type of compression to be used for compressing or extracting files."""
none = "none"
bzip2 = "bzip2"
gzip = "gzip"
xz = "xz"
from ...types.scalars import CompressionType, CompressionTypeValue


class ContentUnit(str, Enum):
Expand Down Expand Up @@ -202,7 +196,7 @@ class PostCompressRequest(FilesystemRequestBase):
target_path: str = Field(..., description="Path to the compressed file", example="/home/user/file.tar.gz")
match_pattern: str|None = Field(default=None, description="Regex pattern to filter files to compress", example=".*\\.txt$")
dereference: bool = Field(default=False, description="If set to `true`, it follows symbolic links and archive the files they point to instead of the links themselves.", example=True)
compression: CompressionType = Field(default="gzip", description="Defines the type of compression to be used. By default gzip is used.", example="gzip")
compression: CompressionTypeValue = Field(default=CompressionType.gzip, description="DOE IRI URN for the compression type. Legacy short tokens are accepted only as input compatibility aliases and are normalized.", example=CompressionType.gzip)
model_config = {
"json_schema_extra": {
"examples": [
Expand All @@ -211,7 +205,7 @@ class PostCompressRequest(FilesystemRequestBase):
"target_path": "/home/user/file.tar.gz",
"match_pattern": "*./[ab].*\\.txt",
"dereference": "true",
"compression": "none",
"compression": CompressionType.none,
}
]
}
Expand All @@ -226,14 +220,14 @@ class PostExtractResponse(BaseModel):
class PostExtractRequest(FilesystemRequestBase):
"""Represents a request to extract a compressed file."""
target_path: str = Field(..., description="Path to the directory where to extract the compressed file", example="/home/user/dir")
compression: CompressionType = Field(default="gzip", description="Defines the type of compression to be used. By default gzip is used.", example="gzip")
compression: CompressionTypeValue = Field(default=CompressionType.gzip, description="DOE IRI URN for the compression type. Legacy short tokens are accepted only as input compatibility aliases and are normalized.", example=CompressionType.gzip)
model_config = {
"json_schema_extra": {
"examples": [
{
"source_path": "/home/user/dir/file.tar.gz",
"target_path": "/home/user/dir",
"compression": "none",
"compression": CompressionType.none,
}
]
}
Expand Down
2 changes: 2 additions & 0 deletions app/routers/status/facility_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async def get_resources(
description: str | None = None,
group: str | None = None,
modified_since: datetime.datetime | None = None,
resource_type: status_models.ResourceTypeValue | None = None,
current_status: status_models.Status|None = None,
resource_type: status_models.ResourceType | None = None,
current_status: status_models.Status | None = None,
capability: Capability | None = None,
Expand Down
26 changes: 4 additions & 22 deletions app/routers/status/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from ...request_context import get_url_prefix
from ...types.base import NamedObject
from ...types.scalars import ResourceType, ResourceTypeValue, canonicalize_resource_type, urn_has_complete_prefix


class Status(enum.Enum):
Expand All @@ -15,23 +16,6 @@ class Status(enum.Enum):
degraded = "degraded"
unknown = "unknown"


class ResourceType(enum.Enum):
"""Represents the type of a resource."""
website = "website"
service = "service"
compute = "compute"
system = "system"
storage = "storage"
network = "network"
unknown = "unknown"


class Endpoint(enum.Enum):
compute = "compute"
filesystem = "filesystem"


class Resource(NamedObject):
"""Represents a resource in the system."""
def _self_path(self) -> str:
Expand All @@ -42,8 +26,7 @@ def _self_path(self) -> str:
capability_ids: list[str] = Field(default_factory=list, exclude=True)
group: str|None = Field(default=None, description="Logical grouping of the resource", example="frontend")
current_status: Status|None = Field(default=None, description="The current status comes from the status of the last event for this resource", example="up")
resource_type: ResourceType = Field(..., description="Type of the resource", example="service")
supported_endpoints: list[Endpoint] = Field(default_factory=list, description="a list of endpoints where this resource can be used")
resource_type: ResourceTypeValue = Field(..., description="DOE IRI URN for the resource type", example=ResourceType.service)

@computed_field(description="URI of the site where this resource is located")
@property
Expand All @@ -63,9 +46,8 @@ def find(cls, items, name=None, description=None, modified_since=None, group=Non
if group:
items = [item for item in items if item.group == group]
if resource_type:
if isinstance(resource_type, str):
resource_type = ResourceType(resource_type)
items = [item for item in items if item.resource_type == resource_type]
resource_type = canonicalize_resource_type(resource_type)
items = [item for item in items if urn_has_complete_prefix(resource_type, item.resource_type)]
if current_status:
items = [item for item in items if item.current_status == current_status]
if capability:
Expand Down
12 changes: 9 additions & 3 deletions app/routers/status/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from fastapi import Depends, HTTPException, Query, Request

from ...types.http import forbidExtraQueryParams
from ...types.scalars import AllocationUnit, StrictDateTime
from ...types.scalars import AllocationUnitValue, StrictDateTime, doe_iri_domain_urn_min_length, doe_iri_domain_urn_schema_pattern
from .. import iri_router
from ..error_handlers import DEFAULT_RESPONSES
from ..iri_meta import iri_meta_dict
Expand Down Expand Up @@ -33,9 +33,15 @@ async def get_resources(
offset: int = Query(default=0, ge=0),
limit: int = Query(default=100, ge=0, le=1000),
modified_since: StrictDateTime = Query(default=None),
resource_type: models.ResourceType = Query(default=None),
resource_type: models.ResourceTypeValue = Query(
default=None,
min_length=doe_iri_domain_urn_min_length("resource"),
pattern=doe_iri_domain_urn_schema_pattern("resource"),
description="DOE IRI resource type URN. Legacy short tokens are accepted only as input compatibility aliases and are normalized to canonical URNs.",
examples=[models.ResourceType.compute, models.ResourceType.storage],
),
current_status: models.Status = Query(default=None),
capability: List[AllocationUnit] = Query(default=None, min_length=1),
capability: List[AllocationUnitValue] = Query(default=None, min_length=1),
_forbid=Depends(forbidExtraQueryParams("name", "description", "group", "offset", "limit", "modified_since", "resource_type", "current_status", "capability", multiParams={"capability"})),
) -> list[models.Resource]:
return await router.adapter.get_resources(
Expand Down
4 changes: 2 additions & 2 deletions app/types/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydantic import Field

from .base import NamedObject
from .scalars import AllocationUnit, StrictDateTime
from .scalars import AllocationUnit, AllocationUnitValue, StrictDateTime


class Capability(NamedObject):
Expand All @@ -20,4 +20,4 @@ def _self_path(self) -> str:

last_modified: StrictDateTime|None = Field(default=None, description="ISO 8601 timestamp when this object was last modified.", example="2026-02-21T12:00:00Z")

units: list[AllocationUnit] = Field(..., description="Allocation units supported by this capability", example=["node_hours"])
units: list[AllocationUnitValue] = Field(..., description="Allocation units supported by this capability", example=[AllocationUnit.node_hours])
Loading
Loading