From 97130e0254495aa4c6e18878ec968a28d8837d4f Mon Sep 17 00:00:00 2001 From: Daniel Vigovszky Date: Mon, 2 Oct 2023 11:39:29 +0200 Subject: [PATCH] Update to latest golem-client with new naming --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/clients/template.rs | 20 ++++++++-------- src/clients/worker.rs | 24 +++++++++---------- src/main.rs | 12 +++++----- src/model.rs | 52 ++++++++++++++++++++--------------------- 6 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca60d0f..c81c430 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -610,9 +610,9 @@ dependencies = [ [[package]] name = "golem-client" -version = "0.0.42" +version = "0.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c3f2d90a0af9cdeef2dc960cee3c295639d6cd3f8865f7a13813e9fadc78ac" +checksum = "d9d398781e0b08c1bd0b1c755ca2bacd4de1d1e6c7a0f2c727144c5848f9c271" dependencies = [ "async-trait", "bytes", diff --git a/Cargo.toml b/Cargo.toml index bba3a5c..82bb7d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ clap = { version = "4.4.1", features = ["derive"] } clap-verbosity-flag = "2.0.1" derive_more = "0.99.17" futures-util = "0.3.28" -golem-client = "0.0.42" +golem-client = "0.0.45" golem-examples = "0.1.6" http = "0.2.9" indoc = "2.0.3" diff --git a/src/clients/template.rs b/src/clients/template.rs index 98bb9c7..d82d00f 100644 --- a/src/clients/template.rs +++ b/src/clients/template.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use async_trait::async_trait; use golem_client::model::{ - Component, ComponentQuery, Export, FunctionParameter, FunctionResult, Type, + Export, FunctionParameter, FunctionResult, Template, TemplateQuery, Type, }; use serde::Serialize; use tokio::fs::File; @@ -36,7 +36,7 @@ pub trait TemplateClient { } #[derive(Clone)] -pub struct TemplateClientLive { +pub struct TemplateClientLive { pub client: C, } @@ -49,8 +49,8 @@ pub struct TemplateView { pub exports: Vec, } -impl From<&Component> for TemplateView { - fn from(value: &Component) -> Self { +impl From<&Template> for TemplateView { + fn from(value: &Template) -> Self { TemplateView { template_id: value.versioned_template_id.raw_template_id.to_string(), template_version: value.versioned_template_id.version, @@ -170,7 +170,7 @@ fn show_exported_function( } #[async_trait] -impl TemplateClient for TemplateClientLive { +impl TemplateClient for TemplateClientLive { async fn find( &self, project_id: Option, @@ -181,7 +181,7 @@ impl TemplateClient for Tem let templates = self .client - .get_components( + .get_all_templates( project_id.map(|ProjectId(id)| id.to_string()).as_deref(), name.map(|TemplateName(s)| s).as_deref(), &auth.header(), @@ -204,12 +204,12 @@ impl TemplateClient for Tem let file = File::open(path) .await .map_err(|e| GolemError(format!("Can't open template file: {e}")))?; - let template_name = golem_client::model::ComponentName { value: name.0 }; + let template_name = golem_client::model::TemplateName { value: name.0 }; let template = self .client - .post_component( - ComponentQuery { + .upload_template( + TemplateQuery { project_id: project_id.map(|ProjectId(id)| id), component_name: template_name, }, @@ -235,7 +235,7 @@ impl TemplateClient for Tem let template = self .client - .put_component(&id.0.to_string(), file, &auth.header()) + .update_template(&id.0.to_string(), file, &auth.header()) .await?; Ok((&template).into()) diff --git a/src/clients/worker.rs b/src/clients/worker.rs index d36d705..6107857 100644 --- a/src/clients/worker.rs +++ b/src/clients/worker.rs @@ -4,7 +4,7 @@ use std::time::Duration; use async_trait::async_trait; use futures_util::{future, pin_mut, SinkExt, StreamExt}; use golem_client::model::{ - ComponentInstance, InstanceMetadata, InvokeParameters, InvokeResult, WorkerCreationRequest, + InvokeParameters, InvokeResult, VersionedWorkerId, WorkerCreationRequest, WorkerMetadata, }; use native_tls::TlsConnector; use reqwest::Url; @@ -28,7 +28,7 @@ pub trait WorkerClient { args: Vec, env: Vec<(String, String)>, auth: &CloudAuthentication, - ) -> Result; + ) -> Result; async fn get_invocation_key( &self, name: &WorkerName, @@ -79,7 +79,7 @@ pub trait WorkerClient { name: WorkerName, template_id: RawTemplateId, auth: &CloudAuthentication, - ) -> Result; + ) -> Result; async fn connect( &self, name: WorkerName, @@ -89,14 +89,14 @@ pub trait WorkerClient { } #[derive(Clone)] -pub struct WorkerClientLive { +pub struct WorkerClientLive { pub client: C, pub base_url: Url, pub allow_insecure: bool, } #[async_trait] -impl WorkerClient for WorkerClientLive { +impl WorkerClient for WorkerClientLive { async fn new_worker( &self, name: WorkerName, @@ -104,12 +104,12 @@ impl WorkerClient for WorkerC args: Vec, env: Vec<(String, String)>, auth: &CloudAuthentication, - ) -> Result { + ) -> Result { info!("Creating worker {name} of {}", template_id.0); Ok(self .client - .launch_new_instance( + .launch_new_worker( &template_id.0.to_string(), WorkerCreationRequest { name: name.0, @@ -200,7 +200,7 @@ impl WorkerClient for WorkerC Ok(self .client - .interrupt_instance( + .interrupt_worker( &template_id.0.to_string(), &name.0, Some(false), @@ -219,7 +219,7 @@ impl WorkerClient for WorkerC Ok(self .client - .interrupt_instance( + .interrupt_worker( &template_id.0.to_string(), &name.0, Some(true), @@ -238,7 +238,7 @@ impl WorkerClient for WorkerC Ok(self .client - .delete_instance(&template_id.0.to_string(), &name.0, &auth.header()) + .delete_worker(&template_id.0.to_string(), &name.0, &auth.header()) .await?) } @@ -247,12 +247,12 @@ impl WorkerClient for WorkerC name: WorkerName, template_id: RawTemplateId, auth: &CloudAuthentication, - ) -> Result { + ) -> Result { info!("Getting worker {}/{} metadata", template_id.0, name.0); Ok(self .client - .get_instance_metadata(&template_id.0.to_string(), &name.0, &auth.header()) + .get_worker_metadata(&template_id.0.to_string(), &name.0, &auth.header()) .await?) } diff --git a/src/main.rs b/src/main.rs index b815935..1cc7eab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,13 +6,13 @@ use std::path::PathBuf; use clap::builder::ValueParser; use clap::{Parser, Subcommand}; use clap_verbosity_flag::Verbosity; -use golem_client::component::ComponentLive; use golem_client::grant::GrantLive; -use golem_client::instance::InstanceLive; -use golem_client::model::{ComponentInstance, InvokeParameters}; +use golem_client::model::{InvokeParameters, VersionedWorkerId}; use golem_client::project::ProjectLive; use golem_client::project_grant::ProjectGrantLive; use golem_client::project_policy::ProjectPolicyLive; +use golem_client::template::TemplateLive; +use golem_client::worker::WorkerLive; use golem_examples::model::{ExampleName, GuestLanguage, GuestLanguageTier, PackageName}; use model::*; use reqwest::Url; @@ -198,7 +198,7 @@ fn main() -> Result<(), Box> { #[derive(Debug, Serialize)] struct DeployResult { template: TemplateView, - worker: ComponentInstance, + worker: VersionedWorkerId, } async fn handle_deploy( @@ -297,7 +297,7 @@ async fn async_main(cmd: GolemCommand) -> Result<(), Box> client: &project_client, }; let template_client = TemplateClientLive { - client: ComponentLive { + client: TemplateLive { base_url: url.clone(), allow_insecure, }, @@ -326,7 +326,7 @@ async fn async_main(cmd: GolemCommand) -> Result<(), Box> project: &project_client, }; let worker_client = WorkerClientLive { - client: InstanceLive { + client: WorkerLive { base_url: url.clone(), allow_insecure, }, diff --git a/src/model.rs b/src/model.rs index 890b041..5fcdae1 100644 --- a/src/model.rs +++ b/src/model.rs @@ -7,14 +7,14 @@ use clap::error::{ContextKind, ContextValue, ErrorKind}; use clap::{Arg, ArgMatches, Command, Error, FromArgMatches}; use derive_more::{Display, FromStr, Into}; use golem_client::account::AccountError; -use golem_client::component::ComponentError; use golem_client::grant::GrantError; -use golem_client::instance::InstanceError; use golem_client::login::LoginError; use golem_client::project::ProjectError; use golem_client::project_grant::ProjectGrantError; use golem_client::project_policy::ProjectPolicyError; +use golem_client::template::TemplateError; use golem_client::token::TokenError; +use golem_client::worker::WorkerError; use golem_examples::model::{Example, ExampleName, GuestLanguage, GuestLanguageTier}; use indoc::indoc; use serde::{Deserialize, Serialize}; @@ -99,28 +99,28 @@ impl From for GolemError { } } -impl From for GolemError { - fn from(value: ComponentError) -> Self { +impl From for GolemError { + fn from(value: TemplateError) -> Self { match value { - ComponentError::RequestFailure(err) => { + TemplateError::RequestFailure(err) => { GolemError(format!("Unexpected request failure: {err}")) } - ComponentError::InvalidHeaderValue(err) => { + TemplateError::InvalidHeaderValue(err) => { GolemError(format!("Unexpected invalid header value: {err}")) } - ComponentError::UnexpectedStatus(sc) => GolemError(format!("Unexpected status: {sc}")), - ComponentError::Status401 { error } => GolemError(format!("Unauthorized: {error}")), - ComponentError::Status504 => GolemError("Gateway Timeout".to_string()), - ComponentError::Status404 { message } => GolemError(message), - ComponentError::Status403 { error } => GolemError(format!("Limit Exceeded: {error}")), - ComponentError::Status400 { errors } => { + TemplateError::UnexpectedStatus(sc) => GolemError(format!("Unexpected status: {sc}")), + TemplateError::Status401 { error } => GolemError(format!("Unauthorized: {error}")), + TemplateError::Status504 => GolemError("Gateway Timeout".to_string()), + TemplateError::Status404 { message } => GolemError(message), + TemplateError::Status403 { error } => GolemError(format!("Limit Exceeded: {error}")), + TemplateError::Status400 { errors } => { let msg = errors.join(", "); GolemError(format!("Invalid API call: {msg}")) } - ComponentError::Status500 { error } => { + TemplateError::Status500 { error } => { GolemError(format!("Internal server error: {error}")) } - ComponentError::Status409 { component_id } => { + TemplateError::Status409 { component_id } => { GolemError(format!("{component_id} already exists")) } } @@ -268,28 +268,28 @@ impl From for GolemError { } } -impl From for GolemError { - fn from(value: InstanceError) -> Self { +impl From for GolemError { + fn from(value: WorkerError) -> Self { match value { - InstanceError::RequestFailure(err) => { + WorkerError::RequestFailure(err) => { GolemError(format!("Unexpected request failure: {err}")) } - InstanceError::InvalidHeaderValue(err) => { + WorkerError::InvalidHeaderValue(err) => { GolemError(format!("Unexpected invalid header value: {err}")) } - InstanceError::UnexpectedStatus(sc) => GolemError(format!("Unexpected status: {sc}")), - InstanceError::Status504 => GolemError("Gateway timeout".to_string()), - InstanceError::Status404 { error } => GolemError(format!("Not found: {error}")), - InstanceError::Status403 { error } => GolemError(format!("Limit Exceeded: {error}")), - InstanceError::Status400 { errors } => { + WorkerError::UnexpectedStatus(sc) => GolemError(format!("Unexpected status: {sc}")), + WorkerError::Status504 => GolemError("Gateway timeout".to_string()), + WorkerError::Status404 { error } => GolemError(format!("Not found: {error}")), + WorkerError::Status403 { error } => GolemError(format!("Limit Exceeded: {error}")), + WorkerError::Status400 { errors } => { let msg = errors.join(", "); GolemError(format!("Invalid API call: {msg}")) } - InstanceError::Status401 { error } => GolemError(format!("Unauthorized: {error}")), - InstanceError::Status500 { golem_error } => { + WorkerError::Status401 { error } => GolemError(format!("Unauthorized: {error}")), + WorkerError::Status500 { golem_error } => { GolemError(format!("Internal server error: {golem_error:?}")) } - InstanceError::Status409 { error } => GolemError(error), + WorkerError::Status409 { error } => GolemError(error), } } }