Browse Source

search'

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

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

@ -359,6 +359,7 @@ cors(corsOptions), (req, res, next) => {
RES.start = req.query["start"]
RES.end = req.query["end"]
RES.swarmlabname = req.query["swarmlabname"]
RES.ok = 'ok'
/*
*
* validate
@ -375,7 +376,7 @@ cors(corsOptions), (req, res, next) => {
console.log("Authserver no " + RES.token);
RES.error = 'no'
}
if(RES.error == 'ok'){
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"
@ -389,64 +390,114 @@ cors(corsOptions), (req, res, next) => {
} 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.fromISO(RES.start).toISODate()
var dateend = DateTime.fromISO(RES.end).toISODate()
var datestart = new Date(RES.start)
var dateend = new Date(RES.end)
if(datestart && dateend){
var search_term = { $and: [ { date: { $gt: datestart } }, { date: { $lt: dateend } } ] };
}else if(datestart){
var search_term = { $and: [ { date: { $gt: datestart } } ] };
}else if(dateend){
var search_term = { $and: [ { date: { $lt: dateend } } ] };
}
var resdataarray = []
var resraw = {}
var reslab = ''
db.collection('logs').find(search_term, {}).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]
console.log(JSON.stringify('mongo ----------------connected'))
console.log('-----test------- '+JSON.stringify(RES))
if ((typeof RES.start !== "undefined") && (typeof RES.end !== "undefined")) {
if(DateTime.fromISO(RES.start).isValid){
var datestart = DateTime.fromISO(RES.start)
var dateend = DateTime.fromISO(RES.end)
var search_term = {
"$and": [
{
"time": {
$gte: datestart
}
},
{
"time": {
$lt: dateend
}
},
]
}
}else{
RES.ok = 'no'
}
}else if(typeof RES.end !== "undefined"){
var dateend = DateTime.fromISO(RES.end)
if(DateTime.fromISO(RES.end).isValid){
var search_term = {
"$and": [
{
"time": {
$lt: dateend
}
}
}
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)
}
})()
]
}
}else{
RES.ok = 'no'
}
}else if(typeof RES.start !== "undefined"){
var datestart = DateTime.fromISO(RES.start)
if(DateTime.fromISO(RES.start).isValid){
var search_term = {
"$and": [
{
"time": {
$gte: datestart
}
}
]
}
}else{
RES.ok = 'no'
}
}
if(RES.ok == 'ok'){
//var search_term = '{"$gte": new Date("2020-12-01T00:00:00.000Z") , "$lt": new Date("2020-12-11T16:17:36.470Z") }'
//var search_term = {"time" : {$lte : datenow}}
var resdataarray = []
var resraw = {}
var reslab = ''
var datestart1 = DateTime.fromISO(RES.start)
console.log('-----now1------- '+JSON.stringify(search_term))
console.log('-----now2------- '+JSON.stringify(datestart1))
console.log('-----now3------- '+JSON.stringify(datestart))
db.collection('logs').find(search_term).toArray()
//db.collection('logs').find({"time" : {$gt : datestart}}).toArray()
.then(item => {
console.log('item '+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];
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 = resdataarray
//RES.dataserver = resdataarray
//RES.dataservertmp = resdata
res.json(RES)
})
.catch(err => {
console.error(err)
RES.error_msg = err
res.json(RES)
})
} else{ // RES.ok
RES.error_msg = 'no date'
res.json(RES)
}
} // error mongo connect
}); // mongo connect
}else{ // token error
RES.data = 'no'
RES.error_msg = "token err"
res.json(RES)
}
})()
});

Loading…
Cancel
Save