Skip to content

Commit 50afcb0

Browse files
author
Soichi Hayashi
committed
added taskevent api
removed resource reporting moved package.json under /api
1 parent 796074e commit 50afcb0

File tree

12 files changed

+559
-382
lines changed

12 files changed

+559
-382
lines changed

Dockerfile

Lines changed: 0 additions & 27 deletions
This file was deleted.

api/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:16
2+
3+
MAINTAINER Soichi Hayashi <[email protected]>
4+
5+
WORKDIR /app
6+
7+
COPY controllers .
8+
COPY resource_test.sh .
9+
COPY *.js ./
10+
11+
COPY package.json .
12+
COPY package-lock.json .
13+
14+
RUN npm install --production
15+
CMD [ "node", "server.js" ]

api/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker build -t brainlife/amaretti-api:1.0 .

api/controllers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ router.use('/instance', require('./instance'));
5555
router.use('/resource', require('./resource'));
5656
router.use('/event', require('./event'));
5757
router.use('/admin', require('./admin'));
58+
router.use('/taskevent', require('./taskevent'));
5859

5960
//TODO DEPRECATED (currently used by th /wf/#!/resources UI)
6061
//use (get) /resource/type instead

api/controllers/taskevent.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
const express = require('express');
4+
const router = express.Router();
5+
const async = require('async');
6+
const mongoose = require('mongoose');
7+
const path = require('path');
8+
const mime = require('mime');
9+
const multer = require('multer');
10+
const fs = require('fs');
11+
12+
const config = require('../../config');
13+
const db = require('../models');
14+
const events = require('../events');
15+
const common = require('../common');
16+
17+
/**
18+
* @apiGroup Taskevent
19+
* @api {get} /taskevent/:taskid
20+
Query Task events
21+
* @apiDescription Returns all task status update events for a given task id
22+
*
23+
* @apiHeader {String} authorization A valid JWT token "Bearer: xxxxx"
24+
*
25+
* @apiSuccess {Object} List of taskevents
26+
*/
27+
router.get('/:taskId', common.jwt(), function(req, res, next) {
28+
let find = {task_id: req.params.taskId};
29+
30+
//access control
31+
if(!req.user.scopes.amaretti || !~req.user.scopes.amaretti.indexOf("admin")) {
32+
find['$or'] = [
33+
{user_id: req.user.sub},
34+
{_group_id: {$in: req.user.gids||[]}},
35+
];
36+
}
37+
38+
//if(req.query.select) console.log("select:"+req.query.select);
39+
db.Taskevent.find(find)
40+
.lean()
41+
.sort('date')
42+
.exec(function(err, taskevents) {
43+
if(err) return next(err);
44+
res.json({taskevents});
45+
});
46+
});
47+
48+
module.exports = router;
49+

api/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ function publish_or_log(ex, key, msg, cb) {
9090
}
9191
}
9292

93-
//deprecate this
9493
exports.task = function(task) {
9594

9695
//get previous task status to see if status changed
@@ -113,7 +112,7 @@ exports.task = function(task) {
113112
});
114113
taskevent.save();
115114
}
116-
115+
117116
//some fields are populated (foreign keys are de-referenced)
118117
//to normalize the field type, let's load the record from database
119118
//TODO - can't I just test to see if _id exists for those field and replace them with it?
@@ -151,3 +150,4 @@ exports.publish = (key, message, cb)=>{
151150
message.timestamp = (new Date().getTime())/1000; //it's crazy that amqp doesn't set this?
152151
publish_or_log(amaretti_ex, key, message, cb);
153152
}
153+

api/health.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const logger = winston.createLogger(config.logger.winston);
77
const db = require('./models');
88
const common = require('./common');
99

10-
const pkg = require('../package.json');
10+
const pkg = require('./package.json');
1111

1212
var redis_client = redis.createClient(config.redis.port, config.redis.server);
1313
redis_client.on('error', err=>{throw err});

api/models.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exports.init = async function(cb, connectEvent = true) {
2020
return cb(err);
2121
}
2222
}
23-
23+
2424
console.log("connecting to mongodb");
2525
mongoose.connect(config.mongodb, {
2626
//writeConcern: majority slows down things.. let's just read/write
@@ -33,9 +33,7 @@ exports.init = async function(cb, connectEvent = true) {
3333
//requires writeConcern to be set to "majority" also.
3434
level: 'majority',
3535
},
36-
writeConcern: {
37-
w: 'majority',
38-
},
36+
writeConcern: { w: 'majority', },
3937
*/
4038
useNewUrlParser: true,
4139
useUnifiedTopology: true,
@@ -258,8 +256,7 @@ var taskSchema = mongoose.Schema({
258256

259257
status_msg: String,
260258

261-
//resource where the task is currently running (or was). It gets cleared if rerun
262-
//resource_id: {type: mongoose.Schema.Types.ObjectId, ref: 'Resource', index: true}, //accesses.ops is 0
259+
//resource where the task is last run (or attempted to run)
263260
resource_id: {type: mongoose.Schema.Types.ObjectId, ref: 'Resource' },
264261

265262
//resources where task dir exits (where it ran, or synced)
@@ -323,6 +320,16 @@ taskSchema.index({service: 1, status: 1, "config._tid": 1, user_id: 1, _group_id
323320
//taskSchema.index({follow_task_id: 1 });
324321
taskSchema.index({finish_date: 1, "config._app": 1, follow_task_id: 1 }); //sample tasks for an app
325322

323+
///////////////////////
324+
//
325+
// for finding validator (can't merge these 2 as it will cause "CannotIndexParallelArrays"
326+
//
327+
taskSchema.index({"deps_config.task": 1});
328+
taskSchema.index({service: 1, instance_id: 1, "config._outputs.id": 1 }); //still testing to see if this helps
329+
//
330+
///////////////////////
331+
332+
326333
exports.Task = mongoose.model('Task', taskSchema);
327334

328335
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -402,6 +409,8 @@ var serviceinfoSchema = mongoose.Schema({
402409
success_rate: Number,
403410

404411
readme_status: String, //I think I am going to deprecate this (by status/status_msg)
412+
413+
//monthlyCount: [Number], //dheeraj still working on this?
405414
});
406415
exports.Serviceinfo = mongoose.model('Serviceinfo', serviceinfoSchema);
407416

0 commit comments

Comments
 (0)