-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add operation to list all clusters (#717)
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
- Loading branch information
1 parent
ee7547b
commit 1f4b169
Showing
7 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "cluster-list" | ||
version = "0.0.1" | ||
edition = "2018" | ||
authors = ["Rivet Gaming, LLC <developer@rivet.gg>"] | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
chirp-client = { path = "../../../../../lib/chirp/client" } | ||
prost = "0.10" | ||
rivet-operation = { path = "../../../../../lib/operation/core" } | ||
|
||
[dependencies.sqlx] | ||
version = "0.7" | ||
default-features = false | ||
|
||
[dev-dependencies] | ||
chirp-worker = { path = "../../../../../lib/chirp/worker" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[service] | ||
name = "cluster-list" | ||
|
||
[runtime] | ||
kind = "rust" | ||
|
||
[operation] | ||
|
||
[databases] | ||
db-cluster = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use proto::backend::{self, pkg::*}; | ||
use rivet_operation::prelude::*; | ||
|
||
#[derive(sqlx::FromRow)] | ||
struct Cluster { | ||
cluster_id: Uuid, | ||
name_id: String, | ||
owner_team_id: Option<Uuid>, | ||
create_ts: i64, | ||
} | ||
|
||
impl From<Cluster> for backend::cluster::Cluster { | ||
fn from(value: Cluster) -> Self { | ||
backend::cluster::Cluster { | ||
cluster_id: Some(value.cluster_id.into()), | ||
name_id: value.name_id, | ||
owner_team_id: value.owner_team_id.map(Into::into), | ||
create_ts: value.create_ts, | ||
} | ||
} | ||
} | ||
|
||
#[operation(name = "cluster-list")] | ||
pub async fn handle( | ||
ctx: OperationContext<cluster::list::Request>, | ||
) -> GlobalResult<cluster::list::Response> { | ||
let crdb = ctx.crdb().await?; | ||
|
||
let cluster_ids = sql_fetch_all!( | ||
[ctx, Cluster, &crdb] | ||
" | ||
SELECT | ||
cluster_id, | ||
name_id, | ||
owner_team_id, | ||
create_ts | ||
FROM db_cluster.clusters | ||
", | ||
) | ||
.await? | ||
.into_iter() | ||
.map(|cluster| cluster.cluster_id.into()) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok(cluster::list::Response { cluster_ids }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use chirp_worker::prelude::*; | ||
use proto::backend::pkg::*; | ||
|
||
#[worker_test] | ||
async fn list_single_cluster(ctx: TestCtx) { | ||
let cluster_id = Uuid::new_v4(); | ||
|
||
msg!([ctx] cluster::msg::create(cluster_id) -> cluster::msg::create_complete { | ||
cluster_id: Some(cluster_id.into()), | ||
name_id: util::faker::ident(), | ||
owner_team_id: None, | ||
}) | ||
.await | ||
.unwrap(); | ||
|
||
let res = op!([ctx] cluster_list {}).await.unwrap(); | ||
let new_cluster_id = res.cluster_ids.first().expect("cluster id not found"); | ||
|
||
assert_eq!(cluster_id, new_cluster_id.as_uuid()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
syntax = "proto3"; | ||
|
||
package rivet.backend.pkg.cluster.list; | ||
|
||
import "proto/common.proto"; | ||
import "proto/backend/cluster.proto"; | ||
|
||
message Request {} | ||
|
||
message Response { | ||
repeated rivet.common.Uuid cluster_ids = 1; | ||
} |