From a139c55f109ecc3629cd814c5e19d0be28b4c482 Mon Sep 17 00:00:00 2001 From: Robin Leber <rleber98@gmail.com> Date: Wed, 12 Jun 2024 17:00:10 +0200 Subject: [PATCH] Scaling Anzeige --- src/functions/helperFunctions.js | 25 +++++++++++++++++++++++++ src/routes/deployRouter.js | 11 +++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/functions/helperFunctions.js b/src/functions/helperFunctions.js index 61ef2e3..4563984 100644 --- a/src/functions/helperFunctions.js +++ b/src/functions/helperFunctions.js @@ -222,6 +222,30 @@ const scaleOut = async (id) => { } }; +const scalingCounter = async () => { + const customCodes = await getCustomCodes(); + + const idCounts = {}; + + customCodes.forEach((code) => { + if (code.id !== undefined) { + if (!idCounts[code.id] && code.isScaled === "") { + idCounts[code.id] = 0; + idCounts[code.id]++; + } + if (code.isScaled !== "") { + idCounts[code.isScaled]++; + } + } + }); + + const result = Object.keys(idCounts).map((id) => { + return { id: id, count: idCounts[id] }; + }); + + return result; +}; + module.exports = { emptyDockerJS, fillDockerJS, @@ -233,4 +257,5 @@ module.exports = { stopArchitecture, restartArchitecture, scaleOut, + scalingCounter, }; diff --git a/src/routes/deployRouter.js b/src/routes/deployRouter.js index afd3122..c0d86da 100644 --- a/src/routes/deployRouter.js +++ b/src/routes/deployRouter.js @@ -5,6 +5,7 @@ const { restartArchitecture, clearArchitecture, scaleOut, + scalingCounter, } = require("../functions/helperFunctions"); const deployRouter = express.Router(); @@ -60,4 +61,14 @@ deployRouter.post("/scaleOut", async (req, res) => { } }); +deployRouter.get("/scaleValues", async (req, res) => { + try { + const result = await scalingCounter(); + res.status(200).json({ result, message: "Scale Values erfolgreich" }); + } catch (e) { + console.error(e); + res.status(500).json({ message: "Scale Values fehlgeschlagen" }); + } +}); + module.exports = deployRouter; -- GitLab