diff --git a/src/functions/helperFunctions.js b/src/functions/helperFunctions.js index 61ef2e3383f60977d6ed88e708142df0ba81b293..456398402c2de52219c9a63cd392ea83b171edac 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 afd312251997aff4d52a5690773e8830da05c92c..c0d86da10254e905f38b86b32780c4f1f6a3edfc 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;