UNPKG

@hpcc-js/comms

Version:
138 lines 5.54 kB
import * as tslib_1 from "tslib"; import { Cache, StateObject } from "@hpcc-js/util"; import { MachineService } from "../services/wsMachine"; import { TopologyService } from "../services/wsTopology"; import { Machine } from "./machine"; var TargetClusterCache = /** @class */ (function (_super) { tslib_1.__extends(TargetClusterCache, _super); function TargetClusterCache() { return _super.call(this, function (obj) { return obj.Name; }) || this; } return TargetClusterCache; }(Cache)); export { TargetClusterCache }; var _targetCluster = new TargetClusterCache(); var TargetCluster = /** @class */ (function (_super) { tslib_1.__extends(TargetCluster, _super); function TargetCluster(optsConnection, name) { var _this = _super.call(this) || this; if (optsConnection instanceof TopologyService) { _this.connection = optsConnection; _this.machineConnection = new MachineService(optsConnection.connectionOptions()); } else { _this.connection = new TopologyService(optsConnection); _this.machineConnection = new MachineService(optsConnection); } _this.clear({ Name: name }); return _this; } Object.defineProperty(TargetCluster.prototype, "Name", { get: function () { return this.get("Name"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "Prefix", { get: function () { return this.get("Prefix"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "Type", { get: function () { return this.get("Type"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpClusters", { get: function () { return this.get("TpClusters"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclCCServers", { get: function () { return this.get("TpEclCCServers"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclServers", { get: function () { return this.get("TpEclServers"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclAgents", { get: function () { return this.get("TpEclAgents"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclSchedulers", { get: function () { return this.get("TpEclSchedulers"); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "MachineInfoEx", { get: function () { return this.get("MachineInfoEx", []); }, enumerable: true, configurable: true }); Object.defineProperty(TargetCluster.prototype, "CMachineInfoEx", { get: function () { var _this = this; return this.MachineInfoEx.map(function (machineInfoEx) { return Machine.attach(_this.machineConnection, machineInfoEx.Address, machineInfoEx); }); }, enumerable: true, configurable: true }); TargetCluster.attach = function (optsConnection, name, state) { var retVal = _targetCluster.get({ Name: name }, function () { return new TargetCluster(optsConnection, name); }); if (state) { retVal.set(tslib_1.__assign({}, state)); } return retVal; }; TargetCluster.prototype.fetchMachines = function (request) { var _this = this; if (request === void 0) { request = {}; } return this.machineConnection.GetTargetClusterInfo(tslib_1.__assign({ TargetClusters: { Item: [this.Type + ":" + this.Name] } }, request)).then(function (response) { var retVal = []; for (var _i = 0, _a = response.TargetClusterInfoList.TargetClusterInfo; _i < _a.length; _i++) { var machineInfo = _a[_i]; for (var _b = 0, _c = machineInfo.Processes.MachineInfoEx; _b < _c.length; _b++) { var machineInfoEx = _c[_b]; retVal.push(machineInfoEx); } } _this.set("MachineInfoEx", retVal); return _this.CMachineInfoEx; }); }; TargetCluster.prototype.machineStats = function () { var maxDisk = 0; var totalFree = 0; var total = 0; for (var _i = 0, _a = this.CMachineInfoEx; _i < _a.length; _i++) { var machine = _a[_i]; for (var _b = 0, _c = machine.Storage.StorageInfo; _b < _c.length; _b++) { var storageInfo = _c[_b]; totalFree += storageInfo.Available; total += storageInfo.Total; var usage = 1 - storageInfo.Available / storageInfo.Total; if (usage > maxDisk) { maxDisk = usage; } } } return { maxDisk: maxDisk, meanDisk: 1 - (total ? totalFree / total : 1) }; }; return TargetCluster; }(StateObject)); export { TargetCluster }; //# sourceMappingURL=targetCluster.js.map