3333from murfey .client .tui .status_bar import StatusBar
3434from murfey .client .watchdir import DirWatcher
3535from murfey .client .watchdir_multigrid import MultigridDirWatcher
36+ from murfey .server .api .file_manip import router as file_manip_router
37+ from murfey .server .api .prometheus import router as prom_router
38+ from murfey .server .api .session_control import router as session_router
39+ from murfey .server .api .workflow import router as workflow_router
40+ from murfey .server .api .workflow import spa_router as workflow_spa_router
41+ from murfey .server .api .workflow import tomo_router as workflow_tomo_router
3642from murfey .util import posix_path
3743from murfey .util .client import (
3844 capture_post ,
@@ -156,7 +162,7 @@ def _start_rsyncer_multigrid(
156162 log .info (f"starting multigrid rsyncer: { source } " )
157163 destination_overrides = destination_overrides or {}
158164 machine_data = requests .get (
159- f"{ self ._environment .url .geturl ()} /instruments/ { instrument_name } /machine "
165+ f"{ self ._environment .url .geturl ()} { session_router . url_path_for ( 'machine_info_by_instrument' , instrument_name = instrument_name ) } "
160166 ).json ()
161167 if destination_overrides .get (source ):
162168 destination = destination_overrides [source ] + f"/{ extra_directory } "
@@ -208,7 +214,7 @@ def _start_rsyncer(
208214 log .info (f"starting rsyncer: { source } " )
209215 if transfer :
210216 # Always make sure the destination directory exists
211- make_directory_url = f"{ str (self ._url .geturl ())} /sessions/ { str ( self ._environment .murfey_session )} /make_rsyncer_destination "
217+ make_directory_url = f"{ str (self ._url .geturl ())} { file_manip_router . url_path_for ( 'make_rsyncer_destination' , session_id = self ._environment .murfey_session )} "
212218 capture_post (make_directory_url , json = {"destination" : destination })
213219 if self ._environment :
214220 self ._environment .default_destinations [source ] = destination
@@ -274,7 +280,7 @@ def rsync_result(update: RSyncerUpdate):
274280 ),
275281 secondary = True ,
276282 )
277- url = f"{ str (self ._url .geturl ())} /sessions/ { str ( self ._environment .murfey_session )} /rsyncer "
283+ url = f"{ str (self ._url .geturl ())} { session_router . url_path_for ( 'register_rsyncer' , session_id = self ._environment .murfey_session )} "
278284 rsyncer_data = {
279285 "source" : str (source ),
280286 "destination" : destination ,
@@ -344,7 +350,7 @@ def _increment_file_count(
344350 self , observed_files : List [Path ], source : str , destination : str
345351 ):
346352 if len (observed_files ):
347- url = f"{ str (self ._url .geturl ())} /visits/ { str ( self ._visit )} /increment_rsync_file_count "
353+ url = f"{ str (self ._url .geturl ())} { prom_router . url_path_for ( 'increment_rsync_file_count' , visit_name = self ._visit )} "
348354 num_data_files = len (
349355 [
350356 f
@@ -368,7 +374,7 @@ def _increment_transferred_files_prometheus(
368374 self , update : RSyncerUpdate , source : str , destination : str
369375 ):
370376 if update .outcome is TransferResult .SUCCESS :
371- url = f"{ str (self ._url .geturl ())} /visits/ { str ( self ._visit )} /increment_rsync_transferred_files_prometheus "
377+ url = f"{ str (self ._url .geturl ())} { prom_router . url_path_for ( 'increment_rsync_transferred_files_prometheus' , visit_name = self ._visit )} "
372378 data_files = (
373379 [update ]
374380 if update .file_path .suffix in self ._data_suffixes
@@ -397,7 +403,7 @@ def _increment_transferred_files(
397403 ]
398404 if not checked_updates :
399405 return
400- url = f"{ str (self ._url .geturl ())} /visits/ { str ( self ._visit )} /increment_rsync_transferred_files "
406+ url = f"{ str (self ._url .geturl ())} { prom_router . url_path_for ( 'increment_rsync_transferred_files' , visit_name = self ._visit )} "
401407 data_files = [
402408 u
403409 for u in updates
@@ -487,7 +493,7 @@ def _start_dc(self, json, from_form: bool = False):
487493 log .info ("Registering tomography processing parameters" )
488494 if self .app ._environment .data_collection_parameters .get ("num_eer_frames" ):
489495 eer_response = requests .post (
490- f"{ str (self .app ._environment .url .geturl ())} /visits/ { self .app ._environment .visit } / { self .app ._environment .murfey_session } /eer_fractionation_file " ,
496+ f"{ str (self .app ._environment .url .geturl ())} { file_manip_router . url_path_for ( 'write_eer_fractionation_file' , visit_name = self .app ._environment .visit , session_id = self .app ._environment .murfey_session ) } " ,
491497 json = {
492498 "num_frames" : self .app ._environment .data_collection_parameters [
493499 "num_eer_frames"
@@ -504,16 +510,16 @@ def _start_dc(self, json, from_form: bool = False):
504510 eer_fractionation_file = eer_response .json ()["eer_fractionation_file" ]
505511 json .update ({"eer_fractionation_file" : eer_fractionation_file })
506512 requests .post (
507- f"{ self .app ._environment .url .geturl ()} /sessions/ { self .app ._environment .murfey_session } /tomography_processing_parameters " ,
513+ f"{ self .app ._environment .url .geturl ()} { workflow_tomo_router . url_path_for ( 'register_tomo_proc_params' , session_id = self .app ._environment .murfey_session ) } " ,
508514 json = json ,
509515 )
510516 capture_post (
511- f"{ self .app ._environment .url .geturl ()} /visits/ { self ._visit } / { self .app ._environment .murfey_session } /flush_tomography_processing " ,
517+ f"{ self .app ._environment .url .geturl ()} { workflow_tomo_router . url_path_for ( 'flush_tomography_processing' , visit_name = self ._visit , session_id = self .app ._environment .murfey_session ) } " ,
512518 json = {"rsync_source" : str (source )},
513519 )
514520 log .info ("Tomography processing flushed" )
515521 elif isinstance (context , SPAModularContext ):
516- url = f"{ str (self ._url .geturl ())} /visits/ { str ( self ._visit ) } / { self ._environment .murfey_session } /register_data_collection_group "
522+ url = f"{ str (self ._url .geturl ())} { workflow_router . url_path_for ( 'register_dc_group' , visit_name = self ._visit , session_id = self ._environment .murfey_session ) } "
517523 dcg_data = {
518524 "experiment_type" : "single particle" ,
519525 "experiment_type_id" : 37 ,
@@ -552,7 +558,7 @@ def _start_dc(self, json, from_form: bool = False):
552558 "phase_plate" : json .get ("phase_plate" , False ),
553559 }
554560 capture_post (
555- f"{ str (self ._url .geturl ())} /visits/ { str ( self ._visit ) } / { self ._environment .murfey_session } /start_data_collection " ,
561+ f"{ str (self ._url .geturl ())} { workflow_router . url_path_for ( 'start_dc' , visit_name = self ._visit , session_id = self ._environment .murfey_session ) } " ,
556562 json = data ,
557563 )
558564 for recipe in (
@@ -563,7 +569,7 @@ def _start_dc(self, json, from_form: bool = False):
563569 "em-spa-refine" ,
564570 ):
565571 capture_post (
566- f"{ str (self ._url .geturl ())} /visits/ { str ( self ._visit ) } / { self ._environment .murfey_session } /register_processing_job " ,
572+ f"{ str (self ._url .geturl ())} { workflow_router . url_path_for ( 'register_proc' , visit_name = self ._visit , session_id = self ._environment .murfey_session ) } " ,
567573 json = {
568574 "tag" : str (source ),
569575 "source" : str (source ),
@@ -572,7 +578,7 @@ def _start_dc(self, json, from_form: bool = False):
572578 )
573579 log .info (f"Posting SPA processing parameters: { json } " )
574580 response = capture_post (
575- f"{ self .app ._environment .url .geturl ()} /sessions/ { self .app ._environment .murfey_session } /spa_processing_parameters " ,
581+ f"{ self .app ._environment .url .geturl ()} { workflow_spa_router . url_path_for ( 'register_spa_proc_params' , session_id = self .app ._environment .murfey_session ) } " ,
576582 json = {
577583 ** {k : None if v == "None" else v for k , v in json .items ()},
578584 "tag" : str (source ),
@@ -586,7 +592,7 @@ def _start_dc(self, json, from_form: bool = False):
586592 if not str (response .status_code ).startswith ("2" ):
587593 log .warning (f"{ response .reason } " )
588594 capture_post (
589- f"{ self .app ._environment .url .geturl ()} /visits/ { self .app ._environment .visit } / { self .app ._environment .murfey_session } /flush_spa_processing " ,
595+ f"{ self .app ._environment .url .geturl ()} { workflow_spa_router . url_path_for ( 'flush_spa_processing' , visit_name = self .app ._environment .visit , session_id = self .app ._environment .murfey_session ) } " ,
590596 json = {"tag" : str (source )},
591597 )
592598
0 commit comments