UNPKG

@hawtio/react

Version:

A Hawtio reimplementation based on TypeScript + React.

180 lines (168 loc) 10.6 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _chunkBJ6TSPQKjs = require('./chunk-BJ6TSPQK.js'); var _chunkBHIEXRGKjs = require('./chunk-BHIEXRGK.js'); // src/plugins/diagnostics/flight-recorder-service.ts var FlightRecorderService = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); } __init() {this.recordings = []} __init2() {this.currentRecording = { state: 0 /* NOT_CREATED */ }} __init3() {this.initialized = false} async setUp() { if (!this.jfrMBean) { const jfr = await this.getFlightRecoderMBean(); if (!jfr) return this; } await this.retrieveConfigurations(); await this.retrieveRecordings(); await this.retrieveSettings(); this.initialized = true; return this; } async hasFlightRecorderMBean() { if (!this.jfrMBean) { await this.getFlightRecoderMBean(); } return this.jfrMBean !== void 0; } async getFlightRecoderMBean() { if (this.jfrMBean) return this.jfrMBean; await _chunkBJ6TSPQKjs.workspace.findMBeans("jdk.management.jfr", { type: "FlightRecorder" }).then((mbeans) => this.jfrMBean = mbeans[0]); return this.jfrMBean; } async retrieveConfigurations() { if (this.jfrConfigs) return this.jfrConfigs; if (!this.jfrMBean) await this.getFlightRecoderMBean(); this.jfrConfigs = await _asyncOptionalChain([(await _chunkBJ6TSPQKjs.jolokiaService.readAttribute(_optionalChain([this, 'access', _ => _.jfrMBean, 'optionalAccess', _2 => _2.objectName]), "Configurations").catch((e) => { _chunkBHIEXRGKjs.eventService.notify({ type: "warning", message: _chunkBJ6TSPQKjs.jolokiaService.errorMessage(e) }); return []; })), 'optionalAccess', async _3 => _3.map, 'call', async _4 => _4((config) => ({ name: config.name, label: config.label, description: config.description }))]); return this.jfrConfigs; } async retrieveRecordings() { if (!this.jfrMBean) await this.getFlightRecoderMBean(); const jfrRecordings = await _chunkBJ6TSPQKjs.jolokiaService.readAttribute(_optionalChain([this, 'access', _5 => _5.jfrMBean, 'optionalAccess', _6 => _6.objectName]), "Recordings").catch((e) => { _chunkBHIEXRGKjs.eventService.notify({ type: "warning", message: _chunkBJ6TSPQKjs.jolokiaService.errorMessage(e) }); return []; }); this.recordings = await this.listSavedRecordings(jfrRecordings); this.currentRecording = await this.configureCurrentRecording(jfrRecordings); return [this.recordings || [], this.currentRecording, jfrRecordings]; } async listSavedRecordings(jfrRecordings) { const jolokiaUrl = await _chunkBJ6TSPQKjs.jolokiaService.getFullJolokiaUrl(); return jfrRecordings.filter((recording) => _optionalChain([recording, 'optionalAccess', _7 => _7.state]) === "STOPPED").map( (recording) => ({ number: "" + recording.id, size: `${recording.size}b`, file: `${recording.name}.jfr`, time: recording.stopTime, canDownload: true, downloadLink: `${jolokiaUrl}/exec/jdk.management.jfr:type=FlightRecorder/copyTo(long,java.lang.String)/${recording.id}/${recording.id}.jfr` }) ); } async configureCurrentRecording(jfrRecordings) { const current = jfrRecordings && jfrRecordings.length > 0 && jfrRecordings[jfrRecordings.length - 1]; if (current && _optionalChain([current, 'optionalAccess', _8 => _8.state]) === "RUNNING") return { state: 2 /* RECORDING */, number: Number(_optionalChain([jfrRecordings, 'optionalAccess', _9 => _9[jfrRecordings.length - 1], 'optionalAccess', _10 => _10.id])) }; if (current && _optionalChain([current, 'optionalAccess', _11 => _11.state]) === "NEW") return { state: 1 /* CREATED */, number: Number(_optionalChain([jfrRecordings, 'optionalAccess', _12 => _12[jfrRecordings.length - 1], 'optionalAccess', _13 => _13.id])) }; return { state: 1 /* CREATED */, number: await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _14 => _14.jfrMBean, 'optionalAccess', _15 => _15.objectName]), "newRecording") }; } async retrieveSettings() { if (!this.jfrMBean) await this.getFlightRecoderMBean(); if (!this.currentRecording) await this.retrieveRecordings(); const initialSettings = await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _16 => _16.jfrMBean, 'optionalAccess', _17 => _17.objectName]), "getRecordingOptions", [ _optionalChain([this, 'access', _18 => _18.currentRecording, 'optionalAccess', _19 => _19.number]) ]); const limitType = Number(initialSettings["duration"]) !== 0 ? "duration" : Number(initialSettings["maxSize"]) !== 0 ? "maxSize" : "unlimited"; this.userJfrSettings = { configuration: initialSettings["configuration"] || "default", name: initialSettings["name"], isUserSelectedName: _optionalChain([this, 'access', _20 => _20.userJfrSettings, 'optionalAccess', _21 => _21.isUserSelectedName]) || false, dumpOnExit: initialSettings["dumpOnExit"] === "true", recordingNumber: _optionalChain([this, 'access', _22 => _22.currentRecording, 'optionalAccess', _23 => _23.number]), limitType, limitValue: limitType !== "unlimited" ? Number(initialSettings[limitType]) : 0 }; return this.userJfrSettings; } async startRecording(userJfrSettings) { this.userJfrSettings = { ...this.userJfrSettings, ...userJfrSettings || {} }; await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _24 => _24.jfrMBean, 'optionalAccess', _25 => _25.objectName]), "setRecordingOptions", [ _optionalChain([this, 'access', _26 => _26.currentRecording, 'optionalAccess', _27 => _27.number]), this.convertSettingsToJfrOptions(this.userJfrSettings) ]); await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _28 => _28.jfrMBean, 'optionalAccess', _29 => _29.objectName]), "setPredefinedConfiguration", [ _optionalChain([this, 'access', _30 => _30.currentRecording, 'optionalAccess', _31 => _31.number]), _optionalChain([this, 'access', _32 => _32.userJfrSettings, 'optionalAccess', _33 => _33.configuration]) ]); await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _34 => _34.jfrMBean, 'optionalAccess', _35 => _35.objectName]), "startRecording", [_optionalChain([this, 'access', _36 => _36.currentRecording, 'optionalAccess', _37 => _37.number])]); this.currentRecording.state = 2 /* RECORDING */; } async stopRecording() { await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _38 => _38.jfrMBean, 'optionalAccess', _39 => _39.objectName]), "stopRecording", [this.currentRecording.number]); await this.retrieveRecordings(); if (this.userJfrSettings && !_optionalChain([this, 'access', _40 => _40.userJfrSettings, 'optionalAccess', _41 => _41.isUserSelectedName]) && this.recordings.length > 0) { const previousRecording = this.recordings[this.recordings.length - 1]; this.userJfrSettings.name = (Number(_optionalChain([previousRecording, 'optionalAccess', _42 => _42.number])) + 1).toString() || ""; } } async downloadRecording(id, name) { const fileData = await this.retrieveFileData(id); const fileUrl = URL.createObjectURL(new Blob([fileData], { type: "application/octet-stream" })); const fileDownload = document.createElement("a"); fileDownload.href = fileUrl; fileDownload.download = `${name}`; fileDownload.click(); URL.revokeObjectURL(fileDownload.toString()); } async retrieveFileData(id) { const responses = []; let fileRead = false; const streamToRead = await _chunkBJ6TSPQKjs.jolokiaService.execute( _optionalChain([this, 'access', _43 => _43.jfrMBean, 'optionalAccess', _44 => _44.objectName]), "openStream(long, javax.management.openmbean.TabularData)", [id, {}] ); while (!fileRead) await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _45 => _45.jfrMBean, 'optionalAccess', _46 => _46.objectName]), "readStream(long)", [streamToRead]).then((response) => { if (!response) { fileRead = true; return; } responses.push(new Uint8Array(response)); }); await _chunkBJ6TSPQKjs.jolokiaService.execute(_optionalChain([this, 'access', _47 => _47.jfrMBean, 'optionalAccess', _48 => _48.objectName]), "closeStream(long)", [streamToRead]); return this.concatenateUInt32Array(responses); } convertSettingsToJfrOptions(jfrOptions) { return { name: "" + jfrOptions.name, dumpOnExit: "" + jfrOptions.dumpOnExit, duration: jfrOptions.limitType === "duration" ? `${jfrOptions.limitValue}s` : void 0, maxSize: jfrOptions.limitType === "maxSize" ? jfrOptions.limitValue : void 0 }; } concatenateUInt32Array(uint8arrays) { const totalLength = uint8arrays.reduce((total, uint8Array) => total + uint8Array.byteLength, 0); const result = new Uint8Array(totalLength); let offset = 0; uint8arrays.forEach((uint8arrays2) => { result.set(uint8arrays2, offset); offset += uint8arrays2.byteLength; }); return result; } }, _class); var flightRecorderService = new FlightRecorderService(); exports.flightRecorderService = flightRecorderService; //# sourceMappingURL=chunk-WYFZRJ4C.js.map