@@ -3,7 +3,7 @@ use std::path::PathBuf;
33use color_eyre:: { Result , eyre:: eyre} ;
44
55use crate :: {
6- config:: Config ,
6+ config:: { ComputePlatform , Config } ,
77 cscs:: {
88 api_client:: { CscsApi , FileSystemType , Job , JobDetail , System } ,
99 oauth2:: {
@@ -54,10 +54,10 @@ pub async fn cscs_login_device_code() -> Result<(Secret, Option<Secret>)> {
5454 finish_cscs_device_login ( details) . await
5555}
5656
57- pub async fn cscs_system_list ( ) -> Result < Vec < System > > {
57+ pub async fn cscs_system_list ( platform : Option < ComputePlatform > ) -> Result < Vec < System > > {
5858 match get_access_token ( ) . await {
5959 Ok ( access_token) => {
60- let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
60+ let api_client = CscsApi :: new ( access_token. 0 , platform ) . unwrap ( ) ;
6161 api_client. list_systems ( ) . await
6262 }
6363 Err ( e) => Err ( e) ,
@@ -77,51 +77,62 @@ pub async fn cscs_system_set(system_name: String, global: bool) -> Result<()> {
7777 Ok ( ( ) )
7878}
7979
80- pub async fn cscs_job_list ( ) -> Result < Vec < Job > > {
80+ pub async fn cscs_job_list ( system : Option < String > , platform : Option < ComputePlatform > ) -> Result < Vec < Job > > {
8181 match get_access_token ( ) . await {
8282 Ok ( access_token) => {
83- let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
83+ let api_client = CscsApi :: new ( access_token. 0 , platform ) . unwrap ( ) ;
8484 let config = Config :: new ( ) . unwrap ( ) ;
85- api_client. list_jobs ( & config. cscs . current_system , Some ( true ) ) . await
85+ api_client
86+ . list_jobs ( & system. unwrap_or ( config. cscs . current_system ) , Some ( true ) )
87+ . await
8688 }
8789 Err ( e) => Err ( e) ,
8890 }
8991}
9092
91- pub async fn cscs_job_details ( job_id : i64 ) -> Result < Option < JobDetail > > {
93+ pub async fn cscs_job_details (
94+ job_id : i64 ,
95+ system : Option < String > ,
96+ platform : Option < ComputePlatform > ,
97+ ) -> Result < Option < JobDetail > > {
9298 match get_access_token ( ) . await {
9399 Ok ( access_token) => {
94- let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
100+ let api_client = CscsApi :: new ( access_token. 0 , platform ) . unwrap ( ) ;
95101 let config = Config :: new ( ) . unwrap ( ) ;
96- api_client. get_job ( & config. cscs . current_system , job_id) . await
102+ api_client
103+ . get_job ( & system. unwrap_or ( config. cscs . current_system ) , job_id)
104+ . await
97105 }
98106 Err ( e) => Err ( e) ,
99107 }
100108}
101109
102- pub async fn cscs_job_log ( job_id : i64 ) -> Result < String > {
110+ pub async fn cscs_job_log ( job_id : i64 , system : Option < String > , platform : Option < ComputePlatform > ) -> Result < String > {
103111 match get_access_token ( ) . await {
104112 Ok ( access_token) => {
105- let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
113+ let api_client = CscsApi :: new ( access_token. 0 , platform ) . unwrap ( ) ;
106114 let config = Config :: new ( ) . unwrap ( ) ;
107- let job = api_client. get_job ( & config. cscs . current_system , job_id) . await ?;
115+ let current_system = & system. unwrap_or ( config. cscs . current_system ) ;
116+ let job = api_client. get_job ( current_system, job_id) . await ?;
108117 if job. is_none ( ) {
109118 return Err ( eyre ! ( "couldn't find job {}" , job_id) ) ;
110119 }
111120 api_client
112- . tail ( & config . cscs . current_system , PathBuf :: from ( job. unwrap ( ) . stdout ) , 100 )
121+ . tail ( current_system, PathBuf :: from ( job. unwrap ( ) . stdout ) , 100 )
113122 . await
114123 }
115124 Err ( e) => Err ( e) ,
116125 }
117126}
118127
119- pub async fn cscs_job_cancel ( job_id : i64 ) -> Result < ( ) > {
128+ pub async fn cscs_job_cancel ( job_id : i64 , system : Option < String > , platform : Option < ComputePlatform > ) -> Result < ( ) > {
120129 match get_access_token ( ) . await {
121130 Ok ( access_token) => {
122- let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
131+ let api_client = CscsApi :: new ( access_token. 0 , platform ) . unwrap ( ) ;
123132 let config = Config :: new ( ) . unwrap ( ) ;
124- api_client. cancel_job ( & config. cscs . current_system , job_id) . await
133+ api_client
134+ . cancel_job ( & system. unwrap_or ( config. cscs . current_system ) , job_id)
135+ . await
125136 }
126137 Err ( e) => Err ( e) ,
127138 }
@@ -133,14 +144,17 @@ pub async fn cscs_start_job(
133144 command : Option < Vec < String > > ,
134145 container_workdir : Option < String > ,
135146 env : Vec < ( String , String ) > ,
147+ system : Option < String > ,
148+ platform : Option < ComputePlatform > ,
136149) -> Result < ( ) > {
137150 match get_access_token ( ) . await {
138151 Ok ( access_token) => {
139- let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
152+ let api_client = CscsApi :: new ( access_token. 0 , platform ) . unwrap ( ) ;
140153 let config = Config :: new ( ) . unwrap ( ) ;
141- let user_info = api_client. get_userinfo ( & config. cscs . current_system ) . await ?;
142- let current_system = api_client. get_system ( & config. cscs . current_system ) . await ?;
143- let scratch = match current_system {
154+ let current_system = & system. unwrap_or ( config. cscs . current_system ) ;
155+ let user_info = api_client. get_userinfo ( current_system) . await ?;
156+ let current_system_info = api_client. get_system ( current_system) . await ?;
157+ let scratch = match current_system_info {
144158 Some ( system) => PathBuf :: from (
145159 system
146160 . file_systems
@@ -151,10 +165,7 @@ pub async fn cscs_start_job(
151165 . clone ( ) ,
152166 ) ,
153167 None => {
154- return Err ( eyre ! (
155- "couldn't get system description for {}" ,
156- config. cscs. current_system
157- ) ) ;
168+ return Err ( eyre ! ( "couldn't get system description for {}" , current_system) ) ;
158169 }
159170 } ;
160171 let container_workdir = container_workdir. unwrap_or ( config. cscs . workdir . unwrap_or ( "/scratch" . to_owned ( ) ) ) ;
@@ -173,7 +184,7 @@ pub async fn cscs_start_job(
173184
174185 let docker_image = image. unwrap_or ( config. cscs . image . try_into ( ) ?) ;
175186 let meta = docker_image. inspect ( ) . await ?;
176- if let Some ( system_info) = config. cscs . systems . get ( & config . cscs . current_system ) {
187+ if let Some ( system_info) = config. cscs . systems . get ( current_system) {
177188 let mut compatible = false ;
178189 for sys_platform in system_info. architecture . iter ( ) {
179190 if meta. platforms . contains ( & sys_platform. clone ( ) . into ( ) ) {
@@ -184,7 +195,7 @@ pub async fn cscs_start_job(
184195 if !compatible {
185196 return Err ( eyre ! (
186197 "System {} only supports images with architecture(s) '{}' but the supplied image is for architecture(s) '{}'" ,
187- config . cscs . current_system,
198+ current_system,
188199 system_info. architecture. join( "," ) ,
189200 meta. platforms
190201 . iter( )
@@ -201,16 +212,10 @@ pub async fn cscs_start_job(
201212 context. insert ( "env" , & envvars) ;
202213
203214 let environment_file = tera. render ( "environment.toml" , & context) ?;
204- api_client. mkdir ( & config. cscs . current_system , base_path. clone ( ) ) . await ?;
205- api_client
206- . chmod ( & config. cscs . current_system , base_path. clone ( ) , "700" )
207- . await ?;
215+ api_client. mkdir ( current_system, base_path. clone ( ) ) . await ?;
216+ api_client. chmod ( current_system, base_path. clone ( ) , "700" ) . await ?;
208217 api_client
209- . upload (
210- & config. cscs . current_system ,
211- environment_path. clone ( ) ,
212- environment_file. into_bytes ( ) ,
213- )
218+ . upload ( current_system, environment_path. clone ( ) , environment_file. into_bytes ( ) )
214219 . await ?;
215220
216221 // upload script
@@ -227,12 +232,12 @@ pub async fn cscs_start_job(
227232 context. insert ( "container_workdir" , & container_workdir) ;
228233 let script = tera. render ( "script.sh" , & context) ?;
229234 api_client
230- . upload ( & config . cscs . current_system , script_path. clone ( ) , script. into_bytes ( ) )
235+ . upload ( current_system, script_path. clone ( ) , script. into_bytes ( ) )
231236 . await ?;
232237
233238 // start job
234239 api_client
235- . start_job ( & config . cscs . current_system , & name, script_path, envvars)
240+ . start_job ( current_system, & name, script_path, envvars)
236241 . await ?;
237242 Ok ( ( ) )
238243 }
0 commit comments