Skip to content

Commit

Permalink
Merge pull request #108 from depot/v4-cloud-service
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie authored Sep 12, 2024
2 parents 55f95be + 344ceb9 commit db78fda
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 365 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
syntax = "proto3";

package depot.cloud.v2;
package depot.cloud.v4;

service CloudService {
rpc GetDesiredStateUnary(GetDesiredStateUnaryRequest) returns (GetDesiredStateUnaryResponse) {}
rpc GetDesiredState(GetDesiredStateRequest) returns (GetDesiredStateResponse) {}
rpc ReportCurrentState(ReportCurrentStateRequest) returns (ReportCurrentStateResponse) {}
rpc ReportErrors(ReportErrorsRequest) returns (ReportErrorsResponse);
rpc GetActiveAgentVersion(GetActiveAgentVersionRequest) returns (GetActiveAgentVersionResponse);
Expand All @@ -14,17 +14,8 @@ service CloudService {

// Messages

message GetDesiredStateUnaryRequest {
GetDesiredStateRequest request = 1;
}

message GetDesiredStateUnaryResponse {
GetDesiredStateResponse response = 1;
}

message GetDesiredStateRequest {
string connection_id = 1;
string client_id = 2;
string client_id = 1;
}

message GetDesiredStateResponse {
Expand All @@ -34,16 +25,15 @@ message GetDesiredStateResponse {
repeated VolumeChange volume_changes = 4;

message NewMachine {
reserved 2;
string id = 1;
Kind kind = 3;
Architecture architecture = 4;
string image = 5;
SecurityGroup security_group = 6;
RootVolume root_volume = 7;
optional string user_data = 8;
optional FlyMachineOptions fly_options = 9;
optional string zone = 10;
Kind kind = 2;
Architecture architecture = 3;
string image = 4;
SecurityGroup security_group = 5;
RootVolume root_volume = 6;
optional string user_data = 7;
optional FlyMachineOptions fly_options = 8;
optional string zone = 9;

message FlyMachineOptions {
// Volume to attach to the machine.
Expand All @@ -54,12 +44,11 @@ message GetDesiredStateResponse {
}

message NewVolume {
reserved 2;
string id = 1;
Kind kind = 3;
Architecture architecture = 4;
int32 size = 5;
optional string zone = 6;
Kind kind = 2;
Architecture architecture = 3;
int32 size = 4;
optional string zone = 5;
}

message MachineChange {
Expand Down Expand Up @@ -123,33 +112,25 @@ message GetDesiredStateResponse {
}

message ReplaceVolumeRequest {
string connection_id = 1;
string id = 2;
string id = 1;
}

message ReplaceVolumeResponse {}

message ReportCurrentStateRequest {
string connection_id = 1;
oneof state {
CloudState replace = 2;
}
reserved 3;
string client_id = 4;
CloudState state = 1;
string client_id = 2;
}

message ReportCurrentStateResponse {}

message ReportErrorsRequest {
string connection_id = 1;
repeated string errors = 2;
repeated string errors = 1;
}

message ReportErrorsResponse {}

message GetActiveAgentVersionRequest {
string connection_id = 1;
}
message GetActiveAgentVersionRequest {}

message GetActiveAgentVersionResponse {
string newer_than = 1;
Expand Down
38 changes: 13 additions & 25 deletions src/handlers/state.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {PlainMessage} from '@bufbuild/protobuf'
import {Code, ConnectError} from '@connectrpc/connect'
import {compare} from 'fast-json-patch'
import {GetDesiredStateResponse, ReportCurrentStateRequest} from '../proto/depot/cloud/v2/cloud_pb'
import {GetDesiredStateResponse, ReportCurrentStateRequest} from '../proto/depot/cloud/v4/cloud_pb'
import {CurrentState as AwsCurrentState} from '../types'
import {getCurrentState as getCurrentAwsState, reconcile as reconcileAws} from '../utils/aws'
import {clientID} from '../utils/clientID'
import {sleep} from '../utils/common'
import {CLOUD_AGENT_CONNECTION_ID} from '../utils/env'
import {reportError} from '../utils/errors'
import {
CurrentState as FlyCurrentState,
Expand Down Expand Up @@ -40,11 +39,8 @@ export async function startStateStream<T>(signal: AbortSignal, provider: CloudPr

await provider.reportCurrentState(currentState)

const {response} = await client.getDesiredStateUnary(
{request: {connectionId: CLOUD_AGENT_CONNECTION_ID, clientId: clientID}},
{signal},
)
if (!response || isEmptyResponse(response)) continue
const response = await client.getDesiredState({clientId: clientID}, {signal})
if (isEmptyResponse(response)) continue

currentState = await provider.getCurrentState()

Expand Down Expand Up @@ -74,17 +70,13 @@ function reportAwsState(): (state: AwsCurrentState) => Promise<void> {
let stateCache: StateCache<AwsCurrentState> | null = null
return async function reportCurrentState(currentState: AwsCurrentState) {
const request: PlainMessage<ReportCurrentStateRequest> = {
connectionId: CLOUD_AGENT_CONNECTION_ID,
clientId: clientID,
state: {
case: 'replace',
value: {
state: {
case: 'aws',
value: {
availabilityZone: currentState.availabilityZone,
state: JSON.stringify(currentState),
},
state: {
case: 'aws',
value: {
availabilityZone: currentState.availabilityZone,
state: JSON.stringify(currentState),
},
},
},
Expand All @@ -106,17 +98,13 @@ function reportFlyState(): (state: FlyCurrentState) => Promise<void> {
let stateCache: StateCache<FlyCurrentState> | null = null
return async function reportCurrentState(currentState: FlyCurrentState) {
const request: PlainMessage<ReportCurrentStateRequest> = {
connectionId: CLOUD_AGENT_CONNECTION_ID,
clientId: clientID,
state: {
case: 'replace',
value: {
state: {
case: currentState.cloud,
value: {
region: currentState.region,
state: JSON.stringify(currentState),
},
state: {
case: currentState.cloud,
value: {
region: currentState.region,
state: JSON.stringify(currentState),
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/volumes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ReportVolumeUpdatesRequest,
ResizeVolumeAction,
TrimVolumeAction,
} from '../proto/depot/cloud/v2/cloud_pb'
} from '../proto/depot/cloud/v4/cloud_pb'
import {
authCaps,
authGetKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts,import_extension=none"
// @generated from file depot/cloud/v2/cloud.proto (package depot.cloud.v2, syntax proto3)
// @generated from file depot/cloud/v4/cloud.proto (package depot.cloud.v4, syntax proto3)
/* eslint-disable */
// @ts-nocheck

import {MethodKind} from '@bufbuild/protobuf'
import {
GetActiveAgentVersionRequest,
GetActiveAgentVersionResponse,
GetDesiredStateUnaryRequest,
GetDesiredStateUnaryResponse,
GetDesiredStateRequest,
GetDesiredStateResponse,
ReconcileVolumesRequest,
ReconcileVolumesResponse,
ReplaceVolumeRequest,
Expand All @@ -22,22 +22,22 @@ import {
} from './cloud_pb'

/**
* @generated from service depot.cloud.v2.CloudService
* @generated from service depot.cloud.v4.CloudService
*/
export const CloudService = {
typeName: 'depot.cloud.v2.CloudService',
typeName: 'depot.cloud.v4.CloudService',
methods: {
/**
* @generated from rpc depot.cloud.v2.CloudService.GetDesiredStateUnary
* @generated from rpc depot.cloud.v4.CloudService.GetDesiredState
*/
getDesiredStateUnary: {
name: 'GetDesiredStateUnary',
I: GetDesiredStateUnaryRequest,
O: GetDesiredStateUnaryResponse,
getDesiredState: {
name: 'GetDesiredState',
I: GetDesiredStateRequest,
O: GetDesiredStateResponse,
kind: MethodKind.Unary,
},
/**
* @generated from rpc depot.cloud.v2.CloudService.ReportCurrentState
* @generated from rpc depot.cloud.v4.CloudService.ReportCurrentState
*/
reportCurrentState: {
name: 'ReportCurrentState',
Expand All @@ -46,7 +46,7 @@ export const CloudService = {
kind: MethodKind.Unary,
},
/**
* @generated from rpc depot.cloud.v2.CloudService.ReportErrors
* @generated from rpc depot.cloud.v4.CloudService.ReportErrors
*/
reportErrors: {
name: 'ReportErrors',
Expand All @@ -55,7 +55,7 @@ export const CloudService = {
kind: MethodKind.Unary,
},
/**
* @generated from rpc depot.cloud.v2.CloudService.GetActiveAgentVersion
* @generated from rpc depot.cloud.v4.CloudService.GetActiveAgentVersion
*/
getActiveAgentVersion: {
name: 'GetActiveAgentVersion',
Expand All @@ -64,7 +64,7 @@ export const CloudService = {
kind: MethodKind.Unary,
},
/**
* @generated from rpc depot.cloud.v2.CloudService.ReconcileVolumes
* @generated from rpc depot.cloud.v4.CloudService.ReconcileVolumes
*/
reconcileVolumes: {
name: 'ReconcileVolumes',
Expand All @@ -73,7 +73,7 @@ export const CloudService = {
kind: MethodKind.ServerStreaming,
},
/**
* @generated from rpc depot.cloud.v2.CloudService.ReportVolumeUpdates
* @generated from rpc depot.cloud.v4.CloudService.ReportVolumeUpdates
*/
reportVolumeUpdates: {
name: 'ReportVolumeUpdates',
Expand All @@ -82,7 +82,7 @@ export const CloudService = {
kind: MethodKind.Unary,
},
/**
* @generated from rpc depot.cloud.v2.CloudService.ReplaceVolume
* @generated from rpc depot.cloud.v4.CloudService.ReplaceVolume
*/
replaceVolume: {
name: 'ReplaceVolume',
Expand Down
Loading

0 comments on commit db78fda

Please sign in to comment.