Skip to content

Commit cfb0d46

Browse files
committed
implement
1 parent e4ccbf0 commit cfb0d46

File tree

13 files changed

+1544
-278
lines changed

13 files changed

+1544
-278
lines changed

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ import {
3939
StopWorkspaceRequest,
4040
StopWorkspaceResponse,
4141
AdmissionLevel,
42+
CreateWorkspaceSnapshotRequest,
43+
CreateWorkspaceSnapshotResponse,
44+
ListWorkspaceSnapshotsRequest,
45+
ListWorkspaceSnapshotsResponse,
46+
WaitForWorkspaceSnapshotRequest,
47+
WaitForWorkspaceSnapshotResponse,
4248
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
4349
import { converter } from "./public-api";
4450
import { getGitpodService } from "./service";
@@ -359,4 +365,49 @@ export class JsonRpcWorkspaceClient implements PromiseClient<typeof WorkspaceSer
359365
response.workspaceClasses = list.map((i) => converter.toWorkspaceClass(i));
360366
return response;
361367
}
368+
369+
async createWorkspaceSnapshot(
370+
req: PartialMessage<CreateWorkspaceSnapshotRequest>,
371+
_options?: CallOptions | undefined,
372+
): Promise<CreateWorkspaceSnapshotResponse> {
373+
if (!req.workspaceId) {
374+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "workspaceId is required");
375+
}
376+
const snapshotId = await getGitpodService().server.takeSnapshot({
377+
workspaceId: req.workspaceId,
378+
dontWait: true,
379+
});
380+
return new CreateWorkspaceSnapshotResponse({
381+
snapshot: converter.toWorkspaceSnapshot({
382+
id: snapshotId,
383+
originalWorkspaceId: req.workspaceId,
384+
}),
385+
});
386+
}
387+
388+
async waitForWorkspaceSnapshot(
389+
req: PartialMessage<WaitForWorkspaceSnapshotRequest>,
390+
_options?: CallOptions | undefined,
391+
): Promise<WaitForWorkspaceSnapshotResponse> {
392+
if (!req.snapshotId || !uuidValidate(req.snapshotId)) {
393+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "snapshotId is required");
394+
}
395+
await getGitpodService().server.waitForSnapshot(req.snapshotId);
396+
return new WaitForWorkspaceSnapshotResponse();
397+
}
398+
399+
async listWorkspaceSnapshots(
400+
req: PartialMessage<ListWorkspaceSnapshotsRequest>,
401+
_options?: CallOptions | undefined,
402+
): Promise<ListWorkspaceSnapshotsResponse> {
403+
if (!req.workspaceId) {
404+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "workspaceId is required");
405+
}
406+
const snapshotIdList = await getGitpodService().server.getSnapshots(req.workspaceId);
407+
return new ListWorkspaceSnapshotsResponse({
408+
snapshots: snapshotIdList.map((id) =>
409+
converter.toWorkspaceSnapshot({ id, originalWorkspaceId: req.workspaceId }),
410+
),
411+
});
412+
}
362413
}

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ 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) {}
73+
74+
// ListWorkspaceSnapshots lists the snapshots.
75+
rpc ListWorkspaceSnapshots(ListWorkspaceSnapshotsRequest) returns (ListWorkspaceSnapshotsResponse) {}
6676
}
6777

6878
message GetWorkspaceRequest {
@@ -753,3 +763,48 @@ message WorkspaceClass {
753763
// is_default indicates if this workspace class is the default one
754764
bool is_default = 4;
755765
}
766+
767+
message CreateWorkspaceSnapshotRequest {
768+
// workspace_id specifies the workspace to create snapshot
769+
//
770+
// +required
771+
string workspace_id = 1;
772+
}
773+
774+
message CreateWorkspaceSnapshotResponse {
775+
WorkspaceSnapshot snapshot = 1;
776+
}
777+
778+
message WaitForWorkspaceSnapshotRequest {
779+
// snapshot_id specifies the snapshot to wait for
780+
//
781+
// +required
782+
string snapshot_id = 1;
783+
}
784+
785+
message WaitForWorkspaceSnapshotResponse {}
786+
787+
message ListWorkspaceSnapshotsRequest {
788+
PaginationRequest pagination = 1;
789+
790+
// workspace_id
791+
//
792+
// +required
793+
string workspace_id = 2;
794+
}
795+
796+
message ListWorkspaceSnapshotsResponse {
797+
PaginationResponse pagination = 1;
798+
799+
repeated WorkspaceSnapshot snapshots = 2;
800+
}
801+
802+
message WorkspaceSnapshot {
803+
// id is the unique identifier of the snapshot
804+
string id = 1;
805+
806+
// workspace_id is the source workspace id of snapshot
807+
string workspace_id = 2;
808+
809+
google.protobuf.Timestamp creation_time = 3;
810+
}

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

Lines changed: 74 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: 30 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)