From 39b64a4ecd85d54f78ce88627bdbc36954896272 Mon Sep 17 00:00:00 2001 From: william Date: Sun, 14 Feb 2016 11:02:08 -0500 Subject: [PATCH 01/18] timeout --- routes/api.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/routes/api.js b/routes/api.js index 4fb20de..fae6331 100644 --- a/routes/api.js +++ b/routes/api.js @@ -8,7 +8,26 @@ var client = redis.createClient(); var request = require('request'); var lxc = require('../lxc'); + +var timeoutEvents = {}; +var ip2name = {}; + +var lxcTimeout = function(ip, time){ + var name = ip2name[ip]; + console.log(name) + time = time || 100000; + var keys = Object.keys(timeoutEvents) + if(keys.indexOf(name) !== -1){ + clearTimeout(timeoutEvents[name]) + } + timeoutEvents[name] = setTimeout(function(){ + lxc.stop(name); + }, time); +} + + var runner = function(req, res, ip){ + lxcTimeout(ip, 30000); return request.post({url:'http://'+ip, form: req.body}, function(error, response, body){ body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); @@ -113,6 +132,7 @@ router.post('/run/:ip?', function doRun(req, res, next){ }else{ var name = 'u1-'+(Math.random()*100).toString().replace('.',''); return lxc.startEphemeral(name, 'u1', function(data){ + ip2name[data.ip] = name; return runner(req, res, data.ip); }); } From 147d7ab41fcdf76ffa8d3b56fc2fbb67ba7e9cf9 Mon Sep 17 00:00:00 2001 From: william Date: Sun, 14 Feb 2016 11:24:48 -0500 Subject: [PATCH 02/18] timeout --- routes/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/api.js b/routes/api.js index fae6331..fd54287 100644 --- a/routes/api.js +++ b/routes/api.js @@ -21,6 +21,7 @@ var lxcTimeout = function(ip, time){ clearTimeout(timeoutEvents[name]) } timeoutEvents[name] = setTimeout(function(){ + console.log('killing:', name) lxc.stop(name); }, time); } From 57cfc24e926aaa89d425f558387dd9d71824553c Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 12:21:03 -0400 Subject: [PATCH 03/18] crunner --- routes/api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/api.js b/routes/api.js index fd54287..6887d20 100644 --- a/routes/api.js +++ b/routes/api.js @@ -15,7 +15,7 @@ var ip2name = {}; var lxcTimeout = function(ip, time){ var name = ip2name[ip]; console.log(name) - time = time || 100000; + time = time || 900000; // 15 minutes var keys = Object.keys(timeoutEvents) if(keys.indexOf(name) !== -1){ clearTimeout(timeoutEvents[name]) @@ -28,7 +28,7 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ - lxcTimeout(ip, 30000); + lxcTimeout(ip); return request.post({url:'http://'+ip, form: req.body}, function(error, response, body){ body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); @@ -131,8 +131,8 @@ router.post('/run/:ip?', function doRun(req, res, next){ if(found){ return runner(req, res, ip) }else{ - var name = 'u1-'+(Math.random()*100).toString().replace('.',''); - return lxc.startEphemeral(name, 'u1', function(data){ + var name = 'crunner-'+(Math.random()*100).toString().replace('.',''); + return lxc.startEphemeral(name, 'crunner', function(data){ ip2name[data.ip] = name; return runner(req, res, data.ip); }); From b7c8335a82c468d25a198a5745cb3b8db22ef2c5 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 12:32:42 -0400 Subject: [PATCH 04/18] crunner --- routes/api.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/api.js b/routes/api.js index 6887d20..dba9df5 100644 --- a/routes/api.js +++ b/routes/api.js @@ -116,6 +116,8 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function doRun(req, res, next){ // check if server is + console.log(req.body); + return lxc.list(function(data){ if(!req.params.ip) data = []; var ip = '10.0.'+ req.params.ip; From 56cebedf0404f896355c951d825ecc5d758a3ea4 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 12:36:21 -0400 Subject: [PATCH 05/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index dba9df5..db8e308 100644 --- a/routes/api.js +++ b/routes/api.js @@ -116,7 +116,7 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function doRun(req, res, next){ // check if server is - console.log(req.body); + console.log(req); return lxc.list(function(data){ if(!req.params.ip) data = []; From fbc9a308b9f0dd3f2a54a6065b9d1700cc62467b Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 12:55:37 -0400 Subject: [PATCH 06/18] crunner --- routes/api.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/routes/api.js b/routes/api.js index db8e308..02fa6ab 100644 --- a/routes/api.js +++ b/routes/api.js @@ -29,7 +29,7 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ lxcTimeout(ip); - return request.post({url:'http://'+ip, form: req.body}, function(error, response, body){ + return request.post({url:'http://'+ip, body: JSON.stringify({code: req.params.code}) }, function(error, response, body){ body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); return res.json(body); @@ -116,8 +116,6 @@ router.get('/list', function(req, res, next) { router.post('/run/:ip?', function doRun(req, res, next){ // check if server is - console.log(req); - return lxc.list(function(data){ if(!req.params.ip) data = []; var ip = '10.0.'+ req.params.ip; From 96b032f8165d8f92ec10e142544f6e62d7a6be36 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 12:59:52 -0400 Subject: [PATCH 07/18] crunner --- routes/api.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 02fa6ab..24bb334 100644 --- a/routes/api.js +++ b/routes/api.js @@ -29,8 +29,10 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ lxcTimeout(ip); + console.log('runner!!!'); return request.post({url:'http://'+ip, body: JSON.stringify({code: req.params.code}) }, function(error, response, body){ - body = JSON.parse(body); + console.log(body); + // body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); return res.json(body); }); From 491f6c57e84f7683a0cff84286a265f6fbc0d9ab Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 13:00:47 -0400 Subject: [PATCH 08/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 24bb334..8a4ebbe 100644 --- a/routes/api.js +++ b/routes/api.js @@ -29,7 +29,7 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ lxcTimeout(ip); - console.log('runner!!!'); + console.log('code to run:\n', req.params.code); return request.post({url:'http://'+ip, body: JSON.stringify({code: req.params.code}) }, function(error, response, body){ console.log(body); // body = JSON.parse(body); From 3a313a21d1ce06ba09eb3c431e2e350e17501704 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 13:03:04 -0400 Subject: [PATCH 09/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 8a4ebbe..6b5acf3 100644 --- a/routes/api.js +++ b/routes/api.js @@ -29,7 +29,7 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ lxcTimeout(ip); - console.log('code to run:\n', req.params.code); + console.log('code to run:\n', req.params); return request.post({url:'http://'+ip, body: JSON.stringify({code: req.params.code}) }, function(error, response, body){ console.log(body); // body = JSON.parse(body); From 77d8f2b743a4ab8127cbde53daee8ef98e4b4733 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 13:07:45 -0400 Subject: [PATCH 10/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 6b5acf3..3029b7e 100644 --- a/routes/api.js +++ b/routes/api.js @@ -29,7 +29,7 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ lxcTimeout(ip); - console.log('code to run:\n', req.params); + console.log('code to run:\n', req.body); return request.post({url:'http://'+ip, body: JSON.stringify({code: req.params.code}) }, function(error, response, body){ console.log(body); // body = JSON.parse(body); From 2ea36dc963c93dfe4b89356b6b196453d14adf59 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 13:08:46 -0400 Subject: [PATCH 11/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 3029b7e..2074b3a 100644 --- a/routes/api.js +++ b/routes/api.js @@ -30,7 +30,7 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ lxcTimeout(ip); console.log('code to run:\n', req.body); - return request.post({url:'http://'+ip, body: JSON.stringify({code: req.params.code}) }, function(error, response, body){ + return request.post({url:'http://'+ip, body: req.body }, function(error, response, body){ console.log(body); // body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); From c9b66b1bd6637d5d6727ea16bcdd8207102c219b Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 14:39:35 -0400 Subject: [PATCH 12/18] crunner --- routes/api.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routes/api.js b/routes/api.js index 2074b3a..9e4e483 100644 --- a/routes/api.js +++ b/routes/api.js @@ -28,9 +28,10 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ + console.log('ip:', ip); lxcTimeout(ip); - console.log('code to run:\n', req.body); - return request.post({url:'http://'+ip, body: req.body }, function(error, response, body){ + console.log('code to run:\n', req.body.code); + return request.post({url:'http://'+ip, body: {code: req.body.code} }, function(error, response, body){ console.log(body); // body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); From 96c931ba5c5727d4c48ee1a3ccfe36d698e2893c Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 22:50:19 -0400 Subject: [PATCH 13/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 9e4e483..317c6b8 100644 --- a/routes/api.js +++ b/routes/api.js @@ -31,7 +31,7 @@ var runner = function(req, res, ip){ console.log('ip:', ip); lxcTimeout(ip); console.log('code to run:\n', req.body.code); - return request.post({url:'http://'+ip, body: {code: req.body.code} }, function(error, response, body){ + return request.post({url:'http://'+ip, body: JSON.stringify({code: req.body.code}) }, function(error, response, body){ console.log(body); // body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); From 7e2c575a06c5bafd41c8162158a8b4064e68de79 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 22:54:15 -0400 Subject: [PATCH 14/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 317c6b8..82522ee 100644 --- a/routes/api.js +++ b/routes/api.js @@ -32,7 +32,7 @@ var runner = function(req, res, ip){ lxcTimeout(ip); console.log('code to run:\n', req.body.code); return request.post({url:'http://'+ip, body: JSON.stringify({code: req.body.code}) }, function(error, response, body){ - console.log(body); + console.log(response); // body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); return res.json(body); From 1dce0358cc822cf371355cc4ceebce62bc26aba8 Mon Sep 17 00:00:00 2001 From: william Date: Fri, 22 Apr 2016 22:56:47 -0400 Subject: [PATCH 15/18] crunner --- routes/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 82522ee..696152e 100644 --- a/routes/api.js +++ b/routes/api.js @@ -32,7 +32,7 @@ var runner = function(req, res, ip){ lxcTimeout(ip); console.log('code to run:\n', req.body.code); return request.post({url:'http://'+ip, body: JSON.stringify({code: req.body.code}) }, function(error, response, body){ - console.log(response); + console.log('arguments:\n', arguments); // body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); return res.json(body); From 299040be6fb65a6df6fdf4156b7b3409676a148b Mon Sep 17 00:00:00 2001 From: william Date: Mon, 25 Apr 2016 12:52:00 -0400 Subject: [PATCH 16/18] crunner --- routes/api.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routes/api.js b/routes/api.js index 696152e..4029cca 100644 --- a/routes/api.js +++ b/routes/api.js @@ -14,7 +14,7 @@ var ip2name = {}; var lxcTimeout = function(ip, time){ var name = ip2name[ip]; - console.log(name) + console.log(name); time = time || 900000; // 15 minutes var keys = Object.keys(timeoutEvents) if(keys.indexOf(name) !== -1){ @@ -30,8 +30,13 @@ var lxcTimeout = function(ip, time){ var runner = function(req, res, ip){ console.log('ip:', ip); lxcTimeout(ip); - console.log('code to run:\n', req.body.code); - return request.post({url:'http://'+ip, body: JSON.stringify({code: req.body.code}) }, function(error, response, body){ + console.log('code to run:', '\n'+req.body.code); + return request.post({ + url: 'http://'+ip+':15000', + body: JSON.stringify({ + code: req.body.code + }) + }, function(error, response, body){ console.log('arguments:\n', arguments); // body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); From 5c914145213df1410e9e6c12ae2d7c6334bae131 Mon Sep 17 00:00:00 2001 From: william Date: Mon, 25 Apr 2016 13:32:16 -0400 Subject: [PATCH 17/18] crunner --- routes/api.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/routes/api.js b/routes/api.js index 4029cca..0e68e1b 100644 --- a/routes/api.js +++ b/routes/api.js @@ -14,7 +14,7 @@ var ip2name = {}; var lxcTimeout = function(ip, time){ var name = ip2name[ip]; - console.log(name); + console.log(name) time = time || 900000; // 15 minutes var keys = Object.keys(timeoutEvents) if(keys.indexOf(name) !== -1){ @@ -31,14 +31,17 @@ var runner = function(req, res, ip){ console.log('ip:', ip); lxcTimeout(ip); console.log('code to run:', '\n'+req.body.code); - return request.post({ - url: 'http://'+ip+':15000', + + var httpOptions = { + url:'http://' + ip + ':15000', body: JSON.stringify({ code: req.body.code }) - }, function(error, response, body){ - console.log('arguments:\n', arguments); - // body = JSON.parse(body); + }; + + return request.post(httpOptions, function(error, response, body){ + console.log('body:\n', body); + body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); return res.json(body); }); From 049972b2787df973d67bf7e6a54fc8c57afe6787 Mon Sep 17 00:00:00 2001 From: william Date: Mon, 25 Apr 2016 13:39:38 -0400 Subject: [PATCH 18/18] crunner is a go! --- routes/api.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/routes/api.js b/routes/api.js index 0e68e1b..f01df4d 100644 --- a/routes/api.js +++ b/routes/api.js @@ -21,16 +21,13 @@ var lxcTimeout = function(ip, time){ clearTimeout(timeoutEvents[name]) } timeoutEvents[name] = setTimeout(function(){ - console.log('killing:', name) lxc.stop(name); }, time); } var runner = function(req, res, ip){ - console.log('ip:', ip); lxcTimeout(ip); - console.log('code to run:', '\n'+req.body.code); var httpOptions = { url:'http://' + ip + ':15000', @@ -40,7 +37,6 @@ var runner = function(req, res, ip){ }; return request.post(httpOptions, function(error, response, body){ - console.log('body:\n', body); body = JSON.parse(body); body['ip'] = ip.replace('10.0.', ''); return res.json(body); @@ -63,7 +59,6 @@ var addToRedis = function(){ router.get('/start/:name', function(req, res, next){ return lxc.start(req.params.name, function(data){ - console.log('start', arguments); if(!data){ return res.json({status: 500, name: req.params.name, message: data}); }else{