@@ -6,8 +6,8 @@ use crate::{
66 cscs:: {
77 api_client:: { CscsApi , FileSystemType , Job , JobDetail , System } ,
88 oauth2:: {
9- CLIENT_ID_SECRET_NAME , CLIENT_SECRET_SECRET_NAME ,
10- client_credentials_login , finish_cscs_device_login, start_cscs_device_login,
9+ CLIENT_ID_SECRET_NAME , CLIENT_SECRET_SECRET_NAME , client_credentials_login ,
10+ finish_cscs_device_login, start_cscs_device_login,
1111 } ,
1212 } ,
1313 util:: {
@@ -61,17 +61,22 @@ pub async fn cscs_job_list() -> Result<Vec<Job>> {
6161 Ok ( access_token) => {
6262 let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
6363 let config = Config :: new ( ) . unwrap ( ) ;
64- api_client. list_jobs ( & config. cscs . system , Some ( true ) ) . await
64+ api_client
65+ . list_jobs ( & config. cscs . current_system , Some ( true ) )
66+ . await
6567 }
6668 Err ( e) => Err ( e) ,
6769 }
6870}
71+
6972pub async fn cscs_job_details ( job_id : i64 ) -> Result < Option < JobDetail > > {
7073 match get_access_token ( ) . await {
7174 Ok ( access_token) => {
7275 let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
7376 let config = Config :: new ( ) . unwrap ( ) ;
74- api_client. get_job ( & config. cscs . system , job_id) . await
77+ api_client
78+ . get_job ( & config. cscs . current_system , job_id)
79+ . await
7580 }
7681 Err ( e) => Err ( e) ,
7782 }
@@ -86,9 +91,9 @@ pub async fn cscs_start_job(
8691 Ok ( access_token) => {
8792 let api_client = CscsApi :: new ( access_token. 0 ) . unwrap ( ) ;
8893 let config = Config :: new ( ) . unwrap ( ) ;
89- let user_info = api_client. get_userinfo ( & config. cscs . system ) . await ?;
90- let system = api_client. get_system ( & config. cscs . system ) . await ?;
91- let scratch = match system {
94+ let user_info = api_client. get_userinfo ( & config. cscs . current_system ) . await ?;
95+ let current_system = api_client. get_system ( & config. cscs . current_system ) . await ?;
96+ let scratch = match current_system {
9297 Some ( system) => PathBuf :: from (
9398 system
9499 . file_systems
@@ -101,7 +106,7 @@ pub async fn cscs_start_job(
101106 None => {
102107 return Err ( eyre ! (
103108 "couldn't get system description for {}" ,
104- config. cscs. system
109+ config. cscs. current_system
105110 ) ) ;
106111 }
107112 } ;
@@ -113,21 +118,43 @@ pub async fn cscs_start_job(
113118 let environment_path = base_path. join ( "environment.toml" ) ;
114119 let environment_template = config. cscs . edf_file_template ;
115120 tera. add_raw_template ( "environment.toml" , & environment_template) ?;
121+
122+ let docker_image = image. unwrap_or ( config. cscs . image . try_into ( ) ?) ;
123+ let meta = docker_image. inspect ( ) . await ?;
124+ if let Some ( system_info) = config. cscs . systems . get ( & config. cscs . current_system ) {
125+ let mut compatible = false ;
126+ for sys_platform in system_info. architecture . iter ( ) {
127+ if meta. platforms . contains ( & sys_platform. clone ( ) . into ( ) ) {
128+ compatible = true ;
129+ }
130+ }
131+
132+ if !compatible {
133+ return Err ( eyre ! (
134+ "System {} only supports images with architecture(s) '{}' but the supplied image is for architecture(s) '{}'" ,
135+ config. cscs. current_system,
136+ system_info. architecture. join( "," ) ,
137+ meta. platforms
138+ . iter( )
139+ . map( |p| p. to_string( ) )
140+ . collect:: <Vec <String >>( )
141+ . join( "," )
142+ ) ) ;
143+ }
144+ }
145+
116146 let mut context = tera:: Context :: new ( ) ;
117- context. insert (
118- "edf_image" ,
119- & image. unwrap_or ( config. cscs . image . try_into ( ) ?) . to_edf ( ) ,
120- ) ;
147+ context. insert ( "edf_image" , & docker_image. to_edf ( ) ) ;
121148 let environment_file = tera. render ( "environment.toml" , & context) ?;
122149 api_client
123- . mkdir ( & config. cscs . system , base_path. clone ( ) )
150+ . mkdir ( & config. cscs . current_system , base_path. clone ( ) )
124151 . await ?;
125152 api_client
126- . chmod ( & config. cscs . system , base_path. clone ( ) , "700" )
153+ . chmod ( & config. cscs . current_system , base_path. clone ( ) , "700" )
127154 . await ?;
128155 api_client
129156 . upload (
130- & config. cscs . system ,
157+ & config. cscs . current_system ,
131158 environment_path. clone ( ) ,
132159 environment_file. into_bytes ( ) ,
133160 )
@@ -150,15 +177,15 @@ pub async fn cscs_start_job(
150177 let script = tera. render ( "script.sh" , & context) ?;
151178 api_client
152179 . upload (
153- & config. cscs . system ,
180+ & config. cscs . current_system ,
154181 script_path. clone ( ) ,
155182 script. into_bytes ( ) ,
156183 )
157184 . await ?;
158185
159186 // start job
160187 api_client
161- . start_job ( & config. cscs . system , & name, script_path)
188+ . start_job ( & config. cscs . current_system , & name, script_path)
162189 . await ?;
163190 Ok ( ( ) )
164191 }
0 commit comments