@@ -30,15 +30,15 @@ use crate::model::app::{
3030 AppComponentName , ApplicationComponentSelectMode , BuildProfileName , DynamicHelpSections ,
3131} ;
3232use crate :: model:: app:: { DependencyType , InitialComponentFile } ;
33- use crate :: model:: component:: { Component , ComponentView } ;
33+ use crate :: model:: component:: { Component , ComponentSelection , ComponentView } ;
3434use crate :: model:: deploy:: TryUpdateAllWorkersResult ;
3535use crate :: model:: text:: component:: { ComponentCreateView , ComponentGetView , ComponentUpdateView } ;
3636use crate :: model:: text:: fmt:: { log_error, log_text_view, log_warn} ;
3737use crate :: model:: text:: help:: ComponentNameHelp ;
3838use crate :: model:: to_cloud:: ToCloud ;
3939use crate :: model:: {
40- ComponentName , ComponentNameMatchKind , ProjectNameAndId , SelectedComponents , WorkerName ,
41- WorkerUpdateMode ,
40+ ComponentName , ComponentNameMatchKind , ComponentVersionSelection , ProjectNameAndId ,
41+ SelectedComponents , WorkerUpdateMode ,
4242} ;
4343use anyhow:: { anyhow, bail, Context as AnyhowContext } ;
4444use golem_client:: api:: ComponentClient as ComponentClientOss ;
@@ -801,9 +801,9 @@ impl ComponentCommandHandler {
801801 let mut components = Vec :: with_capacity ( selected_component_names. component_names . len ( ) ) ;
802802 for component_name in & selected_component_names. component_names {
803803 match self
804- . component_by_name (
804+ . component (
805805 selected_component_names. project . as_ref ( ) ,
806- component_name,
806+ component_name. into ( ) ,
807807 None ,
808808 )
809809 . await ?
@@ -1037,10 +1037,10 @@ impl ComponentCommandHandler {
10371037 project : Option < & ProjectNameAndId > ,
10381038 component_match_kind : ComponentNameMatchKind ,
10391039 component_name : & ComponentName ,
1040- worker_name : Option < & WorkerName > ,
1040+ component_version_selection : Option < ComponentVersionSelection < ' _ > > ,
10411041 ) -> anyhow:: Result < Component > {
10421042 match self
1043- . component_by_name ( project, component_name, worker_name )
1043+ . component ( project, component_name. into ( ) , component_version_selection )
10441044 . await ?
10451045 {
10461046 Some ( component) => Ok ( component) ,
@@ -1100,7 +1100,7 @@ impl ComponentCommandHandler {
11001100 . await ?;
11011101 self . ctx
11021102 . component_handler ( )
1103- . component_by_name ( project, component_name, None )
1103+ . component ( project, component_name. into ( ) , None )
11041104 . await ?
11051105 . ok_or_else ( || {
11061106 anyhow ! ( "Component ({}) not found after deployment" , component_name)
@@ -1115,63 +1115,84 @@ impl ComponentCommandHandler {
11151115 // TODO: server: we might want to have a filter for batch name lookups on the server side
11161116 // TODO: server: also the search returns all versions
11171117 // TODO: maybe add transient or persistent cache for all the meta
1118- pub async fn component_by_name (
1118+ // TODO: merge these 3 args into "component lookup" or "selection" struct
1119+ pub async fn component (
11191120 & self ,
11201121 project : Option < & ProjectNameAndId > ,
1121- component_name : & ComponentName ,
1122- worker_name : Option < & WorkerName > ,
1122+ component_name_or_id : ComponentSelection < ' _ > ,
1123+ component_version_selection : Option < ComponentVersionSelection < ' _ > > ,
11231124 ) -> anyhow:: Result < Option < Component > > {
1124- let component = match self . ctx . golem_clients ( ) . await ? {
1125- GolemClients :: Oss ( clients) => {
1126- let mut components = clients
1125+ let component = match component_name_or_id {
1126+ ComponentSelection :: Name ( component_name) => match self . ctx . golem_clients ( ) . await ? {
1127+ GolemClients :: Oss ( clients) => {
1128+ let mut components = clients
1129+ . component
1130+ . get_components ( Some ( & component_name. 0 ) )
1131+ . await
1132+ . map_service_error ( ) ?;
1133+ if !components. is_empty ( ) {
1134+ Some ( Component :: from ( components. pop ( ) . unwrap ( ) ) )
1135+ } else {
1136+ None
1137+ }
1138+ }
1139+ GolemClients :: Cloud ( clients) => {
1140+ let mut components = clients
1141+ . component
1142+ . get_components (
1143+ project. as_ref ( ) . map ( |p| & p. project_id . 0 ) ,
1144+ Some ( & component_name. 0 ) ,
1145+ )
1146+ . await
1147+ . map_service_error ( ) ?;
1148+ if !components. is_empty ( ) {
1149+ Some ( Component :: from ( components. pop ( ) . unwrap ( ) ) )
1150+ } else {
1151+ None
1152+ }
1153+ }
1154+ } ,
1155+ ComponentSelection :: Id ( component_id) => match self . ctx . golem_clients ( ) . await ? {
1156+ GolemClients :: Oss ( clients) => clients
11271157 . component
1128- . get_components ( Some ( & component_name . 0 ) )
1158+ . get_latest_component_metadata ( & component_id )
11291159 . await
1130- . map_service_error ( ) ?;
1131- if !components. is_empty ( ) {
1132- Some ( Component :: from ( components. pop ( ) . unwrap ( ) ) )
1133- } else {
1134- None
1135- }
1136- }
1137- GolemClients :: Cloud ( clients) => {
1138- let mut components = clients
1160+ . map ( Component :: from)
1161+ . map_service_error_not_found_as_opt ( ) ?,
1162+ GolemClients :: Cloud ( clients) => clients
11391163 . component
1140- . get_components (
1141- project. as_ref ( ) . map ( |p| & p. project_id . 0 ) ,
1142- Some ( & component_name. 0 ) ,
1143- )
1164+ . get_latest_component_metadata ( & component_id)
11441165 . await
1145- . map_service_error ( ) ?;
1146- if !components. is_empty ( ) {
1147- Some ( Component :: from ( components. pop ( ) . unwrap ( ) ) )
1148- } else {
1149- None
1150- }
1151- }
1166+ . map ( Component :: from)
1167+ . map_service_error_not_found_as_opt ( ) ?,
1168+ } ,
11521169 } ;
11531170
1154- match ( component, worker_name) {
1155- ( Some ( component) , Some ( worker_name) ) => {
1156- let worker_metadata = self
1157- . ctx
1158- . worker_handler ( )
1159- . worker_metadata (
1160- component. versioned_component_id . component_id ,
1161- & component. component_name ,
1162- worker_name,
1163- )
1164- . await
1165- . ok ( ) ;
1171+ match ( component, component_version_selection) {
1172+ ( Some ( component) , Some ( component_version_selection) ) => {
1173+ let version = match component_version_selection {
1174+ ComponentVersionSelection :: ByWorkerName ( worker_name) => self
1175+ . ctx
1176+ . worker_handler ( )
1177+ . worker_metadata (
1178+ component. versioned_component_id . component_id ,
1179+ & component. component_name ,
1180+ worker_name,
1181+ )
1182+ . await
1183+ . ok ( )
1184+ . map ( |worker_metadata| worker_metadata. component_version ) ,
1185+ ComponentVersionSelection :: ByExplicitVersion ( version) => Some ( version) ,
1186+ } ;
11661187
1167- match worker_metadata {
1168- Some ( worker_metadata ) => {
1188+ match version {
1189+ Some ( version ) => {
11691190 let component = match self . ctx . golem_clients ( ) . await ? {
11701191 GolemClients :: Oss ( clients) => clients
11711192 . component
11721193 . get_component_metadata (
11731194 & component. versioned_component_id . component_id ,
1174- & worker_metadata . component_version . to_string ( ) ,
1195+ & version . to_string ( ) ,
11751196 )
11761197 . await
11771198 . map_service_error ( )
@@ -1180,7 +1201,7 @@ impl ComponentCommandHandler {
11801201 . component
11811202 . get_component_metadata (
11821203 & component. versioned_component_id . component_id ,
1183- & worker_metadata . component_version . to_string ( ) ,
1204+ & version . to_string ( ) ,
11841205 )
11851206 . await
11861207 . map_service_error ( )
@@ -1203,7 +1224,7 @@ impl ComponentCommandHandler {
12031224 component_name : & ComponentName ,
12041225 ) -> anyhow:: Result < Option < ComponentId > > {
12051226 Ok ( self
1206- . component_by_name ( project, component_name, None )
1227+ . component ( project, component_name. into ( ) , None )
12071228 . await ?
12081229 . map ( |c| ComponentId ( c. versioned_component_id . component_id ) ) )
12091230 }
0 commit comments