From 3fc9b57216886c46f7de9cc24afaf31adce48e4d Mon Sep 17 00:00:00 2001 From: Joe Meyer Date: Sat, 27 Jul 2024 17:39:20 -0500 Subject: [PATCH] snake_case all the props --- scripts/http/assignments.rest | 6 +++--- scripts/http/computers.rest | 11 +++++++---- scripts/http/gpus.rest | 8 ++++---- src/controllers/assignments.ts | 22 +++++++++++----------- src/controllers/computer.ts | 8 ++++---- src/controllers/gpu.ts | 12 ++++++------ src/services/edge.ts | 2 +- src/services/tables/gpus.ts | 20 ++++++++++---------- src/services/tables/types.ts | 2 +- 9 files changed, 47 insertions(+), 44 deletions(-) diff --git a/scripts/http/assignments.rest b/scripts/http/assignments.rest index bd04a3b..d45664e 100644 --- a/scripts/http/assignments.rest +++ b/scripts/http/assignments.rest @@ -10,9 +10,9 @@ Content-Type: application/json { "name": "New Assignment", - "modelName": "Model1", + "model_name": "Model1", "maestroPort": 8080, - "gpuIds": [1, 2] + "gpu_ids": [1, 2] } ### Delete an assignment @@ -29,5 +29,5 @@ Content-Type: application/json "name": "Updated Assignment", "modelName": "Model2", "maestroPort": 8081, - "gpuIds": [2, 3] + "gpu_ids": [2, 3] } diff --git a/scripts/http/computers.rest b/scripts/http/computers.rest index 1d281c6..fc40b46 100644 --- a/scripts/http/computers.rest +++ b/scripts/http/computers.rest @@ -17,10 +17,13 @@ Content-Type: application/json DELETE {{baseMaestroUrl}}:{{maestroPort}}/api/computers/ ### Update an computer -PUT {{baseMaestroUrl}}:{{maestroPort}}/api/computers/ +PUT {{baseMaestroUrl}}:{{maestroPort}}/api/computers/1 Content-Type: application/json { - "name": "Updated Computer", - "ipAddr": "0.0.0.1" -} + "id": 1, + "name": "3090 Cluster - 1", + "ip_addr": "192.168.1.32", + "edge_server_port": 4000, + "display_order": 1 + } diff --git a/scripts/http/gpus.rest b/scripts/http/gpus.rest index 65531d5..7a300c7 100644 --- a/scripts/http/gpus.rest +++ b/scripts/http/gpus.rest @@ -10,8 +10,8 @@ Content-Type: application/json { "name": "New GPU", - "vramSize": 4, - "computerId": 123, + "vram_size": 4, + "computer_id": 123, "weight": 1 } @@ -24,7 +24,7 @@ Content-Type: application/json { "name": "Updated GPU", - "vramSize": 4.3, - "computerId": 123, + "vram_size": 4.3, + "computer_id": 123, "weight": 15 } diff --git a/src/controllers/assignments.ts b/src/controllers/assignments.ts index aa62937..91d5d97 100644 --- a/src/controllers/assignments.ts +++ b/src/controllers/assignments.ts @@ -15,10 +15,10 @@ export const getAllAssignments = async (_req: Request, res: Response) => { const assignmentGpusForAssignment = assignmentGpus.filter( ({ assignment_id }) => assignment_id === assignment.id ); - const gpuIds = assignmentGpusForAssignment.map(({ gpu_id }) => gpu_id); + const gpu_ids = assignmentGpusForAssignment.map(({ gpu_id }) => gpu_id); return { ...assignment, - gpuIds: gpuIds, + gpu_ids: gpu_ids, }; }); @@ -33,11 +33,11 @@ export const getAssignmentById = async (req: Request, res: Response) => { }; export const createAssignment = async (req: Request, res: Response) => { - const { name, modelName, port, gpuIds, display_order } = req.body as { + const { name, modelName, port, gpu_ids, display_order } = req.body as { name: string; modelName: string; port: number; - gpuIds: number[]; + gpu_ids: number[]; display_order: number; }; const assignmentId = await AssignmentService.createAssignment( @@ -47,7 +47,7 @@ export const createAssignment = async (req: Request, res: Response) => { display_order ); await Promise.all( - gpuIds.map((gpuId) => + gpu_ids.map((gpuId) => AssignmentGpuService.createDBAssignmentGPU(assignmentId, gpuId) ) ); @@ -64,11 +64,11 @@ export const deleteAssignment = async (req: Request, res: Response) => { export const updateAssignment = async (req: Request, res: Response) => { const { id } = req.params; - const { name, modelName, port, gpuIds, display_order } = req.body as { + const { name, modelName, port, gpu_ids, display_order } = req.body as { name: string; modelName: string; port: number; - gpuIds: number[]; + gpu_ids: number[]; display_order: number; }; const idAsNumber = Number(id); @@ -87,7 +87,7 @@ export const updateAssignment = async (req: Request, res: Response) => { // Now look to see which assignment gpus we need to delete/create await Promise.all( - gpuIds + gpu_ids .map((gpuId) => { if (!currentAssignmentGpus.find((ag) => ag.gpu_id === gpuId)) { return AssignmentGpuService.createDBAssignmentGPU(idAsNumber, gpuId); @@ -96,7 +96,7 @@ export const updateAssignment = async (req: Request, res: Response) => { .concat( currentAssignmentGpus .map((ag) => { - if (!gpuIds.find((gpuId) => ag.gpu_id === gpuId)) { + if (!gpu_ids.find((gpuId) => ag.gpu_id === gpuId)) { return AssignmentGpuService.deleteAssignmentGpu( idAsNumber, ag.gpu_id @@ -128,7 +128,7 @@ export const deployAssignments = async (req: Request, res: Response) => { const makeAndLoadContainerPromises: Promise[] = []; assignments.forEach((assignment) => { const ipAddr = computers.find(({ id }) => { - return id === gpus[0].computerId; + return id === gpus[0].computer_id; })?.ip_addr; const isDiffusionModel = diffusors.some( ({ name }) => name === assignment.model_name @@ -139,7 +139,7 @@ export const deployAssignments = async (req: Request, res: Response) => { await EdgeServerService.makeContainer(ipAddr, { containerName: assignment.name, port: String(assignment.port), - gpuIds: assignmentGpus + gpu_ids: assignmentGpus .filter(({ assignment_id }) => assignment.id === assignment_id) .map(({ gpu_id }) => gpu_id), diffusionModel: isDiffusionModel diff --git a/src/controllers/computer.ts b/src/controllers/computer.ts index b3e1fd1..3ed6d46 100644 --- a/src/controllers/computer.ts +++ b/src/controllers/computer.ts @@ -14,8 +14,8 @@ export const getComputerById = async (req: Request, res: Response) => { }; export const createComputer = async (req: Request, res: Response) => { - const { name, ipAddr, display_order } = req.body; - const id = await ComputerService.createComputer(name, ipAddr, display_order); + const { name, ip_addr, display_order } = req.body; + const id = await ComputerService.createComputer(name, ip_addr, display_order); res.json({ id }); }; @@ -26,11 +26,11 @@ export const deleteComputer = async (req: Request, res: Response) => { }; export const updateComputer = async (req: Request, res: Response) => { - const { id, name, ipAddr, display_order } = req.body; + const { id, name, ip_addr, display_order } = req.body; const affectedRows = await ComputerService.updateComputer( id, name, - ipAddr, + ip_addr, display_order ); res.json({ affectedRows }); diff --git a/src/controllers/gpu.ts b/src/controllers/gpu.ts index bb7052c..b55433b 100644 --- a/src/controllers/gpu.ts +++ b/src/controllers/gpu.ts @@ -15,11 +15,11 @@ export const getGpuById = async (req: Request, res: Response) => { }; export const createGPU = async (req: Request, res: Response) => { - const { name, vramSize, computerId, weight, display_order } = req.body; + const { name, vram_size, computer_id, weight, display_order } = req.body; const id = await GpuService.createGPU( name, - vramSize, - computerId, + vram_size, + computer_id, display_order, weight ); @@ -34,12 +34,12 @@ export const deleteGPU = async (req: Request, res: Response) => { export const updateGPU = async (req: Request, res: Response) => { const { id } = req.params; - const { name, vramSize, computerId, weight, display_order } = req.body; + const { name, vram_size, computer_id, weight, display_order } = req.body; await GpuService.updateGPU( Number(id), name, - vramSize, - computerId, + vram_size, + computer_id, display_order, weight ); diff --git a/src/services/edge.ts b/src/services/edge.ts index cf097f9..3f522f7 100644 --- a/src/services/edge.ts +++ b/src/services/edge.ts @@ -1,7 +1,7 @@ interface MakeContainerProps { containerName: string; port: string; - gpuIds: number[]; + gpu_ids: number[]; diffusionModel?: string; // 'sdxl-turbo' or 'sd-turbo' } diff --git a/src/services/tables/gpus.ts b/src/services/tables/gpus.ts index b9cc27a..b86d47a 100644 --- a/src/services/tables/gpus.ts +++ b/src/services/tables/gpus.ts @@ -3,16 +3,16 @@ import { pool } from '../db'; interface GPU { id: number; name: string; - vramSize: number; - computerId: number; + vram_size: number; + computer_id: number; weight?: number; } // Create a new GPU export const createGPU = async ( name: string, - vramSize: number, - computerId: number, + vram_size: number, + computer_id: number, display_order: number, weight?: number ): Promise => { @@ -20,8 +20,8 @@ export const createGPU = async ( 'INSERT INTO gpus (name, vram_size, computer_id, weight, display_order) VALUES (?, ?, ?, ?)'; const result = await pool.query(query, [ name, - vramSize, - computerId, + vram_size, + computer_id, weight || null, display_order, ]); @@ -50,8 +50,8 @@ export const getGPUById = async (id: number): Promise => { export const updateGPU = async ( id: number, name: string, - vramSize: number, - computerId: number, + vram_size: number, + computer_id: number, display_order: number, weight?: number ): Promise => { @@ -59,8 +59,8 @@ export const updateGPU = async ( 'UPDATE gpus SET name = ?, vram_size = ?, computer_id = ?, weight = ?, display_order = ? WHERE id = ?'; const result = await pool.query(query, [ name, - vramSize, - computerId, + vram_size, + computer_id, weight || null, display_order, id, diff --git a/src/services/tables/types.ts b/src/services/tables/types.ts index 245fab7..3e2d4a9 100644 --- a/src/services/tables/types.ts +++ b/src/services/tables/types.ts @@ -38,7 +38,7 @@ export interface Assignment { id: number; name: string; model_name: string; - gpuIds: number[]; + gpu_ids: number[]; port: number; display_order: number; }