Skip to content

Commit

Permalink
chore: add servers backwards compatability (#1335)
Browse files Browse the repository at this point in the history
<!-- 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
NathanFlurry committed Nov 13, 2024
1 parent c7ec0af commit a470cec
Show file tree
Hide file tree
Showing 190 changed files with 10,898 additions and 1,143 deletions.
157 changes: 149 additions & 8 deletions packages/api/actor/src/route/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ pub async fn get_deprecated(
env_id: Uuid,
actor_id: Uuid,
watch_index: WatchIndexQuery,
) -> GlobalResult<models::ActorGetActorResponse> {
) -> GlobalResult<models::ServersGetServerResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
get(ctx, actor_id, watch_index, global).await
let get_res = get(ctx, actor_id, watch_index, global).await?;
Ok(models::ServersGetServerResponse {
server: Box::new(legacy_convert_actor_to_server(*get_res.actor)),
})
}

// MARK: POST /actors
Expand Down Expand Up @@ -190,10 +193,79 @@ pub async fn create_deprecated(
ctx: Ctx<Auth>,
game_id: Uuid,
env_id: Uuid,
body: models::ActorCreateActorRequest,
) -> GlobalResult<models::ActorCreateActorResponse> {
body: models::ServersCreateServerRequest,
) -> GlobalResult<models::ServersCreateServerResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
create(ctx, body, global).await
let create_res = create(
ctx,
models::ActorCreateActorRequest {
datacenter: body.datacenter,
lifecycle: body.lifecycle.map(|l| {
Box::new(models::ActorLifecycle {
kill_timeout: l.kill_timeout,
})
}),
network: Box::new(models::ActorCreateActorNetworkRequest {
mode: body.network.mode.map(|n| match n {
models::ServersNetworkMode::Host => models::ActorNetworkMode::Host,
models::ServersNetworkMode::Bridge => models::ActorNetworkMode::Bridge,
}),
ports: body
.network
.ports
.into_iter()
.map(|(k, p)| {
(
k,
models::ActorCreateActorPortRequest {
internal_port: p.internal_port,
protocol: match p.protocol {
models::ServersPortProtocol::Http => {
models::ActorPortProtocol::Http
}
models::ServersPortProtocol::Https => {
models::ActorPortProtocol::Https
}
models::ServersPortProtocol::Tcp => {
models::ActorPortProtocol::Tcp
}
models::ServersPortProtocol::TcpTls => {
models::ActorPortProtocol::TcpTls
}
models::ServersPortProtocol::Udp => {
models::ActorPortProtocol::Udp
}
},
routing: p.routing.map(|r| {
Box::new(models::ActorPortRouting {
game_guard: r.game_guard.map(|_| {
Box::new(models::ActorGameGuardRouting::default())
}),
host: r.host.map(|_| json!({})),
})
}),
},
)
})
.collect(),
}),
resources: Box::new(models::ActorResources {
cpu: body.resources.cpu,
memory: body.resources.memory,
}),
runtime: Box::new(models::ActorCreateActorRuntimeRequest {
arguments: body.runtime.arguments,
environment: body.runtime.environment,
build: body.runtime.build,
}),
tags: body.tags,
},
global,
)
.await?;
Ok(models::ServersCreateServerResponse {
server: Box::new(legacy_convert_actor_to_server(*create_res.actor)),
})
}

// MARK: DELETE /actors/{}
Expand Down Expand Up @@ -306,13 +378,82 @@ pub async fn list_actors(
Ok(models::ActorListActorsResponse { actors: servers })
}

pub async fn list_actors_deprecated(
pub async fn list_servers_deprecated(
ctx: Ctx<Auth>,
game_id: Uuid,
env_id: Uuid,
watch_index: WatchIndexQuery,
query: ListQuery,
) -> GlobalResult<models::ActorListActorsResponse> {
) -> GlobalResult<models::ServersListServersResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
list_actors(ctx, watch_index, ListQuery { global, ..query }).await
let actors_res = list_actors(ctx, watch_index, ListQuery { global, ..query }).await?;
Ok(models::ServersListServersResponse {
servers: actors_res
.actors
.into_iter()
.map(legacy_convert_actor_to_server)
.collect(),
})
}

fn legacy_convert_actor_to_server(a: models::ActorActor) -> models::ServersServer {
models::ServersServer {
created_at: a.created_at,
datacenter: a.datacenter,
destroyed_at: a.destroyed_at,
environment: a.environment,
id: a.id,
lifecycle: Box::new(models::ServersLifecycle {
kill_timeout: a.lifecycle.kill_timeout,
}),
network: Box::new(models::ServersNetwork {
mode: a.network.mode.map(|n| match n {
models::ActorNetworkMode::Host => models::ServersNetworkMode::Host,
models::ActorNetworkMode::Bridge => models::ServersNetworkMode::Bridge,
}),
ports: a
.network
.ports
.into_iter()
.map(|(k, p)| {
(
k,
models::ServersPort {
internal_port: p.internal_port,
protocol: match p.protocol {
models::ActorPortProtocol::Http => {
models::ServersPortProtocol::Http
}
models::ActorPortProtocol::Https => {
models::ServersPortProtocol::Https
}
models::ActorPortProtocol::Tcp => models::ServersPortProtocol::Tcp,
models::ActorPortProtocol::TcpTls => {
models::ServersPortProtocol::TcpTls
}
models::ActorPortProtocol::Udp => models::ServersPortProtocol::Udp,
},
public_hostname: p.public_hostname,
public_port: p.public_port,
routing: Box::new(models::ServersPortRouting {
game_guard: p.routing.game_guard.map(|_| json!({})),
host: p.routing.host.map(|_| json!({})),
}),
},
)
})
.collect(),
}),
resources: Box::new(models::ServersResources {
cpu: a.resources.cpu,
memory: a.resources.memory,
}),
runtime: Box::new(models::ServersRuntime {
arguments: a.runtime.arguments,
build: a.runtime.build,
environment: a.runtime.environment,
}),
started_at: a.started_at,
tags: a.tags,
}
}
81 changes: 68 additions & 13 deletions packages/api/actor/src/route/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,18 @@ pub async fn get_deprecated(
env_id: Uuid,
build_id: Uuid,
watch_index: WatchIndexQuery,
) -> GlobalResult<models::ActorGetBuildResponse> {
) -> GlobalResult<models::ServersGetBuildResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
get(ctx, build_id, watch_index, global).await
let builds_res = get(ctx, build_id, watch_index, global).await?;
Ok(models::ServersGetBuildResponse {
build: Box::new(models::ServersBuild {
content_length: builds_res.build.content_length,
created_at: builds_res.build.created_at,
id: builds_res.build.id,
name: builds_res.build.name,
tags: builds_res.build.tags,
}),
})
}

// MARK: GET /builds
Expand Down Expand Up @@ -144,9 +153,9 @@ pub async fn list_deprecated(
env_id: Uuid,
watch_index: WatchIndexQuery,
query: ListQuery,
) -> GlobalResult<models::ActorListBuildsResponse> {
) -> GlobalResult<models::ServersListBuildsResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
list(
let builds_res = list(
ctx,
watch_index,
ListQuery {
Expand All @@ -155,7 +164,20 @@ pub async fn list_deprecated(
tags_json: query.tags_json,
},
)
.await
.await?;
Ok(models::ServersListBuildsResponse {
builds: builds_res
.builds
.into_iter()
.map(|b| models::ServersBuild {
content_length: b.content_length,
created_at: b.created_at,
id: b.id,
name: b.name,
tags: b.tags,
})
.collect(),
})
}

// MARK: PATCH /builds/{}/tags
Expand Down Expand Up @@ -195,18 +217,27 @@ pub async fn patch_tags_deprecated(
game_id: Uuid,
env_id: Uuid,
build_id: Uuid,
body: models::ActorPatchBuildTagsRequest,
body: models::ServersPatchBuildTagsRequest,
) -> GlobalResult<serde_json::Value> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
patch_tags(ctx, build_id, body, global).await
patch_tags(
ctx,
build_id,
models::ActorPatchBuildTagsRequest {
exclusive_tags: body.exclusive_tags,
tags: body.tags,
},
global,
)
.await
}

// MARK: POST /builds/prepare
pub async fn create_build(
ctx: Ctx<Auth>,
body: models::ActorCreateBuildRequest,
body: models::ActorPrepareBuildRequest,
query: GlobalQuery,
) -> GlobalResult<models::ActorCreateBuildResponse> {
) -> GlobalResult<models::ActorPrepareBuildResponse> {
let CheckOutput { game_id, env_id } = ctx.auth().check(ctx.op_ctx(), &query, false).await?;

// TODO: Read and validate image file
Expand Down Expand Up @@ -293,7 +324,7 @@ pub async fn create_build(
None
};

Ok(models::ActorCreateBuildResponse {
Ok(models::ActorPrepareBuildResponse {
build: build_id,
image_presigned_request,
image_presigned_requests,
Expand All @@ -304,10 +335,34 @@ pub async fn create_build_deprecated(
ctx: Ctx<Auth>,
game_id: Uuid,
env_id: Uuid,
body: models::ActorCreateBuildRequest,
) -> GlobalResult<models::ActorCreateBuildResponse> {
body: models::ServersCreateBuildRequest,
) -> GlobalResult<models::ServersCreateBuildResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
create_build(ctx, body, global).await
let build_res = create_build(
ctx,
models::ActorPrepareBuildRequest {
compression: body.compression.map(|c| match c {
models::ServersBuildCompression::None => models::ActorBuildCompression::None,
models::ServersBuildCompression::Lz4 => models::ActorBuildCompression::Lz4,
}),
image_file: body.image_file,
image_tag: body.image_tag,
kind: body.kind.map(|k| match k {
models::ServersBuildKind::DockerImage => models::ActorBuildKind::DockerImage,
models::ServersBuildKind::OciBundle => models::ActorBuildKind::OciBundle,
}),
multipart_upload: body.multipart_upload,
name: body.name,
prewarm_datacenters: body.prewarm_datacenters,
},
global,
)
.await?;
Ok(models::ServersCreateBuildResponse {
build: build_res.build,
image_presigned_request: build_res.image_presigned_request,
image_presigned_requests: build_res.image_presigned_requests,
})
}

// MARK: POST /builds/{}/complete
Expand Down
15 changes: 13 additions & 2 deletions packages/api/actor/src/route/dc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ pub async fn list_deprecated(
game_id: Uuid,
env_id: Uuid,
watch_index: WatchIndexQuery,
) -> GlobalResult<models::ActorListDatacentersResponse> {
) -> GlobalResult<models::ServersListDatacentersResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
list(ctx, watch_index, global).await
let dc_res = list(ctx, watch_index, global).await?;
Ok(models::ServersListDatacentersResponse {
datacenters: dc_res
.datacenters
.into_iter()
.map(|dc| models::ServersDatacenter {
id: dc.id,
name: dc.name,
slug: dc.slug,
})
.collect(),
})
}
11 changes: 8 additions & 3 deletions packages/api/actor/src/route/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ pub async fn get_logs_deprecated(
server_id: Uuid,
watch_index: WatchIndexQuery,
query: GetActorLogsQuery,
) -> GlobalResult<models::ActorGetActorLogsResponse> {
) -> GlobalResult<models::ServersGetServerLogsResponse> {
let global = build_global_query_compat(&ctx, game_id, env_id).await?;
get_logs(
let logs_res = get_logs(
ctx,
server_id,
watch_index,
Expand All @@ -150,5 +150,10 @@ pub async fn get_logs_deprecated(
stream: query.stream,
},
)
.await
.await?;
Ok(models::ServersGetServerLogsResponse {
lines: logs_res.lines,
timestamps: logs_res.timestamps,
watch: logs_res.watch,
})
}
Loading

0 comments on commit a470cec

Please sign in to comment.