Skip to content
Merged
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
898 changes: 452 additions & 446 deletions svc/Cargo.lock

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions svc/api/servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,20 @@ uuid = { version = "1", features = ["v4"] }

build-create = { path = "../../pkg/build/ops/create" }
build-get = { path = "../../pkg/build/ops/get" }
game-namespace-get = { path = "../../pkg/game/ops/namespace-get" }
build-list-for-game = { path = "../../pkg/build/ops/list-for-game" }
cluster-datacenter-get = { path = "../../pkg/cluster/ops/datacenter-get" }
cluster-datacenter-list = { path = "../../pkg/cluster/ops/datacenter-list" }
cluster-datacenter-resolve-for-name-id = { path = "../../pkg/cluster/ops/datacenter-resolve-for-name-id" }
cluster-get = { path = "../../pkg/cluster/ops/get" }
cluster-get-for-game = { path = "../../pkg/cluster/ops/get-for-game" }
game-version-get = { path = "../../pkg/game/ops/version-get" }
cluster-list = { path = "../../pkg/cluster/ops/list" }
cluster-resolve-for-name-id = { path = "../../pkg/cluster/ops/resolve-for-name-id" }
cluster = { path = "../../pkg/cluster" }
ds-server-create = { path = "../../pkg/ds/ops/server-create" }
ds-server-list-for-game = { path = "../../pkg/ds/ops/server-list-for-game" }
ds-server-delete = { path = "../../pkg/ds/ops/server-delete" }
ds-server-get = { path = "../../pkg/ds/ops/server-get" }
user-identity-get = { path = "../../pkg/user-identity/ops/get" }
ds-server-list-for-game = { path = "../../pkg/ds/ops/server-list-for-game" }
game-get = { path = "../../pkg/game/ops/get" }
game-namespace-get = { path = "../../pkg/game/ops/namespace-get" }
game-version-get = { path = "../../pkg/game/ops/version-get" }
token-revoke = { path = "../../pkg/token/ops/revoke" }
upload-complete = { path = "../../pkg/upload/ops/complete" }
upload-get = { path = "../../pkg/upload/ops/get" }
user-get = { path = "../../pkg/user/ops/get" }
user-identity-get = { path = "../../pkg/user-identity/ops/get" }
user-team-list = { path = "../../pkg/user/ops/team-list" }

[dev-dependencies]
Expand Down
32 changes: 17 additions & 15 deletions svc/api/servers/src/route/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,37 @@ pub async fn create(
body: models::ServersCreateServerRequest,
) -> GlobalResult<models::ServersCreateServerResponse> {
let game_id = ctx.auth().server()?.game_id;
let games = op!([ctx] cluster_get_for_game {
game_ids: vec![game_id.into()]
})
.await?
.games;
let games = ctx
.op(cluster::ops::get_for_game::Input {
game_ids: vec![game_id],
})
.await?
.games;

let cluster_id = unwrap!(unwrap!(games.first()).cluster_id);
let cluster_id = unwrap!(games.first()).cluster_id;

let datacenters = op!([ctx] cluster_datacenter_resolve_for_name_id {
cluster_id: Some(cluster_id),
name_ids: vec![body.datacenter.clone()]
})
.await?
.datacenters;
let datacenters = ctx
.op(cluster::ops::datacenter::resolve_for_name_id::Input {
cluster_id,
name_ids: vec![body.datacenter.clone()],
})
.await?
.datacenters;

if datacenters.is_empty() {
bail_with!(CLUSTER_DATACENTER_NOT_FOUND);
}

let datacenter_id = unwrap!(unwrap!(datacenters.first()).datacenter_id);
let datacenter_id = unwrap!(datacenters.first()).datacenter_id;

let tags = serde_json::from_value(body.tags.unwrap_or_default())?;

tracing::info!("Creating server with tags: {:?}", tags);

let server = op!([ctx] ds_server_create {
game_id: Some(game_id.into()),
datacenter_id: Some(datacenter_id),
cluster_id: Some(cluster_id),
datacenter_id: Some(datacenter_id.into()),
cluster_id: Some(cluster_id.into()),
tags: tags,
resources: Some((*body.resources).api_into()),
kill_timeout_ms: body.kill_timeout.unwrap_or_default(),
Expand Down
1 change: 0 additions & 1 deletion svc/pkg/cloud/worker/src/workers/version_name_reserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ async fn worker(

Ok(())
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use tracing_subscriber::prelude::*;
use chirp_workflow::prelude::*;
use tracing_subscriber::prelude::*;

#[tokio::test(flavor = "multi_thread")]
async fn basic() {
Expand Down
2 changes: 1 addition & 1 deletion svc/pkg/cluster/standalone/gc/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ::cluster_gc::run_from_env;
use tracing_subscriber::prelude::*;
use chirp_workflow::prelude::*;
use serde_json::json;
use tracing_subscriber::prelude::*;

use cluster::types::{BuildDeliveryMethod, Hardware, Pool, PoolType, Provider};

Expand Down
12 changes: 6 additions & 6 deletions svc/pkg/ds/ops/server-create/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = "Apache-2.0"
[dependencies]
chirp-client = { path = "../../../../../lib/chirp/client" }
chirp-worker = { path = "../../../../../lib/chirp/worker" }
chirp-workflow = { path = "../../../../../lib/chirp-workflow/core" }
rivet-operation = { path = "../../../../../lib/operation/core" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down Expand Up @@ -35,16 +36,15 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
"ansi",
] }

mm-lobby-list-for-user-id = { path = "../../../mm/ops/lobby-list-for-user-id" }
build-get = { path = "../../../build/ops/get" }
user-identity-get = { path = "../../../user-identity/ops/get" }
upload-get = { path = "../../../upload/ops/get" }
region-get = { path = "../../../region/ops/get" }
cluster = { path = "../../../cluster" }
ip-info = { path = "../../../ip/ops/info" }
mm-lobby-list-for-user-id = { path = "../../../mm/ops/lobby-list-for-user-id" }
region-get = { path = "../../../region/ops/get" }
tier-list = { path = "../../../tier/ops/list" }
token-create = { path = "../../../token/ops/create" }
cluster-datacenter-list = { path = "../../../cluster/ops/datacenter-list" }
cluster-list = { path = "../../../cluster/ops/list" }
upload-get = { path = "../../../upload/ops/get" }
user-identity-get = { path = "../../../user-identity/ops/get" }

[dependencies.nomad_client]
package = "nomad_client"
Expand Down
24 changes: 15 additions & 9 deletions svc/pkg/ds/ops/server-create/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
// use chirp_worker::prelude::*;
use std::{
collections::HashMap,
hash::{DefaultHasher, Hasher},
net::IpAddr,
time::Duration,
};

use crate::sqlx;
use futures_util::FutureExt;
use nomad_client::models::*;
use nomad_job::{
escape_go_template, gen_oci_bundle_config, inject_consul_env_template, nomad_host_port_env_var,
template_env_var, template_env_var_int, DecodedPort, ProxyProtocol, TransportProtocol,
};
use proto::backend::{self};
use proto::{backend::pkg::*, chirp::response::Ok};
use proto::{
backend::{self, pkg::*},
chirp::response::Ok,
};
use rand::Rng;
use regex::Regex;
use rivet_operation::prelude::*;
use serde_json::json;
use sha2::{Digest, Sha256};
use std::hash::Hasher;
use std::{collections::HashMap, hash::DefaultHasher, net::IpAddr, time::Duration};
use team::member_get::request;

mod nomad_job;
Expand Down Expand Up @@ -1208,7 +1214,7 @@ pub async fn handle(
FROM db_cluster.servers
WHERE
datacenter_id = $1 AND
pool_type = $2 AND
pool_type2 = $2 AND
vlan_ip IS NOT NULL AND
install_complete_ts IS NOT NULL AND
drain_ts IS NULL AND
Expand All @@ -1222,7 +1228,7 @@ pub async fn handle(
",
// NOTE: region_id is just the old name for datacenter_id
&region_id,
backend::cluster::PoolType::Ats as i64,
serde_json::to_string(&cluster::types::PoolType::Ats)?,
hash,
)
.await?;
Expand Down Expand Up @@ -1495,7 +1501,7 @@ async fn resolve_job_runner_binary_url(
FROM db_cluster.servers
WHERE
datacenter_id = $1 AND
pool_type = $2 AND
pool_type2 = $2 AND
vlan_ip IS NOT NULL AND
install_complete_ts IS NOT NULL AND
drain_ts IS NULL AND
Expand All @@ -1508,7 +1514,7 @@ async fn resolve_job_runner_binary_url(
",
// NOTE: region_id is just the old name for datacenter_id
&region_id,
backend::cluster::PoolType::Ats as i64,
serde_json::to_string(&cluster::types::PoolType::Ats)?,
)
.await?;

Expand Down
43 changes: 24 additions & 19 deletions svc/pkg/ds/ops/server-create/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::collections::HashMap;

use chirp_worker::prelude::*;
use proto::backend::{
use chirp_workflow::prelude::*;
use rivet_api::{apis::*, models};
use rivet_operation::prelude::proto::{
self,
pkg::{dynamic_servers, token},
backend::{
self,
pkg::{dynamic_servers, token},
},
};
use rivet_api::{apis::*, models};

#[worker_test]
#[workflow_test]
async fn create(ctx: TestCtx) {
let game_res = op!([ctx] faker_game {
..Default::default()
Expand Down Expand Up @@ -40,7 +43,8 @@ async fn create(ctx: TestCtx) {
tracing::info!("token_res for key: {:?}", token_res);

// Pick an existing cluster
let cluster_id = op!([ctx] cluster_list {})
let cluster_id = ctx
.op(cluster::ops::list::Input {})
.await
.unwrap()
.cluster_ids
Expand All @@ -49,18 +53,19 @@ async fn create(ctx: TestCtx) {
.to_owned();

// Pick an existing datacenter
let datacenter_id = op!([ctx] cluster_datacenter_list {
cluster_ids: vec![cluster_id],
})
.await
.unwrap()
.clusters
.first()
.unwrap()
.datacenter_ids
.first()
.unwrap()
.to_owned();
let datacenter_id = ctx
.op(cluster::ops::datacenter::list::Input {
cluster_ids: vec![cluster_id],
})
.await
.unwrap()
.clusters
.first()
.unwrap()
.datacenter_ids
.first()
.unwrap()
.to_owned();

let build_res: backend::pkg::faker::build::Response = op!([ctx] faker_build {
game_id: Some(game_id),
Expand Down Expand Up @@ -96,7 +101,7 @@ async fn create(ctx: TestCtx) {

let server = op!([ctx] ds_server_create {
game_id: Some(game_id),
cluster_id: Some(cluster_id),
cluster_id: Some(cluster_id.into()),
datacenter_id: faker_region.region_id,
resources: Some(proto::backend::ds::ServerResources { cpu_millicores: 100, memory_mib: 200 }),
kill_timeout_ms: 0,
Expand Down
37 changes: 21 additions & 16 deletions svc/pkg/ds/ops/server-create/tests/print_test_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use chirp_worker::prelude::*;
use proto::backend::{self, pkg::token};
use chirp_workflow::prelude::*;
use rivet_operation::prelude::proto::{
self,
backend::{self, pkg::token},
};

#[worker_test]
#[workflow_test]
async fn print_test_data(ctx: TestCtx) {
let game_res = op!([ctx] faker_game {
..Default::default()
Expand All @@ -18,7 +21,8 @@ async fn print_test_data(ctx: TestCtx) {
let user_id = user_res.user_id.unwrap();

// Pick an existing cluster
let cluster_id = op!([ctx] cluster_list {})
let cluster_id = ctx
.op(cluster::ops::list::Input {})
.await
.unwrap()
.cluster_ids
Expand All @@ -27,18 +31,19 @@ async fn print_test_data(ctx: TestCtx) {
.to_owned();

// Pick an existing datacenter
let datacenter_id = op!([ctx] cluster_datacenter_list {
cluster_ids: vec![cluster_id],
})
.await
.unwrap()
.clusters
.first()
.unwrap()
.datacenter_ids
.first()
.unwrap()
.to_owned();
let datacenter_id = ctx
.op(cluster::ops::datacenter::list::Input {
cluster_ids: vec![cluster_id],
})
.await
.unwrap()
.clusters
.first()
.unwrap()
.datacenter_ids
.first()
.unwrap()
.to_owned();

let build_res: backend::pkg::faker::build::Response = op!([ctx] faker_build {
game_id: Some(game_id),
Expand Down
3 changes: 2 additions & 1 deletion svc/pkg/ds/ops/server-get/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license = "Apache-2.0"

[dependencies]
chirp-client = { path = "../../../../../lib/chirp/client" }
chirp-workflow = { path = "../../../../../lib/chirp-workflow/core" }
rivet-operation = { path = "../../../../../lib/operation/core" }
util-ds = { package = "rivet-util-ds", path = "../../util" }

Expand All @@ -19,7 +20,7 @@ default-features = false
chirp-worker = { path = "../../../../../lib/chirp/worker" }

ds-server-create = { path = "../server-create" }
cluster-list = { path = "../../../cluster/ops/list" }
cluster = { path = "../../../cluster" }
faker-build = { path = "../../../faker/ops/build" }
faker-game = { path = "../../../faker/ops/game" }
faker-region = { path = "../../../faker/ops/region" }
Expand Down
14 changes: 9 additions & 5 deletions svc/pkg/ds/ops/server-get/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::collections::HashMap;

use chirp_worker::prelude::*;
use proto::backend::{self, pkg::dynamic_servers};
use chirp_workflow::prelude::*;
use rivet_operation::prelude::proto::{
self,
backend::{self, pkg::dynamic_servers},
};

#[worker_test]
#[workflow_test]
async fn server_get(ctx: TestCtx) {
let game_res = op!([ctx] faker_game {
..Default::default()
Expand All @@ -13,7 +16,8 @@ async fn server_get(ctx: TestCtx) {
let game_id = game_res.game_id.unwrap();

// Pick an existing cluster
let cluster_id = op!([ctx] cluster_list {})
let cluster_id = ctx
.op(cluster::ops::list::Input {})
.await
.unwrap()
.cluster_ids
Expand Down Expand Up @@ -55,7 +59,7 @@ async fn server_get(ctx: TestCtx) {

let server = op!([ctx] ds_server_create {
game_id: Some(game_id),
cluster_id: Some(cluster_id),
cluster_id: Some(cluster_id.into()),
datacenter_id: faker_region.region_id,
resources: Some(proto::backend::ds::ServerResources { cpu_millicores: 100, memory_mib: 200 }),
kill_timeout_ms: 0,
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion svc/pkg/ds/worker/src/workers/nomad_monitor_eval_update.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use self::sqlx;
use chirp_worker::prelude::*;
use proto::backend::pkg::*;
use serde::Deserialize;
Expand Down
2 changes: 1 addition & 1 deletion svc/pkg/linode/standalone/gc/tests/integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ::linode_gc::run_from_env;
use tracing_subscriber::prelude::*;
use chirp_workflow::prelude::*;
use tracing_subscriber::prelude::*;

#[tokio::test(flavor = "multi_thread")]
async fn basic() {
Expand Down