Skip to content

Commit

Permalink
Merge pull request #81 from EventStore/brockshelton/clo-751-add-resiz…
Browse files Browse the repository at this point in the history
…e-and-upgrade-api-calls-to-esc-repo

add cli commands for resize and upgrade
  • Loading branch information
bshelton authored Feb 6, 2024
2 parents 9ba18a2 + 48c4d3a commit 20bd935
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 66 deletions.
65 changes: 65 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ enum ClustersCommand {
Update(UpdateCluster),
Delete(DeleteCluster),
Expand(ExpandCluster),
Resize(ResizeCluster),
Upgrade(UpgradeCluster),
}

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -987,6 +989,41 @@ struct ExpandCluster {
disk_type: Option<String>,
}

#[derive(Debug, StructOpt)]
#[structopt(about = "Resize a cluster")]
struct ResizeCluster {
#[structopt(long, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the cluster relates to")]
org_id: OrgId,

#[structopt(long, parse(try_from_str = parse_project_id), default_value = "", help = "The project id the cluster relates to")]
project_id: esc_api::resources::ProjectId,

#[structopt(long, short, parse(try_from_str = parse_cluster_id), help = "Id of the cluster you want to resize")]
id: esc_api::ClusterId,

#[structopt(long, help = "The target instance size. (C4, M8, etc)")]
target_size: String,
}

#[derive(Debug, StructOpt)]
#[structopt(about = "Upgrade a cluster")]
struct UpgradeCluster {
#[structopt(long, parse(try_from_str = parse_org_id), default_value = "", help = "The organization id the cluster relates to")]
org_id: OrgId,

#[structopt(long, parse(try_from_str = parse_project_id), default_value = "", help = "The project id the cluster relates to")]
project_id: esc_api::resources::ProjectId,

#[structopt(long, short, parse(try_from_str = parse_cluster_id), help = "Id of the cluster you want to upgrade")]
id: esc_api::ClusterId,

#[structopt(
long,
help = "The target tag you want to upgrade to. This must include the full version (23.10.1)."
)]
target_tag: String,
}

#[derive(Debug, StructOpt)]
#[structopt(about = "Gathers backup management commands")]
struct Backups {
Expand Down Expand Up @@ -2385,6 +2422,34 @@ async fn call_api<'a, 'b>(
)
.await?;
}

ClustersCommand::Resize(params) => {
let client = client_builder.create().await?;
esc_api::mesdb::resize_cluster(
&client,
params.org_id,
params.project_id,
params.id,
esc_api::mesdb::ResizeClusterRequest {
target_size: params.target_size,
},
)
.await?;
}

ClustersCommand::Upgrade(params) => {
let client = client_builder.create().await?;
esc_api::mesdb::upgrade_cluster(
&client,
params.org_id,
params.project_id,
params.id,
esc_api::mesdb::UpgradeClusterRequest {
target_tag: params.target_tag,
},
)
.await?;
}
},
MesdbCommand::Backups(clusters) => match clusters.backups_command {
BackupsCommand::Create(params) => {
Expand Down
64 changes: 64 additions & 0 deletions generated/src/mesdb/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,38 @@ pub async fn list_clusters(
.await
}

/// resize a cluster
///
/// # Arguments
///
/// * `organization_id` - The id of the organization the cluster is owned by
/// * `project_id` - The id of the project the cluster is organized by
/// * `cluster_id` - The id of the cluster
/// * `resize_cluster_request`
pub async fn resize_cluster(
client: &Client,
organization_id: OrganizationId,
project_id: ProjectId,
cluster_id: ClusterId,
// describes how to resize the cluster
resize_cluster_request: ResizeClusterRequest,
) -> Result<ResizeClusterResponse> {
let url = format!(
"/mesdb/v1/organizations/{organizationId}/projects/{projectId}/clusters/{clusterId}/commands/resize",
organizationId = urlencode(organization_id),
projectId = urlencode(project_id),
clusterId = urlencode(cluster_id),
);
client
.send_request::<ResizeClusterRequest, ResizeClusterResponse>(
Method::PUT,
url,
Some(&resize_cluster_request),
None,
)
.await
}

/// restart a cluster
///
/// # Arguments
Expand Down Expand Up @@ -289,3 +321,35 @@ pub async fn update_cluster(
)
.await
}

/// upgrades a cluster
///
/// # Arguments
///
/// * `organization_id` - The id of the organization the cluster is owned by
/// * `project_id` - The id of the project the cluster is organized by
/// * `cluster_id` - The id of the cluster
/// * `upgrade_cluster_request`
pub async fn upgrade_cluster(
client: &Client,
organization_id: OrganizationId,
project_id: ProjectId,
cluster_id: ClusterId,
// describes how to upgrade the cluster
upgrade_cluster_request: UpgradeClusterRequest,
) -> Result<UpgradeClusterResponse> {
let url = format!(
"/mesdb/v1/organizations/{organizationId}/projects/{projectId}/clusters/{clusterId}/commands/upgrade",
organizationId = urlencode(organization_id),
projectId = urlencode(project_id),
clusterId = urlencode(cluster_id),
);
client
.send_request::<UpgradeClusterRequest, UpgradeClusterResponse>(
Method::PUT,
url,
Some(&upgrade_cluster_request),
None,
)
.await
}
161 changes: 95 additions & 66 deletions generated/src/mesdb/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,76 +50,11 @@ pub struct Cluster {
pub region: String,
pub server_version: String,
pub server_version_tag: String,
pub status: ClusterStatus,
pub status: Status,
pub topology: Topology,
pub protected: bool,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum ClusterStatus {
#[serde(rename = "provisioning")]
Provisioning,
#[serde(rename = "disks available")]
DisksAvailable,
#[serde(rename = "expanding disks")]
ExpandingDisks,
#[serde(rename = "restarting")]
Restarting,
#[serde(rename = "available")]
Available,
#[serde(rename = "defunct")]
Defunct,
#[serde(rename = "inconsistent")]
Inconsistent,
#[serde(rename = "deleting instances")]
DeletingInstances,
#[serde(rename = "instances deleted")]
InstancesDeleted,
#[serde(rename = "deleting disks")]
DeletingDisks,
#[serde(rename = "deleted")]
Deleted,
}
impl std::fmt::Display for ClusterStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ClusterStatus::Provisioning => write!(f, "provisioning"),
ClusterStatus::DisksAvailable => write!(f, "disks available"),
ClusterStatus::ExpandingDisks => write!(f, "expanding disks"),
ClusterStatus::Restarting => write!(f, "restarting"),
ClusterStatus::Available => write!(f, "available"),
ClusterStatus::Defunct => write!(f, "defunct"),
ClusterStatus::Inconsistent => write!(f, "inconsistent"),
ClusterStatus::DeletingInstances => write!(f, "deleting instances"),
ClusterStatus::InstancesDeleted => write!(f, "instances deleted"),
ClusterStatus::DeletingDisks => write!(f, "deleting disks"),
ClusterStatus::Deleted => write!(f, "deleted"),
}
}
}
impl std::cmp::PartialEq<&str> for ClusterStatus {
fn eq(&self, other: &&str) -> bool {
match self {
ClusterStatus::Provisioning => *other == "provisioning",
ClusterStatus::DisksAvailable => *other == "disks available",
ClusterStatus::ExpandingDisks => *other == "expanding disks",
ClusterStatus::Restarting => *other == "restarting",
ClusterStatus::Available => *other == "available",
ClusterStatus::Defunct => *other == "defunct",
ClusterStatus::Inconsistent => *other == "inconsistent",
ClusterStatus::DeletingInstances => *other == "deleting instances",
ClusterStatus::InstancesDeleted => *other == "instances deleted",
ClusterStatus::DeletingDisks => *other == "deleting disks",
ClusterStatus::Deleted => *other == "deleted",
}
}
}
impl std::cmp::PartialEq<ClusterStatus> for &str {
fn eq(&self, other: &ClusterStatus) -> bool {
other == self
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateBackupRequest {
Expand Down Expand Up @@ -274,12 +209,94 @@ impl std::cmp::PartialEq<ProjectionLevel> for &str {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResizeClusterRequest {
pub target_size: String,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResizeClusterResponse {
pub id: String,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RestartClusterResponse {
pub id: String,
}

/// The status of the cluster
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum Status {
#[serde(rename = "provisioning")]
Provisioning,
#[serde(rename = "disks available")]
DisksAvailable,
#[serde(rename = "expanding disks")]
ExpandingDisks,
#[serde(rename = "restarting")]
Restarting,
#[serde(rename = "available")]
Available,
#[serde(rename = "defunct")]
Defunct,
#[serde(rename = "inconsistent")]
Inconsistent,
#[serde(rename = "upgrading")]
Upgrading,
#[serde(rename = "deleting instances")]
DeletingInstances,
#[serde(rename = "instances deleted")]
InstancesDeleted,
#[serde(rename = "deleting disks")]
DeletingDisks,
#[serde(rename = "deleted")]
Deleted,
}
impl std::fmt::Display for Status {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Status::Provisioning => write!(f, "provisioning"),
Status::DisksAvailable => write!(f, "disks available"),
Status::ExpandingDisks => write!(f, "expanding disks"),
Status::Restarting => write!(f, "restarting"),
Status::Available => write!(f, "available"),
Status::Defunct => write!(f, "defunct"),
Status::Inconsistent => write!(f, "inconsistent"),
Status::Upgrading => write!(f, "upgrading"),
Status::DeletingInstances => write!(f, "deleting instances"),
Status::InstancesDeleted => write!(f, "instances deleted"),
Status::DeletingDisks => write!(f, "deleting disks"),
Status::Deleted => write!(f, "deleted"),
}
}
}
impl std::cmp::PartialEq<&str> for Status {
fn eq(&self, other: &&str) -> bool {
match self {
Status::Provisioning => *other == "provisioning",
Status::DisksAvailable => *other == "disks available",
Status::ExpandingDisks => *other == "expanding disks",
Status::Restarting => *other == "restarting",
Status::Available => *other == "available",
Status::Defunct => *other == "defunct",
Status::Inconsistent => *other == "inconsistent",
Status::Upgrading => *other == "upgrading",
Status::DeletingInstances => *other == "deleting instances",
Status::InstancesDeleted => *other == "instances deleted",
Status::DeletingDisks => *other == "deleting disks",
Status::Deleted => *other == "deleted",
}
}
}
impl std::cmp::PartialEq<Status> for &str {
fn eq(&self, other: &Status) -> bool {
other == self
}
}

/// Either single-node or three-node-multi-zone
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum Topology {
Expand Down Expand Up @@ -318,3 +335,15 @@ pub struct UpdateClusterRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub protected: Option<bool>,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpgradeClusterRequest {
pub target_tag: String,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UpgradeClusterResponse {
pub id: String,
}

0 comments on commit 20bd935

Please sign in to comment.