Skip to content

Commit bb2473e

Browse files
authored
Migrate WorkspaceService snapshot methods (#19204)
* Migrate WorkspaceService snapshot methods * Add test cases * Remove list snapshots
1 parent ba07eb9 commit bb2473e

18 files changed

+1185
-279
lines changed

components/dashboard/src/service/json-rpc-workspace-client.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ import {
3939
StopWorkspaceRequest,
4040
StopWorkspaceResponse,
4141
AdmissionLevel,
42+
CreateWorkspaceSnapshotRequest,
43+
CreateWorkspaceSnapshotResponse,
44+
WaitForWorkspaceSnapshotRequest,
45+
WaitForWorkspaceSnapshotResponse,
4246
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
4347
import { converter } from "./public-api";
4448
import { getGitpodService } from "./service";
@@ -359,4 +363,34 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
359363
response.workspaceClasses = list.map((i) => converter.toWorkspaceClass(i));
360364
return response;
361365
}
366+
367+
async createWorkspaceSnapshot(
368+
req: PartialMessage<CreateWorkspaceSnapshotRequest>,
369+
_options?: CallOptions | undefined,
370+
): Promise<CreateWorkspaceSnapshotResponse> {
371+
if (!req.workspaceId) {
372+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "workspaceId is required");
373+
}
374+
const snapshotId = await getGitpodService().server.takeSnapshot({
375+
workspaceId: req.workspaceId,
376+
dontWait: true,
377+
});
378+
return new CreateWorkspaceSnapshotResponse({
379+
snapshot: converter.toWorkspaceSnapshot({
380+
id: snapshotId,
381+
originalWorkspaceId: req.workspaceId,
382+
}),
383+
});
384+
}
385+
386+
async waitForWorkspaceSnapshot(
387+
req: PartialMessage<WaitForWorkspaceSnapshotRequest>,
388+
_options?: CallOptions | undefined,
389+
): Promise<WaitForWorkspaceSnapshotResponse> {
390+
if (!req.snapshotId || !uuidValidate(req.snapshotId)) {
391+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "snapshotId is required");
392+
}
393+
await getGitpodService().server.waitForSnapshot(req.snapshotId);
394+
return new WaitForWorkspaceSnapshotResponse();
395+
}
362396
}

components/public-api/gitpod/v1/workspace.proto

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ service WorkspaceService {
6363
// GetWorkspaceEditorCredentials returns an credentials that is used in editor
6464
// to encrypt and decrypt secrets
6565
rpc GetWorkspaceEditorCredentials(GetWorkspaceEditorCredentialsRequest) returns (GetWorkspaceEditorCredentialsResponse) {}
66+
67+
// CreateWorkspaceSnapshot creates a snapshot of the workspace that can be
68+
// shared with others.
69+
rpc CreateWorkspaceSnapshot(CreateWorkspaceSnapshotRequest) returns (CreateWorkspaceSnapshotResponse) {}
70+
71+
// WaitWorkspaceSnapshot waits for the snapshot to be available or failed.
72+
rpc WaitForWorkspaceSnapshot(WaitForWorkspaceSnapshotRequest) returns (WaitForWorkspaceSnapshotResponse) {}
6673
}
6774

6875
message GetWorkspaceRequest {
@@ -753,3 +760,33 @@ message WorkspaceClass {
753760
// is_default indicates if this workspace class is the default one
754761
bool is_default = 4;
755762
}
763+
764+
message CreateWorkspaceSnapshotRequest {
765+
// workspace_id specifies the workspace to create snapshot
766+
//
767+
// +required
768+
string workspace_id = 1;
769+
}
770+
771+
message CreateWorkspaceSnapshotResponse {
772+
WorkspaceSnapshot snapshot = 1;
773+
}
774+
775+
message WaitForWorkspaceSnapshotRequest {
776+
// snapshot_id specifies the snapshot to wait for
777+
//
778+
// +required
779+
string snapshot_id = 1;
780+
}
781+
782+
message WaitForWorkspaceSnapshotResponse {}
783+
784+
message WorkspaceSnapshot {
785+
// id is the unique identifier of the snapshot
786+
string id = 1;
787+
788+
// workspace_id is the source workspace id of snapshot
789+
string workspace_id = 2;
790+
791+
google.protobuf.Timestamp creation_time = 3;
792+
}

components/public-api/go/v1/v1connect/workspace.connect.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/public-api/go/v1/v1connect/workspace.proxy.connect.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)