diff --git a/src/functions/helperFunctions.js b/src/functions/helperFunctions.js index 4e5b0b61a1ce7af22169fbbbf14d51d910de3282..725031851b4ea4b55994ce0a02aab8ffd1633c44 100644 --- a/src/functions/helperFunctions.js +++ b/src/functions/helperFunctions.js @@ -194,6 +194,29 @@ const clearArchitecture = async () => { } }; +const scaleOut = async (id) => { + try { + const dataFilePath = path.resolve( + __dirname, + "../../customCodeDatabase.json" + ); + const customCodes = await getCustomCodes(); + const codeToScale = customCodes.find((code) => code.id === id); + const scaledCode = JSON.parse(JSON.stringify(codeToScale)); + scaledCode.isScaled = true; + scaledCode.id; + customCodes.push(scaledCode); + await fs.writeFile( + dataFilePath, + JSON.stringify(customCodes, null, 2), + "utf8" + ); + } catch (err) { + console.error(err); + throw err; + } +}; + module.exports = { emptyDockerJS, fillDockerJS, @@ -204,4 +227,5 @@ module.exports = { clearArchitecture, stopArchitecture, restartArchitecture, + scaleOut, }; diff --git a/src/routes/deployRouter.js b/src/routes/deployRouter.js index 2f34cb62a31c51747d418676f9530845d7ca2e4f..d6a151604d84fb0f4c8ecc9ed11c10bcbbd4cb53 100644 --- a/src/routes/deployRouter.js +++ b/src/routes/deployRouter.js @@ -4,6 +4,7 @@ const { stopArchitecture, restartArchitecture, clearArchitecture, + scaleOut, } = require("../functions/helperFunctions"); const deployRouter = express.Router(); @@ -38,7 +39,7 @@ deployRouter.post("/restart", async (req, res) => { } }); -deployRouter.get("/clearArchitecture", async (rey, res) => { +deployRouter.get("/clearArchitecture", async (req, res) => { try { await clearArchitecture(); res.status(200).json({ message: "Docker leeren erfoglreich" }); @@ -48,4 +49,15 @@ deployRouter.get("/clearArchitecture", async (rey, res) => { } }); +deployRouter.post("/scaleOut", async (req, res) => { + try { + const { codeId } = req.body; + await scaleOut(codeId); + res.status(200).json({ message: "Scale Out erfolgreich" }); + } catch (e) { + console.error(e); + res.status(500).json({ message: "Scale Out fehlgeschlagen" }); + } +}); + module.exports = deployRouter;