From 09100405b5801199642526541fa9f3aa375f00b1 Mon Sep 17 00:00:00 2001 From: Anas Osman Date: Wed, 25 Aug 2021 15:07:20 +0300 Subject: [PATCH] fix: synched queries of start/stop and GPU list --- package-lock.json | 4 ++-- package.json | 2 +- src/app.controller.js | 4 ++-- src/app.js | 36 +++++++++++++++++++++--------------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd8e0e6..ef24627 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "server-management", - "version": "1.0.0", + "version": "1.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -804,4 +804,4 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index a042698..14dfffa 100644 --- a/package.json +++ b/package.json @@ -19,4 +19,4 @@ "open": "^7.2.1" }, "devDependencies": {} -} \ No newline at end of file +} diff --git a/src/app.controller.js b/src/app.controller.js index 1fe4945..8920ab5 100644 --- a/src/app.controller.js +++ b/src/app.controller.js @@ -135,11 +135,10 @@ module.exports = { } }); }, - stContainer: function(containerName, gpu) { + stContainer: function(containerName, gpu, callback) { commandName = editName(containerName); model.getContainer(containerName, gpu, function(query) { if (query) { - console.log(query); if (query.isOnline) { cmd("docker stop " + commandName); model.setContainerOff(containerName, gpu); @@ -150,6 +149,7 @@ module.exports = { console.log("docker start " + commandName); } } + return callback("Done"); }); } }; diff --git a/src/app.js b/src/app.js index 1001527..b8d3866 100644 --- a/src/app.js +++ b/src/app.js @@ -83,22 +83,27 @@ app.get('/signout', function(req, res) { }); app.post("/auth", function(req, res) { - req.session.currGPU = String(ip.address()); controller.containersJSON(function(wsInfo) { req.session.GPUs = wsInfo["gpu_address"].filter((x, i) => i === wsInfo["gpu_address"].indexOf(x)); - }); - console.log(req.session.currGPU); - req.session.username = req.body.username; - var password = req.body.password; - controller.auth(req.session.username, password, function(loggedin) { - req.session.wrongUserPass = loggedin.wrongUserPass; - req.session.adminLoggedIn = loggedin.adminLoggedIn; - req.session.loggedin = !req.session.wrongUserPass; - if (req.session.loggedin) { - res.redirect("/sysInfo"); - } else { - res.redirect("/"); + if (req.session.GPUs) { + req.session.currGPU = req.session.GPUs[0]; } + else { + req.session.currGPU = String(ip.address()); + } + console.log(req.session.currGPU); + req.session.username = req.body.username; + var password = req.body.password; + controller.auth(req.session.username, password, function(loggedin) { + req.session.wrongUserPass = loggedin.wrongUserPass; + req.session.adminLoggedIn = loggedin.adminLoggedIn; + req.session.loggedin = !req.session.wrongUserPass; + if (req.session.loggedin) { + res.redirect("/sysInfo"); + } else { + res.redirect("/"); + } + }); }); }); @@ -138,7 +143,8 @@ app.post("/deleteWorkspace", function(req, res) { app.post("/stWorkspace", function(req, res) { var containerToSt = req.body.workspaceName; - controller.stContainer(containerToSt, String(ip.address())); - res.redirect("/workspaces/" + req.session.currGPU); + controller.stContainer(containerToSt, String(ip.address()), function(done) { + res.redirect("/workspaces/" + req.session.currGPU); + }); }); app.listen(3000);