Skip to content

Commit

Permalink
Merge pull request #61 from camicroscope/develop
Browse files Browse the repository at this point in the history
For 3.8.2
  • Loading branch information
birm authored Nov 10, 2020
2 parents 5473792 + 329b564 commit 2a5be46
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 90 deletions.
2 changes: 2 additions & 0 deletions caracal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fs = require('fs');

// handlers
const auth = require('./handlers/authHandlers.js');
const monitor = require('./handlers/monitorHandlers.js');
const userFunction = require('./handlers/userFunction.js');
const iipHandler = require('./handlers/iipHandler.js');
const proxyHandler = require('./handlers/proxyHandler.js');
Expand Down Expand Up @@ -88,6 +89,7 @@ var HANDLERS = {
"sanitizeBody": function() {
return sanitizeBody;
},
"monitorCheck": monitor.check,
"mongoFind": dataHandlers.General.find,
"mongoAdd": dataHandlers.General.add,
"mongoUpdate": dataHandlers.General.update,
Expand Down
57 changes: 26 additions & 31 deletions handlers/dataHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,41 +386,36 @@ Mark.findMarkTypes = function(req, res, next) {
query['provenance.image.slide'] = query.slide;
delete query.slide;
}
if (query.name) {
query['provenance.analysis.execution_id'] = query.name;
delete query.name;
if (query.type) {
query['provenance.analysis.source'] = query.type;
delete query.type;
}
delete query.token;
const pipeline = [
{
"$match": query,
}, {
"$group": {
"_id": {
"creator": "$creator",
"analysis": "$provenance.analysis",
"shape": "$geometries.features.geometry.type",
},
},
}, {
"$project": {
"_id": 0,
"creator": "$_id.creator",
"source": "$_id.analysis.source",
"execution_id": "$_id.analysis.execution_id",
"name": "$_id.analysis.name",
"type": "$_id.analysis.type",
"isGrid": "$_id.analysis.isGrid",
"shape": {
"$arrayElemAt": ["$_id.shape", 0],

if (query['provenance.analysis.source'] == 'human') {
const pipeline = [
{
"$match": query,
}, {
"$group": {
"_id": {
"creator": "$creator",
"analysis": "$provenance.analysis",
"shape": "$geometries.features.geometry.type",
},
},
},
},
];
mongoAggregate('camic', 'mark', pipeline).then((x) => {
req.data = x;
next();
}).catch((e) => next(e));
];
mongoAggregate('camic', 'mark', pipeline).then((x) => {
req.data = x;
next();
}).catch((e) => next(e));
} else {
mongoDistinct('camic', 'mark', 'provenance.analysis', query).then((x) => {
req.data = x;
next();
}).catch((e) => next(e));
}
};

var Heatmap = {};
Expand Down
29 changes: 29 additions & 0 deletions handlers/monitorHandlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var mongo = require('mongodb');

var MONGO_URI = process.env.MONGO_URI || 'mongodb://localhost';
// handle monitoring checks

let monitor = {};

monitor.check = function(type) {
if (type == "basic") {
return new Promise(function(res, rej) {
let checkMsg = {"status": "up", "checkType": "basic"};
res(checkMsg);
});
}
if (type == "mongo") {
return new Promise(function(res, rej) {
mongo.MongoClient.connect(MONGO_URI, function(err, db) {
if (err) {
rej(err);
} else {
res({"status": "up", "checkType": "mongo"});
}
});
});
}
};


module.exports = monitor;
Loading

0 comments on commit 2a5be46

Please sign in to comment.