Skip to content

Commit

Permalink
feat(bolt): add lost servers list and prune commands (#1096)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->
Fixes RVT-3816
## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Aug 27, 2024
1 parent 9b56efc commit 0480702
Show file tree
Hide file tree
Showing 50 changed files with 2,342 additions and 330 deletions.
4 changes: 3 additions & 1 deletion fern/definition/admin/clusters/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ types:
display_name: string
provider: Provider
provider_datacenter_id: string
provider_api_token: optional<string>
pools: list<Pool>
build_delivery_method: BuildDeliveryMethod
prebakes_enabled: boolean

Server:
properties:
server_id: uuid
datacenter_id: uuid
pool_type: PoolType
public_ip: optional<string>

PoolUpdate:
Expand Down
23 changes: 23 additions & 0 deletions fern/definition/admin/clusters/servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ service:
pool: optional<localCommons.PoolType>
public_ip: optional<string>

listLost:
path: /lost
method: GET
request:
name: ListLostServersRequest
query-parameters:
server_id: optional<string>
datacenter: optional<string>
pool: optional<localCommons.PoolType>
public_ip: optional<string>
response: ListServersResponse

prune:
path: /prune
method: POST
request:
name: PruneServersRequest
query-parameters:
server_id: optional<string>
datacenter: optional<string>
pool: optional<localCommons.PoolType>
public_ip: optional<string>

types:
ListServersResponse:
properties:
Expand Down
104 changes: 85 additions & 19 deletions lib/bolt/cli/src/commands/cluster/datacenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use anyhow::*;
use bolt_core::context::ProjectContext;
use clap::{Parser, ValueEnum};
use rivet_api::{apis::*, models};
use tabled::Tabled;
use uuid::Uuid;

#[derive(ValueEnum, Clone)]
pub enum DatacenterProvider {
Expand Down Expand Up @@ -59,10 +57,10 @@ pub enum SubCommand {
/// Creates a new datacenter
Create {
/// The name id of the cluster
#[clap(long, short = 'c')]
#[clap(index = 1)]
cluster: String,
/// The name id of the datacenter
#[clap(long, short = 'd')]
#[clap(index = 2)]
name_id: String,
/// The display name of the datacenter
#[clap(long)]
Expand All @@ -83,19 +81,19 @@ pub enum SubCommand {
/// Lists all datacenters of a cluster
List {
/// The name id of the cluster
#[clap(long, short = 'c')]
#[clap(index = 1)]
cluster: String,
},
/// Update a datacenter's pools
Update {
/// The name id of the cluster
#[clap(long, short = 'c')]
#[clap(index = 1)]
cluster: String,
/// The name id of the datacenter
#[clap(index = 1)]
#[clap(index = 2)]
name_id: String,
/// The pool type
#[clap(index = 2)]
#[clap(index = 3)]
pool: DatacenterPoolType,
/// The hardware types
#[clap(long)]
Expand All @@ -118,12 +116,6 @@ pub enum SubCommand {
},
}

#[derive(Tabled)]
struct DatacenterTableRow {
name_id: String,
datacenter_id: Uuid,
}

impl SubCommand {
pub async fn execute(self, ctx: ProjectContext) -> Result<()> {
match self {
Expand Down Expand Up @@ -191,11 +183,10 @@ impl SubCommand {
.await?
.datacenters;

rivet_term::status::success("Datacenters", "");
rivet_term::format::table(datacenters.iter().map(|d| DatacenterTableRow {
name_id: d.name_id.clone(),
datacenter_id: d.datacenter_id,
}));
rivet_term::status::success("Datacenters", datacenters.len().to_string());
if !datacenters.is_empty() {
render::datacenters(datacenters);
}
}
Self::Update {
cluster: cluster_name_id,
Expand Down Expand Up @@ -264,3 +255,78 @@ impl SubCommand {
Ok(())
}
}

mod render {
use rivet_api::models;
use tabled::Tabled;
use uuid::Uuid;

use super::super::render::display_option;

#[derive(Tabled, Default)]
struct DcTableRow {
#[tabled(display_with = "display_option")]
pub name_id: Option<String>,
#[tabled(display_with = "display_option")]
pub datacenter_id: Option<Uuid>,
#[tabled(display_with = "display_provider")]
pub provider: Option<models::AdminClustersProvider>,
#[tabled(inline)]
pub pool: PoolTableRow,
#[tabled(display_with = "display_option")]
pub prebakes_enabled: Option<bool>,
}

#[derive(Tabled, Default)]
struct PoolTableRow {
#[tabled(display_with = "display_pool_type")]
pub pool_type: Option<models::AdminClustersPoolType>,
#[tabled(display_with = "display_option")]
pub min_count: Option<i32>,
#[tabled(display_with = "display_option")]
pub desired_count: Option<i32>,
#[tabled(display_with = "display_option")]
pub max_count: Option<i32>,
}

pub fn datacenters(mut datacenters: Vec<models::AdminClustersDatacenter>) {
let rows = datacenters.iter_mut().flat_map(|d| {
d.pools.sort_by_key(|pool| pool.pool_type);

std::iter::once(DcTableRow {
name_id: Some(d.name_id.clone()),
datacenter_id: Some(d.datacenter_id),
provider: Some(d.provider),
prebakes_enabled: Some(d.prebakes_enabled),
..Default::default()
})
.chain(d.pools.iter().cloned().map(|pool| DcTableRow {
pool: PoolTableRow {
pool_type: Some(pool.pool_type),
min_count: Some(pool.min_count),
desired_count: Some(pool.desired_count),
max_count: Some(pool.max_count),
},
..Default::default()
}))
});

rivet_term::format::table(rows);
}

fn display_provider(item: &Option<models::AdminClustersProvider>) -> String {
match item {
Some(models::AdminClustersProvider::Linode) => "Linode".to_string(),
None => String::new(),
}
}

fn display_pool_type(item: &Option<models::AdminClustersPoolType>) -> String {
match item {
Some(models::AdminClustersPoolType::Job) => "Job".to_string(),
Some(models::AdminClustersPoolType::Gg) => "GG".to_string(),
Some(models::AdminClustersPoolType::Ats) => "ATS".to_string(),
None => String::new(),
}
}
}
Loading

0 comments on commit 0480702

Please sign in to comment.