UNPKG

firmament-vita

Version:

Firmament module for automating VITA tasks

136 lines 7.62 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); var inversify_1 = require("inversify"); var firmament_yargs_1 = require("firmament-yargs"); var inversify_config_1 = require("../inversify.config"); var path = require('path'); var PostalAgentImpl = (function (_super) { __extends(PostalAgentImpl, _super); function PostalAgentImpl(postal, commandUtil, vitaTasks) { var _this = _super.call(this) || this; _this.postal = postal; _this.commandUtil = commandUtil; _this.vitaTasks = vitaTasks; var me = _this; me.postal.subscribe({ channel: 'FirmamentVita', topic: 'ProcessFileWithFlow', callback: function (ppfwf) { ppfwf.etlFile.addFlows([{ name: ppfwf.flowName }], function (err, etlFlows) { if (me.commandUtil.logError(err) || !etlFlows || etlFlows.length != 1) { return; } var etlFlow = etlFlows[0]; etlFlow.addSteps([ { name: 'decryptAndUnTar', index: 0 }, { name: 'unZipFile', index: 1 }, { name: 'mergePcap', index: 2 } ], function (err, etlSteps) { if (me.commandUtil.logError(err) || !etlSteps || etlSteps.length != 3) { return; } etlFlow.loadEntireObject(function (err, etlFlow) { var fullPipeline = inversify_config_1.default.get('FullPipeline'); fullPipeline.decryptAndUnTarOptions.encryptedFiles = [path.resolve(ppfwf.etlFile.path, ppfwf.etlFile.name)]; fullPipeline.decryptAndUnTarOptions.password = ppfwf.fileEncryptionPassword; etlFlow.currentStepIndex = Number.MAX_SAFE_INTEGER; vitaTasks.processFullPipelineInstance(fullPipeline, function (err, status) { if (status.mergePcapFilesStatus && etlFlow.currentStepIndex !== 2) { etlFlow.currentStepIndex = 2; etlFlow.steps[etlFlow.currentStepIndex].startTime = etlFlow.steps[etlFlow.currentStepIndex - 1].endTime = new Date(); } else if (status.unZipFileStatus && etlFlow.currentStepIndex !== 1) { etlFlow.currentStepIndex = 1; etlFlow.steps[etlFlow.currentStepIndex].startTime = etlFlow.steps[etlFlow.currentStepIndex - 1].endTime = new Date(); } else if (status.decryptAndUnTarStatus && etlFlow.currentStepIndex !== 0) { etlFlow.currentStepIndex = 0; etlFlow.steps[etlFlow.currentStepIndex].startTime = new Date(); } switch (etlFlow.currentStepIndex) { case 0: etlFlow.steps[etlFlow.currentStepIndex].progress = status.decryptAndUnTarStatus.current / status.decryptAndUnTarStatus.total; break; case 1: etlFlow.steps[etlFlow.currentStepIndex].progress = status.unZipFileStatus.current / status.unZipFileStatus.total; break; case 2: etlFlow.steps[etlFlow.currentStepIndex].progress = status.mergePcapFilesStatus.current / status.mergePcapFilesStatus.total; break; } status = status || { status: 'Running' }; etlFlow.steps[etlFlow.currentStepIndex].status = status.status; etlFlow.steps[etlFlow.currentStepIndex].currentTime = new Date(); etlFlow.steps[etlFlow.currentStepIndex].writeToDb(function () { me.postal.publish({ channel: 'FirmamentVita', topic: ppfwf.operationUUID, data: { err: err, status: status } }); }); }, function (err, result) { result = result || { status: 'Finished' }; me.postal.publish({ channel: 'FirmamentVita', topic: ppfwf.operationUUID, data: { err: err, result: result } }); }); }); }); }); } }); return _this; } PostalAgentImpl = __decorate([ inversify_1.injectable(), __param(0, inversify_1.inject('IPostal')), __param(1, inversify_1.inject('CommandUtil')), __param(2, inversify_1.inject('VitaTasks')), __metadata("design:paramtypes", [Object, Object, Object]) ], PostalAgentImpl); return PostalAgentImpl; }(firmament_yargs_1.ForceErrorImpl)); exports.PostalAgentImpl = PostalAgentImpl; //# sourceMappingURL=postal-agent-impl.js.map