From 35e9b59290236f6ecee5b9007805be10b049af18 Mon Sep 17 00:00:00 2001 From: zeus Date: Fri, 27 Nov 2020 19:26:44 +0200 Subject: [PATCH] nginx --- .../nginx/swarmlab-stats-proxy-server.conf | 6 +- swarmlab-app/src/run/app.js | 173 +++++++++++------- 2 files changed, 110 insertions(+), 69 deletions(-) diff --git a/swarmlab-app/nginx/swarmlab-stats-proxy-server.conf b/swarmlab-app/nginx/swarmlab-stats-proxy-server.conf index f6404cb..9314363 100644 --- a/swarmlab-app/nginx/swarmlab-stats-proxy-server.conf +++ b/swarmlab-app/nginx/swarmlab-stats-proxy-server.conf @@ -1,7 +1,9 @@ upstream factory_servers { - server 127.0.0.1:3000; - keepalive 64; ip_hash; + #server 127.0.0.1:3000; + server readmongo:3000; + keepalive 64; + #ip_hash; } proxy_cache_path /var/tmp levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; diff --git a/swarmlab-app/src/run/app.js b/swarmlab-app/src/run/app.js index 46e9ee1..8a477fe 100755 --- a/swarmlab-app/src/run/app.js +++ b/swarmlab-app/src/run/app.js @@ -4,7 +4,27 @@ var pathmodule = require('path'); var app = require('express')(); var http = require('http').Server(app); var https = require('https'); -var io = require('socket.io')(http); +const io = require("socket.io")(http, { +// pingTimeout: 30000, +// allowUpgrades: false, +// serveClient: false, +// pingInterval: 10000, +// //transports: [ 'websocket', 'polling' ], +// transports: [ 'polling', 'websocket' ], + cors: { + origin: "http://localhost:8080", + methods: ["GET", "POST"], + allowedHeaders: ["my-custom-header"], + credentials: true + }, + cookie: { + name: "test", + httpOnly: false, + path: "/custom" + } +}); + + //import { createAdapter } from 'socket.io-redis'; const createAdapter = require('socket.io-redis'); @@ -20,6 +40,7 @@ const subClient = pubClient.duplicate(); io.adapter(createAdapter({ pubClient, subClient })); + pubClient.on("connect", function() { console.log("You are now connected"); }); @@ -393,7 +414,6 @@ cors(corsOptions), (req, res, next) => { // socket // *************************************************** -io.origins('*:*') // for latest version function onCollection(err, collection) { @@ -408,78 +428,87 @@ function onCollection(err, collection) { var reslog = new Object(); var now = new Date(); cursor.on('data', function (data) { - console.log('+++++++++ondata<<<<<<<<<<<<<<<<<<<<<<' + data); - io.in('anagnostopoulos@uniwa.gr').emit("logdata", data); + //io.in('anagnostopoulos@uniwa.gr').emit("logdata", data); - var pathfileval = pathmodule.basename(data.tailed_path); - var arrfile = pathfileval.toString().split("-"); - var pathfile = arrfile[0]; + console.log('++++++++' + JSON.stringify(data)); - var indexupdate = true - var resob = {} - //var indexfind1 = global.pipelines.findIndex(x => x.pathlogfile==pathfileval); + var pathfileval = pathmodule.basename(data.tailed_path); + var arrfile = pathfileval.toString().split("-"); + var pathfile = arrfile[0]; + + var indexupdate = "yes" + var resob = {} + //var indexfind1 = global.pipelines.findIndex(x => x.pathlogfile==pathfileval); pubClient.get(pathfileval, function(err, object) { - if(object){ - indexupdate = false - }else{ - console.log('redis '+JSON.stringify(object)); - } - }); - if (indexupdate ){ - (async() => { - var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto - var resdata = await getpipelines(token,pathfile) - resob.pathlogfile = pathfileval - var resobarray = [] - var resob1 = {} - var i = 0 - resob1.data = resdata.data[i].res25swarmlabname - resob1.user25user = resdata.data[i].res25user - resob1.res25creator = resdata.data[i].res25creator - resob1.res25fileforce = resdata.data[i].res25fileforce - resob1.tailed_path = pathfileval - //resobarray.push(resob1) - var resob1string = JSON.stringify(resob1); - console.log('+++++++++++++++++' + resob1string + '<<<<<<<<<<<<<<<<<<<<<<' + pathfileval); - pubClient.set(pathfileval, resob1string, function(err, res) { - }); - reslog.data = resob1 - reslog.log = data - reslog.date = convertDateToUTC(now) - var user = resob1.res25creator - console.log('datauser ' + JSON.stringify(user)); - //io.in(user).emit("logdata", reslog); - var user = 'anagnostopoulos@uniwa.gr' - io.in(user).emit("logdata", reslog); - itemsProcessed++; - })() - }else{ + console.log('----------------' + err + '<<<<<<<<<<<<<<<<<<<<<<' + object); + if(object){ + indexupdate = "no" + }else{ + console.log('redis '+JSON.stringify(object)); + } + console.log('update '+JSON.stringify(indexupdate)); + if (indexupdate == "yes" ){ + (async() => { + var token = "d2539e5a7ae1f9f1b0eb2b8f22ca467a86d28407"; // desto + var resdata = await getpipelines(token,pathfile) + resob.pathlogfile = pathfileval + var resobarray = [] + var resob1 = {} + var i = 0 + resob1.data = resdata.data[i].res25swarmlabname + resob1.user25user = resdata.data[i].res25user + resob1.res25creator = resdata.data[i].res25creator + resob1.res25fileforce = resdata.data[i].res25fileforce + resob1.tailed_path = pathfileval + var resob1string = JSON.stringify(resob1); + pubClient.set(pathfileval, resob1string, function(err, res) { + }); + reslog.data = resob1 + reslog.log = data + reslog.date = convertDateToUTC(now) + var user = resob1.res25creator + console.log('datauser ' + JSON.stringify(user)); + console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(reslog)); + io.in(user).emit("logdata", reslog); + itemsProcessed++; + })() + }else{ + + pubClient.get(pathfileval, function(err, object) { + var objecttmp = JSON.parse(object); + var resob1 = {} + resob1.data = objecttmp.res25swarmlabname + resob1.user25user = objecttmp.res25user + resob1.res25creator = objecttmp.res25creator + resob1.res25fileforce = objecttmp.res25fileforce + resob1.tailed_path = objecttmp.tailed_path + + reslog.data = resob1 + reslog.log = data + reslog.date = convertDateToUTC(now) + + console.log('<<<<<<<<<<<---------------------<<<<<<<<<<<<<<<---------------------------<<<<<<<<<<<< '+JSON.stringify(object)); + console.log('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< '+JSON.stringify(reslog)); + var user = objecttmp.user25user + //io.join(user); + //io.to(user).emit(reslog); + + //console.log("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRr", JSON.stringify(io.sockets.adapter.rooms)); // Set { } + + io.in(user).emit("logdata", reslog); + itemsProcessed++; + }); + } + }); - pubClient.get(pathfileval, function(err, object) { - var resob1 = {} - var i = 0 - resob1.data = object.res25swarmlabname - resob1.user25user = object.res25user - resob1.res25creator = object.res25creator - resob1.res25fileforce = object.res25fileforce - resob1.tailed_path = object.tailed_path - - reslog.data = resob1 - reslog.log = data - reslog.date = convertDateToUTC(now) - - console.log('>>>>>>>>>>2222222222222>>>>>>>>>>>>>>>>>>>>>>>>>>>>> '+JSON.stringify(object)); - var user = object.user25user - io.in(user).emit("logdata", reslog); - itemsProcessed++; - }); - } }); setInterval(function () { console.log('itemsProcessed', itemsProcessed); - }, 1000); +// this method is also exposed by the Server instance + //console.log(adapter.rooms); + }, 8000); } @@ -506,6 +535,11 @@ function onCollection(err, collection) { io.on('connection', s => { console.error('socket connection'); +//s.set('transports', ['websocket']); +//s.set('pingTimeout', 30000); +//s.set('allowUpgrades', false); +//s.set('serveClient', false); +//s.set('pingInterval', 10000); // ------------------------------ // --- set // ------------------------------ @@ -515,6 +549,8 @@ io.on('connection', s => { console.error('socket ...'); s.auth = false; + s.join('test'); + console.log('test' + ' created ') // ------------------------------ // --- authenticate // ------------------------------ @@ -525,6 +561,8 @@ io.on('connection', s => { var isvalid = await checkToken(token); if(isvalid.action == 'ok'){ console.log("Authserver ok ", s.id + ' - ' + token); + // pubClient.set(session, resob1string, function(err, res) { + // }); usersession.SOCKET.user = isvalid.user usersession.SOCKET.scope = isvalid.scope // space delimeter usersession.SOCKET.token = isvalid.token @@ -539,12 +577,13 @@ io.on('connection', s => { setTimeout(function(){ if (!s.auth) { console.log("Disconnecting timeout socket ", s.id); - s.disconnect('unauthorized'); + //s.disconnect('unauthorized'); }else{ var room = usersession.SOCKET.user //s.on("subscribe", function (room) { - // console.log("joining room", room); s.join(room); + console.log("joining rooom", s.rooms); + console.log(room + ' created ') // }); } }, 30000);