snapshots stuff
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
"@hapi/boom": "^9.1.0",
|
||||
"@ng-bootstrap/ng-bootstrap": "6.2.0",
|
||||
"@types/chart.js": "^2.9.16",
|
||||
"@QMI/qmi-cloud-common": "2.0.7",
|
||||
"@QMI/qmi-cloud-common": "2.0.8",
|
||||
"adal-angular4": "^4.0.12",
|
||||
"angular-bootstrap-md": "9.0.0",
|
||||
"animate.css": "^3.7.2",
|
||||
|
||||
@@ -222,9 +222,14 @@ const get = async (model, filter, select, skip, limit, populates, reply) => {
|
||||
}
|
||||
}
|
||||
|
||||
const getById = async (model, id, reply) => {
|
||||
const getById = async (model, id, populates, reply) => {
|
||||
try {
|
||||
var exec = model.findById(id);
|
||||
if (populates){
|
||||
populates.forEach(p=> {
|
||||
exec = exec.populate(p);
|
||||
});
|
||||
} else {
|
||||
if ( model === Provision ) {
|
||||
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
|
||||
}
|
||||
@@ -248,6 +253,10 @@ const getById = async (model, id, reply) => {
|
||||
if ( model === TrainingSession ) {
|
||||
exec = exec.populate('user').populate('template');
|
||||
}
|
||||
if ( model === Snapshot ) {
|
||||
exec = exec.populate('owner').populate('provision');
|
||||
}
|
||||
}
|
||||
const entity = await exec;
|
||||
return entity;
|
||||
} catch (err) {
|
||||
@@ -255,9 +264,15 @@ const getById = async (model, id, reply) => {
|
||||
}
|
||||
};
|
||||
|
||||
const getOne = async (model, filter, reply) => {
|
||||
const getOne = async (model, filter, populates, reply) => {
|
||||
try {
|
||||
var exec = model.findOne(filter);
|
||||
if (populates){
|
||||
populates.forEach(p=> {
|
||||
exec = exec.populate(p);
|
||||
});
|
||||
} else {
|
||||
|
||||
if ( model === Provision ) {
|
||||
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
|
||||
}
|
||||
@@ -279,6 +294,10 @@ const getOne = async (model, filter, reply) => {
|
||||
if ( model === TrainingSession ) {
|
||||
exec = exec.populate('user').populate('template');
|
||||
}
|
||||
if ( model === Snapshot ) {
|
||||
exec = exec.populate('owner').populate('provision');
|
||||
}
|
||||
}
|
||||
const entity = await exec;
|
||||
return entity;
|
||||
} catch (err) {
|
||||
@@ -319,6 +338,9 @@ const update = async (model, id, body, reply) => {
|
||||
if ( model === TrainingSession ) {
|
||||
exec = exec.populate('user').populate('template');
|
||||
}
|
||||
if ( model === Snapshot ) {
|
||||
exec = exec.populate('owner').populate('provision');
|
||||
}
|
||||
const update = await exec;
|
||||
return update;
|
||||
} catch (err) {
|
||||
@@ -352,6 +374,9 @@ const updateMany = async (model, filter, body, reply) => {
|
||||
if ( model === TrainingSession ) {
|
||||
exec = exec.populate('user').populate('template');
|
||||
}
|
||||
if ( model === Snapshot ) {
|
||||
exec = exec.populate('owner').populate('provision');
|
||||
}
|
||||
|
||||
return await exec;
|
||||
|
||||
@@ -393,11 +418,11 @@ function _m(model) {
|
||||
getPage: async (filter, page, populates, select, reply) => {
|
||||
return getPage(model, filter, page, populates, select, reply);
|
||||
},
|
||||
getById: async (id, reply) => {
|
||||
return getById(model, id, reply);
|
||||
getById: async (id, populates, reply) => {
|
||||
return getById(model, id, populates, reply);
|
||||
},
|
||||
getOne: async (filter, reply)=> {
|
||||
return getOne(model, filter, reply);
|
||||
getOne: async (filter, populates, reply)=> {
|
||||
return getOne(model, filter, populates, reply);
|
||||
},
|
||||
add: async (data, reply) => {
|
||||
return add(model, data, reply);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@QMI/qmi-cloud-common",
|
||||
"version": "2.0.7",
|
||||
"version": "2.0.8",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-ec2": "^3.590.0",
|
||||
"@aws-sdk/client-rds": "^3.590.0",
|
||||
|
||||
@@ -5,12 +5,6 @@ const passport = require('../passport-okta');
|
||||
const fs = require('fs-extra');
|
||||
const cli = require('@QMI/qmi-cloud-common/cli');
|
||||
|
||||
|
||||
const MYQUEUES = require('@QMI/qmi-cloud-common/queues');
|
||||
const queues = MYQUEUES.queues;
|
||||
const SYNAPSE_QUEUE = MYQUEUES.SYNAPSE_QUEUE;
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /provisions:
|
||||
@@ -89,33 +83,6 @@ router.get('/', passport.ensureAuthenticatedAndAdmin, async (req, res, next) =>
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /provisions/snapshotslogs:
|
||||
* get:
|
||||
* description: Get logs for snapshots
|
||||
* summary: Get logs for snapshots
|
||||
* tags:
|
||||
* - admin
|
||||
* produces:
|
||||
* - application/json
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 404:
|
||||
* description: Not found
|
||||
*
|
||||
*/
|
||||
router.get('/snapshotslogs', passport.ensureAuthenticatedAndAdmin, async (req, res, next) => {
|
||||
try {
|
||||
|
||||
return res.sendFile("/logs/general/qmi-snapshots.log");
|
||||
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /provisions/optionssLogs:
|
||||
|
||||
@@ -3,6 +3,9 @@ const router = express.Router();
|
||||
const db = require('@QMI/qmi-cloud-common/mongo');
|
||||
const passport = require('../passport-okta');
|
||||
|
||||
const MYQUEUES = require('@QMI/qmi-cloud-common/queues');
|
||||
const queues = MYQUEUES.queues;
|
||||
const SYNAPSE_QUEUE = MYQUEUES.SYNAPSE_QUEUE;
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
@@ -80,10 +83,45 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /snapshots/{id}:
|
||||
* get:
|
||||
* description: Get all snaphots
|
||||
* summary: Get all snaphots
|
||||
* tags:
|
||||
* - admin
|
||||
* parameters:
|
||||
* - name: filter
|
||||
* in: query
|
||||
* required: false
|
||||
* type: object
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* produces:
|
||||
* - application/json
|
||||
* responses:
|
||||
* 200:
|
||||
* description: User
|
||||
*/
|
||||
router.get('/:id', passport.ensureAuthenticated, async (req, res, next) => {
|
||||
try {
|
||||
const result = await db.snapshot.getById(req.params.id);
|
||||
if (!result){
|
||||
return res.status(404).json({"msg": "Not found"});
|
||||
}
|
||||
return res.json(result);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /snapshots/:id/copy:
|
||||
* /snapshots/{id}/copy:
|
||||
* get:
|
||||
* description: Get Status of copy snapshots into regions
|
||||
* summary: Get Status of copy snapshots into regions
|
||||
@@ -112,6 +150,8 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
||||
}
|
||||
|
||||
queues[SYNAPSE_QUEUE].add("synapse_job", {
|
||||
snapId: snap._id,
|
||||
provision: snap.provision,
|
||||
snapName: snap.name,
|
||||
tasktype: "check-copy-snapshots"
|
||||
});
|
||||
@@ -125,7 +165,7 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /snapshots/:id/copy:
|
||||
* /snapshots/{id}/copy:
|
||||
* post:
|
||||
* description: Copy snapshots into regions
|
||||
* summary: Copy snapshots into regions
|
||||
@@ -142,10 +182,6 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
||||
* in: query
|
||||
* required: true
|
||||
* type: string
|
||||
* - name: rg
|
||||
* in: query
|
||||
* required: true
|
||||
* type: string
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
@@ -162,8 +198,9 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
||||
}
|
||||
|
||||
queues[SYNAPSE_QUEUE].add("synapse_job", {
|
||||
snapId: snap._id,
|
||||
provision: snap.provision,
|
||||
snapName: snap.name,
|
||||
rGroup: req.query.rg,
|
||||
regions: req.query.regions,
|
||||
tasktype: "copy-snapshots"
|
||||
});
|
||||
@@ -175,6 +212,36 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /snapshots/{id}/logs:
|
||||
* get:
|
||||
* description: Get logs for snapshots
|
||||
* summary: Get logs for snapshots
|
||||
* tags:
|
||||
* - admin
|
||||
* produces:
|
||||
* - application/json
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* 404:
|
||||
* description: Not found
|
||||
*
|
||||
*/
|
||||
router.get('/:id/logs', passport.ensureAuthenticatedAndAdmin, async (req, res, next) => {
|
||||
try {
|
||||
|
||||
const snap = await db.snapshot.getById(req.params.id);
|
||||
if (!snap){
|
||||
return res.status(404).json({"msg": "Not found"});
|
||||
}
|
||||
return res.sendFile(`/logs/snapshot/${snap._id}.log`);
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user