From 3e1b37f5e0aa8546536993e804ea711f747ce600 Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Mon, 9 Dec 2024 09:49:00 +0100 Subject: [PATCH 1/2] Do not call worker enumeration for invokes --- golem-cli/src/service/worker.rs | 42 +++++++-------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/golem-cli/src/service/worker.rs b/golem-cli/src/service/worker.rs index 2d58877e8..635a8bf10 100644 --- a/golem-cli/src/service/worker.rs +++ b/golem-cli/src/service/worker.rs @@ -216,40 +216,16 @@ async fn resolve_worker_component_version( components: &(dyn ComponentService + Send + Sync), worker_urn: WorkerUrn, ) -> Result, GolemError> { - let TargetWorkerId { - component_id, - worker_name, - } = worker_urn.id; - - if let Some(worker_name) = worker_name { - let component_urn = ComponentUrn { id: component_id }; - - let worker_meta = client - .find_metadata( - component_urn.clone(), - Some(WorkerFilter::Name(WorkerNameFilter { - comparator: StringFilterComparator::Equal, - value: worker_name, - })), - None, - Some(2), - Some(true), - ) - .await?; + if worker_urn.id.worker_name.is_some() { + let component_urn = ComponentUrn { + id: worker_urn.id.component_id.clone(), + }; - if worker_meta.workers.len() > 1 { - Err(GolemError( - "Multiple workers with the same name".to_string(), - )) - } else if let Some(worker) = worker_meta.workers.first() { - Ok(Some( - components - .get_metadata(&component_urn, worker.component_version) - .await?, - )) - } else { - Ok(None) - } + let worker_metadata = client.get_metadata(worker_urn).await?; + let component_metadata = components + .get_metadata(&component_urn, worker_metadata.component_version) + .await?; + Ok(Some(component_metadata)) } else { Ok(None) } From 74e62648cc9eac5f7ae45af93423c971c8f193af Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Mon, 9 Dec 2024 10:23:09 +0100 Subject: [PATCH 2/2] Fix --- golem-cli/src/clients/worker.rs | 4 ++++ golem-cli/src/oss/clients/worker.rs | 20 ++++++++++++++++++++ golem-cli/src/service/worker.rs | 18 +++++++++++------- golem-worker-service-base/src/api/error.rs | 11 ++++++++--- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/golem-cli/src/clients/worker.rs b/golem-cli/src/clients/worker.rs index 9f6010a3b..6bb6ec7ff 100644 --- a/golem-cli/src/clients/worker.rs +++ b/golem-cli/src/clients/worker.rs @@ -53,6 +53,10 @@ pub trait WorkerClient { async fn simulated_crash(&self, worker_urn: WorkerUrn) -> Result<(), GolemError>; async fn delete(&self, worker_urn: WorkerUrn) -> Result<(), GolemError>; async fn get_metadata(&self, worker_urn: WorkerUrn) -> Result; + async fn get_metadata_opt( + &self, + worker_urn: WorkerUrn, + ) -> Result, GolemError>; async fn find_metadata( &self, component_urn: ComponentUrn, diff --git a/golem-cli/src/oss/clients/worker.rs b/golem-cli/src/oss/clients/worker.rs index a291e5352..a9d3e9b92 100644 --- a/golem-cli/src/oss/clients/worker.rs +++ b/golem-cli/src/oss/clients/worker.rs @@ -205,6 +205,26 @@ impl WorkerClient for WorkerCl .into()) } + async fn get_metadata_opt( + &self, + worker_urn: WorkerUrn, + ) -> Result, GolemError> { + info!("Getting worker {worker_urn} metadata"); + + match self + .client + .get_worker_metadata( + &worker_urn.id.component_id.0, + &worker_name_required(&worker_urn)?, + ) + .await + { + Ok(metadata) => Ok(Some(metadata.into())), + Err(Error::Item(WorkerError::Error404(_))) => Ok(None), + Err(err) => Err(err.into()), + } + } + async fn find_metadata( &self, component_urn: ComponentUrn, diff --git a/golem-cli/src/service/worker.rs b/golem-cli/src/service/worker.rs index 635a8bf10..29dad749e 100644 --- a/golem-cli/src/service/worker.rs +++ b/golem-cli/src/service/worker.rs @@ -26,8 +26,8 @@ use crate::model::{ }; use crate::service::component::ComponentService; use async_trait::async_trait; -use golem_client::model::{AnalysedType, InvokeParameters, InvokeResult, ScanCursor, WorkerFilter}; -use golem_common::model::{StringFilterComparator, TargetWorkerId, WorkerNameFilter}; +use golem_client::model::{AnalysedType, InvokeParameters, InvokeResult, ScanCursor}; +use golem_common::model::TargetWorkerId; use golem_common::uri::oss::uri::{ComponentUri, WorkerUri}; use golem_common::uri::oss::url::{ComponentUrl, WorkerUrl}; use golem_common::uri::oss::urn::{ComponentUrn, WorkerUrn}; @@ -221,11 +221,15 @@ async fn resolve_worker_component_version( id: worker_urn.id.component_id.clone(), }; - let worker_metadata = client.get_metadata(worker_urn).await?; - let component_metadata = components - .get_metadata(&component_urn, worker_metadata.component_version) - .await?; - Ok(Some(component_metadata)) + let worker_metadata = client.get_metadata_opt(worker_urn).await?; + if let Some(worker_metadata) = worker_metadata { + let component_metadata = components + .get_metadata(&component_urn, worker_metadata.component_version) + .await?; + Ok(Some(component_metadata)) + } else { + Ok(None) + } } else { Ok(None) } diff --git a/golem-worker-service-base/src/api/error.rs b/golem-worker-service-base/src/api/error.rs index 45244c553..d7b1afff9 100644 --- a/golem-worker-service-base/src/api/error.rs +++ b/golem-worker-service-base/src/api/error.rs @@ -105,9 +105,14 @@ impl From for WorkerApiBaseError { | ServiceError::WorkerNotFound(_) => WorkerApiBaseError::NotFound(Json(ErrorBody { error: error.to_safe_string(), })), - ServiceError::Golem(golem_error) => { - WorkerApiBaseError::InternalError(Json(GolemErrorBody { golem_error })) - } + ServiceError::Golem(golem_error) => match golem_error { + GolemError::WorkerNotFound(error) => { + WorkerApiBaseError::NotFound(Json(ErrorBody { + error: error.to_safe_string(), + })) + } + _ => WorkerApiBaseError::InternalError(Json(GolemErrorBody { golem_error })), + }, ServiceError::Component(error) => error.into(), ServiceError::InternalCallError(_) => internal(error.to_safe_string()), ServiceError::FileNotFound(_) => WorkerApiBaseError::NotFound(Json(ErrorBody {