snapshots stuff
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
"@hapi/boom": "^9.1.0",
|
"@hapi/boom": "^9.1.0",
|
||||||
"@ng-bootstrap/ng-bootstrap": "6.2.0",
|
"@ng-bootstrap/ng-bootstrap": "6.2.0",
|
||||||
"@types/chart.js": "^2.9.16",
|
"@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",
|
"adal-angular4": "^4.0.12",
|
||||||
"angular-bootstrap-md": "9.0.0",
|
"angular-bootstrap-md": "9.0.0",
|
||||||
"animate.css": "^3.7.2",
|
"animate.css": "^3.7.2",
|
||||||
|
|||||||
@@ -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 {
|
try {
|
||||||
var exec = model.findById(id);
|
var exec = model.findById(id);
|
||||||
if ( model === Provision ) {
|
if (populates){
|
||||||
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
|
populates.forEach(p=> {
|
||||||
}
|
exec = exec.populate(p);
|
||||||
if ( model === SharedProvision ) {
|
});
|
||||||
exec = exec.populate('provision').populate({path: 'sharedWithUser', select: 'displayName upn oid active'}).populate({path: 'user', select: 'displayName upn'});
|
} else {
|
||||||
}
|
if ( model === Provision ) {
|
||||||
if ( model === ApiKey ) {
|
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
|
||||||
exec = exec.populate('user');
|
}
|
||||||
}
|
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 ) {
|
if ( model === Webhook ) {
|
||||||
exec = exec.populate('owner');
|
exec = exec.populate('owner');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( model === Scenario ) {
|
if ( model === Scenario ) {
|
||||||
exec = exec.populate('subscription').populate('deployOpts').populate('allowedUsers');
|
exec = exec.populate('subscription').populate('deployOpts').populate('allowedUsers');
|
||||||
}
|
}
|
||||||
if ( model === Event ) {
|
if ( model === Event ) {
|
||||||
exec = exec.populate({path: 'user', select: 'displayName'});
|
exec = exec.populate({path: 'user', select: 'displayName'});
|
||||||
}
|
}
|
||||||
if ( model === TrainingSession ) {
|
if ( model === TrainingSession ) {
|
||||||
exec = exec.populate('user').populate('template');
|
exec = exec.populate('user').populate('template');
|
||||||
|
}
|
||||||
|
if ( model === Snapshot ) {
|
||||||
|
exec = exec.populate('owner').populate('provision');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const entity = await exec;
|
const entity = await exec;
|
||||||
return entity;
|
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 {
|
try {
|
||||||
var exec = model.findOne(filter);
|
var exec = model.findOne(filter);
|
||||||
if ( model === Provision ) {
|
if (populates){
|
||||||
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
|
populates.forEach(p=> {
|
||||||
}
|
exec = exec.populate(p);
|
||||||
if ( model === SharedProvision ) {
|
});
|
||||||
exec = exec.populate('provision').populate({path: 'sharedWithUser', select: 'displayName upn oid active'}).populate({path: 'user', select: 'displayName upn'});
|
} else {
|
||||||
}
|
|
||||||
if ( model === ApiKey ) {
|
if ( model === Provision ) {
|
||||||
exec = exec.populate('user');
|
exec = exec.populate('user').populate('destroy').populate('_scenarioDoc').populate("schedule").populate('deployOpts');
|
||||||
}
|
}
|
||||||
if ( model === Webhook ) {
|
if ( model === SharedProvision ) {
|
||||||
exec = exec.populate('owner');
|
exec = exec.populate('provision').populate({path: 'sharedWithUser', select: 'displayName upn oid active'}).populate({path: 'user', select: 'displayName upn'});
|
||||||
}
|
}
|
||||||
if ( model === Scenario ) {
|
if ( model === ApiKey ) {
|
||||||
exec = exec.populate('subscription').populate('deployOpts').populate('allowedUsers');
|
exec = exec.populate('user');
|
||||||
}
|
}
|
||||||
if ( model === Event ) {
|
if ( model === Webhook ) {
|
||||||
exec = exec.populate({path: 'user', select: 'displayName'});
|
exec = exec.populate('owner');
|
||||||
}
|
}
|
||||||
if ( model === TrainingSession ) {
|
if ( model === Scenario ) {
|
||||||
exec = exec.populate('user').populate('template');
|
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;
|
const entity = await exec;
|
||||||
return entity;
|
return entity;
|
||||||
@@ -319,6 +338,9 @@ const update = async (model, id, body, reply) => {
|
|||||||
if ( model === TrainingSession ) {
|
if ( model === TrainingSession ) {
|
||||||
exec = exec.populate('user').populate('template');
|
exec = exec.populate('user').populate('template');
|
||||||
}
|
}
|
||||||
|
if ( model === Snapshot ) {
|
||||||
|
exec = exec.populate('owner').populate('provision');
|
||||||
|
}
|
||||||
const update = await exec;
|
const update = await exec;
|
||||||
return update;
|
return update;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -352,6 +374,9 @@ const updateMany = async (model, filter, body, reply) => {
|
|||||||
if ( model === TrainingSession ) {
|
if ( model === TrainingSession ) {
|
||||||
exec = exec.populate('user').populate('template');
|
exec = exec.populate('user').populate('template');
|
||||||
}
|
}
|
||||||
|
if ( model === Snapshot ) {
|
||||||
|
exec = exec.populate('owner').populate('provision');
|
||||||
|
}
|
||||||
|
|
||||||
return await exec;
|
return await exec;
|
||||||
|
|
||||||
@@ -393,11 +418,11 @@ function _m(model) {
|
|||||||
getPage: async (filter, page, populates, select, reply) => {
|
getPage: async (filter, page, populates, select, reply) => {
|
||||||
return getPage(model, filter, page, populates, select, reply);
|
return getPage(model, filter, page, populates, select, reply);
|
||||||
},
|
},
|
||||||
getById: async (id, reply) => {
|
getById: async (id, populates, reply) => {
|
||||||
return getById(model, id, reply);
|
return getById(model, id, populates, reply);
|
||||||
},
|
},
|
||||||
getOne: async (filter, reply)=> {
|
getOne: async (filter, populates, reply)=> {
|
||||||
return getOne(model, filter, reply);
|
return getOne(model, filter, populates, reply);
|
||||||
},
|
},
|
||||||
add: async (data, reply) => {
|
add: async (data, reply) => {
|
||||||
return add(model, data, reply);
|
return add(model, data, reply);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@QMI/qmi-cloud-common",
|
"name": "@QMI/qmi-cloud-common",
|
||||||
"version": "2.0.7",
|
"version": "2.0.8",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-ec2": "^3.590.0",
|
"@aws-sdk/client-ec2": "^3.590.0",
|
||||||
"@aws-sdk/client-rds": "^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 fs = require('fs-extra');
|
||||||
const cli = require('@QMI/qmi-cloud-common/cli');
|
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
|
* @swagger
|
||||||
* /provisions:
|
* /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
|
* @swagger
|
||||||
* /provisions/optionssLogs:
|
* /provisions/optionssLogs:
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ const router = express.Router();
|
|||||||
const db = require('@QMI/qmi-cloud-common/mongo');
|
const db = require('@QMI/qmi-cloud-common/mongo');
|
||||||
const passport = require('../passport-okta');
|
const passport = require('../passport-okta');
|
||||||
|
|
||||||
|
const MYQUEUES = require('@QMI/qmi-cloud-common/queues');
|
||||||
|
const queues = MYQUEUES.queues;
|
||||||
|
const SYNAPSE_QUEUE = MYQUEUES.SYNAPSE_QUEUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @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
|
* @swagger
|
||||||
* /snapshots/:id/copy:
|
* /snapshots/{id}/copy:
|
||||||
* get:
|
* get:
|
||||||
* description: Get Status of copy snapshots into regions
|
* description: Get Status of copy snapshots into regions
|
||||||
* summary: 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", {
|
queues[SYNAPSE_QUEUE].add("synapse_job", {
|
||||||
|
snapId: snap._id,
|
||||||
|
provision: snap.provision,
|
||||||
snapName: snap.name,
|
snapName: snap.name,
|
||||||
tasktype: "check-copy-snapshots"
|
tasktype: "check-copy-snapshots"
|
||||||
});
|
});
|
||||||
@@ -125,7 +165,7 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* /snapshots/:id/copy:
|
* /snapshots/{id}/copy:
|
||||||
* post:
|
* post:
|
||||||
* description: Copy snapshots into regions
|
* description: Copy snapshots into regions
|
||||||
* summary: Copy snapshots into regions
|
* summary: Copy snapshots into regions
|
||||||
@@ -142,10 +182,6 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
|||||||
* in: query
|
* in: query
|
||||||
* required: true
|
* required: true
|
||||||
* type: string
|
* type: string
|
||||||
* - name: rg
|
|
||||||
* in: query
|
|
||||||
* required: true
|
|
||||||
* type: string
|
|
||||||
* responses:
|
* responses:
|
||||||
* 200:
|
* 200:
|
||||||
* description: OK
|
* description: OK
|
||||||
@@ -162,8 +198,9 @@ router.get('/', passport.ensureAuthenticated, async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
queues[SYNAPSE_QUEUE].add("synapse_job", {
|
queues[SYNAPSE_QUEUE].add("synapse_job", {
|
||||||
|
snapId: snap._id,
|
||||||
|
provision: snap.provision,
|
||||||
snapName: snap.name,
|
snapName: snap.name,
|
||||||
rGroup: req.query.rg,
|
|
||||||
regions: req.query.regions,
|
regions: req.query.regions,
|
||||||
tasktype: "copy-snapshots"
|
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