Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Update to latest golem-client with new naming #25

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 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 @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions src/clients/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,7 +36,7 @@ pub trait TemplateClient {
}

#[derive(Clone)]
pub struct TemplateClientLive<C: golem_client::component::Component + Sync + Send> {
pub struct TemplateClientLive<C: golem_client::template::Template + Sync + Send> {
pub client: C,
}

Expand All @@ -49,8 +49,8 @@ pub struct TemplateView {
pub exports: Vec<String>,
}

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,
Expand Down Expand Up @@ -170,7 +170,7 @@ fn show_exported_function(
}

#[async_trait]
impl<C: golem_client::component::Component + Sync + Send> TemplateClient for TemplateClientLive<C> {
impl<C: golem_client::template::Template + Sync + Send> TemplateClient for TemplateClientLive<C> {
async fn find(
&self,
project_id: Option<ProjectId>,
Expand All @@ -181,7 +181,7 @@ impl<C: golem_client::component::Component + Sync + Send> 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(),
Expand All @@ -204,12 +204,12 @@ impl<C: golem_client::component::Component + Sync + Send> 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,
},
Expand All @@ -235,7 +235,7 @@ impl<C: golem_client::component::Component + Sync + Send> 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())
Expand Down
24 changes: 12 additions & 12 deletions src/clients/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +28,7 @@ pub trait WorkerClient {
args: Vec<String>,
env: Vec<(String, String)>,
auth: &CloudAuthentication,
) -> Result<ComponentInstance, GolemError>;
) -> Result<VersionedWorkerId, GolemError>;
async fn get_invocation_key(
&self,
name: &WorkerName,
Expand Down Expand Up @@ -79,7 +79,7 @@ pub trait WorkerClient {
name: WorkerName,
template_id: RawTemplateId,
auth: &CloudAuthentication,
) -> Result<InstanceMetadata, GolemError>;
) -> Result<WorkerMetadata, GolemError>;
async fn connect(
&self,
name: WorkerName,
Expand All @@ -89,27 +89,27 @@ pub trait WorkerClient {
}

#[derive(Clone)]
pub struct WorkerClientLive<C: golem_client::instance::Instance + Send + Sync> {
pub struct WorkerClientLive<C: golem_client::worker::Worker + Send + Sync> {
pub client: C,
pub base_url: Url,
pub allow_insecure: bool,
}

#[async_trait]
impl<C: golem_client::instance::Instance + Send + Sync> WorkerClient for WorkerClientLive<C> {
impl<C: golem_client::worker::Worker + Send + Sync> WorkerClient for WorkerClientLive<C> {
async fn new_worker(
&self,
name: WorkerName,
template_id: RawTemplateId,
args: Vec<String>,
env: Vec<(String, String)>,
auth: &CloudAuthentication,
) -> Result<ComponentInstance, GolemError> {
) -> Result<VersionedWorkerId, GolemError> {
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,
Expand Down Expand Up @@ -200,7 +200,7 @@ impl<C: golem_client::instance::Instance + Send + Sync> WorkerClient for WorkerC

Ok(self
.client
.interrupt_instance(
.interrupt_worker(
&template_id.0.to_string(),
&name.0,
Some(false),
Expand All @@ -219,7 +219,7 @@ impl<C: golem_client::instance::Instance + Send + Sync> WorkerClient for WorkerC

Ok(self
.client
.interrupt_instance(
.interrupt_worker(
&template_id.0.to_string(),
&name.0,
Some(true),
Expand All @@ -238,7 +238,7 @@ impl<C: golem_client::instance::Instance + Send + Sync> 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?)
}

Expand All @@ -247,12 +247,12 @@ impl<C: golem_client::instance::Instance + Send + Sync> WorkerClient for WorkerC
name: WorkerName,
template_id: RawTemplateId,
auth: &CloudAuthentication,
) -> Result<InstanceMetadata, GolemError> {
) -> Result<WorkerMetadata, GolemError> {
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?)
}

Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,7 +198,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Debug, Serialize)]
struct DeployResult {
template: TemplateView,
worker: ComponentInstance,
worker: VersionedWorkerId,
}

async fn handle_deploy(
Expand Down Expand Up @@ -297,7 +297,7 @@ async fn async_main(cmd: GolemCommand) -> Result<(), Box<dyn std::error::Error>>
client: &project_client,
};
let template_client = TemplateClientLive {
client: ComponentLive {
client: TemplateLive {
base_url: url.clone(),
allow_insecure,
},
Expand Down Expand Up @@ -326,7 +326,7 @@ async fn async_main(cmd: GolemCommand) -> Result<(), Box<dyn std::error::Error>>
project: &project_client,
};
let worker_client = WorkerClientLive {
client: InstanceLive {
client: WorkerLive {
base_url: url.clone(),
allow_insecure,
},
Expand Down
52 changes: 26 additions & 26 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -99,28 +99,28 @@ impl From<TokenError> for GolemError {
}
}

impl From<ComponentError> for GolemError {
fn from(value: ComponentError) -> Self {
impl From<TemplateError> 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"))
}
}
Expand Down Expand Up @@ -268,28 +268,28 @@ impl From<ProjectGrantError> for GolemError {
}
}

impl From<InstanceError> for GolemError {
fn from(value: InstanceError) -> Self {
impl From<WorkerError> 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),
}
}
}
Expand Down
Loading