Skip to content

Commit

Permalink
Merge branch 'main' into cassandra-key-value-storage-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
irach-ramos committed Sep 23, 2024
2 parents 2b407ac + 08eedaa commit a230e1b
Show file tree
Hide file tree
Showing 61 changed files with 2,592 additions and 670 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ futures-core = "0.3.29"
futures-util = "0.3.29"
git-version = "0.3.9"
golem-wasm-ast = "1.0.0"
golem-wasm-rpc = { version = "1.0.2", default-features = false, features = [
golem-wasm-rpc = { version = "1.0.3", default-features = false, features = [
"host",
] }
http = "1.0.0" # keep in sync with wasmtime
Expand Down
10 changes: 10 additions & 0 deletions golem-api-grpc/proto/golem/worker/target_worker_id.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

import "golem/component/component_id.proto";

package golem.worker;

message TargetWorkerId {
golem.component.ComponentId component_id = 1;
optional string name = 2;
}
9 changes: 5 additions & 4 deletions golem-api-grpc/proto/golem/worker/v1/worker_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import public "golem/worker/log_event.proto";
import public "golem/worker/worker_id.proto";
import public "golem/component/component_id.proto";
import public "golem/worker/update_mode.proto";
import public "golem/worker/target_worker_id.proto";

service WorkerService {
rpc LaunchNewWorker (LaunchNewWorkerRequest) returns (LaunchNewWorkerResponse);
Expand Down Expand Up @@ -102,7 +103,7 @@ message InterruptWorkerResponse {
}

message InvokeAndAwaitRequest {
golem.worker.WorkerId workerId = 1;
golem.worker.TargetWorkerId workerId = 1;
golem.worker.IdempotencyKey idempotencyKey = 2;
string function = 3;
golem.worker.InvokeParameters invokeParameters = 4;
Expand All @@ -117,7 +118,7 @@ message InvokeAndAwaitResponse {
}

message InvokeAndAwaitJsonRequest {
golem.worker.WorkerId workerId = 1;
golem.worker.TargetWorkerId workerId = 1;
golem.worker.IdempotencyKey idempotencyKey = 2;
string function = 3;
repeated string invokeParameters = 4;
Expand All @@ -132,7 +133,7 @@ message InvokeAndAwaitJsonResponse {
}

message InvokeRequest {
golem.worker.WorkerId workerId = 1;
golem.worker.TargetWorkerId workerId = 1;
golem.worker.IdempotencyKey idempotencyKey = 2;
string function = 3;
golem.worker.InvokeParameters invokeParameters = 4;
Expand All @@ -147,7 +148,7 @@ message InvokeResponse {
}

message InvokeJsonRequest {
golem.worker.WorkerId workerId = 1;
golem.worker.TargetWorkerId workerId = 1;
golem.worker.IdempotencyKey idempotencyKey = 2;
string function = 3;
repeated string invokeParameters = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import public "golem/shardmanager/shard_id.proto";
import public "golem/component/component_id.proto";
import public "golem/worker/cursor.proto";
import public "golem/worker/update_mode.proto";
import public "golem/worker/target_worker_id.proto";
import public "golem/worker/worker_id.proto";
import public "golem/worker/worker_metadata.proto";
import public "golem/worker/worker_status.proto";
Expand Down Expand Up @@ -101,7 +102,7 @@ message CreateWorkerResponse {


message InvokeAndAwaitWorkerRequest {
golem.worker.WorkerId worker_id = 1;
golem.worker.TargetWorkerId worker_id = 1;
string name = 2;
repeated wasm.rpc.Val input = 3;
golem.worker.IdempotencyKey idempotency_key = 4;
Expand Down Expand Up @@ -135,7 +136,7 @@ message InvokeAndAwaitWorkerSuccessTyped {


message InvokeWorkerRequest {
golem.worker.WorkerId worker_id = 1;
golem.worker.TargetWorkerId worker_id = 1;
string name = 2;
repeated wasm.rpc.Val input = 3;
golem.worker.IdempotencyKey idempotency_key = 4;
Expand Down
26 changes: 24 additions & 2 deletions golem-api-grpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ pub mod proto {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use crate::proto::golem;
use prost::Message;
use std::str::FromStr;

#[test]
fn test_uuid() {
Expand All @@ -206,5 +206,27 @@ pub mod proto {
println!("template_id_proto: {:?}", template_id_proto);
println!("token_proto: {:?}", token_proto);
}

#[test]
fn target_worker_id_and_worker_id_are_bin_compatible() {
let component_id_uuid = uuid::Uuid::new_v4();
let component_id_uuid: golem::common::Uuid = component_id_uuid.into();
let component_id = golem::component::ComponentId {
value: Some(component_id_uuid),
};
let target_worker_id = golem::worker::TargetWorkerId {
component_id: Some(component_id.clone()),
name: Some("hello".to_string()),
};
let worker_id = golem::worker::WorkerId {
component_id: Some(component_id),
name: "hello".to_string(),
};

let target_worker_id_bytes = target_worker_id.encode_to_vec();
let worker_id_bytes = worker_id.encode_to_vec();

assert_eq!(target_worker_id_bytes, worker_id_bytes);
}
}
}
2 changes: 1 addition & 1 deletion golem-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ futures-util = { workspace = true }
golem-examples = "1.0.5"
golem-wasm-ast = { workspace = true }
golem-wasm-rpc = { workspace = true }
golem-wasm-rpc-stubgen = { version = "1.0.2", optional = true }
golem-wasm-rpc-stubgen = { version = "1.0.3", optional = true }
h2 = "0.3.24"
http = { workspace = true }
humansize = { workspace = true }
Expand Down
7 changes: 7 additions & 0 deletions golem-cli/src/clients/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ pub trait WorkerClient {
target_version: u64,
) -> Result<(), GolemError>;
}

pub fn worker_name_required(urn: &WorkerUrn) -> Result<String, GolemError> {
urn.id
.worker_name
.clone()
.ok_or_else(|| GolemError("Must specify the worker's name".to_string()))
}
26 changes: 18 additions & 8 deletions golem-cli/src/command/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::command::ComponentRefSplit;
use clap::builder::ValueParser;
use clap::{ArgMatches, Args, Error, FromArgMatches, Subcommand};
use golem_client::model::ScanCursor;
use golem_common::model::WorkerId;
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};
Expand Down Expand Up @@ -123,9 +123,9 @@ impl From<&OssWorkerNameOrUriArg> for OssWorkerUriArg {
match &value.component {
Some(ComponentUri::URN(component_urn)) => {
let uri = WorkerUri::URN(WorkerUrn {
id: WorkerId {
id: TargetWorkerId {
component_id: component_urn.id.clone(),
worker_name,
worker_name: Some(worker_name),
},
});
OssWorkerUriArg {
Expand All @@ -137,7 +137,7 @@ impl From<&OssWorkerNameOrUriArg> for OssWorkerUriArg {
Some(ComponentUri::URL(component_url)) => {
let uri = WorkerUri::URL(WorkerUrl {
component_name: component_url.name.to_string(),
worker_name,
worker_name: Some(worker_name),
});

OssWorkerUriArg {
Expand All @@ -150,7 +150,7 @@ impl From<&OssWorkerNameOrUriArg> for OssWorkerUriArg {
let component_name = value.component_name.clone().unwrap();
let uri = WorkerUri::URL(WorkerUrl {
component_name,
worker_name,
worker_name: Some(worker_name),
});

OssWorkerUriArg {
Expand Down Expand Up @@ -185,7 +185,11 @@ impl From<&OssWorkerUriArg> for OssWorkerNameOrUriArg {
worker: None,
component: Some(component_uri),
component_name: None,
worker_name: Some(WorkerName(urn.id.worker_name.to_string())),
worker_name: urn
.id
.worker_name
.as_ref()
.map(|n| WorkerName(n.to_string())),
}
}
WorkerUri::URL(url) => {
Expand All @@ -194,7 +198,10 @@ impl From<&OssWorkerUriArg> for OssWorkerNameOrUriArg {
worker: None,
component: None,
component_name: Some(url.component_name.to_string()),
worker_name: Some(WorkerName(url.worker_name.to_string())),
worker_name: url
.worker_name
.as_ref()
.map(|n| WorkerName(n.to_string())),
}
} else {
let component_uri = ComponentUri::URL(ComponentUrl {
Expand All @@ -205,7 +212,10 @@ impl From<&OssWorkerUriArg> for OssWorkerNameOrUriArg {
worker: None,
component: Some(component_uri),
component_name: None,
worker_name: Some(WorkerName(url.worker_name.to_string())),
worker_name: url
.worker_name
.as_ref()
.map(|n| WorkerName(n.to_string())),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions golem-cli/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use clap_verbosity_flag::Verbosity;
use derive_more::{Display, FromStr};
use golem_client::model::{ApiDefinitionInfo, ApiSite, ScanCursor};
use golem_common::model::trim_date::TrimDateTime;
use golem_common::model::{ComponentId, WorkerId};
use golem_common::model::{ComponentId, TargetWorkerId};
use golem_common::uri::oss::uri::ComponentUri;
use golem_common::uri::oss::url::ComponentUrl;
use golem_common::uri::oss::urn::WorkerUrn;
Expand Down Expand Up @@ -540,9 +540,9 @@ impl From<WorkerMetadata> for WorkerMetadataView {

WorkerMetadataView {
worker_urn: WorkerUrn {
id: WorkerId {
id: TargetWorkerId {
component_id: ComponentId(worker_id.component_id),
worker_name: worker_id.worker_name,
worker_name: Some(worker_id.worker_name),
},
},
account_id,
Expand Down
32 changes: 20 additions & 12 deletions golem-cli/src/model/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,14 @@ pub mod worker {

impl MessageWithFields for WorkerAddView {
fn message(&self) -> String {
format!(
"Added worker {}",
format_message_highlight(&self.0.id.worker_name)
)
if let Some(worker_name) = &self.0.id.worker_name {
format!("Added worker {}", format_message_highlight(&worker_name))
} else {
format!(
"Added worker with a {}",
format_message_highlight("random generated name")
)
}
}

fn fields(&self) -> Vec<(&'static str, String)> {
Expand All @@ -704,7 +708,7 @@ pub mod worker {
.fmt_field("Component URN", &self.0.id.component_id, |id| {
format_id(&ComponentUrn { id: id.clone() })
})
.fmt_field("Worker name", &self.0.id.worker_name, format_id);
.fmt_field_option("Worker name", &(self.0.id.worker_name.as_ref()), format_id);

fields.build()
}
Expand All @@ -727,10 +731,14 @@ pub mod worker {

impl MessageWithFields for WorkerGetView {
fn message(&self) -> String {
format!(
"Got metadata for worker {}",
format_message_highlight(&self.0.worker_urn.id.worker_name)
)
if let Some(worker_name) = &self.0.worker_urn.id.worker_name {
format!(
"Got metadata for worker {}",
format_message_highlight(worker_name)
)
} else {
"Got metadata for worker".to_string()
}
}

fn fields(&self) -> Vec<(&'static str, String)> {
Expand All @@ -741,7 +749,7 @@ pub mod worker {
.fmt_field("Component URN", &self.0.worker_urn.id.component_id, |id| {
format_id(&ComponentUrn { id: id.clone() })
})
.fmt_field("Worker name", &self.0.worker_urn.id.worker_name, format_id)
.fmt_field_option("Worker name", &self.0.worker_urn.id.worker_name, format_id)
.fmt_field("Component version", &self.0.component_version, format_id)
.field("Created at", &self.0.created_at)
.fmt_field("Component size", &self.0.component_size, format_binary_size)
Expand Down Expand Up @@ -799,7 +807,7 @@ pub mod worker {
component_urn: ComponentUrn {
id: value.worker_urn.id.component_id.clone(),
},
worker_name: value.worker_urn.id.worker_name.to_string(),
worker_name: value.worker_urn.id.worker_name.clone().unwrap_or_default(),
status: format_status(&value.status),
component_version: value.component_version,
created_at: value.created_at,
Expand Down Expand Up @@ -860,7 +868,7 @@ pub mod worker {
fn from(value: &WorkerUrn) -> Self {
WorkerUrnTableView {
worker_urn: value.clone(),
worker_name: value.id.worker_name.clone(),
worker_name: value.id.worker_name.clone().unwrap_or_default(),
}
}
}
Expand Down
Loading

0 comments on commit a230e1b

Please sign in to comment.