Skip to content

v1

Definition of /admin routes.

download_job_logs(job_id, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Download job folder

Source code in fractal_server/app/routes/admin/v1.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
@router_admin_v1.get(
    "/job/{job_id}/download/",
    response_class=StreamingResponse,
)
async def download_job_logs(
    job_id: int,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> StreamingResponse:
    """
    Download job folder
    """
    # Get job from DB
    job = await db.get(ApplyWorkflow, job_id)
    if job is None:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=f"Job {job_id} not found",
        )
    # Create and return byte stream for zipped log folder
    PREFIX_ZIP = Path(job.working_dir).name
    zip_filename = f"{PREFIX_ZIP}_archive.zip"
    return StreamingResponse(
        _zip_folder_to_byte_stream_iterator(folder=job.working_dir),
        media_type="application/x-zip-compressed",
        headers={"Content-Disposition": f"attachment;filename={zip_filename}"},
    )

stop_job(job_id, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Stop execution of a workflow job.

Source code in fractal_server/app/routes/admin/v1.py
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
@router_admin_v1.get("/job/{job_id}/stop/", status_code=202)
async def stop_job(
    job_id: int,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> Response:
    """
    Stop execution of a workflow job.
    """

    _check_shutdown_is_supported()

    job = await db.get(ApplyWorkflow, job_id)
    if job is None:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=f"Job {job_id} not found",
        )

    _write_shutdown_file(job=job)

    return Response(status_code=status.HTTP_202_ACCEPTED)

update_job(job_update, job_id, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Change the status of an existing job.

This endpoint is only open to superusers, and it does not apply project-based access-control to jobs.

Source code in fractal_server/app/routes/admin/v1.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
@router_admin_v1.patch(
    "/job/{job_id}/",
    response_model=ApplyWorkflowReadV1,
)
async def update_job(
    job_update: ApplyWorkflowUpdateV1,
    job_id: int,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> Optional[ApplyWorkflowReadV1]:
    """
    Change the status of an existing job.

    This endpoint is only open to superusers, and it does not apply
    project-based access-control to jobs.
    """
    job = await db.get(ApplyWorkflow, job_id)
    if job is None:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail=f"Job {job_id} not found",
        )

    if job_update.status != JobStatusTypeV1.FAILED:
        raise HTTPException(
            status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
            detail=f"Cannot set job status to {job_update.status}",
        )

    setattr(job, "status", job_update.status)
    setattr(job, "end_timestamp", get_timestamp())
    await db.commit()
    await db.refresh(job)
    await db.close()
    return job

view_dataset(id=None, user_id=None, project_id=None, name_contains=None, type=None, timestamp_created_min=None, timestamp_created_max=None, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Query dataset table.

Parameters:

Name Type Description Default
id Optional[int]

If not None, select a given dataset.id.

None
project_id Optional[int]

If not None, select a given dataset.project_id.

None
name_contains Optional[str]

If not None, select datasets such that their name attribute contains name_contains (case-insensitive).

None
type Optional[str]

If not None, select a given dataset.type.

None
Source code in fractal_server/app/routes/admin/v1.py
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@router_admin_v1.get("/dataset/", response_model=list[DatasetReadV1])
async def view_dataset(
    id: Optional[int] = None,
    user_id: Optional[int] = None,
    project_id: Optional[int] = None,
    name_contains: Optional[str] = None,
    type: Optional[str] = None,
    timestamp_created_min: Optional[datetime] = None,
    timestamp_created_max: Optional[datetime] = None,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> list[DatasetReadV1]:
    """
    Query `dataset` table.

    Args:
        id: If not `None`, select a given `dataset.id`.
        project_id: If not `None`, select a given `dataset.project_id`.
        name_contains: If not `None`, select datasets such that their
            `name` attribute contains `name_contains` (case-insensitive).
        type: If not `None`, select a given `dataset.type`.
    """
    _raise_if_naive_datetime(timestamp_created_min, timestamp_created_max)

    stm = select(Dataset)

    if user_id is not None:
        stm = stm.join(Project).where(
            Project.user_list.any(UserOAuth.id == user_id)
        )
    if id is not None:
        stm = stm.where(Dataset.id == id)
    if project_id is not None:
        stm = stm.where(Dataset.project_id == project_id)
    if name_contains is not None:
        # SQLAlchemy2: use icontains
        stm = stm.where(
            func.lower(Dataset.name).contains(name_contains.lower())
        )
    if type is not None:
        stm = stm.where(Dataset.type == type)
    if timestamp_created_min is not None:
        stm = stm.where(Dataset.timestamp_created >= timestamp_created_min)
    if timestamp_created_max is not None:
        stm = stm.where(Dataset.timestamp_created <= timestamp_created_max)

    res = await db.execute(stm)
    dataset_list = res.scalars().all()
    await db.close()

    return dataset_list

view_job(id=None, user_id=None, project_id=None, input_dataset_id=None, output_dataset_id=None, workflow_id=None, status=None, start_timestamp_min=None, start_timestamp_max=None, end_timestamp_min=None, end_timestamp_max=None, log=True, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Query ApplyWorkflow table.

Parameters:

Name Type Description Default
id Optional[int]

If not None, select a given applyworkflow.id.

None
project_id Optional[int]

If not None, select a given applyworkflow.project_id.

None
input_dataset_id Optional[int]

If not None, select a given applyworkflow.input_dataset_id.

None
output_dataset_id Optional[int]

If not None, select a given applyworkflow.output_dataset_id.

None
workflow_id Optional[int]

If not None, select a given applyworkflow.workflow_id.

None
status Optional[JobStatusTypeV1]

If not None, select a given applyworkflow.status.

None
start_timestamp_min Optional[datetime]

If not None, select a rows with start_timestamp after start_timestamp_min.

None
start_timestamp_max Optional[datetime]

If not None, select a rows with start_timestamp before start_timestamp_min.

None
end_timestamp_min Optional[datetime]

If not None, select a rows with end_timestamp after end_timestamp_min.

None
end_timestamp_max Optional[datetime]

If not None, select a rows with end_timestamp before end_timestamp_min.

None
log bool

If True, include job.log, if False job.log is set to None.

True
Source code in fractal_server/app/routes/admin/v1.py
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
@router_admin_v1.get("/job/", response_model=list[ApplyWorkflowReadV1])
async def view_job(
    id: Optional[int] = None,
    user_id: Optional[int] = None,
    project_id: Optional[int] = None,
    input_dataset_id: Optional[int] = None,
    output_dataset_id: Optional[int] = None,
    workflow_id: Optional[int] = None,
    status: Optional[JobStatusTypeV1] = None,
    start_timestamp_min: Optional[datetime] = None,
    start_timestamp_max: Optional[datetime] = None,
    end_timestamp_min: Optional[datetime] = None,
    end_timestamp_max: Optional[datetime] = None,
    log: bool = True,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> list[ApplyWorkflowReadV1]:
    """
    Query `ApplyWorkflow` table.

    Args:
        id: If not `None`, select a given `applyworkflow.id`.
        project_id: If not `None`, select a given `applyworkflow.project_id`.
        input_dataset_id: If not `None`, select a given
            `applyworkflow.input_dataset_id`.
        output_dataset_id: If not `None`, select a given
            `applyworkflow.output_dataset_id`.
        workflow_id: If not `None`, select a given `applyworkflow.workflow_id`.
        status: If not `None`, select a given `applyworkflow.status`.
        start_timestamp_min: If not `None`, select a rows with
            `start_timestamp` after `start_timestamp_min`.
        start_timestamp_max: If not `None`, select a rows with
            `start_timestamp` before `start_timestamp_min`.
        end_timestamp_min: If not `None`, select a rows with `end_timestamp`
            after `end_timestamp_min`.
        end_timestamp_max: If not `None`, select a rows with `end_timestamp`
            before `end_timestamp_min`.
        log: If `True`, include `job.log`, if `False`
            `job.log` is set to `None`.
    """
    _raise_if_naive_datetime(
        start_timestamp_min,
        start_timestamp_max,
        end_timestamp_min,
        end_timestamp_max,
    )

    stm = select(ApplyWorkflow)

    if id is not None:
        stm = stm.where(ApplyWorkflow.id == id)
    if user_id is not None:
        stm = stm.join(Project).where(
            Project.user_list.any(UserOAuth.id == user_id)
        )
    if project_id is not None:
        stm = stm.where(ApplyWorkflow.project_id == project_id)
    if input_dataset_id is not None:
        stm = stm.where(ApplyWorkflow.input_dataset_id == input_dataset_id)
    if output_dataset_id is not None:
        stm = stm.where(ApplyWorkflow.output_dataset_id == output_dataset_id)
    if workflow_id is not None:
        stm = stm.where(ApplyWorkflow.workflow_id == workflow_id)
    if status is not None:
        stm = stm.where(ApplyWorkflow.status == status)
    if start_timestamp_min is not None:
        stm = stm.where(ApplyWorkflow.start_timestamp >= start_timestamp_min)
    if start_timestamp_max is not None:
        stm = stm.where(ApplyWorkflow.start_timestamp <= start_timestamp_max)
    if end_timestamp_min is not None:
        stm = stm.where(ApplyWorkflow.end_timestamp >= end_timestamp_min)
    if end_timestamp_max is not None:
        stm = stm.where(ApplyWorkflow.end_timestamp <= end_timestamp_max)

    res = await db.execute(stm)
    job_list = res.scalars().all()
    await db.close()
    if not log:
        for job in job_list:
            setattr(job, "log", None)

    return job_list

view_project(id=None, user_id=None, timestamp_created_min=None, timestamp_created_max=None, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Query project table.

Parameters:

Name Type Description Default
id Optional[int]

If not None, select a given project.id.

None
user_id Optional[int]

If not None, select a given project.user_id.

None
Source code in fractal_server/app/routes/admin/v1.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@router_admin_v1.get("/project/", response_model=list[ProjectReadV1])
async def view_project(
    id: Optional[int] = None,
    user_id: Optional[int] = None,
    timestamp_created_min: Optional[datetime] = None,
    timestamp_created_max: Optional[datetime] = None,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> list[ProjectReadV1]:
    """
    Query `project` table.

    Args:
        id: If not `None`, select a given `project.id`.
        user_id: If not `None`, select a given `project.user_id`.
    """
    _raise_if_naive_datetime(timestamp_created_min, timestamp_created_max)

    stm = select(Project)

    if id is not None:
        stm = stm.where(Project.id == id)

    if user_id is not None:
        stm = stm.where(Project.user_list.any(UserOAuth.id == user_id))
    if timestamp_created_min is not None:
        stm = stm.where(Project.timestamp_created >= timestamp_created_min)
    if timestamp_created_max is not None:
        stm = stm.where(Project.timestamp_created <= timestamp_created_max)

    res = await db.execute(stm)
    project_list = res.scalars().all()
    await db.close()

    return project_list

view_workflow(id=None, user_id=None, project_id=None, name_contains=None, timestamp_created_min=None, timestamp_created_max=None, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Query workflow table.

Parameters:

Name Type Description Default
id Optional[int]

If not None, select a given workflow.id.

None
project_id Optional[int]

If not None, select a given workflow.project_id.

None
name_contains Optional[str]

If not None, select workflows such that their name attribute contains name_contains (case-insensitive).

None
Source code in fractal_server/app/routes/admin/v1.py
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@router_admin_v1.get("/workflow/", response_model=list[WorkflowReadV1])
async def view_workflow(
    id: Optional[int] = None,
    user_id: Optional[int] = None,
    project_id: Optional[int] = None,
    name_contains: Optional[str] = None,
    timestamp_created_min: Optional[datetime] = None,
    timestamp_created_max: Optional[datetime] = None,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> list[WorkflowReadV1]:
    """
    Query `workflow` table.

    Args:
        id: If not `None`, select a given `workflow.id`.
        project_id: If not `None`, select a given `workflow.project_id`.
        name_contains: If not `None`, select workflows such that their
            `name` attribute contains `name_contains` (case-insensitive).
    """
    _raise_if_naive_datetime(timestamp_created_min, timestamp_created_max)

    stm = select(Workflow)

    if user_id is not None:
        stm = stm.join(Project).where(
            Project.user_list.any(UserOAuth.id == user_id)
        )
    if id is not None:
        stm = stm.where(Workflow.id == id)
    if project_id is not None:
        stm = stm.where(Workflow.project_id == project_id)
    if name_contains is not None:
        # SQLAlchemy2: use icontains
        stm = stm.where(
            func.lower(Workflow.name).contains(name_contains.lower())
        )
    if timestamp_created_min is not None:
        stm = stm.where(Workflow.timestamp_created >= timestamp_created_min)
    if timestamp_created_max is not None:
        stm = stm.where(Workflow.timestamp_created <= timestamp_created_max)

    res = await db.execute(stm)
    workflow_list = res.scalars().all()
    await db.close()

    return workflow_list