Skip to content
Open
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
64 changes: 55 additions & 9 deletions cli/src/clients/admin_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ use futures::StreamExt;
use futures::stream;
use http::{Uri, Version};
use indicatif::ProgressBar;
use restate_admin_rest_model::deployments::*;
use restate_admin_rest_model::deployments::{
HttpDeploymentResponse, HttpDetailedDeploymentResponse, LambdaDeploymentResponse,
LambdaDetailedDeploymentResponse, RegisterDeploymentRequest, RegisterDeploymentResponse,
ServiceNameRevPair,
};
use restate_admin_rest_model::invocations::RestartAsNewInvocationResponse;
use restate_admin_rest_model::services::*;
use restate_admin_rest_model::version::VersionInformation;
Expand All @@ -23,8 +27,50 @@ use restate_serde_util::SerdeableHeaderHashMap;
use restate_types::identifiers::{DeploymentId, LambdaARN};
use restate_types::schema::deployment::ProtocolType;
use restate_types::schema::service::ServiceMetadata;
use serde::Deserialize;
use std::collections::HashMap;

// Local untagged versions of deployment response enums for backward-compatible deserialization.
// The server model uses #[serde(tag = "type")] for OpenAPI discriminator support, but the CLI
// needs #[serde(untagged)] to also work with older servers that don't emit the "type" field.

#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
pub enum DeploymentResponse {
Http(HttpDeploymentResponse),
Lambda(LambdaDeploymentResponse),
}

impl DeploymentResponse {
pub fn id(&self) -> DeploymentId {
match self {
Self::Http(h) => h.id,
Self::Lambda(l) => l.id,
}
}
}

#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
pub enum DetailedDeploymentResponse {
Http(HttpDetailedDeploymentResponse),
Lambda(LambdaDetailedDeploymentResponse),
}

impl DetailedDeploymentResponse {
pub fn id(&self) -> DeploymentId {
match self {
Self::Http(h) => h.id,
Self::Lambda(l) => l.id,
}
}
}

#[derive(Debug, Deserialize)]
pub struct ListDeploymentsResponse {
pub deployments: Vec<DeploymentResponse>,
}

const MAX_PARALLEL_REQUESTS: usize = 500;

pub trait AdminClientInterface {
Expand Down Expand Up @@ -325,7 +371,7 @@ impl Deployment {
deployment_response: DeploymentResponse,
) -> (DeploymentId, Self, Vec<ServiceNameRevPair>) {
match deployment_response {
DeploymentResponse::Http {
DeploymentResponse::Http(HttpDeploymentResponse {
id,
uri,
protocol_type,
Expand All @@ -338,7 +384,7 @@ impl Deployment {
metadata,
sdk_version,
..
} => (
}) => (
id,
Deployment::Http {
uri,
Expand All @@ -353,7 +399,7 @@ impl Deployment {
},
services,
),
DeploymentResponse::Lambda {
DeploymentResponse::Lambda(LambdaDeploymentResponse {
id,
arn,
assume_role_arn,
Expand All @@ -365,7 +411,7 @@ impl Deployment {
metadata,
sdk_version,
..
} => (
}) => (
id,
Deployment::Lambda {
arn,
Expand All @@ -386,7 +432,7 @@ impl Deployment {
detailed_deployment_response: DetailedDeploymentResponse,
) -> (DeploymentId, Self, Vec<ServiceMetadata>) {
match detailed_deployment_response {
DetailedDeploymentResponse::Http {
DetailedDeploymentResponse::Http(HttpDetailedDeploymentResponse {
id,
uri,
protocol_type,
Expand All @@ -399,7 +445,7 @@ impl Deployment {
metadata,
sdk_version,
..
} => (
}) => (
id,
Deployment::Http {
uri,
Expand All @@ -414,7 +460,7 @@ impl Deployment {
},
services,
),
DetailedDeploymentResponse::Lambda {
DetailedDeploymentResponse::Lambda(LambdaDetailedDeploymentResponse {
id,
arn,
assume_role_arn,
Expand All @@ -426,7 +472,7 @@ impl Deployment {
metadata,
sdk_version,
..
} => (
}) => (
id,
Deployment::Lambda {
arn,
Expand Down
2 changes: 2 additions & 0 deletions cli/src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ pub use self::admin_client::AdminClient;
pub use self::admin_client::Error as MetasClientError;
pub use self::admin_client::{MAX_ADMIN_API_VERSION, MIN_ADMIN_API_VERSION};
pub use self::admin_interface::Deployment;
pub use self::admin_interface::DeploymentResponse;
pub use self::admin_interface::DetailedDeploymentResponse;
pub use self::admin_interface::{AdminClientInterface, batch_execute};
pub use self::datafusion_http_client::DataFusionHttpClient;
6 changes: 3 additions & 3 deletions cli/src/commands/deployments/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
use cling::prelude::*;
use comfy_table::Table;
use http::{HeaderName, HeaderValue, StatusCode, Uri};
use indicatif::ProgressBar;

Check warning on line 19 in cli/src/commands/deployments/register.rs

View workflow job for this annotation

GitHub Actions / Build and test (warp-ubuntu-latest-x64-16x)

Diff in /home/runner/work/restate/restate/cli/src/commands/deployments/register.rs
use indoc::indoc;

use restate_admin_rest_model::deployments::{
DetailedDeploymentResponse, RegisterDeploymentRequest, RegisterDeploymentResponse,
};
use restate_admin_rest_model::deployments::{RegisterDeploymentRequest, RegisterDeploymentResponse};

use crate::clients::DetailedDeploymentResponse;
use restate_admin_rest_model::version::AdminApiVersion;
use restate_cli_util::ui::console::{Styled, StyledTable, confirm_or_exit};
use restate_cli_util::ui::stylesheet::Style;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/services/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use anyhow::{Context, Result};
use cling::prelude::*;
use comfy_table::Table;

use restate_admin_rest_model::deployments::DeploymentResponse;
use crate::clients::DeploymentResponse;
use restate_cli_util::ui::console::StyledTable;
use restate_cli_util::ui::watcher::Watch;
use restate_cli_util::{c_error, c_println};
Expand Down
Loading
Loading