Browse Source

add rest

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

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

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

Loading…
Cancel
Save