Skip to content

Commit

Permalink
added taskevent api
Browse files Browse the repository at this point in the history
removed resource reporting
moved package.json under /api
  • Loading branch information
soichih committed Jul 7, 2022
1 parent 796074e commit 50afcb0
Show file tree
Hide file tree
Showing 12 changed files with 559 additions and 382 deletions.
27 changes: 0 additions & 27 deletions Dockerfile

This file was deleted.

15 changes: 15 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:16

MAINTAINER Soichi Hayashi <hayashis@iu.edu>

WORKDIR /app

COPY controllers .
COPY resource_test.sh .
COPY *.js ./

COPY package.json .
COPY package-lock.json .

RUN npm install --production
CMD [ "node", "server.js" ]
1 change: 1 addition & 0 deletions api/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t brainlife/amaretti-api:1.0 .
1 change: 1 addition & 0 deletions api/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ router.use('/instance', require('./instance'));
router.use('/resource', require('./resource'));
router.use('/event', require('./event'));
router.use('/admin', require('./admin'));
router.use('/taskevent', require('./taskevent'));

//TODO DEPRECATED (currently used by th /wf/#!/resources UI)
//use (get) /resource/type instead
Expand Down
49 changes: 49 additions & 0 deletions api/controllers/taskevent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

const express = require('express');
const router = express.Router();
const async = require('async');
const mongoose = require('mongoose');
const path = require('path');
const mime = require('mime');
const multer = require('multer');
const fs = require('fs');

const config = require('../../config');
const db = require('../models');
const events = require('../events');
const common = require('../common');

/**
* @apiGroup Taskevent
* @api {get} /taskevent/:taskid
Query Task events
* @apiDescription Returns all task status update events for a given task id
*
* @apiHeader {String} authorization A valid JWT token "Bearer: xxxxx"
*
* @apiSuccess {Object} List of taskevents
*/
router.get('/:taskId', common.jwt(), function(req, res, next) {
let find = {task_id: req.params.taskId};

//access control
if(!req.user.scopes.amaretti || !~req.user.scopes.amaretti.indexOf("admin")) {
find['$or'] = [
{user_id: req.user.sub},
{_group_id: {$in: req.user.gids||[]}},
];
}

//if(req.query.select) console.log("select:"+req.query.select);
db.Taskevent.find(find)
.lean()
.sort('date')
.exec(function(err, taskevents) {
if(err) return next(err);
res.json({taskevents});
});
});

module.exports = router;

4 changes: 2 additions & 2 deletions api/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function publish_or_log(ex, key, msg, cb) {
}
}

//deprecate this
exports.task = function(task) {

//get previous task status to see if status changed
Expand All @@ -113,7 +112,7 @@ exports.task = function(task) {
});
taskevent.save();
}

//some fields are populated (foreign keys are de-referenced)
//to normalize the field type, let's load the record from database
//TODO - can't I just test to see if _id exists for those field and replace them with it?
Expand Down Expand Up @@ -151,3 +150,4 @@ exports.publish = (key, message, cb)=>{
message.timestamp = (new Date().getTime())/1000; //it's crazy that amqp doesn't set this?
publish_or_log(amaretti_ex, key, message, cb);
}

2 changes: 1 addition & 1 deletion api/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const logger = winston.createLogger(config.logger.winston);
const db = require('./models');
const common = require('./common');

const pkg = require('../package.json');
const pkg = require('./package.json');

var redis_client = redis.createClient(config.redis.port, config.redis.server);
redis_client.on('error', err=>{throw err});
Expand Down
21 changes: 15 additions & 6 deletions api/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports.init = async function(cb, connectEvent = true) {
return cb(err);
}
}

console.log("connecting to mongodb");
mongoose.connect(config.mongodb, {
//writeConcern: majority slows down things.. let's just read/write
Expand All @@ -33,9 +33,7 @@ exports.init = async function(cb, connectEvent = true) {
//requires writeConcern to be set to "majority" also.
level: 'majority',
},
writeConcern: {
w: 'majority',
},
writeConcern: { w: 'majority', },
*/
useNewUrlParser: true,
useUnifiedTopology: true,
Expand Down Expand Up @@ -258,8 +256,7 @@ var taskSchema = mongoose.Schema({

status_msg: String,

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

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

///////////////////////
//
// for finding validator (can't merge these 2 as it will cause "CannotIndexParallelArrays"
//
taskSchema.index({"deps_config.task": 1});
taskSchema.index({service: 1, instance_id: 1, "config._outputs.id": 1 }); //still testing to see if this helps
//
///////////////////////


exports.Task = mongoose.model('Task', taskSchema);

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -402,6 +409,8 @@ var serviceinfoSchema = mongoose.Schema({
success_rate: Number,

readme_status: String, //I think I am going to deprecate this (by status/status_msg)

//monthlyCount: [Number], //dheeraj still working on this?
});
exports.Serviceinfo = mongoose.model('Serviceinfo', serviceinfoSchema);

Loading

0 comments on commit 50afcb0

Please sign in to comment.