diff --git a/Makefile.toml b/Makefile.toml index 2d54c69dd3..a27cda7688 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -364,11 +364,19 @@ description = "Generates openapi spec from the code and saves it to the openapi [tasks.generate-worker-service-openapi] description = "Generates openapi spec for worker service" -script = "./target/debug/golem-worker-service --dump-openapi-yaml > ./target/golem-worker-service.yaml" +cwd = "./target/debug" +script = ''' +mkdir -pv ../data +./golem-worker-service --dump-openapi-yaml > ../golem-worker-service.yaml +''' [tasks.generate-component-service-openapi] description = "Generates openapi spec for component service" -script = "./target/debug/golem-component-service --dump-openapi-yaml > ./target/golem-component-service.yaml" +cwd = "./target/debug" +script = ''' +mkdir -pv ../data +./golem-component-service --dump-openapi-yaml > ../golem-component-service.yaml +''' [tasks.merge-openapi] install_crate = { crate_name = "golem-openapi-client-generator", version = "0.0.8" } diff --git a/golem-component-service-base/src/service/component.rs b/golem-component-service-base/src/service/component.rs index 4ac02e793d..6fdfde511b 100644 --- a/golem-component-service-base/src/service/component.rs +++ b/golem-component-service-base/src/service/component.rs @@ -27,7 +27,6 @@ use tracing::{error, info}; use crate::model::Component; use crate::repo::component::ComponentRepo; use crate::repo::RepoError; -use golem_common::model::component_metadata::ComponentMetadata; use golem_service_base::model::{ComponentName, VersionedComponentId}; use golem_service_base::service::component_object_store::ComponentObjectStore; use golem_service_base::stream::ByteStream; @@ -599,151 +598,6 @@ impl ComponentServiceDefault { } } -#[derive(Default)] -pub struct ComponentServiceNoop {} - -#[async_trait] -impl<Namespace: Display + Eq + Clone + Send + Sync> ComponentService<Namespace> - for ComponentServiceNoop -{ - async fn create( - &self, - component_id: &ComponentId, - component_name: &ComponentName, - component_type: ComponentType, - _data: Vec<u8>, - namespace: &Namespace, - ) -> Result<Component<Namespace>, ComponentError> { - let fake_component = Component { - namespace: namespace.clone(), - component_name: component_name.clone(), - component_size: 0, - metadata: ComponentMetadata { - exports: vec![], - producers: vec![], - memories: vec![], - }, - versioned_component_id: VersionedComponentId { - component_id: component_id.clone(), - version: 0, - }, - created_at: Utc::now(), - component_type, - }; - - Ok(fake_component) - } - - async fn update( - &self, - component_id: &ComponentId, - _data: Vec<u8>, - _component_type: Option<ComponentType>, - namespace: &Namespace, - ) -> Result<Component<Namespace>, ComponentError> { - let fake_component = Component { - namespace: namespace.clone(), - component_name: ComponentName("fake".to_string()), - component_size: 0, - metadata: ComponentMetadata { - exports: vec![], - producers: vec![], - memories: vec![], - }, - versioned_component_id: VersionedComponentId { - component_id: component_id.clone(), - version: 0, - }, - created_at: Utc::now(), - component_type: ComponentType::Durable, - }; - - Ok(fake_component) - } - - async fn download( - &self, - _component_id: &ComponentId, - _version: Option<u64>, - _namespace: &Namespace, - ) -> Result<Vec<u8>, ComponentError> { - Ok(vec![]) - } - - async fn download_stream( - &self, - _component_id: &ComponentId, - _version: Option<u64>, - _namespace: &Namespace, - ) -> Result<ByteStream, ComponentError> { - Ok(ByteStream::empty()) - } - - async fn find_id_by_name( - &self, - _component_name: &ComponentName, - _namespace: &Namespace, - ) -> Result<Option<ComponentId>, ComponentError> { - Ok(None) - } - - async fn get_protected_data( - &self, - _component_id: &ComponentId, - _version: Option<u64>, - _namespace: &Namespace, - ) -> Result<Option<Vec<u8>>, ComponentError> { - Ok(None) - } - - async fn find_by_name( - &self, - _component_name: Option<ComponentName>, - _namespace: &Namespace, - ) -> Result<Vec<Component<Namespace>>, ComponentError> { - Ok(vec![]) - } - - async fn get_by_version( - &self, - _component_id: &VersionedComponentId, - _namespace: &Namespace, - ) -> Result<Option<Component<Namespace>>, ComponentError> { - Ok(None) - } - - async fn get_latest_version( - &self, - _component_id: &ComponentId, - _namespace: &Namespace, - ) -> Result<Option<Component<Namespace>>, ComponentError> { - Ok(None) - } - - async fn get( - &self, - _component_id: &ComponentId, - _namespace: &Namespace, - ) -> Result<Vec<Component<Namespace>>, ComponentError> { - Ok(vec![]) - } - - async fn get_namespace( - &self, - _component_id: &ComponentId, - ) -> Result<Option<Namespace>, ComponentError> { - Ok(None) - } - - async fn delete( - &self, - _component_id: &ComponentId, - _namespace: &Namespace, - ) -> Result<(), ComponentError> { - Ok(()) - } -} - #[cfg(test)] mod tests { use crate::repo::RepoError; diff --git a/golem-component-service/src/server.rs b/golem-component-service/src/server.rs index 75013dcadb..75622df094 100644 --- a/golem-component-service/src/server.rs +++ b/golem-component-service/src/server.rs @@ -31,9 +31,10 @@ use tracing::{error, info}; fn main() -> Result<(), std::io::Error> { if std::env::args().any(|arg| arg == "--dump-openapi-yaml") { - let service = make_open_api_service(&Services::noop()); - println!("{}", service.spec_yaml()); - Ok(()) + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()? + .block_on(dump_openapi_yaml()) } else if let Some(config) = make_config_loader().load_or_dump_config() { init_tracing_with_default_env_filter(&config.tracing); @@ -52,14 +53,24 @@ fn main() -> Result<(), std::io::Error> { tokio::runtime::Builder::new_multi_thread() .enable_all() - .build() - .unwrap() + .build()? .block_on(async_main(&config, prometheus)) } else { Ok(()) } } +async fn dump_openapi_yaml() -> Result<(), std::io::Error> { + let config = ComponentServiceConfig::default(); + let services = Services::new(&config).await.map_err(|e| { + error!("Services - init error: {}", e); + std::io::Error::new(std::io::ErrorKind::Other, e) + })?; + let service = make_open_api_service(&services); + println!("{}", service.spec_yaml()); + Ok(()) +} + async fn async_main( config: &ComponentServiceConfig, prometheus_registry: Registry, diff --git a/golem-component-service/src/service.rs b/golem-component-service/src/service.rs index 36569d52e7..59dc2c7e69 100644 --- a/golem-component-service/src/service.rs +++ b/golem-component-service/src/service.rs @@ -27,9 +27,7 @@ use crate::config::ComponentServiceConfig; use golem_component_service_base::repo::component::{ ComponentRepo, DbComponentRepo, LoggedComponentRepo, }; -use golem_component_service_base::service::component::{ - ComponentService, ComponentServiceDefault, ComponentServiceNoop, -}; +use golem_component_service_base::service::component::{ComponentService, ComponentServiceDefault}; use golem_service_base::auth::DefaultNamespace; #[derive(Clone)] @@ -91,17 +89,4 @@ impl Services { compilation_service, }) } - - pub fn noop() -> Self { - let component_service: Arc<dyn ComponentService<DefaultNamespace> + Sync + Send> = - Arc::new(ComponentServiceNoop::default()); - - let compilation_service: Arc<dyn ComponentCompilationService + Sync + Send> = - Arc::new(ComponentCompilationServiceDisabled); - - Services { - component_service, - compilation_service, - } - } } diff --git a/golem-worker-executor-base/Cargo.toml b/golem-worker-executor-base/Cargo.toml index 7ef96d90ab..80af0a09e8 100644 --- a/golem-worker-executor-base/Cargo.toml +++ b/golem-worker-executor-base/Cargo.toml @@ -14,7 +14,6 @@ autotests = false path = "src/lib.rs" [features] -mocks = [] [dependencies] golem-api-grpc = { path = "../golem-api-grpc", version = "0.0.0" } diff --git a/golem-worker-executor-base/src/services/component.rs b/golem-worker-executor-base/src/services/component.rs index d02eaf9966..aad1633ba1 100644 --- a/golem-worker-executor-base/src/services/component.rs +++ b/golem-worker-executor-base/src/services/component.rs @@ -836,41 +836,3 @@ impl ComponentService for ComponentServiceLocalFileSystem { } } } - -#[cfg(any(feature = "mocks", test))] -pub struct ComponentServiceMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for ComponentServiceMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl ComponentServiceMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl ComponentService for ComponentServiceMock { - async fn get( - &self, - _engine: &Engine, - _component_id: &ComponentId, - _component_version: u64, - ) -> Result<(Component, ComponentMetadata), GolemError> { - unimplemented!() - } - - async fn get_metadata( - &self, - _component_id: &ComponentId, - _forced_version: Option<ComponentVersion>, - ) -> Result<ComponentMetadata, GolemError> { - unimplemented!() - } -} diff --git a/golem-worker-executor-base/src/services/mod.rs b/golem-worker-executor-base/src/services/mod.rs index c407d1adf8..138b07863d 100644 --- a/golem-worker-executor-base/src/services/mod.rs +++ b/golem-worker-executor-base/src/services/mod.rs @@ -290,62 +290,6 @@ impl<Ctx: WorkerCtx> All<Ctx> { } } - #[cfg(any(feature = "mocks", test))] - pub async fn mocked(mocked_extra_deps: Ctx::ExtraDeps) -> Self { - let active_workers = Arc::new(active_workers::ActiveWorkers::new( - &crate::services::golem_config::MemoryConfig::default(), - )); - let engine = Arc::new(wasmtime::Engine::default()); - let linker = Arc::new(wasmtime::component::Linker::new(&engine)); - let runtime = Handle::current(); - let component_service = Arc::new(component::ComponentServiceMock::new()); - let worker_service = Arc::new(worker::WorkerServiceMock::new()); - let worker_enumeration_service = - Arc::new(worker_enumeration::WorkerEnumerationServiceMock::new()); - let running_worker_enumeration_service = - Arc::new(worker_enumeration::RunningWorkerEnumerationServiceMock::new()); - let promise_service = Arc::new(promise::PromiseServiceMock::new()); - let golem_config = Arc::new(golem_config::GolemConfig::default()); - let shard_service = Arc::new(shard::ShardServiceDefault::new()); - let shard_manager_service = Arc::new(shard_manager::ShardManagerServiceSingleShard::new()); - let key_value_service = Arc::new(key_value::DefaultKeyValueService::new(Arc::new( - crate::storage::keyvalue::memory::InMemoryKeyValueStorage::new(), - ))); - let blob_storage = Arc::new(crate::storage::blob::memory::InMemoryBlobStorage::new()); - let blob_store_service = Arc::new(blob_store::DefaultBlobStoreService::new( - blob_storage.clone(), - )); - let oplog_service = Arc::new(oplog::mock::OplogServiceMock::new()); - let rpc = Arc::new(rpc::RpcMock::new()); - let scheduler_service = Arc::new(scheduler::SchedulerServiceMock::new()); - let worker_activator = Arc::new(worker_activator::WorkerActivatorMock::new()); - let worker_proxy = Arc::new(worker_proxy::WorkerProxyMock::new()); - let events = Arc::new(Events::new(32768)); - Self { - active_workers, - engine, - linker, - runtime, - component_service, - shard_manager_service, - worker_service, - worker_enumeration_service, - running_worker_enumeration_service, - promise_service, - golem_config, - shard_service, - key_value_service, - blob_store_service, - oplog_service, - rpc, - scheduler_service, - worker_activator, - worker_proxy, - events, - extra_deps: mocked_extra_deps, - } - } - pub fn from_other<T: HasAll<Ctx>>(this: &T) -> All<Ctx> { All::new( this.active_workers(), diff --git a/golem-worker-executor-base/src/services/oplog/mock.rs b/golem-worker-executor-base/src/services/oplog/mock.rs deleted file mode 100644 index 415e643396..0000000000 --- a/golem-worker-executor-base/src/services/oplog/mock.rs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2024 Golem Cloud -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::error::GolemError; -use crate::services::oplog::{Oplog, OplogService}; -use async_trait::async_trait; -use golem_common::model::oplog::{OplogEntry, OplogIndex}; -use golem_common::model::{AccountId, ComponentId, OwnedWorkerId, ScanCursor}; -use std::collections::BTreeMap; -use std::sync::Arc; - -#[cfg(any(feature = "mocks", test))] -#[derive(Debug)] -pub struct OplogServiceMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for OplogServiceMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl OplogServiceMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl OplogService for OplogServiceMock { - async fn create( - &self, - _owned_worker_id: &OwnedWorkerId, - _initial_entry: OplogEntry, - ) -> Arc<dyn Oplog + Send + Sync> { - unimplemented!() - } - - async fn open( - &self, - _owned_worker_id: &OwnedWorkerId, - _last_oplog_index: OplogIndex, - ) -> Arc<dyn Oplog + Send + Sync> { - unimplemented!() - } - - async fn get_last_index(&self, _owned_worker_id: &OwnedWorkerId) -> OplogIndex { - unimplemented!() - } - - async fn delete(&self, _owned_worker_id: &OwnedWorkerId) { - unimplemented!() - } - - async fn read( - &self, - _owned_worker_id: &OwnedWorkerId, - _idx: OplogIndex, - _n: u64, - ) -> BTreeMap<OplogIndex, OplogEntry> { - unimplemented!() - } - - async fn exists(&self, _owned_worker_id: &OwnedWorkerId) -> bool { - unimplemented!() - } - - async fn scan_for_component( - &self, - _account_id: &AccountId, - _component_id: &ComponentId, - _cursor: ScanCursor, - _count: u64, - ) -> Result<(ScanCursor, Vec<OwnedWorkerId>), GolemError> { - unimplemented!() - } -} diff --git a/golem-worker-executor-base/src/services/oplog/mod.rs b/golem-worker-executor-base/src/services/oplog/mod.rs index bc85be7dd4..fa50ca0ab6 100644 --- a/golem-worker-executor-base/src/services/oplog/mod.rs +++ b/golem-worker-executor-base/src/services/oplog/mod.rs @@ -45,8 +45,6 @@ mod compressed; mod multilayer; mod primary; -#[cfg(any(feature = "mocks", test))] -pub mod mock; #[cfg(test)] mod tests; diff --git a/golem-worker-executor-base/src/services/promise.rs b/golem-worker-executor-base/src/services/promise.rs index f21f14d912..cf7302b111 100644 --- a/golem-worker-executor-base/src/services/promise.rs +++ b/golem-worker-executor-base/src/services/promise.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] use std::collections::HashSet; use std::ops::DerefMut; use std::sync::Arc; @@ -272,19 +272,19 @@ pub enum RedisPromiseState { Complete(Vec<u8>), } -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] pub struct PromiseServiceMock { completed: Arc<Mutex<HashSet<PromiseId>>>, } -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] impl Default for PromiseServiceMock { fn default() -> Self { Self::new() } } -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] impl PromiseServiceMock { pub fn new() -> Self { Self { @@ -297,7 +297,7 @@ impl PromiseServiceMock { } } -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] #[async_trait] impl PromiseService for PromiseServiceMock { async fn create(&self, _worker_id: &WorkerId, _oplog_idx: OplogIndex) -> PromiseId { diff --git a/golem-worker-executor-base/src/services/rpc.rs b/golem-worker-executor-base/src/services/rpc.rs index c5e111a893..1586a69a63 100644 --- a/golem-worker-executor-base/src/services/rpc.rs +++ b/golem-worker-executor-base/src/services/rpc.rs @@ -574,54 +574,3 @@ impl<Ctx: WorkerCtx> Rpc for DirectWorkerInvocationRpc<Ctx> { } impl RpcDemand for () {} - -#[cfg(any(feature = "mocks", test))] -pub struct RpcMock; - -#[cfg(any(feature = "mocks", test))] -impl Default for RpcMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl RpcMock { - pub fn new() -> Self { - Self - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl Rpc for RpcMock { - async fn create_demand(&self, _owned_worker_id: &OwnedWorkerId) -> Box<dyn RpcDemand> { - Box::new(()) - } - - async fn invoke_and_await( - &self, - _owned_worker_id: &OwnedWorkerId, - _idempotency_key: Option<IdempotencyKey>, - _function_name: String, - _function_params: Vec<WitValue>, - _self_worker_id: &WorkerId, - _self_args: &[String], - _self_env: &[(String, String)], - ) -> Result<WitValue, RpcError> { - unimplemented!() - } - - async fn invoke( - &self, - _owned_worker_id: &OwnedWorkerId, - _idempotency_key: Option<IdempotencyKey>, - _function_name: String, - _function_params: Vec<WitValue>, - _self_worker_id: &WorkerId, - _self_args: &[String], - _self_env: &[(String, String)], - ) -> Result<(), RpcError> { - unimplemented!() - } -} diff --git a/golem-worker-executor-base/src/services/scheduler.rs b/golem-worker-executor-base/src/services/scheduler.rs index 2c0b69e685..8c884f815d 100644 --- a/golem-worker-executor-base/src/services/scheduler.rs +++ b/golem-worker-executor-base/src/services/scheduler.rs @@ -269,38 +269,9 @@ impl SchedulerService for SchedulerServiceDefault { } } -#[cfg(any(feature = "mocks", test))] -pub struct SchedulerServiceMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for SchedulerServiceMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl SchedulerServiceMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl SchedulerService for SchedulerServiceMock { - async fn schedule(&self, _time: DateTime<Utc>, _action: ScheduledAction) -> ScheduleId { - unimplemented!() - } - - async fn cancel(&self, _id: ScheduleId) { - unimplemented!() - } -} - #[cfg(test)] mod tests { - use std::collections::HashMap; + use std::collections::{HashMap, HashSet}; use std::str::FromStr; use std::sync::Arc; use std::time::Duration; @@ -311,15 +282,18 @@ mod tests { use uuid::Uuid; - use crate::services::oplog::mock::OplogServiceMock; - use golem_common::model::oplog::OplogIndex; - use golem_common::model::{AccountId, ComponentId, PromiseId, ScheduledAction, WorkerId}; - + use crate::services::oplog::{OplogService, PrimaryOplogService}; use crate::services::promise::PromiseServiceMock; use crate::services::scheduler::{SchedulerService, SchedulerServiceDefault}; - use crate::services::shard::ShardServiceMock; - use crate::services::worker_activator::WorkerActivatorMock; + use crate::services::shard::{ShardService, ShardServiceDefault}; + use crate::services::worker_activator::{WorkerActivator, WorkerActivatorMock}; + use crate::storage::blob::memory::InMemoryBlobStorage; + use crate::storage::indexed::memory::InMemoryIndexedStorage; use crate::storage::keyvalue::memory::InMemoryKeyValueStorage; + use golem_common::model::oplog::OplogIndex; + use golem_common::model::{ + AccountId, ComponentId, PromiseId, ScheduledAction, ShardId, WorkerId, + }; fn serialized_bytes<T: Encode>(entry: &T) -> Vec<u8> { golem_common::serialization::serialize(entry) @@ -327,6 +301,32 @@ mod tests { .to_vec() } + fn create_shard_service_mock() -> Arc<dyn ShardService + Send + Sync> { + let result = Arc::new(ShardServiceDefault::new()); + result.register(1, &HashSet::from_iter(vec![ShardId::new(0)])); + result + } + + fn create_promise_service_mock() -> Arc<PromiseServiceMock> { + Arc::new(PromiseServiceMock::new()) + } + + fn create_worker_activator_mock() -> Arc<dyn WorkerActivator + Send + Sync> { + Arc::new(WorkerActivatorMock::new()) + } + + async fn create_oplog_service_mock() -> Arc<dyn OplogService + Send + Sync> { + Arc::new( + PrimaryOplogService::new( + Arc::new(InMemoryIndexedStorage::new()), + Arc::new(InMemoryBlobStorage::new()), + 1, + 1024, + ) + .await, + ) + } + #[tokio::test] pub async fn promises_added_to_expected_buckets() { let uuid = Uuid::new_v4(); @@ -359,10 +359,10 @@ mod tests { let kvs = Arc::new(InMemoryKeyValueStorage::new()); - let shard_service = Arc::new(ShardServiceMock::new()); - let promise_service = Arc::new(PromiseServiceMock::new()); - let worker_activator = Arc::new(WorkerActivatorMock::new()); - let oplog_service = Arc::new(OplogServiceMock::new()); + let shard_service = create_shard_service_mock(); + let promise_service = create_promise_service_mock(); + let worker_activator = create_worker_activator_mock(); + let oplog_service = create_oplog_service_mock().await; let svc = SchedulerServiceDefault::new( kvs.clone(), @@ -473,10 +473,10 @@ mod tests { let kvs = Arc::new(InMemoryKeyValueStorage::new()); - let shard_service = Arc::new(ShardServiceMock::new()); - let promise_service = Arc::new(PromiseServiceMock::new()); - let worker_activator = Arc::new(WorkerActivatorMock::new()); - let oplog_service = Arc::new(OplogServiceMock::new()); + let shard_service = create_shard_service_mock(); + let promise_service = create_promise_service_mock(); + let worker_activator = create_worker_activator_mock(); + let oplog_service = create_oplog_service_mock().await; let svc = SchedulerServiceDefault::new( kvs.clone(), @@ -572,10 +572,10 @@ mod tests { let kvs = Arc::new(InMemoryKeyValueStorage::new()); - let shard_service = Arc::new(ShardServiceMock::new()); - let promise_service = Arc::new(PromiseServiceMock::new()); - let worker_activator = Arc::new(WorkerActivatorMock::new()); - let oplog_service = Arc::new(OplogServiceMock::new()); + let shard_service = create_shard_service_mock(); + let promise_service = create_promise_service_mock(); + let worker_activator = create_worker_activator_mock(); + let oplog_service = create_oplog_service_mock().await; let svc = SchedulerServiceDefault::new( kvs.clone(), @@ -676,10 +676,10 @@ mod tests { let kvs = Arc::new(InMemoryKeyValueStorage::new()); - let shard_service = Arc::new(ShardServiceMock::new()); - let promise_service = Arc::new(PromiseServiceMock::new()); - let worker_activator = Arc::new(WorkerActivatorMock::new()); - let oplog_service = Arc::new(OplogServiceMock::new()); + let shard_service = create_shard_service_mock(); + let promise_service = create_promise_service_mock(); + let worker_activator = create_worker_activator_mock(); + let oplog_service = create_oplog_service_mock().await; let svc = SchedulerServiceDefault::new( kvs.clone(), @@ -778,10 +778,10 @@ mod tests { let kvs = Arc::new(InMemoryKeyValueStorage::new()); - let shard_service = Arc::new(ShardServiceMock::new()); - let promise_service = Arc::new(PromiseServiceMock::new()); - let worker_activator = Arc::new(WorkerActivatorMock::new()); - let oplog_service = Arc::new(OplogServiceMock::new()); + let shard_service = create_shard_service_mock(); + let promise_service = create_promise_service_mock(); + let worker_activator = create_worker_activator_mock(); + let oplog_service = create_oplog_service_mock().await; let svc = SchedulerServiceDefault::new( kvs.clone(), @@ -886,10 +886,10 @@ mod tests { let kvs = Arc::new(InMemoryKeyValueStorage::new()); - let shard_service = Arc::new(ShardServiceMock::new()); - let promise_service = Arc::new(PromiseServiceMock::new()); - let worker_activator = Arc::new(WorkerActivatorMock::new()); - let oplog_service = Arc::new(OplogServiceMock::new()); + let shard_service = create_shard_service_mock(); + let promise_service = create_promise_service_mock(); + let worker_activator = create_worker_activator_mock(); + let oplog_service = create_oplog_service_mock().await; let svc = SchedulerServiceDefault::new( kvs.clone(), diff --git a/golem-worker-executor-base/src/services/shard.rs b/golem-worker-executor-base/src/services/shard.rs index e2d0568ae1..dc6885b898 100644 --- a/golem-worker-executor-base/src/services/shard.rs +++ b/golem-worker-executor-base/src/services/shard.rs @@ -152,64 +152,6 @@ impl ShardService for ShardServiceDefault { } } -#[cfg(any(feature = "mocks", test))] -pub struct ShardServiceMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for ShardServiceMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl ShardServiceMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -impl ShardService for ShardServiceMock { - fn is_ready(&self) -> bool { - tracing::info!("ShardServiceMock::is_ready"); - true - } - - fn assign_shards(&self, shard_ids: &HashSet<ShardId>) -> Result<(), GolemError> { - tracing::info!("ShardServiceMock::assign_shards {:?}", shard_ids); - Ok(()) - } - - fn check_worker(&self, worker_id: &WorkerId) -> Result<(), GolemError> { - tracing::info!("ShardServiceMock::check_worker {:?}", worker_id); - Ok(()) - } - - fn register(&self, number_of_shards: usize, shard_ids: &HashSet<ShardId>) { - tracing::info!( - "ShardServiceMock::register {} {:?}", - number_of_shards, - shard_ids - ) - } - - fn revoke_shards(&self, shard_ids: &HashSet<ShardId>) -> Result<(), GolemError> { - tracing::info!("ShardServiceMock::revoke_shards {:?}", shard_ids); - Ok(()) - } - - fn current_assignment(&self) -> Result<ShardAssignment, GolemError> { - tracing::info!("ShardServiceMock::current_assignment"); - Ok(ShardAssignment::default()) - } - - fn try_get_current_assignment(&self) -> Option<ShardAssignment> { - tracing::info!("ShardServiceMock::opt_current_assignment"); - None - } -} - fn sharding_not_ready_error() -> GolemError { GolemError::Unknown { details: "Sharding is not ready".to_string(), diff --git a/golem-worker-executor-base/src/services/worker.rs b/golem-worker-executor-base/src/services/worker.rs index 23176fdb9c..af647e3592 100644 --- a/golem-worker-executor-base/src/services/worker.rs +++ b/golem-worker-executor-base/src/services/worker.rs @@ -368,53 +368,3 @@ impl WorkerService for DefaultWorkerService { } } } - -#[cfg(any(feature = "mocks", test))] -pub struct WorkerServiceMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for WorkerServiceMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl WorkerServiceMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl WorkerService for WorkerServiceMock { - async fn add( - &self, - _worker_metadata: &WorkerMetadata, - _component_type: ComponentType, - ) -> Result<(), GolemError> { - unimplemented!() - } - - async fn get(&self, _owned_worker_id: &OwnedWorkerId) -> Option<WorkerMetadata> { - unimplemented!() - } - - async fn get_running_workers_in_shards(&self) -> Vec<WorkerMetadata> { - unimplemented!() - } - - async fn remove(&self, _owned_worker_id: &OwnedWorkerId) { - unimplemented!() - } - - async fn update_status( - &self, - _owned_worker_id: &OwnedWorkerId, - _status_value: &WorkerStatusRecord, - _component_type: ComponentType, - ) { - unimplemented!() - } -} diff --git a/golem-worker-executor-base/src/services/worker_activator.rs b/golem-worker-executor-base/src/services/worker_activator.rs index d533e0ff07..8bed716bda 100644 --- a/golem-worker-executor-base/src/services/worker_activator.rs +++ b/golem-worker-executor-base/src/services/worker_activator.rs @@ -17,8 +17,6 @@ use std::sync::{Arc, Mutex}; use async_trait::async_trait; use golem_common::model::OwnedWorkerId; -#[cfg(any(feature = "mocks", test))] -use tracing::info; use tracing::{error, warn}; use crate::services::HasAll; @@ -108,27 +106,27 @@ impl<Ctx: WorkerCtx, Svcs: HasAll<Ctx> + Send + Sync + 'static> WorkerActivator } } -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] pub struct WorkerActivatorMock {} -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] impl Default for WorkerActivatorMock { fn default() -> Self { Self::new() } } -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] impl WorkerActivatorMock { pub fn new() -> Self { Self {} } } -#[cfg(any(feature = "mocks", test))] +#[cfg(test)] #[async_trait] impl WorkerActivator for WorkerActivatorMock { async fn activate_worker(&self, _owned_worker_id: &OwnedWorkerId) { - info!("WorkerActivatorMock::activate_worker"); + tracing::info!("WorkerActivatorMock::activate_worker"); } } diff --git a/golem-worker-executor-base/src/services/worker_enumeration.rs b/golem-worker-executor-base/src/services/worker_enumeration.rs index 5aa78a427e..4a10199894 100644 --- a/golem-worker-executor-base/src/services/worker_enumeration.rs +++ b/golem-worker-executor-base/src/services/worker_enumeration.rs @@ -67,35 +67,6 @@ impl<Ctx: WorkerCtx> RunningWorkerEnumerationServiceDefault<Ctx> { } } -#[cfg(any(feature = "mocks", test))] -pub struct RunningWorkerEnumerationServiceMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for RunningWorkerEnumerationServiceMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl RunningWorkerEnumerationServiceMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl RunningWorkerEnumerationService for RunningWorkerEnumerationServiceMock { - async fn get( - &self, - _component_id: &ComponentId, - _filter: Option<WorkerFilter>, - ) -> Result<Vec<WorkerMetadata>, GolemError> { - unimplemented!() - } -} - #[async_trait] pub trait WorkerEnumerationService { async fn get( @@ -243,36 +214,3 @@ impl WorkerEnumerationService for DefaultWorkerEnumerationService { Ok((new_cursor, workers)) } } - -#[cfg(any(feature = "mocks", test))] -pub struct WorkerEnumerationServiceMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for WorkerEnumerationServiceMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl WorkerEnumerationServiceMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl WorkerEnumerationService for WorkerEnumerationServiceMock { - async fn get( - &self, - _account_id: &AccountId, - _component_id: &ComponentId, - _filter: Option<WorkerFilter>, - _cursor: ScanCursor, - _count: u64, - _precise: bool, - ) -> Result<(Option<ScanCursor>, Vec<WorkerMetadata>), GolemError> { - unimplemented!() - } -} diff --git a/golem-worker-executor-base/src/services/worker_proxy.rs b/golem-worker-executor-base/src/services/worker_proxy.rs index 98b2815579..7b5b72d96d 100644 --- a/golem-worker-executor-base/src/services/worker_proxy.rs +++ b/golem-worker-executor-base/src/services/worker_proxy.rs @@ -312,59 +312,3 @@ impl WorkerProxy for RemoteWorkerProxy { } } } - -#[cfg(any(feature = "mocks", test))] -pub struct WorkerProxyMock {} - -#[cfg(any(feature = "mocks", test))] -impl Default for WorkerProxyMock { - fn default() -> Self { - Self::new() - } -} - -#[cfg(any(feature = "mocks", test))] -impl WorkerProxyMock { - pub fn new() -> Self { - Self {} - } -} - -#[cfg(any(feature = "mocks", test))] -#[async_trait] -impl WorkerProxy for WorkerProxyMock { - async fn invoke_and_await( - &self, - _owned_worker_id: &OwnedWorkerId, - _idempotency_key: Option<IdempotencyKey>, - _function_name: String, - _function_params: Vec<WitValue>, - _caller_worker_id: WorkerId, - _caller_args: Vec<String>, - _caller_env: HashMap<String, String>, - ) -> Result<WitValue, WorkerProxyError> { - unimplemented!() - } - - async fn invoke( - &self, - _owned_worker_id: &OwnedWorkerId, - _idempotency_key: Option<IdempotencyKey>, - _function_name: String, - _function_params: Vec<WitValue>, - _caller_worker_id: WorkerId, - _caller_args: Vec<String>, - _caller_env: HashMap<String, String>, - ) -> Result<(), WorkerProxyError> { - unimplemented!() - } - - async fn update( - &self, - _owned_worker_id: &OwnedWorkerId, - _target_version: ComponentVersion, - _mode: UpdateMode, - ) -> Result<(), WorkerProxyError> { - unimplemented!() - } -} diff --git a/golem-worker-service-base/src/service/api_definition.rs b/golem-worker-service-base/src/service/api_definition.rs index 54e4211928..568b84f817 100644 --- a/golem-worker-service-base/src/service/api_definition.rs +++ b/golem-worker-service-base/src/service/api_definition.rs @@ -430,84 +430,6 @@ where } } -#[derive(Default)] -pub struct ApiDefinitionServiceNoop {} - -#[async_trait] -impl<AuthCtx, Namespace, ValidationError> ApiDefinitionService<AuthCtx, Namespace, ValidationError> - for ApiDefinitionServiceNoop -where - AuthCtx: Send + Sync, - Namespace: Display + Clone + Send + Sync, -{ - async fn create( - &self, - definition: &HttpApiDefinitionRequest, - _namespace: &Namespace, - _auth_ctx: &AuthCtx, - ) -> ApiResult<CompiledHttpApiDefinition, ValidationError> { - Ok(CompiledHttpApiDefinition { - id: definition.id.clone(), - version: definition.version.clone(), - routes: vec![], - draft: definition.draft, - created_at: Utc::now(), - }) - } - - async fn update( - &self, - definition: &HttpApiDefinitionRequest, - _namespace: &Namespace, - _auth_ctx: &AuthCtx, - ) -> ApiResult<CompiledHttpApiDefinition, ValidationError> { - Ok(CompiledHttpApiDefinition { - id: definition.id.clone(), - version: definition.version.clone(), - routes: vec![], - draft: definition.draft, - created_at: Utc::now(), - }) - } - - async fn get( - &self, - _id: &ApiDefinitionId, - _version: &ApiVersion, - _namespace: &Namespace, - _auth_ctx: &AuthCtx, - ) -> ApiResult<Option<CompiledHttpApiDefinition>, ValidationError> { - Ok(None) - } - - async fn delete( - &self, - _id: &ApiDefinitionId, - _version: &ApiVersion, - _namespace: &Namespace, - _auth_ctx: &AuthCtx, - ) -> ApiResult<(), ValidationError> { - Ok(()) - } - - async fn get_all( - &self, - _namespace: &Namespace, - _auth_ctx: &AuthCtx, - ) -> ApiResult<Vec<CompiledHttpApiDefinition>, ValidationError> { - Ok(vec![]) - } - - async fn get_all_versions( - &self, - _id: &ApiDefinitionId, - _namespace: &Namespace, - _auth_ctx: &AuthCtx, - ) -> ApiResult<Vec<CompiledHttpApiDefinition>, ValidationError> { - Ok(vec![]) - } -} - #[cfg(test)] mod tests { use crate::repo::RepoError; diff --git a/golem-worker-service-base/src/service/api_definition_validator.rs b/golem-worker-service-base/src/service/api_definition_validator.rs index 58eb4885f6..1148ea6f0f 100644 --- a/golem-worker-service-base/src/service/api_definition_validator.rs +++ b/golem-worker-service-base/src/service/api_definition_validator.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use async_trait::async_trait; use serde::{Deserialize, Serialize}; use golem_service_base::model::Component; @@ -33,13 +32,3 @@ pub trait ApiDefinitionValidatorService<ApiDefinition, E> { pub struct ValidationErrors<E> { pub errors: Vec<E>, } - -#[derive(Copy, Clone, Default)] -pub struct ApiDefinitionValidatorNoop {} - -#[async_trait] -impl<A, E> ApiDefinitionValidatorService<A, E> for ApiDefinitionValidatorNoop { - fn validate(&self, _api: &A, _components: &[Component]) -> Result<(), ValidationErrors<E>> { - Ok(()) - } -} diff --git a/golem-worker-service-base/src/service/api_deployment.rs b/golem-worker-service-base/src/service/api_deployment.rs index b7ec501b31..e8870f5b78 100644 --- a/golem-worker-service-base/src/service/api_deployment.rs +++ b/golem-worker-service-base/src/service/api_deployment.rs @@ -548,58 +548,6 @@ where } } -#[derive(Default)] -pub struct ApiDeploymentServiceNoop {} - -#[async_trait] -impl<Namespace: Display + TryFrom<String> + Eq + Clone + Send + Sync> - ApiDeploymentService<Namespace> for ApiDeploymentServiceNoop -{ - async fn deploy( - &self, - _deployment: &ApiDeploymentRequest<Namespace>, - ) -> Result<(), ApiDeploymentError<Namespace>> { - Ok(()) - } - - async fn undeploy( - &self, - _deployment: &ApiDeploymentRequest<Namespace>, - ) -> Result<(), ApiDeploymentError<Namespace>> { - Ok(()) - } - - async fn get_by_id( - &self, - _namespace: &Namespace, - _api_definition_id: &ApiDefinitionId, - ) -> Result<Vec<ApiDeployment<Namespace>>, ApiDeploymentError<Namespace>> { - Ok(vec![]) - } - - async fn get_by_site( - &self, - _site: &ApiSiteString, - ) -> Result<Option<ApiDeployment<Namespace>>, ApiDeploymentError<Namespace>> { - Ok(None) - } - - async fn get_definitions_by_site( - &self, - _site: &ApiSiteString, - ) -> Result<Vec<CompiledHttpApiDefinition>, ApiDeploymentError<Namespace>> { - Ok(vec![]) - } - - async fn delete( - &self, - _namespace: &Namespace, - _site: &ApiSiteString, - ) -> Result<(), ApiDeploymentError<Namespace>> { - Ok(()) - } -} - #[cfg(test)] mod tests { use crate::repo::RepoError; diff --git a/golem-worker-service-base/src/service/component/default.rs b/golem-worker-service-base/src/service/component/default.rs index 7bca30179b..7c057f03e5 100644 --- a/golem-worker-service-base/src/service/component/default.rs +++ b/golem-worker-service-base/src/service/component/default.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; -use chrono::Utc; use http::Uri; use tonic::transport::Channel; @@ -9,7 +8,7 @@ use golem_api_grpc::proto::golem::component::v1::{ }; use golem_common::client::{GrpcClient, GrpcClientConfig}; use golem_common::config::RetryConfig; -use golem_common::model::{ComponentId, ComponentType}; +use golem_common::model::ComponentId; use golem_common::retries::with_retries; use golem_service_base::model::Component; @@ -193,51 +192,3 @@ fn is_retriable(error: &ComponentServiceError) -> bool { _ => false, } } - -#[derive(Clone, Debug, Default)] -pub struct ComponentServiceNoop {} - -impl ComponentServiceNoop { - pub fn test_component() -> Component { - use golem_common::model::component_metadata::ComponentMetadata; - use golem_service_base::model::{ComponentName, VersionedComponentId}; - - let id = VersionedComponentId { - component_id: ComponentId::new_v4(), - version: 1, - }; - - Component { - versioned_component_id: id.clone(), - component_name: ComponentName("test".to_string()), - component_size: 0, - metadata: ComponentMetadata { - exports: vec![], - producers: vec![], - memories: vec![], - }, - created_at: Some(Utc::now()), - component_type: Some(ComponentType::Durable), - } - } -} - -#[async_trait] -impl<AuthCtx> ComponentService<AuthCtx> for ComponentServiceNoop { - async fn get_by_version( - &self, - _component_id: &ComponentId, - _version: u64, - _auth_ctx: &AuthCtx, - ) -> ComponentResult<Component> { - Ok(Self::test_component()) - } - - async fn get_latest( - &self, - _component_id: &ComponentId, - _auth_ctx: &AuthCtx, - ) -> ComponentResult<Component> { - Ok(Self::test_component()) - } -} diff --git a/golem-worker-service-base/src/service/worker/default.rs b/golem-worker-service-base/src/service/worker/default.rs index e5ed82eb19..274e6ad92e 100644 --- a/golem-worker-service-base/src/service/worker/default.rs +++ b/golem-worker-service-base/src/service/worker/default.rs @@ -17,8 +17,7 @@ use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; use golem_wasm_ast::analysis::AnalysedFunctionResult; use golem_wasm_rpc::protobuf::type_annotated_value::TypeAnnotatedValue; -use golem_wasm_rpc::protobuf::{TypedTuple, Val as ProtoVal}; -use poem_openapi::types::ToJSON; +use golem_wasm_rpc::protobuf::Val as ProtoVal; use tonic::transport::Channel; use tonic::Code; use tracing::{error, info}; @@ -38,7 +37,7 @@ use golem_common::config::RetryConfig; use golem_common::model::oplog::OplogIndex; use golem_common::model::{ AccountId, ComponentId, ComponentVersion, FilterComparator, IdempotencyKey, PromiseId, - ScanCursor, TargetWorkerId, Timestamp, WorkerFilter, WorkerId, WorkerStatus, + ScanCursor, TargetWorkerId, WorkerFilter, WorkerId, WorkerStatus, }; use golem_service_base::model::{GolemErrorUnknown, ResourceLimits, WorkerMetadata}; use golem_service_base::routing_table::HasRoutingTableService; @@ -990,190 +989,3 @@ fn is_filter_with_running_status(filter: &WorkerFilter) -> bool { _ => false, } } - -#[derive(Clone, Debug)] -pub struct WorkerServiceNoOp { - pub metadata: WorkerRequestMetadata, -} - -#[async_trait] -impl<AuthCtx> WorkerService<AuthCtx> for WorkerServiceNoOp -where - AuthCtx: Send + Sync, -{ - async fn create( - &self, - _worker_id: &WorkerId, - _component_version: u64, - _arguments: Vec<String>, - _environment_variables: HashMap<String, String>, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<WorkerId> { - Ok(WorkerId { - component_id: ComponentId::new_v4(), - worker_name: "no-op".to_string(), - }) - } - - async fn connect( - &self, - _worker_id: &WorkerId, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<ConnectWorkerStream> { - Err(WorkerServiceError::Internal(anyhow::Error::msg( - "Not supported", - ))) - } - - async fn delete( - &self, - _worker_id: &WorkerId, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<()> { - Ok(()) - } - - async fn invoke_and_await_function_json( - &self, - _worker_id: &TargetWorkerId, - _idempotency_key: Option<IdempotencyKey>, - _function_name: String, - _params: Vec<TypeAnnotatedValue>, - _invocation_context: Option<InvocationContext>, - _metadata: WorkerRequestMetadata, - ) -> WorkerResult<TypeAnnotatedValue> { - Ok(TypeAnnotatedValue::Tuple(TypedTuple { - value: vec![], - typ: vec![], - })) - } - - async fn invoke_and_await_function_proto( - &self, - _worker_id: &TargetWorkerId, - _idempotency_key: Option<ProtoIdempotencyKey>, - _function_name: String, - _params: Vec<ProtoVal>, - _invocation_context: Option<InvocationContext>, - _metadata: WorkerRequestMetadata, - ) -> WorkerResult<InvokeResult> { - Ok(InvokeResult::default()) - } - - async fn invoke_function_json( - &self, - _worker_id: &TargetWorkerId, - _idempotency_key: Option<IdempotencyKey>, - _function_name: String, - _params: Vec<TypeAnnotatedValue>, - _invocation_context: Option<InvocationContext>, - _metadata: WorkerRequestMetadata, - ) -> WorkerResult<()> { - Ok(()) - } - - async fn invoke_function_proto( - &self, - _worker_id: &TargetWorkerId, - _idempotency_key: Option<ProtoIdempotencyKey>, - _function_name: String, - _params: Vec<ProtoVal>, - _invocation_context: Option<InvocationContext>, - _metadata: WorkerRequestMetadata, - ) -> WorkerResult<()> { - Ok(()) - } - - async fn complete_promise( - &self, - _worker_id: &WorkerId, - _oplog_id: u64, - _data: Vec<u8>, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<bool> { - Ok(true) - } - - async fn interrupt( - &self, - _worker_id: &WorkerId, - _recover_immediately: bool, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<()> { - Ok(()) - } - - async fn get_metadata( - &self, - worker_id: &WorkerId, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<WorkerMetadata> { - Ok(WorkerMetadata { - worker_id: worker_id.clone(), - args: vec![], - env: Default::default(), - status: WorkerStatus::Running, - component_version: 0, - retry_count: 0, - pending_invocation_count: 0, - updates: vec![], - created_at: Timestamp::now_utc(), - last_error: None, - component_size: 0, - total_linear_memory_size: 0, - owned_resources: HashMap::new(), - }) - } - - async fn find_metadata( - &self, - _component_id: &ComponentId, - _filter: Option<WorkerFilter>, - _cursor: ScanCursor, - _count: u64, - _precise: bool, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<(Option<ScanCursor>, Vec<WorkerMetadata>)> { - Ok((None, vec![])) - } - - async fn resume( - &self, - _worker_id: &WorkerId, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<()> { - Ok(()) - } - - async fn update( - &self, - _worker_id: &WorkerId, - _update_mode: UpdateMode, - _target_version: ComponentVersion, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<()> { - Ok(()) - } - - async fn get_component_for_worker( - &self, - worker_id: &WorkerId, - _metadata: WorkerRequestMetadata, - _auth_ctx: &AuthCtx, - ) -> WorkerResult<Component> { - let worker_id = WorkerId { - component_id: worker_id.component_id.clone(), - worker_name: worker_id.worker_name.to_json_string(), - }; - Err(WorkerServiceError::WorkerNotFound(worker_id)) - } -} diff --git a/golem-worker-service/src/api/api_definition.rs b/golem-worker-service/src/api/api_definition.rs index 2788e3f564..32974bfdfd 100644 --- a/golem-worker-service/src/api/api_definition.rs +++ b/golem-worker-service/src/api/api_definition.rs @@ -300,21 +300,22 @@ impl RegisterApiDefinitionApi { #[cfg(test)] mod test { + use super::*; + use crate::service::component::ComponentService; + use async_trait::async_trait; use golem_common::config::DbSqliteConfig; + use golem_common::model::ComponentId; use golem_service_base::db; + use golem_service_base::model::Component; use golem_worker_service_base::repo::api_definition::{ApiDefinitionRepo, DbApiDefinitionRepo}; use golem_worker_service_base::repo::api_deployment; use golem_worker_service_base::service::api_definition::ApiDefinitionServiceDefault; - use golem_worker_service_base::service::api_definition_validator::ApiDefinitionValidatorNoop; - use golem_worker_service_base::service::component::ComponentServiceNoop; + use golem_worker_service_base::service::component::ComponentResult; + use golem_worker_service_base::service::http::http_api_definition_validator::HttpApiDefinitionValidator; use http::StatusCode; use poem::test::TestClient; use std::marker::PhantomData; - use crate::service::component::ComponentService; - - use super::*; - struct SqliteDb<'c> { db_path: String, lifetime: PhantomData<&'c ()>, @@ -335,6 +336,30 @@ mod test { } } + struct TestComponentService; + + #[async_trait] + impl golem_worker_service_base::service::component::ComponentService<EmptyAuthCtx> + for TestComponentService + { + async fn get_by_version( + &self, + _component_id: &ComponentId, + _version: u64, + _auth_ctx: &EmptyAuthCtx, + ) -> ComponentResult<Component> { + unimplemented!() + } + + async fn get_latest( + &self, + _component_id: &ComponentId, + _auth_ctx: &EmptyAuthCtx, + ) -> ComponentResult<Component> { + unimplemented!() + } + } + async fn make_route<'c>() -> (poem::Route, SqliteDb<'c>) { let db = SqliteDb::default(); let db_config = DbSqliteConfig { @@ -355,12 +380,12 @@ mod test { db_pool.clone().into(), )); - let component_service: ComponentService = Arc::new(ComponentServiceNoop {}); + let component_service: ComponentService = Arc::new(TestComponentService); let definition_service = ApiDefinitionServiceDefault::new( component_service, api_definition_repo, api_deployment_repo, - Arc::new(ApiDefinitionValidatorNoop {}), + Arc::new(HttpApiDefinitionValidator {}), ); let endpoint = RegisterApiDefinitionApi::new(Arc::new(definition_service)); diff --git a/golem-worker-service/src/main.rs b/golem-worker-service/src/main.rs index 2a35cdb489..8da9de42f8 100644 --- a/golem-worker-service/src/main.rs +++ b/golem-worker-service/src/main.rs @@ -24,14 +24,16 @@ use golem_worker_service_base::metrics; fn main() -> std::io::Result<()> { tokio::runtime::Builder::new_current_thread() .enable_all() - .build() - .unwrap() + .build()? .block_on(async_main()) } async fn async_main() -> std::io::Result<()> { if std::env::args().any(|arg| arg == "--dump-openapi-yaml") { - let services = Services::noop(); + let config = WorkerServiceBaseConfig::default(); + let services = Services::new(&config) + .await + .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?; let api_service = make_open_api_service(&services); println!("{}", api_service.spec_yaml()); Ok(()) @@ -83,14 +85,11 @@ pub async fn app( .with(OpenTelemetryMetrics::new()) .with(Tracing); - poem::Server::new(poem::listener::TcpListener::bind(( - "0.0.0.0", - config.custom_request_port, - ))) - .name("gateway") - .run(route) - .await - .expect("Custom Request server failed") + poem::Server::new(TcpListener::bind(("0.0.0.0", config.custom_request_port))) + .name("gateway") + .run(route) + .await + .expect("Custom Request server failed") }); let worker_server = tokio::spawn(async move { diff --git a/golem-worker-service/src/service/mod.rs b/golem-worker-service/src/service/mod.rs index 4adb64220b..0269bd8826 100644 --- a/golem-worker-service/src/service/mod.rs +++ b/golem-worker-service/src/service/mod.rs @@ -14,20 +14,17 @@ use golem_worker_service_base::http::InputHttpRequest; use golem_worker_service_base::repo::api_definition; use golem_worker_service_base::repo::api_deployment; use golem_worker_service_base::service::api_definition::{ - ApiDefinitionService, ApiDefinitionServiceDefault, ApiDefinitionServiceNoop, + ApiDefinitionService, ApiDefinitionServiceDefault, }; use golem_worker_service_base::service::api_definition_lookup::{ ApiDefinitionsLookup, HttpApiDefinitionLookup, }; -use golem_worker_service_base::service::api_definition_validator::ApiDefinitionValidatorNoop; use golem_worker_service_base::service::api_definition_validator::ApiDefinitionValidatorService; -use golem_worker_service_base::service::component::{ComponentServiceNoop, RemoteComponentService}; +use golem_worker_service_base::service::component::RemoteComponentService; use golem_worker_service_base::service::http::http_api_definition_validator::{ HttpApiDefinitionValidator, RouteValidationError, }; -use golem_worker_service_base::service::worker::{ - WorkerRequestMetadata, WorkerServiceDefault, WorkerServiceNoOp, -}; +use golem_worker_service_base::service::worker::WorkerServiceDefault; use golem_worker_service_base::worker_bridge_execution::WorkerRequestExecutor; use golem_api_grpc::proto::golem::workerexecutor::v1::worker_executor_client::WorkerExecutorClient; @@ -35,7 +32,7 @@ use golem_common::client::{GrpcClientConfig, MultiTargetGrpcClient}; use golem_common::config::RetryConfig; use golem_worker_service_base::service::api_deployment::{ - ApiDeploymentService, ApiDeploymentServiceDefault, ApiDeploymentServiceNoop, + ApiDeploymentService, ApiDeploymentServiceDefault, }; use std::sync::Arc; use std::time::Duration; @@ -167,48 +164,4 @@ impl Services { api_definition_validator_service, }) } - - pub fn noop() -> Services { - let component_service: component::ComponentService = - Arc::new(ComponentServiceNoop::default()); - - let worker_service: worker::WorkerService = Arc::new(WorkerServiceNoOp { - metadata: WorkerRequestMetadata { - account_id: None, - limits: None, - }, - }); - - let api_definition_validator_service: Arc< - dyn ApiDefinitionValidatorService<HttpApiDefinition, RouteValidationError> - + Sync - + Send, - > = Arc::new(ApiDefinitionValidatorNoop::default()); - - let worker_to_http_service: Arc<dyn WorkerRequestExecutor + Sync + Send> = Arc::new( - UnauthorisedWorkerRequestExecutor::new(worker_service.clone()), - ); - - let definition_service: Arc< - dyn ApiDefinitionService<EmptyAuthCtx, DefaultNamespace, RouteValidationError> - + Sync - + Send, - > = Arc::new(ApiDefinitionServiceNoop::default()); - - let deployment_service: Arc<dyn ApiDeploymentService<DefaultNamespace> + Sync + Send> = - Arc::new(ApiDeploymentServiceNoop::default()); - - let http_definition_lookup_service = - Arc::new(HttpApiDefinitionLookup::new(deployment_service.clone())); - - Services { - worker_service, - definition_service, - deployment_service, - http_definition_lookup_service, - worker_to_http_service, - component_service, - api_definition_validator_service, - } - } }