Fixed issue where slaves would not register when ran on VM withou MAC

This commit is contained in:
Danielv123 committed 2018-04-30 23:05:55 +02:00
1 parent 47430b5d28
commit 968a306c5a
2 files changed
+11 -3

No files matched your search

+3 -3
View File
@@ -619,9 +619,10 @@ function instanceManagement() {
function callback(err, mac) { function callback(err, mac) {
if (err) { if (err) {
mac = "unknown";
console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####"); console.log("##### getMac crashed, but we don't really give a shit because we are probably closing down #####");
} else { }
payload.mac = mac payload.mac = mac;
console.log("Registered our precense with master "+config.masterIP+" at " + payload.time); console.log("Registered our precense with master "+config.masterIP+" at " + payload.time);
needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) { needle.post(config.masterIP + ":" + config.masterPort + '/api/getID', payload, needleOptionsWithTokenAuthHeader, function (err, response, body) {
if (err && err.code != "ECONNRESET"){ if (err && err.code != "ECONNRESET"){
@@ -633,7 +634,6 @@ function instanceManagement() {
} }
}); });
} }
}
if(global.mac){ if(global.mac){
callback(undefined, global.mac); callback(undefined, global.mac);
} else { } else {
+8
View File
@@ -291,6 +291,8 @@ POST Get metadata from a single slave. For whenever you find the data returned b
@alias /api/getSlaveMeta @alias /api/getSlaveMeta
*/ */
app.post("/api/getSlaveMeta", function (req, res) { app.post("/api/getSlaveMeta", function (req, res) {
endpointHitCounter.labels(req.route.path).inc();
let reqStartTime = Date.now();
console.log("body", req.body); console.log("body", req.body);
if(req.body && req.body.instanceID && req.body.password){ if(req.body && req.body.instanceID && req.body.password){
console.log("returning meta for ", req.body.instanceID); console.log("returning meta for ", req.body.instanceID);
@@ -299,6 +301,7 @@ app.post("/api/getSlaveMeta", function (req, res) {
res.status(400); res.status(400);
res.send('{"INVALID REQUEST":1}'); res.send('{"INVALID REQUEST":1}');
} }
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
}); });
// mod management // mod management
// should handle uploading and checking if mods are uploaded // should handle uploading and checking if mods are uploaded
@@ -786,6 +789,8 @@ Requires x-access-token header to be set. Find you api token in secret-api-token
@returns {object} Status {auth: bool, message: "Informative error", data:{}} @returns {object} Status {auth: bool, message: "Informative error", data:{}}
*/ */
app.post("/api/runCommand", (req,res) => { app.post("/api/runCommand", (req,res) => {
endpointHitCounter.labels(req.route.path).inc();
let reqStartTime = Date.now();
var token = req.headers['x-access-token']; var token = req.headers['x-access-token'];
if(!token) return res.status(401).send({ auth: false, message: 'No token provided.' }); if(!token) return res.status(401).send({ auth: false, message: 'No token provided.' });
@@ -808,6 +813,7 @@ app.post("/api/runCommand", (req,res) => {
wsSlaves[instanceID].runCommand(body.command); wsSlaves[instanceID].runCommand(body.command);
} }
res.status(200).send({auth: true, message: "success", response: "Cluster wide messaging initiated"}); res.status(200).send({auth: true, message: "success", response: "Cluster wide messaging initiated"});
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
} else if ( } else if (
body.instanceID body.instanceID
&& wsSlaves[body.instanceID] && wsSlaves[body.instanceID]
@@ -818,9 +824,11 @@ app.post("/api/runCommand", (req,res) => {
// execute command // execute command
wsSlaves[body.instanceID].runCommand(body.command, data => { wsSlaves[body.instanceID].runCommand(body.command, data => {
res.status(200).send({auth: true, message: "success", data}); res.status(200).send({auth: true, message: "success", data});
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
}); });
} else { } else {
res.status(400).send({auth: true, message: "Error: invalid request.body"}); res.status(400).send({auth: true, message: "Error: invalid request.body"});
httpRequestDurationMilliseconds.labels(req.route.path).observe(Date.now()-reqStartTime);
} }
}); });
}); });