Skip to content

Commit

Permalink
Merge pull request #17237 from heisner-tillman/invocations_
Browse files Browse the repository at this point in the history
Refactor two of the missing invocation routes to FastAPI
  • Loading branch information
mvdbeek authored Jan 16, 2024
2 parents 412016f + 03a04c0 commit 1e3051d
Show file tree
Hide file tree
Showing 8 changed files with 617 additions and 202 deletions.
302 changes: 293 additions & 9 deletions client/src/api/schema/schema.ts

Large diffs are not rendered by default.

109 changes: 89 additions & 20 deletions lib/galaxy/schema/invocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from galaxy.schema import schema
from galaxy.schema.fields import (
DecodedDatabaseIdField,
EncodedDatabaseIdField,
literal_to_value,
ModelClassField,
Expand All @@ -41,6 +42,7 @@
JOB_MODEL_CLASS,
JobState,
Model,
StoreContentSource,
UpdateTimeField,
WithModelClass,
)
Expand Down Expand Up @@ -304,15 +306,6 @@ class InvocationStepState(str, Enum):
# FAILED = 'failed', TODO: implement and expose


class ExtendedInvocationStepState(str, Enum):
NEW = "new" # Brand new workflow invocation step
READY = "ready" # Workflow invocation step ready for another iteration of scheduling.
SCHEDULED = "scheduled" # Workflow invocation step has been scheduled.
# CANCELLED = 'cancelled', TODO: implement and expose
# FAILED = 'failed', TODO: implement and expose
OK = "ok" # Workflow invocation step has completed successfully - TODO: is this a correct description?


class InvocationStepOutput(Model):
src: INVOCATION_STEP_OUTPUT_SRC = Field(
literal_to_value(INVOCATION_STEP_OUTPUT_SRC),
Expand Down Expand Up @@ -378,9 +371,7 @@ class InvocationStep(Model, WithModelClass):
),
]
]
# TODO The state can differ from InvocationStepState is this intended?
# InvocationStepState is equal to the states attribute of the WorkflowInvocationStep class
state: Optional[ExtendedInvocationStepState] = Field(
state: Optional[Union[InvocationStepState, JobState]] = Field(
default=None,
title="State of the invocation step",
description="Describes where in the scheduling process the workflow invocation step is.",
Expand Down Expand Up @@ -427,12 +418,12 @@ class InvocationReport(Model, WithModelClass):
description="Format of the invocation report.",
)
markdown: Optional[str] = Field(
default="",
default=None,
title="Markdown",
description="Raw galaxy-flavored markdown contents of the report.",
)
invocation_markdown: Optional[str] = Field(
default="",
default=None,
title="Markdown",
description="Raw galaxy-flavored markdown contents of the report.",
)
Expand All @@ -454,19 +445,50 @@ class InvocationReport(Model, WithModelClass):
)
generate_time: Optional[str] = schema.GenerateTimeField
generate_version: Optional[str] = schema.GenerateVersionField
model_config = ConfigDict(extra="allow")

errors: Optional[Dict[str, Any]] = Field(
default=None,
title="Errors",
description="Errors associated with the invocation.",
)

history_datasets: Optional[Dict[str, Any]] = Field(
default=None,
title="History datasets",
description="History datasets associated with the invocation.",
)
workflows: Optional[Dict[str, Any]] = Field(
default=None,
title="Workflows",
description="Workflows associated with the invocation.",
)
history_dataset_collections: Optional[Dict[str, Any]] = Field(
default=None,
title="History dataset collections",
description="History dataset collections associated with the invocation.",
)
jobs: Optional[Dict[str, Any]] = Field(
default=None,
title="Jobs",
description="Jobs associated with the invocation.",
)
histories: Optional[Dict[str, Any]] = Field(
default=None,
title="Histories",
description="Histories associated with the invocation.",
)
invocations: Optional[Dict[str, Any]] = Field(
default=None,
title="Invocations",
description="Other invocations associated with the invocation.",
)


class InvocationUpdatePayload(Model):
action: bool = InvocationStepActionField


class InvocationIOBase(Model):
# TODO - resolve
# the tests in test/integration/test_workflow_tasks.py ,
# between line 42 and 56 fail, if this id is not allowed be None
# They all fail, when trying to populate the response of the show_invocation operation
# Is it intended to allow None here?
id: Optional[EncodedDatabaseIdField] = Field(
default=None, title="ID", description="The encoded ID of the dataset/dataset collection."
)
Expand Down Expand Up @@ -591,3 +613,50 @@ class InvocationStepJobsResponseJobModel(InvocationJobsSummaryBaseModel):

class InvocationStepJobsResponseCollectionJobsModel(InvocationJobsSummaryBaseModel):
model: IMPLICIT_COLLECTION_JOBS_MODEL_CLASS


class CreateInvocationFromStore(StoreContentSource):
history_id: int = Field(
default=..., title="History ID", description="The ID of the history associated with the invocations."
)


class InvocationSerializationView(str, Enum):
element = "element"
collection = "collection"


class InvocationSerializationParams(BaseModel):
"""Contains common parameters for customizing model serialization."""

view: Optional[InvocationSerializationView] = Field(
default=None,
title="View",
description=(
"The name of the view used to serialize this item. "
"This will return a predefined set of attributes of the item."
),
examples=["element"],
)
step_details: bool = Field(
default=False,
title="Include step details",
description="Include details for individual invocation steps and populate a steps attribute in the resulting dictionary",
)
legacy_job_state: bool = Field(
default=False,
description="""Populate the invocation step state with the job state instead of the invocation step state.
This will also produce one step per job in mapping jobs to mimic the older behavior with respect to collections.
Partially scheduled steps may provide incomplete information and the listed steps outputs
are not the mapped over step outputs but the individual job outputs.""",
# TODO: also deprecate on python side, https://github.com/pydantic/pydantic/issues/2255
json_schema_extra={"deprecated": True},
)


class CreateInvocationsFromStorePayload(CreateInvocationFromStore, InvocationSerializationParams):
history_id: DecodedDatabaseIdField = Field(
default=...,
title="History ID",
description="The ID of the history associated with the invocations.",
)
12 changes: 4 additions & 8 deletions lib/galaxy/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,18 +1429,14 @@ class InvocationSortByEnum(str, Enum):


class InvocationIndexQueryPayload(Model):
workflow_id: Optional[DecodedDatabaseIdField] = Field(
workflow_id: Optional[int] = Field(
None, title="Workflow ID", description="Return only invocations for this Workflow ID"
)
history_id: Optional[DecodedDatabaseIdField] = Field(
history_id: Optional[int] = Field(
None, title="History ID", description="Return only invocations for this History ID"
)
job_id: Optional[DecodedDatabaseIdField] = Field(
None, title="Job ID", description="Return only invocations for this Job ID"
)
user_id: Optional[DecodedDatabaseIdField] = Field(
None, title="User ID", description="Return invocations for this User ID"
)
job_id: Optional[int] = Field(None, title="Job ID", description="Return only invocations for this Job ID")
user_id: Optional[int] = Field(None, title="User ID", description="Return invocations for this User ID")
sort_by: Optional[InvocationSortByEnum] = Field(
None, title="Sort By", description="Sort Workflow Invocations by this attribute"
)
Expand Down
14 changes: 8 additions & 6 deletions lib/galaxy/webapps/galaxy/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@
Path(..., title="Quota ID", description="The ID of the Quota."),
]

SerializationViewQueryParam: Optional[str] = Query(
None,
title="View",
description="View to be passed to the serializer",
)
SerializationViewQueryParam = Annotated[
Optional[str],
Query(
title="View",
description="View to be passed to the serializer",
),
]

SerializationKeysQueryParam: Optional[str] = Query(
None,
Expand Down Expand Up @@ -151,7 +153,7 @@ def parse_serialization_params(


def query_serialization_params(
view: Optional[str] = SerializationViewQueryParam,
view: SerializationViewQueryParam = None,
keys: Optional[str] = SerializationKeysQueryParam,
) -> SerializationParams:
return parse_serialization_params(view=view, keys=keys)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/galaxy/api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def whoami(self, trans: ProvidesUserContext = DependsOnTrans) -> Optional[UserMo
def index(
self,
trans: ProvidesUserContext = DependsOnTrans,
view: Optional[str] = SerializationViewQueryParam,
view: SerializationViewQueryParam = None,
keys: Optional[str] = SerializationKeysQueryParam,
) -> Dict[str, Any]:
"""
Expand Down
Loading

0 comments on commit 1e3051d

Please sign in to comment.