Skip to content

Commit

Permalink
More cleanup and adding dynamic linking to the component APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Dec 27, 2024
1 parent be989e5 commit 645db62
Show file tree
Hide file tree
Showing 23 changed files with 731 additions and 267 deletions.
2 changes: 1 addition & 1 deletion golem-api-grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ harness = false

[dependencies]
golem-wasm-ast = { path = "../wasm-ast", version = "0.0.0", default-features = false, features = ["protobuf"] }
golem-wasm-rpc = { path = "../wasm-rpc", version = "0.0.0", default-features = false, features = ["protobuf"] }
golem-wasm-rpc = { path = "../wasm-rpc", version = "0.0.0", default-features = false, features = ["host-bindings", "protobuf"] }

async-trait = { workspace = true }
bincode = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions golem-api-grpc/proto/golem/component/component_metadata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package golem.component;
import "golem/component/export.proto";
import "golem/component/producers.proto";
import "golem/component/linear_memory.proto";
import "golem/component/dynamic_linked_instance.proto";

message ComponentMetadata {
repeated Export exports = 1;
repeated Producers producers = 2;
repeated LinearMemory memories = 3;
map<string, golem.component.DynamicLinkedInstance> dynamic_linking = 4;
}
13 changes: 13 additions & 0 deletions golem-api-grpc/proto/golem/component/dynamic_linked_instance.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";

package golem.component;

message DynamicLinkedInstance {
oneof dynamic_linked_instance {
DynamicLinkedWasmRpc wasm_rpc = 1;
}
}

message DynamicLinkedWasmRpc {
string target_interface_name = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import public "golem/common/project_id.proto";
import public "golem/common/empty.proto";
import public "golem/component/component.proto";
import public "golem/component/component_type.proto";
import public "golem/component/dynamic_linked_instance.proto";
import public "golem/component/v1/component_error.proto";
import public "golem/component/component_id.proto";
import public "golem/component/component_constraints.proto";
Expand Down Expand Up @@ -74,6 +75,7 @@ message CreateComponentRequestHeader {
optional ComponentType componentType = 3;
// All files need to be uploaded to the blob storage before providing them here
repeated InitialComponentFile files = 4;
map<string, golem.component.DynamicLinkedInstance> dynamic_linking = 5;
}

message CreateComponentRequestChunk {
Expand Down Expand Up @@ -148,6 +150,7 @@ message UpdateComponentRequestHeader {
bool updateFiles = 3;
// All files need to be uploaded to the blob storage before providing them here
repeated InitialComponentFile files = 4;
map<string, golem.component.DynamicLinkedInstance> dynamic_linking = 5;
}

message UpdateComponentRequestChunk {
Expand Down
4 changes: 4 additions & 0 deletions golem-cli/src/oss/clients/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl<C: golem_client::api::ComponentClient + Sync + Send> ComponentClient
file,
files_permissions,
files_archive_file,
None,
)
.await?
}
Expand All @@ -131,6 +132,7 @@ impl<C: golem_client::api::ComponentClient + Sync + Send> ComponentClient
bytes,
files_permissions,
files_archive_file,
None,
)
.await?
}
Expand Down Expand Up @@ -172,6 +174,7 @@ impl<C: golem_client::api::ComponentClient + Sync + Send> ComponentClient
file,
files_permissions,
files_archive_file,
None,
)
.await?
}
Expand All @@ -189,6 +192,7 @@ impl<C: golem_client::api::ComponentClient + Sync + Send> ComponentClient
bytes,
files_permissions,
files_archive_file,
None,
)
.await?
}
Expand Down
60 changes: 59 additions & 1 deletion golem-common/src/model/component_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ fn drop_from_constructor(constructor: &AnalysedFunction) -> AnalysedFunction {
#[cfg(feature = "protobuf")]
mod protobuf {
use crate::model::component_metadata::{
ComponentMetadata, LinearMemory, ProducerField, Producers, VersionedName,
ComponentMetadata, DynamicLinkedInstance, DynamicLinkedWasmRpc, LinearMemory,
ProducerField, Producers, VersionedName,
};
use std::collections::HashMap;

Expand Down Expand Up @@ -446,7 +447,64 @@ mod protobuf {
.into_iter()
.map(|memory| memory.into())
.collect(),
dynamic_linking: HashMap::from_iter(
value
.dynamic_linking
.into_iter()
.map(|(k, v)| (k, v.into())),
),
}
}
}

impl From<DynamicLinkedInstance>
for golem_api_grpc::proto::golem::component::DynamicLinkedInstance
{
fn from(value: DynamicLinkedInstance) -> Self {
match value {
DynamicLinkedInstance::WasmRpc(dynamic_linked_wasm_rpc) => Self {
dynamic_linked_instance: Some(
golem_api_grpc::proto::golem::component::dynamic_linked_instance::DynamicLinkedInstance::WasmRpc(
dynamic_linked_wasm_rpc.into())),
},
}
}
}

impl TryFrom<golem_api_grpc::proto::golem::component::DynamicLinkedInstance>
for DynamicLinkedInstance
{
type Error = String;

fn try_from(
value: golem_api_grpc::proto::golem::component::DynamicLinkedInstance,
) -> Result<Self, Self::Error> {
match value.dynamic_linked_instance {
Some(golem_api_grpc::proto::golem::component::dynamic_linked_instance::DynamicLinkedInstance::WasmRpc(dynamic_linked_wasm_rpc)) => Ok(Self::WasmRpc(dynamic_linked_wasm_rpc.try_into()?)),
None => Err("Missing dynamic_linked_instance".to_string()),
}
}
}

impl From<DynamicLinkedWasmRpc> for golem_api_grpc::proto::golem::component::DynamicLinkedWasmRpc {
fn from(value: DynamicLinkedWasmRpc) -> Self {
Self {
target_interface_name: value.target_interface_name,
}
}
}

impl TryFrom<golem_api_grpc::proto::golem::component::DynamicLinkedWasmRpc>
for DynamicLinkedWasmRpc
{
type Error = String;

fn try_from(
value: golem_api_grpc::proto::golem::component::DynamicLinkedWasmRpc,
) -> Result<Self, Self::Error> {
Ok(Self {
target_interface_name: value.target_interface_name,
})
}
}
}
9 changes: 7 additions & 2 deletions golem-component-service-base/src/model/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
use chrono::Utc;
use golem_common::model::component::ComponentOwner;
use golem_common::model::component_constraint::{FunctionConstraint, FunctionConstraintCollection};
use golem_common::model::component_metadata::{ComponentMetadata, ComponentProcessingError};
use golem_common::model::component_metadata::{
ComponentMetadata, ComponentProcessingError, DynamicLinkedInstance,
};
use golem_common::model::plugin::PluginInstallation;
use golem_common::model::InitialComponentFile;
use golem_common::model::{ComponentFilePathWithPermissions, ComponentId, ComponentType};
use golem_service_base::model::{ComponentName, VersionedComponentId};
use rib::WorkerFunctionsInRib;
use std::collections::HashMap;
use std::fmt::Debug;
use std::time::SystemTime;
use tempfile::NamedTempFile;
Expand Down Expand Up @@ -48,9 +51,11 @@ impl<Owner: ComponentOwner> Component<Owner> {
data: &[u8],
files: Vec<InitialComponentFile>,
installed_plugins: Vec<PluginInstallation>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: Owner,
) -> Result<Component<Owner>, ComponentProcessingError> {
let metadata = ComponentMetadata::analyse_component(data)?;
let mut metadata = ComponentMetadata::analyse_component(data)?;
metadata.dynamic_linking = dynamic_linking;

let versioned_component_id = VersionedComponentId {
component_id: component_id.clone(),
Expand Down
17 changes: 15 additions & 2 deletions golem-component-service-base/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

mod component;

use bincode::{Decode, Encode};
pub use component::*;
use golem_common::model::component_metadata::DynamicLinkedInstance;
use golem_common::model::{ComponentFilePathWithPermissionsList, ComponentType};
use golem_service_base::poem::TempFileUpload;
use poem_openapi::types::multipart::Upload;
use poem_openapi::Multipart;
use poem_openapi::types::multipart::{JsonField, Upload};
use poem_openapi::{Multipart, Object};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Multipart)]
#[oai(rename_all = "camelCase")]
Expand All @@ -27,4 +31,13 @@ pub struct UpdatePayload {
pub component: Upload,
pub files_permissions: Option<ComponentFilePathWithPermissionsList>,
pub files: Option<TempFileUpload>,
pub dynamic_linking: Option<JsonField<DynamicLinking>>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Encode, Decode, Object)]
#[oai(rename_all = "camelCase")]
#[serde(rename_all = "camelCase")]
#[derive(Default)]
pub struct DynamicLinking {
pub dynamic_linking: HashMap<String, DynamicLinkedInstance>,
}
42 changes: 36 additions & 6 deletions golem-component-service-base/src/service/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use golem_api_grpc::proto::golem::common::{ErrorBody, ErrorsBody};
use golem_api_grpc::proto::golem::component::v1::component_error;
use golem_common::model::component::ComponentOwner;
use golem_common::model::component_constraint::FunctionConstraintCollection;
use golem_common::model::component_metadata::{ComponentMetadata, ComponentProcessingError};
use golem_common::model::component_metadata::{
ComponentMetadata, ComponentProcessingError, DynamicLinkedInstance,
};
use golem_common::model::plugin::{
ComponentPluginInstallationTarget, PluginInstallation, PluginInstallationCreation,
PluginInstallationUpdate, PluginScope, PluginTypeSpecificDefinition,
Expand Down Expand Up @@ -304,6 +306,7 @@ pub trait ComponentService<Owner: ComponentOwner>: Debug {
data: Vec<u8>,
files: Option<InitialComponentFilesArchiveAndPermissions>,
installed_plugins: Vec<PluginInstallation>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError>;

Expand All @@ -316,6 +319,7 @@ pub trait ComponentService<Owner: ComponentOwner>: Debug {
data: Vec<u8>,
files: Vec<InitialComponentFile>,
installed_plugins: Vec<PluginInstallation>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError>;

Expand All @@ -325,6 +329,7 @@ pub trait ComponentService<Owner: ComponentOwner>: Debug {
data: Vec<u8>,
component_type: Option<ComponentType>,
files: Option<InitialComponentFilesArchiveAndPermissions>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError>;

Expand All @@ -336,6 +341,7 @@ pub trait ComponentService<Owner: ComponentOwner>: Debug {
component_type: Option<ComponentType>,
// None signals that files should be reused from the previous version
files: Option<Vec<InitialComponentFile>>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError>;

Expand Down Expand Up @@ -639,6 +645,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentServiceDefault<Owner, S
data: Vec<u8>,
uploaded_files: Vec<InitialComponentFile>,
installed_plugins: Vec<PluginInstallation>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError> {
let component = Component::new(
Expand All @@ -648,6 +655,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentServiceDefault<Owner, S
&data,
uploaded_files,
installed_plugins,
dynamic_linking,
owner.clone(),
)?;

Expand Down Expand Up @@ -686,10 +694,12 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentServiceDefault<Owner, S
data: Vec<u8>,
component_type: Option<ComponentType>,
files: Option<Vec<InitialComponentFile>>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError> {
let metadata = ComponentMetadata::analyse_component(&data)
let mut metadata = ComponentMetadata::analyse_component(&data)
.map_err(ComponentError::ComponentProcessingError)?;
metadata.dynamic_linking = dynamic_linking;

let constraints = self
.component_repo
Expand Down Expand Up @@ -1004,6 +1014,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
data: Vec<u8>,
files: Option<InitialComponentFilesArchiveAndPermissions>,
installed_plugins: Vec<PluginInstallation>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError> {
info!(owner = %owner, "Create component");
Expand All @@ -1027,6 +1038,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
data,
uploaded_files,
installed_plugins,
dynamic_linking,
owner,
)
.await
Expand All @@ -1040,6 +1052,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
data: Vec<u8>,
files: Vec<InitialComponentFile>,
installed_plugins: Vec<PluginInstallation>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError> {
info!(owner = %owner, "Create component");
Expand Down Expand Up @@ -1074,6 +1087,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
data,
files,
installed_plugins,
dynamic_linking,
owner,
)
.await
Expand All @@ -1085,6 +1099,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
data: Vec<u8>,
component_type: Option<ComponentType>,
files: Option<InitialComponentFilesArchiveAndPermissions>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError> {
info!(owner = %owner, "Update component");
Expand All @@ -1097,8 +1112,15 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
None => None,
};

self.update_unchecked(component_id, data, component_type, uploaded_files, owner)
.await
self.update_unchecked(
component_id,
data,
component_type,
uploaded_files,
dynamic_linking,
owner,
)
.await
}

async fn update_internal(
Expand All @@ -1107,6 +1129,7 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
data: Vec<u8>,
component_type: Option<ComponentType>,
files: Option<Vec<InitialComponentFile>>,
dynamic_linking: HashMap<String, DynamicLinkedInstance>,
owner: &Owner,
) -> Result<Component<Owner>, ComponentError> {
info!(owner = %owner, "Update component");
Expand All @@ -1130,8 +1153,15 @@ impl<Owner: ComponentOwner, Scope: PluginScope> ComponentService<Owner>
}
}

self.update_unchecked(component_id, data, component_type, files, owner)
.await
self.update_unchecked(
component_id,
data,
component_type,
files,
dynamic_linking,
owner,
)
.await
}

async fn download(
Expand Down
Loading

0 comments on commit 645db62

Please sign in to comment.