5656)
5757from murfey .client .rsync import RSyncer
5858from murfey .client .tui .forms import FormDependency
59+ from murfey .server .api .file_manip import router as file_manip_router
60+ from murfey .server .api .prometheus import router as prom_router
61+ from murfey .server .api .session_control import (
62+ correlative_router as session_correlative_router ,
63+ )
64+ from murfey .server .api .session_control import router as session_router
65+ from murfey .server .api .workflow import spa_router as workflow_spa_router
66+ from murfey .server .api .workflow import tomo_router as workflow_tomo_router
5967from murfey .util import posix_path
6068from murfey .util .client import capture_post , get_machine_config_client , read_config
6169from murfey .util .models import ProcessingParametersSPA , ProcessingParametersTomo
@@ -84,7 +92,7 @@ def determine_default_destination(
8492 use_suggested_path : bool = True ,
8593) -> str :
8694 machine_data = requests .get (
87- f"{ environment .url .geturl ()} /instruments/ { environment .instrument_name } /machine "
95+ f"{ environment .url .geturl ()} { session_router . url_path_for ( 'machine_info_by_instrument' , instrument_name = environment .instrument_name ) } "
8896 ).json ()
8997 _default = ""
9098 if environment .processing_only_mode and environment .sources :
@@ -109,7 +117,7 @@ def determine_default_destination(
109117 _default = environment .destination_registry [source_name ]
110118 else :
111119 suggested_path_response = capture_post (
112- url = f"{ str (environment .url .geturl ())} /visits/ { visit } / { environment .murfey_session } /suggested_path " ,
120+ url = f"{ str (environment .url .geturl ())} { file_manip_router . url_path_for ( 'suggest_path' , visit_name = visit , sesion_id = environment .murfey_session ) } " ,
113121 json = {
114122 "base_path" : f"{ destination } /{ visit } /{ mid_path .parent if include_mid_path else '' } /raw" ,
115123 "touch" : touch ,
@@ -265,7 +273,7 @@ def __init__(
265273 def compose (self ):
266274
267275 machine_data = requests .get (
268- f"{ self .app ._environment .url .geturl ()} /instruments/ { instrument_name } /machine "
276+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'machine_info_by_instrument' , instrument_name = instrument_name ) } "
269277 ).json ()
270278 self ._dir_tree = _DirectoryTree (
271279 str (self ._selected_dir ),
@@ -476,16 +484,16 @@ def _write_params(
476484 self .app ._start_dc (params )
477485 if model == ProcessingParametersTomo :
478486 requests .post (
479- f"{ self .app ._environment .url .geturl ()} /sessions/ { self .app ._environment .murfey_session } /tomography_processing_parameters " ,
487+ f"{ self .app ._environment .url .geturl ()} /{ workflow_tomo_router . url_path_for ( 'register_tomo_proc_params' , session_id = self .app ._environment .murfey_session ) } " ,
480488 json = params ,
481489 )
482490 elif model == ProcessingParametersSPA :
483491 requests .post (
484- f"{ self .app ._environment .url .geturl ()} /sessions/ { self .app ._environment .murfey_session } /spa_processing_parameters " ,
492+ f"{ self .app ._environment .url .geturl ()} { workflow_spa_router . url_path_for ( 'register_spa_proc_params' , session_id = self .app ._environment .murfey_session ) } " ,
485493 json = params ,
486494 )
487495 requests .post (
488- f"{ self .app ._environment .url .geturl ()} /visits/ { self .app ._environment .visit } / { self .app ._environment .murfey_session } /flush_spa_processing"
496+ 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 ) } " ,
489497 )
490498
491499 def on_switch_changed (self , event ):
@@ -645,14 +653,16 @@ def on_button_pressed(self, event: Button.Pressed):
645653 self .app .pop_screen ()
646654 session_name = "Client connection"
647655 self .app ._environment .murfey_session = requests .post (
648- f"{ self .app ._environment .url .geturl ()} /instruments/ { self .app ._environment .instrument_name } /clients/ { self .app ._environment .client_id } /session " ,
656+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'link_client_to_session' , instrument_name = self .app ._environment .instrument_name , client_id = self .app ._environment .client_id ) } " ,
649657 json = {"session_id" : session_id , "session_name" : session_name },
650658 ).json ()
651659
652660 def _remove_session (self , session_id : int , ** kwargs ):
653- requests .delete (f"{ self .app ._environment .url .geturl ()} /sessions/{ session_id } " )
661+ requests .delete (
662+ f"{ self .app ._environment .url .geturl ()} { session_router .url_path_for ('remove_session' , session_id = session_id )} "
663+ )
654664 exisiting_sessions = requests .get (
655- f"{ self .app ._environment .url .geturl ()} /sessions "
665+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'get_sessions' ) } "
656666 ).json ()
657667 self .app .uninstall_screen ("session-select-screen" )
658668 if exisiting_sessions :
@@ -674,7 +684,7 @@ def _remove_session(self, session_id: int, **kwargs):
674684 else :
675685 session_name = "Client connection"
676686 resp = capture_post (
677- f"{ self .app ._environment .url .geturl ()} /instruments/ { self ._environment .instrument_name } /clients/ { self .app ._environment .client_id } /session " ,
687+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'link_client_to_session' , instrument_name = self .app . _environment .instrument_name , client_id = self .app ._environment .client_id ) } " ,
678688 json = {"session_id" : None , "session_name" : session_name },
679689 )
680690 if resp :
@@ -735,7 +745,7 @@ def on_button_pressed(self, event: Button.Pressed):
735745
736746 if machine_data .get ("upstream_data_directories" ):
737747 upstream_downloads = requests .get (
738- f"{ self .app ._environment .url .geturl ()} /sessions/ { self .app ._environment .murfey_session } /upstream_visits "
748+ f"{ self .app ._environment .url .geturl ()} { session_correlative_router . url_path_for ( 'find_upstream_visits' , session_id = self .app ._environment .murfey_session ) } "
739749 ).json ()
740750 self .app .install_screen (
741751 UpstreamDownloads (upstream_downloads ), "upstream-downloads"
@@ -768,7 +778,7 @@ def on_button_pressed(self, event: Button.Pressed):
768778 )
769779 log .info (f"Posted visit registration: { response .status_code } " )
770780 machine_data = requests .get (
771- f"{ self .app ._environment .url .geturl ()} /instruments/ { instrument_name } /machine "
781+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'machine_info_by_instrument' , instrument_name = instrument_name ) } "
772782 ).json ()
773783
774784 self .app .install_screen (
@@ -797,7 +807,7 @@ def on_button_pressed(self, event: Button.Pressed):
797807
798808 if machine_data .get ("upstream_data_directories" ):
799809 upstream_downloads = requests .get (
800- f"{ self .app ._environment .url .geturl ()} /sessions/ { self .app ._environment .murfey_session } /upstream_visits "
810+ f"{ self .app ._environment .url .geturl ()} { session_correlative_router . url_path_for ( 'find_upstream_visits' , session_id = self .app ._environment .murfey_session ) } "
801811 ).json ()
802812 self .app .install_screen (
803813 UpstreamDownloads (upstream_downloads ), "upstream-downloads"
@@ -819,7 +829,7 @@ def compose(self):
819829
820830 def on_button_pressed (self , event : Button .Pressed ):
821831 machine_data = requests .get (
822- f"{ self .app ._environment .url .geturl ()} /instruments/ { instrument_name } /machine "
832+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'machine_info_by_instrument' , instrument_name = instrument_name ) } "
823833 ).json ()
824834 if machine_data .get ("upstream_data_download_directory" ):
825835 # Create the directory locally to save files to
@@ -830,7 +840,7 @@ def on_button_pressed(self, event: Button.Pressed):
830840
831841 # Get the paths to the TIFF files generated previously under the same session ID
832842 upstream_tiff_paths_response = requests .get (
833- f"{ self .app ._environment .url .geturl ()} /visits/ { event .button .label } / { self .app ._environment .murfey_session } /upstream_tiff_paths "
843+ f"{ self .app ._environment .url .geturl ()} { session_correlative_router . url_path_for ( 'gather_upstream_tiffs' , visit_name = event .button .label , session_id = self .app ._environment .murfey_session ) } "
834844 )
835845 upstream_tiff_paths = upstream_tiff_paths_response .json () or []
836846
@@ -839,7 +849,7 @@ def on_button_pressed(self, event: Button.Pressed):
839849 (download_dir / tp ).parent .mkdir (exist_ok = True , parents = True )
840850 # Write TIFF to the specified file path
841851 stream_response = requests .get (
842- f"{ self .app ._environment .url .geturl ()} /visits/ { event .button .label } / { self .app ._environment .murfey_session } /upstream_tiff/ { tp } " ,
852+ f"{ self .app ._environment .url .geturl ()} { session_correlative_router . url_path_for ( 'get_tiff' , visit_name = event .button .label , session_id = self .app ._environment .murfey_session , tiff_path = tp ) } " ,
843853 stream = True ,
844854 )
845855 # Write the file chunk-by-chunk to avoid hogging memory
@@ -903,7 +913,7 @@ def on_button_pressed(self, event):
903913 f"Gain reference file { posix_path (self ._dir_tree ._gain_reference )!r} was not successfully transferred to { visit_path } /processing"
904914 )
905915 process_gain_response = requests .post (
906- url = f"{ str (self .app ._environment .url .geturl ())} /sessions/ { self .app ._environment .murfey_session } /process_gain " ,
916+ url = f"{ str (self .app ._environment .url .geturl ())} { file_manip_router . url_path_for ( 'process_gain' , session_id = self .app ._environment .murfey_session ) } " ,
907917 json = {
908918 "gain_ref" : str (self ._dir_tree ._gain_reference ),
909919 "eer" : bool (
@@ -1231,10 +1241,10 @@ def file_copied(self, *args, **kwargs):
12311241 self .query_one (ProgressBar ).advance (1 )
12321242 if self .query_one (ProgressBar ).progress == self .query_one (ProgressBar ).total :
12331243 requests .post (
1234- f"{ self .app ._environment .url .geturl ()} /sessions/ { self .app ._environment .murfey_session } /successful_processing "
1244+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'register_processing_success_in_ispyb' , session_id = self .app ._environment .murfey_session ) } "
12351245 )
12361246 requests .delete (
1237- f"{ self .app ._environment .url .geturl ()} /instruments/ { self . _environment . instrument_name } /clients/ { self .app ._environment .client_id } /session "
1247+ f"{ self .app ._environment .url .geturl ()} { session_router . url_path_for ( 'remove_session' , session_id = self .app ._environment .murfey_session ) } "
12381248 )
12391249 self .app .exit ()
12401250
@@ -1266,5 +1276,5 @@ def compose(self):
12661276
12671277 def on_mount (self , event ):
12681278 requests .post (
1269- f"{ self .app ._environment .url .geturl ()} /visits/ { self .app ._environment .visit } /monitoring/1 "
1279+ f"{ self .app ._environment .url .geturl ()} { prom_router . url_path_for ( 'change_monitoring_status' , visit_name = self .app ._environment .visit , on = 1 ) } "
12701280 )
0 commit comments