UNPKG

raas-server

Version:
90 lines 4.09 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const raas_core_1 = require("raas-core"); const serverRunner_1 = require("../runtime/serverRunner"); const runtimeController_1 = require("../runtime/runtimeController"); const getPort = require('get-port'); const path = require("path"); class RuntimeService { constructor(notificationService) { this.controllers = new Map(); this.notificationService = notificationService; } startServer(serverRunConfig, installation) { return __awaiter(this, void 0, void 0, function* () { if (!serverRunConfig.host && !serverRunConfig.port) { serverRunConfig.host = 'localhost'; serverRunConfig.port = yield getPort({ host: serverRunConfig.host }); } installation.location = this.findExecutable(installation); return serverRunner_1.ServerRunner.run(this.notificationService, serverRunConfig, installation).then(result => { const controller = new runtimeController_1.RuntimeController(result.handle, result.cp, this.notificationService); this.controllers.set(result.handle.id, controller); controller.onShutdown.once(() => { this.controllers.delete(result.handle.id); const analysis = controller.analysis; if (analysis && analysis.state === raas_core_1.Protocol.ServerState.ANALYZING) { analysis.state = raas_core_1.Protocol.ServerState.STOPPED; this.notificationService.onAnalysisCancelled(analysis); } result.handle.state = raas_core_1.Protocol.ServerState.STOPPED; this.notificationService.onServerStopped(result.handle); }); controller.init(); }).catch(msg => { this.notificationService.onErrorStartingServer({ config: serverRunConfig, msg }); }); }); } findExecutable(installation) { // TODO: windows use .bat return path.join(installation.location, 'bin', 'rhamt-cli'); } stopServer(id) { const controller = this.controllers.get(id); if (controller) { controller.shutdown(); } } analyze(config) { const controller = this.controllers.get(config.serverInstanceHandleId); if (controller) { controller.analyze(config); return true; } return false; } cancelAnalysis(analysis) { const controller = this.controllers.get(analysis.analysisConfiguration.serverInstanceHandleId); if (controller && controller.analysis && controller.analysis.state === raas_core_1.Protocol.ServerState.ANALYZING) { controller.shutdown(); return true; } return false; } getServerHandles() { const handles = []; this.controllers.forEach(value => handles.push(value.handle)); return handles; } getAllAnalyses() { const analyses = []; this.controllers.forEach(value => { const analysis = value.analysis; if (analysis && analysis.state === raas_core_1.Protocol.ServerState.ANALYZING) { analyses.push(analysis); } }); return analyses; } } exports.RuntimeService = RuntimeService; //# sourceMappingURL=runtimeService.js.map