|
2 | 2 |
|
3 | 3 | import logging |
4 | 4 | from pathlib import Path |
5 | | -from typing import Dict, List, Optional |
| 5 | +from typing import List, Optional |
6 | 6 |
|
7 | 7 | from fastapi import APIRouter, Depends, Request |
8 | 8 | from fastapi.responses import FileResponse, HTMLResponse |
|
30 | 30 | ClientEnvironment, |
31 | 31 | DataCollection, |
32 | 32 | DataCollectionGroup, |
33 | | - FoilHole, |
34 | | - GridSquare, |
35 | 33 | MagnificationLookup, |
36 | 34 | ProcessingJob, |
37 | 35 | RsyncInstance, |
|
44 | 42 | BLSampleParameters, |
45 | 43 | BLSubSampleParameters, |
46 | 44 | ClientInfo, |
47 | | - CurrentGainRef, |
48 | | - FoilHoleParameters, |
49 | | - GridSquareParameters, |
50 | 45 | MillingParameters, |
51 | | - PostInfo, |
52 | 46 | RegistrationMessage, |
53 | 47 | RsyncerInfo, |
54 | 48 | RsyncerSource, |
55 | 49 | Sample, |
56 | 50 | ) |
57 | | -from murfey.workflows.spa.flush_spa_preprocess import ( |
58 | | - register_foil_hole, |
59 | | - register_grid_square, |
60 | | -) |
61 | 51 |
|
62 | 52 | log = logging.getLogger("murfey.server.api") |
63 | 53 |
|
@@ -132,50 +122,6 @@ def register_client_to_visit(visit_name: str, client_info: ClientInfo, db=murfey |
132 | 122 | return client_info |
133 | 123 |
|
134 | 124 |
|
135 | | -@router.post("/sessions/{session_id}/rsyncer") |
136 | | -def register_rsyncer(session_id: int, rsyncer_info: RsyncerInfo, db=murfey_db): |
137 | | - visit_name = db.exec(select(Session).where(Session.id == session_id)).one().visit |
138 | | - rsync_instance = RsyncInstance( |
139 | | - source=rsyncer_info.source, |
140 | | - session_id=rsyncer_info.session_id, |
141 | | - transferring=rsyncer_info.transferring, |
142 | | - destination=rsyncer_info.destination, |
143 | | - tag=rsyncer_info.tag, |
144 | | - ) |
145 | | - db.add(rsync_instance) |
146 | | - db.commit() |
147 | | - db.close() |
148 | | - prom.seen_files.labels(rsync_source=rsyncer_info.source, visit=visit_name) |
149 | | - prom.seen_data_files.labels(rsync_source=rsyncer_info.source, visit=visit_name) |
150 | | - prom.transferred_files.labels(rsync_source=rsyncer_info.source, visit=visit_name) |
151 | | - prom.transferred_files_bytes.labels( |
152 | | - rsync_source=rsyncer_info.source, visit=visit_name |
153 | | - ) |
154 | | - prom.transferred_data_files.labels( |
155 | | - rsync_source=rsyncer_info.source, visit=visit_name |
156 | | - ) |
157 | | - prom.transferred_data_files_bytes.labels( |
158 | | - rsync_source=rsyncer_info.source, visit=visit_name |
159 | | - ) |
160 | | - prom.seen_files.labels(rsync_source=rsyncer_info.source, visit=visit_name).set(0) |
161 | | - prom.transferred_files.labels( |
162 | | - rsync_source=rsyncer_info.source, visit=visit_name |
163 | | - ).set(0) |
164 | | - prom.transferred_files_bytes.labels( |
165 | | - rsync_source=rsyncer_info.source, visit=visit_name |
166 | | - ).set(0) |
167 | | - prom.seen_data_files.labels(rsync_source=rsyncer_info.source, visit=visit_name).set( |
168 | | - 0 |
169 | | - ) |
170 | | - prom.transferred_data_files.labels( |
171 | | - rsync_source=rsyncer_info.source, visit=visit_name |
172 | | - ).set(0) |
173 | | - prom.transferred_data_files_bytes.labels( |
174 | | - rsync_source=rsyncer_info.source, visit=visit_name |
175 | | - ).set(0) |
176 | | - return rsyncer_info |
177 | | - |
178 | | - |
179 | 125 | @router.delete("/sessions/{session_id}/rsyncer") |
180 | 126 | def delete_rsyncer(session_id: int, source: Path, db=murfey_db): |
181 | 127 | try: |
@@ -288,84 +234,6 @@ class ProcessingDetails(BaseModel): |
288 | 234 | feedback_params: SPAFeedbackParameters |
289 | 235 |
|
290 | 236 |
|
291 | | -@router.get("/sessions/{session_id}/grid_squares") |
292 | | -def get_grid_squares(session_id: MurfeySessionID, db=murfey_db): |
293 | | - grid_squares = db.exec( |
294 | | - select(GridSquare).where(GridSquare.session_id == session_id) |
295 | | - ).all() |
296 | | - tags = {gs.tag for gs in grid_squares} |
297 | | - res = {} |
298 | | - for t in tags: |
299 | | - res[t] = [gs for gs in grid_squares if gs.tag == t] |
300 | | - return res |
301 | | - |
302 | | - |
303 | | -@router.get("/sessions/{session_id}/data_collection_groups/{dcgid}/grid_squares") |
304 | | -def get_grid_squares_from_dcg( |
305 | | - session_id: int, dcgid: int, db=murfey_db |
306 | | -) -> List[GridSquare]: |
307 | | - grid_squares = db.exec( |
308 | | - select(GridSquare, DataCollectionGroup) |
309 | | - .where(GridSquare.session_id == session_id) |
310 | | - .where(GridSquare.tag == DataCollectionGroup.tag) |
311 | | - .where(DataCollectionGroup.id == dcgid) |
312 | | - ).all() |
313 | | - return [gs[0] for gs in grid_squares] |
314 | | - |
315 | | - |
316 | | -@router.get( |
317 | | - "/sessions/{session_id}/data_collection_groups/{dcgid}/grid_squares/{gsid}/foil_holes" |
318 | | -) |
319 | | -def get_foil_holes_from_grid_square( |
320 | | - session_id: int, dcgid: int, gsid: int, db=murfey_db |
321 | | -) -> List[FoilHole]: |
322 | | - foil_holes = db.exec( |
323 | | - select(FoilHole, GridSquare, DataCollectionGroup) |
324 | | - .where(FoilHole.grid_square_id == GridSquare.id) |
325 | | - .where(GridSquare.name == gsid) |
326 | | - .where(GridSquare.session_id == session_id) |
327 | | - .where(GridSquare.tag == DataCollectionGroup.tag) |
328 | | - .where(DataCollectionGroup.id == dcgid) |
329 | | - ).all() |
330 | | - return [fh[0] for fh in foil_holes] |
331 | | - |
332 | | - |
333 | | -@router.post("/sessions/{session_id}/grid_square/{gsid}") |
334 | | -def posted_grid_square( |
335 | | - session_id: MurfeySessionID, |
336 | | - gsid: int, |
337 | | - grid_square_params: GridSquareParameters, |
338 | | - db=murfey_db, |
339 | | -): |
340 | | - return register_grid_square(session_id, gsid, grid_square_params, db) |
341 | | - |
342 | | - |
343 | | -@router.get("/sessions/{session_id}/foil_hole/{fh_name}") |
344 | | -def get_foil_hole( |
345 | | - session_id: MurfeySessionID, fh_name: int, db=murfey_db |
346 | | -) -> Dict[str, int]: |
347 | | - foil_holes = db.exec( |
348 | | - select(FoilHole, GridSquare) |
349 | | - .where(FoilHole.name == fh_name) |
350 | | - .where(FoilHole.session_id == session_id) |
351 | | - .where(GridSquare.id == FoilHole.grid_square_id) |
352 | | - ).all() |
353 | | - return {f[1].tag: f[0].id for f in foil_holes} |
354 | | - |
355 | | - |
356 | | -@router.post("/sessions/{session_id}/grid_square/{gs_name}/foil_hole") |
357 | | -def post_foil_hole( |
358 | | - session_id: MurfeySessionID, |
359 | | - gs_name: int, |
360 | | - foil_hole_params: FoilHoleParameters, |
361 | | - db=murfey_db, |
362 | | -): |
363 | | - log.info( |
364 | | - f"Registering foil hole {foil_hole_params.name} with position {(foil_hole_params.x_location, foil_hole_params.y_location)}" |
365 | | - ) |
366 | | - return register_foil_hole(session_id, gs_name, foil_hole_params, db) |
367 | | - |
368 | | - |
369 | 237 | @router.get("/visit/{visit_name}/samples") |
370 | 238 | def get_samples(visit_name: str, db=murfey.server.ispyb.DB) -> List[Sample]: |
371 | 239 | return murfey.server.ispyb.get_sub_samples_from_visit(visit_name, db=db) |
@@ -470,17 +338,6 @@ def change_monitoring_status(visit_name: str, on: int): |
470 | 338 | prom.monitoring_switch.labels(visit=visit_name).set(on) |
471 | 339 |
|
472 | 340 |
|
473 | | -@router.post("/instruments/{instrument_name}/failed_client_post") |
474 | | -def failed_client_post(instrument_name: str, post_info: PostInfo): |
475 | | - zocalo_message = { |
476 | | - "register": "failed_client_post", |
477 | | - "url": post_info.url, |
478 | | - "json": post_info.data, |
479 | | - } |
480 | | - if _transport_object: |
481 | | - _transport_object.send(_transport_object.feedback_queue, zocalo_message) |
482 | | - |
483 | | - |
484 | 341 | @router.get("/sessions/{session_id}/upstream_visits") |
485 | 342 | async def find_upstream_visits(session_id: MurfeySessionID, db=murfey_db): |
486 | 343 | murfey_session = db.exec(select(Session).where(Session.id == session_id)).one() |
@@ -558,36 +415,6 @@ async def get_tiff(visit_name: str, session_id: int, tiff_path: str, db=murfey_d |
558 | 415 | return FileResponse(path=test_path) |
559 | 416 |
|
560 | 417 |
|
561 | | -@router.post("/instruments/{instrument_name}/visits/{visit}/session/{name}") |
562 | | -def create_session(instrument_name: str, visit: str, name: str, db=murfey_db) -> int: |
563 | | - s = Session(name=name, visit=visit, instrument_name=instrument_name) |
564 | | - db.add(s) |
565 | | - db.commit() |
566 | | - sid = s.id |
567 | | - return sid |
568 | | - |
569 | | - |
570 | | -@router.post("/sessions/{session_id}") |
571 | | -def update_session( |
572 | | - session_id: MurfeySessionID, process: bool = True, db=murfey_db |
573 | | -) -> None: |
574 | | - session = db.exec(select(Session).where(session_id == session_id)).one() |
575 | | - session.process = process |
576 | | - db.add(session) |
577 | | - db.commit() |
578 | | - return None |
579 | | - |
580 | | - |
581 | | -@router.put("/sessions/{session_id}/current_gain_ref") |
582 | | -def update_current_gain_ref( |
583 | | - session_id: MurfeySessionID, new_gain_ref: CurrentGainRef, db=murfey_db |
584 | | -): |
585 | | - session = db.exec(select(Session).where(Session.id == session_id)).one() |
586 | | - session.current_gain_ref = new_gain_ref.path |
587 | | - db.add(session) |
588 | | - db.commit() |
589 | | - |
590 | | - |
591 | 418 | @router.get("/prometheus/{metric_name}") |
592 | 419 | def inspect_prometheus_metrics( |
593 | 420 | metric_name: str, |
|
0 commit comments