Skip to content

Commit

Permalink
Merge pull request #17153 from heisner-tillman/jobs
Browse files Browse the repository at this point in the history
Create pydantic model for the return of show operation -  get: `/api/jobs/{job_id}`
  • Loading branch information
mvdbeek authored Dec 19, 2023
2 parents 038d31e + 1620605 commit 367cf12
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 13 deletions.
173 changes: 169 additions & 4 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4190,7 +4190,7 @@ export interface components {
* Command Version
* @description Tool version indicated during job execution.
*/
command_version: string;
command_version?: string;
/**
* Copied from Job-ID
* @description Reference to cached job if job execution was cached.
Expand Down Expand Up @@ -4218,7 +4218,7 @@ export interface components {
* @description The (major) version of Galaxy used to create this job.
* @example 21.05
*/
galaxy_version: string;
galaxy_version?: string;
/**
* History ID
* @description The encoded ID of the history associated with this item.
Expand Down Expand Up @@ -6631,7 +6631,7 @@ export interface components {
* @description The (major) version of Galaxy used to create this job.
* @example 21.05
*/
galaxy_version: string;
galaxy_version?: string;
/**
* History ID
* @description The encoded ID of the history associated with this item.
Expand Down Expand Up @@ -6756,6 +6756,12 @@ export interface components {
*/
value: string;
};
/**
* JobMetricCollection
* @description Collections of metrics provided by `JobInstrumenter` plugins on a particular job.
* @default []
*/
JobMetricCollection: components["schemas"]["JobMetric"][];
/** JobOutput */
JobOutput: {
/**
Expand Down Expand Up @@ -9020,6 +9026,163 @@ export interface components {
*/
short_term_storage_request_id: string;
};
/**
* ShowFullJobResponse
* @description Basic information about a job.
*/
ShowFullJobResponse: {
/**
* Command Line
* @description The command line produced by the job. Users can see this value if allowed in the configuration, administrator can always see this value.
*/
command_line?: string;
/**
* Command Version
* @description Tool version indicated during job execution.
*/
command_version?: string;
/**
* Copied from Job-ID
* @description Reference to cached job if job execution was cached.
* @example 0123456789ABCDEF
*/
copied_from_job_id?: string;
/**
* Create Time
* Format: date-time
* @description The time and date this item was created.
*/
create_time: string;
/**
* Job dependencies
* @description The dependencies of the job.
*/
dependencies?: Record<string, never>[];
/**
* Exit Code
* @description The exit code returned by the tool. Can be unset if the job is not completed yet.
*/
exit_code?: number;
/**
* External ID
* @description The job id used by the external job runner (Condor, Pulsar, etc.)Only administrator can see this value.
*/
external_id?: string;
/**
* Galaxy Version
* @description The (major) version of Galaxy used to create this job.
* @example 21.05
*/
galaxy_version?: string;
/**
* History ID
* @description The encoded ID of the history associated with this item.
* @example 0123456789ABCDEF
*/
history_id?: string;
/**
* ID
* @description The encoded ID of this entity.
* @example 0123456789ABCDEF
*/
id: string;
/**
* Inputs
* @description Dictionary mapping all the tool inputs (by name) to the corresponding data references.
* @default {}
*/
inputs?: {
[key: string]: components["schemas"]["EncodedDatasetJobInfo"] | undefined;
};
/**
* Job Messages
* @description List with additional information and possible reasons for a failed job.
*/
job_messages?: Record<string, never>[];
/**
* Job Metrics
* @description Collections of metrics provided by `JobInstrumenter` plugins on a particular job. Only administrators can see these metrics.
*/
job_metrics?: components["schemas"]["JobMetricCollection"];
/**
* Job Standard Error
* @description The captured standard error of the job execution.
*/
job_stderr?: string;
/**
* Job Standard Output
* @description The captured standard output of the job execution.
*/
job_stdout?: string;
/**
* Model class
* @description The name of the database model class.
* @default Job
* @enum {string}
*/
model_class: "Job";
/**
* Output collections
* @default {}
*/
output_collections?: {
[key: string]: components["schemas"]["EncodedHdcaSourceId"] | undefined;
};
/**
* Outputs
* @description Dictionary mapping all the tool outputs (by name) to the corresponding data references.
* @default {}
*/
outputs?: {
[key: string]: components["schemas"]["EncodedDatasetJobInfo"] | undefined;
};
/**
* Parameters
* @description Object containing all the parameters of the tool associated with this job. The specific parameters depend on the tool itself.
*/
params: Record<string, never>;
/**
* State
* @description Current state of the job.
*/
state: components["schemas"]["JobState"];
/**
* Standard Error
* @description Combined tool and job standard error streams.
*/
stderr?: string;
/**
* Standard Output
* @description Combined tool and job standard output streams.
*/
stdout?: string;
/**
* Tool ID
* @description Identifier of the tool that generated this job.
*/
tool_id: string;
/**
* Tool Standard Error
* @description The captured standard error of the tool executed by the job.
*/
tool_stderr?: string;
/**
* Tool Standard Output
* @description The captured standard output of the tool executed by the job.
*/
tool_stdout?: string;
/**
* Update Time
* Format: date-time
* @description The last time and date this item was updated.
*/
update_time: string;
/**
* User Email
* @description The email of the user that owns this job. Only the owner of the job and administrators can see this value.
*/
user_email?: string;
};
/**
* Src
* @description An enumeration.
Expand Down Expand Up @@ -15792,7 +15955,9 @@ export interface operations {
/** @description Successful Response */
200: {
content: {
"application/json": Record<string, never>;
"application/json":
| components["schemas"]["ShowFullJobResponse"]
| components["schemas"]["EncodedJobDetails"];
};
};
/** @description Validation Error */
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/model/store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ def _set_job_attributes(
"tool_stderr",
"job_stdout",
"job_stderr",
"galaxy_version",
)
for attribute in ATTRIBUTES:
value = job_attrs.get(attribute)
Expand Down
64 changes: 61 additions & 3 deletions lib/galaxy/schema/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DataItemSourceType,
EncodedDataItemSourceId,
EntityIdField,
JobMetricCollection,
JobState,
JobSummary,
Model,
Expand Down Expand Up @@ -158,7 +159,7 @@ class EncodedDatasetJobInfo(EncodedDataItemSourceId):

class EncodedJobDetails(JobSummary):
command_version: Optional[str] = Field(
...,
default=None,
title="Command Version",
description="Tool version indicated during job execution.",
)
Expand All @@ -181,9 +182,15 @@ class EncodedJobDetails(JobSummary):
description="Dictionary mapping all the tool outputs (by name) to the corresponding data references.",
)
copied_from_job_id: Optional[EncodedDatabaseIdField] = Field(
default=None, title="Copied from Job-ID", description="Reference to cached job if job execution was cached."
default=None,
title="Copied from Job-ID",
description="Reference to cached job if job execution was cached.",
)
output_collections: Dict[str, EncodedHdcaSourceId] = Field(
default={},
title="Output collections",
description="",
)
output_collections: Dict[str, EncodedHdcaSourceId] = Field(default={}, title="Output collections", description="")


class JobDestinationParams(Model):
Expand Down Expand Up @@ -234,3 +241,54 @@ class JobDisplayParametersSummary(Model):
title="Outputs",
description="Dictionary mapping all the tool outputs (by name) with the corresponding dataset information in a nested format.",
)


class ShowFullJobResponse(EncodedJobDetails):
tool_stdout: Optional[str] = Field(
default=None,
title="Tool Standard Output",
description="The captured standard output of the tool executed by the job.",
)
tool_stderr: Optional[str] = Field(
default=None,
title="Tool Standard Error",
description="The captured standard error of the tool executed by the job.",
)
job_stdout: Optional[str] = Field(
default=None,
title="Job Standard Output",
description="The captured standard output of the job execution.",
)
job_stderr: Optional[str] = Field(
default=None,
title="Job Standard Error",
description="The captured standard error of the job execution.",
)
stdout: Optional[str] = Field( # Redundant? it seems to be (tool_stdout + "\n" + job_stdout)
default=None,
title="Standard Output",
description="Combined tool and job standard output streams.",
)
stderr: Optional[str] = Field( # Redundant? it seems to be (tool_stderr + "\n" + job_stderr)
default=None,
title="Standard Error",
description="Combined tool and job standard error streams.",
)
job_messages: Optional[List[Any]] = Field(
default=None,
title="Job Messages",
description="List with additional information and possible reasons for a failed job.",
)
dependencies: Optional[List[Any]] = Field(
default=None,
title="Job dependencies",
description="The dependencies of the job.",
)
job_metrics: Optional[JobMetricCollection] = Field(
default=None,
title="Job Metrics",
description=(
"Collections of metrics provided by `JobInstrumenter` plugins on a particular job. "
"Only administrators can see these metrics."
),
)
4 changes: 2 additions & 2 deletions lib/galaxy/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1851,8 +1851,8 @@ class JobBaseModel(Model):
)
create_time: datetime = CreateTimeField
update_time: datetime = UpdateTimeField
galaxy_version: str = Field(
...,
galaxy_version: Optional[str] = Field(
default=None,
title="Galaxy Version",
description="The (major) version of Galaxy used to create this job.",
example="21.05",
Expand Down
8 changes: 6 additions & 2 deletions lib/galaxy/webapps/galaxy/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
JobOutputAssociation,
ReportJobErrorPayload,
SearchJobsPayload,
ShowFullJobResponse,
)
from galaxy.schema.schema import (
DatasetSourceType,
Expand Down Expand Up @@ -500,8 +501,11 @@ def show(
job_id: Annotated[DecodedDatabaseIdField, JobIdPathParam],
full: Annotated[Optional[bool], FullShowQueryParam] = False,
trans: ProvidesUserContext = DependsOnTrans,
) -> Dict[str, Any]:
return self.service.show(trans, job_id, bool(full))
) -> Union[ShowFullJobResponse, EncodedJobDetails]:
if full:
return ShowFullJobResponse(**self.service.show(trans, job_id, bool(full)))
else:
return EncodedJobDetails(**self.service.show(trans, job_id, bool(full)))

@router.delete(
"/api/jobs/{job_id}",
Expand Down
5 changes: 3 additions & 2 deletions lib/galaxy_test/api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,16 @@ def test_show_security(self, history_id):
assert not job_lock_response.json()["active"]

show_jobs_response = self._get(f"jobs/{job_id}", admin=False)
self._assert_not_has_keys(show_jobs_response.json(), "external_id")
assert show_jobs_response.json()["external_id"] is None

# TODO: Re-activate test case when API accepts privacy settings
# with self._different_user():
# show_jobs_response = self._get( "jobs/%s" % job_id, admin=False )
# self._assert_status_code_is( show_jobs_response, 200 )

show_jobs_response = self._get(f"jobs/{job_id}", admin=True)
self._assert_has_keys(show_jobs_response.json(), "command_line", "external_id")
assert show_jobs_response.json()["external_id"] is not None
assert show_jobs_response.json()["command_line"] is not None

def _run_detect_errors(self, history_id, inputs):
payload = self.dataset_populator.run_tool_payload(
Expand Down

0 comments on commit 367cf12

Please sign in to comment.