snapshots stuff

This commit is contained in:
Manuel Romero
2025-02-11 11:44:20 +01:00
parent 4d2b33cde6
commit f62f0b8253
5 changed files with 147 additions and 88 deletions

View File

@@ -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",

View File

@@ -222,31 +222,40 @@ 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 ( model === Provision ) {
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
}
if ( model === SharedProvision ) {
exec = exec.populate('provision').populate({path: 'sharedWithUser', select: 'displayName upn oid active'}).populate({path: 'user', select: 'displayName upn'});
}
if ( model === ApiKey ) {
exec = exec.populate('user');
}
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');
}
if ( model === SharedProvision ) {
exec = exec.populate('provision').populate({path: 'sharedWithUser', select: 'displayName upn oid active'}).populate({path: 'user', select: 'displayName upn'});
}
if ( model === ApiKey ) {
exec = exec.populate('user');
}
if ( model === Webhook ) {
exec = exec.populate('owner');
}
if ( model === Webhook ) {
exec = exec.populate('owner');
}
if ( model === Scenario ) {
exec = exec.populate('subscription').populate('deployOpts').populate('allowedUsers');
}
if ( model === Event ) {
exec = exec.populate({path: 'user', select: 'displayName'});
}
if ( model === TrainingSession ) {
exec = exec.populate('user').populate('template');
if ( model === Scenario ) {
exec = exec.populate('subscription').populate('deployOpts').populate('allowedUsers');
}
if ( model === Event ) {
exec = exec.populate({path: 'user', select: 'displayName'});
}
if ( model === TrainingSession ) {
exec = exec.populate('user').populate('template');
}
if ( model === Snapshot ) {
exec = exec.populate('owner').populate('provision');
}
}
const entity = await exec;
return entity;
@@ -255,29 +264,39 @@ 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 ( model === Provision ) {
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
}
if ( model === SharedProvision ) {
exec = exec.populate('provision').populate({path: 'sharedWithUser', select: 'displayName upn oid active'}).populate({path: 'user', select: 'displayName upn'});
}
if ( model === ApiKey ) {
exec = exec.populate('user');
}
if ( model === Webhook ) {
exec = exec.populate('owner');
}
if ( model === Scenario ) {
exec = exec.populate('subscription').populate('deployOpts').populate('allowedUsers');
}
if ( model === Event ) {
exec = exec.populate({path: 'user', select: 'displayName'});
}
if ( model === TrainingSession ) {
exec = exec.populate('user').populate('template');
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');
}
if ( model === SharedProvision ) {
exec = exec.populate('provision').populate({path: 'sharedWithUser', select: 'displayName upn oid active'}).populate({path: 'user', select: 'displayName upn'});
}
if ( model === ApiKey ) {
exec = exec.populate('user');
}
if ( model === Webhook ) {
exec = exec.populate('owner');
}
if ( model === Scenario ) {
exec = exec.populate('subscription').populate('deployOpts').populate('allowedUsers');
}
if ( model === Event ) {
exec = exec.populate({path: 'user', select: 'displayName'});
}
if ( model === TrainingSession ) {
exec = exec.populate('user').populate('template');
}
if ( model === Snapshot ) {
exec = exec.populate('owner').populate('provision');
}
}
const entity = await exec;
return entity;
@@ -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);

View File

@@ -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",

View File

@@ -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:

View File

@@ -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);
}
});