Skip to content

Commit

Permalink
Start changing golem cli
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Jun 3, 2024
1 parent 0654c22 commit 01d3ff7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
10 changes: 7 additions & 3 deletions golem-cli/src/clients/api_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use async_trait::async_trait;

use golem_client::model::{ApiDeployment, ApiSite};
use golem_client::model::{ApiDefinitionInfo, ApiDeployment, ApiSite};
use tracing::info;

use crate::model::{ApiDefinitionId, ApiDefinitionVersion, GolemError};
Expand Down Expand Up @@ -59,9 +59,13 @@ impl<C: golem_client::api::ApiDeploymentClient + Sync + Send> ApiDeploymentClien
.map_or("".to_string(), |s| format!("subdomain {}", s))
);

let deployment = ApiDeployment {
api_definition_id: api_definition_id.0.to_string(),
let api_definition = ApiDefinitionInfo {
id: api_definition_id.0.to_string(),
version: version.0.to_string(),
};

let deployment = ApiDeployment {
api_definitions: vec![api_definition],
site: ApiSite {
host: host.to_string(),
subdomain,
Expand Down
24 changes: 13 additions & 11 deletions golem-cli/src/model/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,17 +408,19 @@ impl TextFormat for ScanCursor {

impl TextFormat for ApiDeployment {
fn print(&self) {
printdoc!(
"
API deployment on {} with definition {}/{}
",
match &self.site.subdomain {
Some(subdomain) => format!("{}.{}", subdomain, self.site.host),
None => self.site.host.to_string(),
},
self.api_definition_id,
self.version,
);
for api_defs in self.api_definitions {
printdoc!(
"
API deployment on {} with definition {}/{}.
",
match &self.site.subdomain {
Some(subdomain) => format!("{}.{}", subdomain, self.site.host),
None => self.site.host.to_string(),
},
api_defs.id,
api_defs.version,
);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions golem-worker-service-base/src/api_definition/api_common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;
use std::fmt::Display;

use crate::service::api_definition::ApiDefinitionInfo;
use crate::service::api_definition::ApiDefinitionIdWithVersion;
use bincode::{Decode, Encode};
use poem_openapi::NewType;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -52,7 +52,7 @@ pub trait HasGolemWorkerBindings {
)]
pub struct ApiDeployment<Namespace> {
pub namespace: Namespace,
pub api_definition_keys: Vec<ApiDefinitionInfo>,
pub api_definition_keys: Vec<ApiDefinitionIdWithVersion>,
pub site: ApiSite,
}

Expand Down
12 changes: 6 additions & 6 deletions golem-worker-service-base/src/repo/api_deployment_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use golem_common::redis::{RedisError, RedisPool};
use tracing::{debug, info};

use crate::repo::api_namespace::ApiNamespace;
use crate::service::api_definition::ApiDefinitionInfo;
use crate::service::api_definition::ApiDefinitionIdWithVersion;

const API_DEFINITION_REDIS_NAMESPACE: &str = "apidefinition";

Expand Down Expand Up @@ -192,10 +192,10 @@ impl<Namespace: ApiNamespace> ApiDeploymentRepo<Namespace> for RedisApiDeploy {

let mut api_definition_redis_values = vec![];

for api_key in &deployment.api_definition_keys {
for api_def_with_version in &deployment.api_definition_keys {
let value = self
.pool
.serialize(api_key)
.serialize(api_def_with_version)
.map_err(|e| ApiDeploymentRepoError::Internal(anyhow::Error::msg(e)))?;

api_definition_redis_values.push((1.0, value));
Expand Down Expand Up @@ -270,7 +270,7 @@ impl<Namespace: ApiNamespace> ApiDeploymentRepo<Namespace> for RedisApiDeploy {
let mut api_definition_keys = Vec::new();

for value in site_values {
let api_definition_key: Result<ApiDefinitionInfo, ApiDeploymentRepoError> = self
let api_definition_key: Result<ApiDefinitionIdWithVersion, ApiDeploymentRepoError> = self
.pool
.deserialize(&value)
.map_err(|e| ApiDeploymentRepoError::Internal(anyhow::Error::msg(e.to_string())));
Expand Down Expand Up @@ -420,7 +420,7 @@ mod tests {
api_deployment_redis_key, api_deployments_redis_key,
};
use crate::repo::api_deployment_repo::{ApiDeploymentRepo, InMemoryDeployment};
use crate::service::api_definition::ApiDefinitionInfo;
use crate::service::api_definition::ApiDefinitionIdWithVersion;

#[tokio::test]
pub async fn test_in_memory_deploy() {
Expand All @@ -440,7 +440,7 @@ mod tests {

let deployment = ApiDeployment {
namespace: namespace.clone(),
api_definition_keys: vec![ApiDefinitionInfo {
api_definition_keys: vec![ApiDefinitionIdWithVersion {
id: api_definition_id.clone(),
version: version.clone(),
}],
Expand Down
2 changes: 1 addition & 1 deletion golem-worker-service-base/src/service/api_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct ApiDefinitionKey<Namespace> {
#[derive(
Eq, Hash, PartialEq, Clone, Debug, serde::Deserialize, bincode::Encode, bincode::Decode,
)]
pub struct ApiDefinitionInfo {
pub struct ApiDefinitionIdWithVersion {
pub id: ApiDefinitionId,
pub version: ApiVersion,
}
Expand Down
6 changes: 3 additions & 3 deletions golem-worker-service/src/api/deploy_api_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing::log::info;

use golem_worker_service_base::api::ApiDeployment;
use golem_worker_service_base::api_definition;
use golem_worker_service_base::service::api_definition::ApiDefinitionInfo;
use golem_worker_service_base::service::api_definition::ApiDefinitionIdWithVersion;
use golem_worker_service_base::service::api_deployment::ApiDeploymentService;

pub struct ApiDeploymentApi {
Expand All @@ -35,11 +35,11 @@ impl ApiDeploymentApi {
let api_definition_infos = payload
.api_definitions
.iter()
.map(|k| ApiDefinitionInfo {
.map(|k| ApiDefinitionIdWithVersion {
id: k.id.clone(),
version: k.version.clone(),
})
.collect::<Vec<ApiDefinitionInfo>>();
.collect::<Vec<ApiDefinitionIdWithVersion>>();

info!("Deploy API definitions at site: {}", payload.site);

Expand Down

0 comments on commit 01d3ff7

Please sign in to comment.