Browse Source

add rest

master
zeus 4 years ago
parent
commit
f71ac9535f
  1. 131
      swarmlab-app/src/run/app.js

131
swarmlab-app/src/run/app.js

@ -375,86 +375,67 @@ cors(corsOptions), (req, res, next) => {
console.log("Authserver no " + RES.token);
RES.error = 'no'
}
if(RES.error == 'ok'){
var resdata = await getuserpipelines(RES.token,isvalid.user,RES.swarmlabname)
var mongourl = "mongodb://"+CONFIG.mongo.user+":"+CONFIG.mongo.password+"@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1&authSource=swarmlabplaygroundstats"
const OPTS = {
useNewUrlParser: true,
useUnifiedTopology: true
};
MongoClient.connect(mongourl, OPTS, function(err, client){
if(err){
console.log(err);
} else {
const db = client.db('fluent');
//usersession.SOCKET.user = isvalid.user
//usersession.SOCKET.scope = isvalid.scope // space delimeter
//usersession.SOCKET.token = isvalid.token
//db.collection('log', onCollection);
console.log(JSON.stringify('mongo connected'))
var datestart = DateTime.fromObject(RES.start).toISODate()
var dateend = DateTime.fromObject(RES.end).toISODate()
var search_term = { $and: [ { date: { $gt: datestart } }, { date: { $lt: dateend } } ] };
var resdataarray = []
var resraw = {}
var reslab = ''
db.collection('logs').find({}, {}).toArray()
.then(item => {
console.log('cccccccccccccccccccccccc '+item)
console.log(' vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv '+ JSON.stringify(item))
for (let i in item) {
reslab = item[i].tailed_path
var segment_array = reslab.split( '/' );
var last_segment = segment_array.pop();
var fieldstmp = last_segment.split('-');
var nameofswarmlab = fieldstmp[0];
console.log('------------------- ' + item[i].tailed_path)
console.log('-----++++++++++++++++++++++++--- ' + nameofswarmlab)
//if( resdata.data.filter(item1 => item1.res25swarmlabname.includes(nameofswarmlab)).length > 0 ){
var regexlog = new RegExp(nameofswarmlab);
//const res = data.filter(item => item.Date.indexOf(filterKey) === 0);
for (let ii in resdata.data) {
console.log(')))))))))))))))))))))))))))))))))))))))))) '+resdata.data[ii].res25swarmlabname)
if( regexlog.test(resdata.data[ii].res25swarmlabname) ){
console.log('-----oooooooooooooooooooooo--- ' + JSON.stringify(item[i]))
resdataarray.push(item[i])
RES.found = item[i]
}else{
console.log('-----<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<--- ' + nameofswarmlab)
if(RES.error == 'ok'){
var resdata = await getuserpipelines(RES.token,isvalid.user,RES.swarmlabname)
var mongourl = "mongodb://"+CONFIG.mongo.user+":"+CONFIG.mongo.password+"@ondemand_playground_mongo1:27017,ondemand_playground_mongo2:27017,ondemand_playground_mongo3:27017,ondemand_playground_mongo4:27017,ondemand_playground_mongo5:27017,ondemand_playground_mongo6:27017,ondemand_playground_mongo7:27017/fluent?replicaSet=rs1&authSource=swarmlabplaygroundstats"
const OPTS = {
useNewUrlParser: true,
useUnifiedTopology: true
};
MongoClient.connect(mongourl, OPTS, function(err, client){
if(err){
console.log(err);
} else {
const db = client.db('fluent');
//usersession.SOCKET.user = isvalid.user
//usersession.SOCKET.scope = isvalid.scope // space delimeter
//usersession.SOCKET.token = isvalid.token
//db.collection('log', onCollection);
console.log(JSON.stringify('mongo connected'))
var datestart = DateTime.fromObject(RES.start).toISODate()
var dateend = DateTime.fromObject(RES.end).toISODate()
var search_term = { $and: [ { date: { $gt: datestart } }, { date: { $lt: dateend } } ] };
var resdataarray = []
var resraw = {}
var reslab = ''
db.collection('logs').find({}, {}).toArray()
.then(item => {
for (let i in item) {
reslab = item[i].tailed_path
var segment_array = reslab.split( '/' );
var last_segment = segment_array.pop();
var fieldstmp = last_segment.split('-');
var nameofswarmlab = fieldstmp[0];
var regexlog = new RegExp(nameofswarmlab);
for (let ii in resdata.data) {
if( regexlog.test(resdata.data[ii].res25swarmlabname) ){
resdataarray.push(item[i])
RES.found = item[i]
}
}
}
}
RES.error_msg = "ok"
RES.data = item
RES.dataserver = resdataarray
RES.dataservertmp = resdata
res.json(RES)
})
.catch(err => {
console.error(err)
RES.error_msg = err
res.json(RES)
})
//stream.on('data', function (doc) {
// console.log(JSON.stringify(doc))
//socket.write(JSON.stringify({'action': 'log','param': doc.log}));
//});
}
RES.error_msg = "ok"
RES.data = resdataarray
//RES.dataserver = resdataarray
//RES.dataservertmp = resdata
res.json(RES)
})
.catch(err => {
console.error(err)
RES.error_msg = err
res.json(RES)
})
}
});
}else{
RES.data = 'no'
RES.error_msg = "token err"
res.json(RES)
RES.data = 'no'
RES.error_msg = "token err"
res.json(RES)
}

Loading…
Cancel
Save