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.start = req.query["start"]
RES.end = req.query["end"] RES.end = req.query["end"]
RES.swarmlabname = req.query["swarmlabname"] RES.swarmlabname = req.query["swarmlabname"]
RES.ok = 'ok'
/* /*
* *
* validate * validate
@ -375,7 +376,7 @@ 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"
@ -389,64 +390,114 @@ cors(corsOptions), (req, res, next) => {
} 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 console.log(JSON.stringify('mongo ----------------connected'))
//usersession.SOCKET.token = isvalid.token console.log('-----test------- '+JSON.stringify(RES))
//db.collection('log', onCollection); if ((typeof RES.start !== "undefined") && (typeof RES.end !== "undefined")) {
console.log(JSON.stringify('mongo connected')) if(DateTime.fromISO(RES.start).isValid){
var datestart = DateTime.fromISO(RES.start).toISODate() var datestart = DateTime.fromISO(RES.start)
var dateend = DateTime.fromISO(RES.end).toISODate() var dateend = DateTime.fromISO(RES.end)
var datestart = new Date(RES.start) var search_term = {
var dateend = new Date(RES.end) "$and": [
if(datestart && dateend){ {
var search_term = { $and: [ { date: { $gt: datestart } }, { date: { $lt: dateend } } ] }; "time": {
}else if(datestart){ $gte: datestart
var search_term = { $and: [ { date: { $gt: datestart } } ] }; }
}else if(dateend){ },
var search_term = { $and: [ { date: { $lt: dateend } } ] }; {
} "time": {
var resdataarray = [] $lt: dateend
var resraw = {} }
var reslab = '' },
db.collection('logs').find(search_term, {}).toArray() ]
.then(item => { }
for (let i in item) { }else{
reslab = item[i].tailed_path RES.ok = 'no'
var segment_array = reslab.split( '/' ); }
var last_segment = segment_array.pop(); }else if(typeof RES.end !== "undefined"){
var fieldstmp = last_segment.split('-'); var dateend = DateTime.fromISO(RES.end)
var nameofswarmlab = fieldstmp[0]; if(DateTime.fromISO(RES.end).isValid){
var search_term = {
var regexlog = new RegExp(nameofswarmlab); "$and": [
for (let ii in resdata.data) { {
if( regexlog.test(resdata.data[ii].res25swarmlabname) ){ "time": {
resdataarray.push(item[i]) $lt: dateend
RES.found = item[i]
} }
}
} }
]
RES.error_msg = "ok" }
RES.data = resdataarray }else{
//RES.dataserver = resdataarray RES.ok = 'no'
//RES.dataservertmp = resdata }
res.json(RES) }else if(typeof RES.start !== "undefined"){
}) var datestart = DateTime.fromISO(RES.start)
.catch(err => { if(DateTime.fromISO(RES.start).isValid){
console.error(err) var search_term = {
RES.error_msg = err "$and": [
res.json(RES) {
}) "time": {
} $gte: datestart
}); }
}else{ }
]
RES.data = 'no' }
RES.error_msg = "token err" }else{
res.json(RES) 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