Skip to content

Commit 57d3dc7

Browse files
committed
tryng to add VolumeSnapshot to DB and protocl
1 parent 1c56a7b commit 57d3dc7

File tree

17 files changed

+226
-49
lines changed

17 files changed

+226
-49
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { PrimaryColumn, Column, Entity, Index } from "typeorm";
8+
9+
import { VolumeSnapshot } from "@gitpod/gitpod-protocol";
10+
import { TypeORM } from "../typeorm";
11+
import { Transformer } from "../transformer";
12+
13+
@Entity()
14+
@Index("ind_dbsync", ["creationTime"]) // DBSync
15+
export class DBVolumeSnapshot implements VolumeSnapshot {
16+
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
17+
id: string;
18+
19+
@Column({
20+
type: "timestamp",
21+
precision: 6,
22+
default: () => "CURRENT_TIMESTAMP(6)",
23+
transformer: Transformer.MAP_ISO_STRING_TO_TIMESTAMP_DROP,
24+
})
25+
creationTime: string;
26+
27+
@Column(TypeORM.WORKSPACE_ID_COLUMN_TYPE)
28+
@Index("ind_originalWorkspaceId")
29+
originalWorkspaceId: string;
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
import { tableExists } from "./helper/helper";
9+
10+
export class VolumeSnapshotCreation1651188368768 implements MigrationInterface {
11+
public async up(queryRunner: QueryRunner): Promise<void> {
12+
await queryRunner.query(
13+
`CREATE TABLE IF NOT EXISTS d_b_volume_snapshot ( id char(36) NOT NULL, creationTime timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), originalWorkspaceId char(36) NOT NULL, PRIMARY KEY (id), KEY ind_originalWorkspaceId (originalWorkspaceId), KEY ind_dbsync (creationTime)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`,
14+
);
15+
}
16+
17+
public async down(queryRunner: QueryRunner): Promise<void> {
18+
if (await tableExists(queryRunner, "d_b_volume_snapshot")) {
19+
await queryRunner.query("DROP TABLE `d_b_volume_snapshot`");
20+
}
21+
}
22+
}

components/gitpod-db/src/typeorm/workspace-db-impl.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
WorkspaceInstanceUser,
2626
WhitelistedRepository,
2727
Snapshot,
28+
VolumeSnapshot,
2829
LayoutData,
2930
PrebuiltWorkspace,
3031
RunningWorkspaceInfo,
@@ -41,6 +42,7 @@ import { DBWorkspace } from "./entity/db-workspace";
4142
import { DBWorkspaceInstance } from "./entity/db-workspace-instance";
4243
import { DBLayoutData } from "./entity/db-layout-data";
4344
import { DBSnapshot } from "./entity/db-snapshot";
45+
import { DBVolumeSnapshot } from "./entity/db-volume-snapshot";
4446
import { DBWorkspaceInstanceUser } from "./entity/db-workspace-instance-user";
4547
import { DBRepositoryWhiteList } from "./entity/db-repository-whitelist";
4648
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
@@ -79,6 +81,10 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
7981
return await (await this.getManager()).getRepository<DBSnapshot>(DBSnapshot);
8082
}
8183

84+
protected async getVolumeSnapshotRepo(): Promise<Repository<DBVolumeSnapshot>> {
85+
return await (await this.getManager()).getRepository<DBVolumeSnapshot>(DBVolumeSnapshot);
86+
}
87+
8288
protected async getPrebuiltWorkspaceRepo(): Promise<Repository<DBPrebuiltWorkspace>> {
8389
return await (await this.getManager()).getRepository<DBPrebuiltWorkspace>(DBPrebuiltWorkspace);
8490
}
@@ -700,6 +706,34 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
700706
return snapshots.find({ where: { originalWorkspaceId: workspaceId } });
701707
}
702708

709+
public async findVolumeSnapshotById(volumeSnapshotId: string): Promise<VolumeSnapshot | undefined> {
710+
const volumeSnapshots = await this.getVolumeSnapshotRepo();
711+
return volumeSnapshots.findOne(volumeSnapshotId);
712+
}
713+
714+
public async storeVolumeSnapshot(volumeSnapshot: VolumeSnapshot): Promise<VolumeSnapshot> {
715+
const volumeSnapshots = await this.getVolumeSnapshotRepo();
716+
const dbVolumeSnapshot = volumeSnapshots as DBVolumeSnapshot;
717+
return await volumeSnapshots.save(dbVolumeSnapshot);
718+
}
719+
720+
public async deleteVolumeSnapshot(volumeSnapshotId: string): Promise<void> {
721+
const volumeSnapshots = await this.getVolumeSnapshotRepo();
722+
await volumeSnapshots.delete(volumeSnapshotId);
723+
}
724+
725+
public async updateVolumeSnapshot(
726+
volumeSnapshot: DeepPartial<VolumeSnapshot> & Pick<VolumeSnapshot, "id">,
727+
): Promise<void> {
728+
const volumeSnapshots = await this.getVolumeSnapshotRepo();
729+
await volumeSnapshots.update(volumeSnapshot.id, volumeSnapshot);
730+
}
731+
732+
public async findVolumeSnapshotsByWorkspaceId(workspaceId: string): Promise<VolumeSnapshot[]> {
733+
const volumeSnapshots = await this.getVolumeSnapshotRepo();
734+
return volumeSnapshots.find({ where: { originalWorkspaceId: workspaceId } });
735+
}
736+
703737
public async storePrebuiltWorkspace(pws: PrebuiltWorkspace): Promise<PrebuiltWorkspace> {
704738
const repo = await this.getPrebuiltWorkspaceRepo();
705739
if (pws.error && pws.error.length > 255) {

components/gitpod-db/src/workspace-db.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
WorkspaceInstanceUser,
1414
WhitelistedRepository,
1515
Snapshot,
16+
VolumeSnapshot,
1617
LayoutData,
1718
PrebuiltWorkspace,
1819
PrebuiltWorkspaceUpdatable,
@@ -159,6 +160,12 @@ export interface WorkspaceDB {
159160
deleteSnapshot(snapshotId: string): Promise<void>;
160161
updateSnapshot(snapshot: DeepPartial<Snapshot> & Pick<Snapshot, "id">): Promise<void>;
161162

163+
findVolumeSnapshotById(volumeSnapshotId: string): Promise<VolumeSnapshot | undefined>;
164+
findVolumeSnapshotsByWorkspaceId(workspaceId: string): Promise<VolumeSnapshot[]>;
165+
storeVolumeSnapshot(snapshot: VolumeSnapshot): Promise<VolumeSnapshot>;
166+
deleteVolumeSnapshot(volumeSnapshotId: string): Promise<void>;
167+
updateVolumeSnapshot(snapshot: DeepPartial<VolumeSnapshot> & Pick<VolumeSnapshot, "id">): Promise<void>;
168+
162169
storePrebuiltWorkspace(pws: PrebuiltWorkspace): Promise<PrebuiltWorkspace>;
163170
findPrebuiltWorkspaceByCommit(cloneURL: string, commit: string): Promise<PrebuiltWorkspace | undefined>;
164171
findPrebuildsWithWorkpace(cloneURL: string): Promise<PrebuildWithWorkspace[]>;

components/gitpod-protocol/src/protocol.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ export interface Snapshot {
441441
message?: string;
442442
}
443443

444+
export interface VolumeSnapshot {
445+
id: string;
446+
creationTime: string;
447+
originalWorkspaceId: string;
448+
}
449+
444450
export type SnapshotState = "pending" | "available" | "error";
445451

446452
export interface LayoutData {

components/ws-manager-api/core.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ message WorkspaceConditions {
370370

371371
// stopped_by_request is true if the workspace was stopped using a StopWorkspace call
372372
WorkspaceConditionBool stopped_by_request = 11;
373+
374+
// pvc_snapshot_volume contains the name of snapshot volume that was used to save persistent volume
375+
string pvc_snapshot_volume = 12;
373376
}
374377

375378
// WorkspaceConditionBool is a trinary bool: true/false/empty

components/ws-manager-api/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/gitpod-io/generated_code_dependencies
22

33
go 1.18
4+
5+
require google.golang.org/protobuf v1.28.0 // indirect

components/ws-manager-api/go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
2+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
3+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
4+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
5+
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
6+
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=

components/ws-manager-api/go/core.pb.go

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

components/ws-manager-api/go/core_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)