Skip to content

Commit c984e91

Browse files
Merge pull request #320 from kthcloud/main
Finish resource migration, minor improvements, bug fixes
2 parents 14f164b + d294b40 commit c984e91

File tree

21 files changed

+436
-343
lines changed

21 files changed

+436
-343
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ console uses these services for its functionality.
2121
kthcloud maintained:
2222

2323
- [go-deploy](https://github.com/kthcloud/go-deploy): Backend for creation, and management of resources
24-
- [sys-api](https://github.com/kthcloud/sys-api): Provides stats and capacities
2524
- [alert](https://alert.app.cloud.cbh.kth.se/): Provides alerts
2625
- [llama](https://llama.app.cloud.cbh.kth.se/): Enables genAI features
2726
- [llama-prefetch](https://github.com/kthcloud/llama-prefetch/): Reduces genAI features latency by prefetching queries
@@ -31,7 +30,6 @@ External:
3130

3231
- [Gravatar](https://gravatar.com): Provides user avatars
3332
- [Google Fonts](https://fonts.google.com): Provides fonts
34-
- [GitHub SSO](https://github.com): Enables linking GitHub repos for continuous delivery
3533

3634
## Setup
3735

bun.lockb

12.7 KB
Binary file not shown.

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
"@emotion/react": "^11.11.4",
1616
"@emotion/styled": "^11.11.5",
1717
"@iconify/react": "^4.1.1",
18-
"@kthcloud/go-deploy-types": "^1.0.17",
19-
"@mui/icons-material": "^5.15.19",
18+
"@kthcloud/go-deploy-types": "^1.0.20",
19+
"@mui/icons-material": "^5.15.20",
2020
"@mui/lab": "^5.0.0-alpha.170",
21-
"@mui/material": "^5.15.19",
21+
"@mui/material": "^5.15.20",
2222
"@mui/material-next": "^6.0.0-alpha.126",
23-
"@mui/x-tree-view": "^7.6.1",
23+
"@mui/x-tree-view": "^7.7.0",
2424
"@react-keycloak/web": "^3.4.0",
25-
"@react-three/fiber": "^8.16.7",
25+
"@react-three/fiber": "^8.16.8",
2626
"@sanity/eventsource": "^5.0.2",
2727
"@types/crypto-js": "^4.2.2",
2828
"@types/numeral": "^2.0.5",
@@ -49,28 +49,28 @@
4949
"react-helmet-async": "^2.0.5",
5050
"react-i18next": "^14.1.2",
5151
"react-router-dom": "^6.23.1",
52-
"simplebar": "^6.2.6",
53-
"simplebar-react": "^3.2.5",
52+
"simplebar": "^6.2.7",
53+
"simplebar-react": "^3.2.6",
5454
"three": "^0.164.1",
5555
"three-stdlib": "^2.30.3",
56-
"yaml": "^2.4.3"
56+
"yaml": "^2.4.5"
5757
},
5858
"devDependencies": {
5959
"@faker-js/faker": "^8.4.1",
6060
"@types/react": "^18.3.3",
6161
"@types/react-copy-to-clipboard": "^5.0.7",
6262
"@types/react-dom": "^18.3.0",
63-
"@typescript-eslint/eslint-plugin": "^7.12.0",
64-
"@typescript-eslint/parser": "^7.12.0",
65-
"@vitejs/plugin-react": "^4.3.0",
63+
"@typescript-eslint/eslint-plugin": "^7.13.0",
64+
"@typescript-eslint/parser": "^7.13.0",
65+
"@vitejs/plugin-react": "^4.3.1",
6666
"@vitejs/plugin-react-swc": "^3.7.0",
6767
"eslint": "^9.4.0",
6868
"eslint-plugin-react": "^7.34.2",
6969
"eslint-plugin-react-hooks": "^4.6.2",
7070
"eslint-plugin-react-refresh": "^0.4.7",
71-
"prettier": "^3.3.0",
71+
"prettier": "^3.3.2",
7272
"prettier-plugin-nginx": "^1.0.3",
7373
"typescript": "^5.4.5",
74-
"vite": "^5.2.12"
74+
"vite": "^5.3.0"
7575
}
7676
}

src/api/deploy/deployments.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,3 @@ export const applyCommand = async (id: string, command: any, token: string) => {
167167
}
168168
return true;
169169
};
170-
171-
export const acceptDeploymentTransfer = async (
172-
token: any,
173-
id: any,
174-
code: any
175-
) => {
176-
const url = `${import.meta.env.VITE_DEPLOY_API_URL}/deployments/${id}`;
177-
const body = { transferCode: code };
178-
179-
const response = await fetch(url, {
180-
method: "POST",
181-
headers: {
182-
Authorization: `Bearer ${token}`,
183-
"Content-Type": "application/json",
184-
},
185-
body: JSON.stringify(body),
186-
});
187-
188-
const result = await response.json();
189-
return result;
190-
};

src/api/deploy/resourceMigrations.ts

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { ResourceMigrationCreate } from "@kthcloud/go-deploy-types/types/v2/body";
1+
import {
2+
ResourceMigrationCreate,
3+
ResourceMigrationUpdate,
4+
} from "@kthcloud/go-deploy-types/types/v2/body";
25
import { Jwt } from "../../types";
36

47
export const createResourceMigration = async (
@@ -20,3 +23,68 @@ export const createResourceMigration = async (
2023
}
2124
return result;
2225
};
26+
27+
export const getMigration = async (token: Jwt, id: string) => {
28+
const url = `${import.meta.env.VITE_DEPLOY_API_URL}/resourceMigrations/${id}`;
29+
const response = await fetch(url, {
30+
headers: {
31+
Authorization: `Bearer ${token}`,
32+
},
33+
});
34+
const result = await response.json();
35+
if (!response.ok) {
36+
throw result;
37+
}
38+
return result;
39+
};
40+
41+
export const listMigrations = async (token: Jwt) => {
42+
const url = `${import.meta.env.VITE_DEPLOY_API_URL}/resourceMigrations`;
43+
const response = await fetch(url, {
44+
headers: {
45+
Authorization: `Bearer ${token}`,
46+
},
47+
});
48+
const result = await response.json();
49+
if (!response.ok) {
50+
throw result;
51+
}
52+
return result;
53+
};
54+
55+
export const deleteMigration = async (token: Jwt, id: string) => {
56+
const url = `${import.meta.env.VITE_DEPLOY_API_URL}/resourceMigrations/${id}`;
57+
const response = await fetch(url, {
58+
method: "DELETE",
59+
headers: {
60+
Authorization: `Bearer ${token}`,
61+
},
62+
});
63+
const result = await response.json();
64+
if (!response.ok) {
65+
throw result;
66+
}
67+
return result;
68+
};
69+
70+
export const acceptMigration = async (token: Jwt, id: string, code: string) => {
71+
const body: ResourceMigrationUpdate = {
72+
status: "accepted",
73+
code: code,
74+
};
75+
76+
const url = `${import.meta.env.VITE_DEPLOY_API_URL}/resourceMigrations/${id}`;
77+
const response = await fetch(url, {
78+
method: "POST",
79+
headers: {
80+
"Content-Type": "application/json",
81+
Authorization: `Bearer ${token}`,
82+
},
83+
body: JSON.stringify(body),
84+
});
85+
const result = await response.json();
86+
if (!response.ok) {
87+
throw result;
88+
}
89+
return result;
90+
};

src/api/deploy/users.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ApiKeyCreated,
33
UserRead,
4+
UserReadDiscovery,
45
UserUpdate,
56
} from "@kthcloud/go-deploy-types/types/v2/body";
67
import { Jwt, Uuid } from "../../types";
@@ -128,3 +129,27 @@ export const createApiKey = async (
128129
}
129130
return await res.json();
130131
};
132+
133+
export const discoverUserById = async (
134+
userId: string,
135+
token: string
136+
): Promise<UserReadDiscovery> => {
137+
const res = await fetch(
138+
import.meta.env.VITE_DEPLOY_API_URL + "/users/" + userId + "?discover=true",
139+
{
140+
method: "GET",
141+
headers: {
142+
Authorization: "Bearer " + token,
143+
},
144+
}
145+
);
146+
147+
if (!res.ok) {
148+
const body = await res.json();
149+
if (body) {
150+
throw body;
151+
}
152+
throw res;
153+
}
154+
return await res.json();
155+
};

src/api/sys/index.ts

Whitespace-only changes.

src/contexts/ResourceContext.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getVMById, listVMs } from "../api/deploy/vms";
1616

1717
import {
1818
NotificationRead as Notification,
19+
ResourceMigrationRead,
1920
TeamRead as Team,
2021
ZoneRead as Zone,
2122
} from "@kthcloud/go-deploy-types/types/v2/body/index";
@@ -26,6 +27,7 @@ import {
2627
} from "@kthcloud/go-deploy-types/types/v2/body";
2728
import { listGpuGroups } from "../api/deploy/gpuGroups";
2829
import { listGpuLeases } from "../api/deploy/gpuLeases";
30+
import { listMigrations } from "../api/deploy/resourceMigrations";
2931

3032
type ResourceContextType = {
3133
rows: Resource[];
@@ -50,6 +52,8 @@ type ResourceContextType = {
5052
setGpuGroups: (gpuGroups: GpuGroupRead[]) => void;
5153
gpuLeases: GpuLeaseRead[];
5254
setGpuLeases: (gpuLeases: GpuLeaseRead[]) => void;
55+
resourceMigrations: ResourceMigrationRead[];
56+
setResourceMigrations: (resourceMigrations: ResourceMigrationRead[]) => void;
5357
queueJob: (job: Job) => void;
5458
beginFastLoad: () => void;
5559
initialLoad: boolean;
@@ -83,6 +87,8 @@ const initialState: ResourceContextType = {
8387
setGpuGroups: () => {},
8488
gpuLeases: new Array<GpuLeaseRead>(),
8589
setGpuLeases: () => {},
90+
resourceMigrations: new Array<ResourceMigrationRead>(),
91+
setResourceMigrations: () => {},
8692
queueJob: () => {},
8793
initialLoad: false,
8894
setInitialLoad: () => {},
@@ -118,6 +124,9 @@ export const ResourceContextProvider = ({
118124
const [zones, setZones] = useState<Zone[]>([]);
119125
const [gpuGroups, setGpuGroups] = useState<GpuGroupRead[]>([]);
120126
const [gpuLeases, setGpuLeases] = useState<GpuLeaseRead[]>([]);
127+
const [resourceMigrations, setResourceMigrations] = useState<
128+
ResourceMigrationRead[]
129+
>([]);
121130

122131
// Loading and connection error handler
123132
const [initialLoad, setInitialLoad] = useState<boolean>(false);
@@ -244,6 +253,20 @@ export const ResourceContextProvider = ({
244253
}
245254
};
246255

256+
const loadResourceMigrations = async () => {
257+
if (!(initialized && keycloak.authenticated && keycloak.token)) return;
258+
try {
259+
const migrations = await listMigrations(keycloak.token);
260+
setResourceMigrations(migrations);
261+
} catch (error: any) {
262+
errorHandler(error).forEach((e) =>
263+
enqueueSnackbar("Error fetching migrations: " + e, {
264+
variant: "error",
265+
})
266+
);
267+
}
268+
};
269+
247270
const loadNotifications = async () => {
248271
if (!(initialized && keycloak.authenticated && keycloak.token)) return;
249272
try {
@@ -368,6 +391,7 @@ export const ResourceContextProvider = ({
368391
loadZones();
369392
loadGpuGroups();
370393
loadGpuLeases();
394+
loadResourceMigrations();
371395

372396
// eslint-disable-next-line
373397
}, [user]);
@@ -416,6 +440,8 @@ export const ResourceContextProvider = ({
416440
setGpuGroups,
417441
gpuLeases,
418442
setGpuLeases,
443+
resourceMigrations,
444+
setResourceMigrations,
419445
queueJob,
420446
beginFastLoad,
421447
initialLoad,

src/locales/en.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"error-creating-vm": "Error creating VM",
2626
"error-all-fields": "Please fill all fields",
2727
"resource-deployments": "Deployments",
28-
"resource-kubernetes-deployment": "Kubernetes deployment",
29-
"resource-vms": "Virtual machines",
30-
"resource-vm": "Virtual machine",
28+
"deployment": "Deployment",
29+
"vms": "Virtual machines",
30+
"vm": "Virtual machine",
3131
"resource-gpus": "GPUs",
3232
"resource-gpu": "GPU",
3333
"resource-users": "Users",
@@ -531,6 +531,9 @@
531531
"not-permitted-to-gpu-page": "Cannot access GPU page: Not allowed to use GPUs",
532532
"nothing-to-do": "Nothing to do",
533533
"image-tag": "Image tag",
534-
"too-many-run-args": "Too many run args, max 100"
534+
"too-many-run-args": "Too many run args, max 100",
535+
"pending-migrations": "Pending migrations",
536+
"migration": "Migration",
537+
"of": "of"
535538
}
536539
}

src/locales/se.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"menu-label": "Meny",
2121
"create-deployment-app-path-label": "Filsökväg i appen",
2222
"create-deployment-github-title": "Koppla GitHub projekt",
23-
"resource-vm": "Virtuell maskin",
23+
"vm": "Virtuell maskin",
2424
"login-with-github": "Logga in med GitHub",
2525
"admin-name-call-to-action": "Proxy kommer att ha namnet: ",
2626
"gpu-drivers-3": " för att installera senaste drivrutinerna.",
@@ -263,7 +263,7 @@
263263
"admin-leased-until": "Lånat till",
264264
"specs-subheader": "Ändra storlek utifrån dina behov",
265265
"onboarding-deployments": "Resurstyp: Deployments",
266-
"resource-kubernetes-deployment": "Kubernetes deployment",
266+
"deployment": "Deployment",
267267
"tcp-first": "Exponera en TCP port först",
268268
"gpu-lease": "Låna grafikkort",
269269
"admin-user": "Användare",
@@ -288,7 +288,7 @@
288288
"take-me-back": "Ta mig hem",
289289
"admin-status": "Status",
290290
"revert": "Återgå",
291-
"resource-vms": "Virtuella maskiner",
291+
"vms": "Virtuella maskiner",
292292
"create-deployment-env-key": "Variabel",
293293
"error-all-fields": "Fyll i alla fält",
294294
"create-vm-minimum-disk-size": "Minst diskutrymme",
@@ -530,6 +530,9 @@
530530
"run-args": "Argument till körning",
531531
"nothing-to-do": "Inget att göra",
532532
"image-tag": "Image tagg",
533-
"too-many-run-args": "För många argument, max 100"
533+
"too-many-run-args": "För många argument, max 100",
534+
"pending-migrations": "Pågående överföringar",
535+
"migration": "Överföring",
536+
"of": "av"
534537
}
535538
}

0 commit comments

Comments
 (0)