UNPKG

@hpcc-js/comms

Version:
194 lines 7.67 kB
import { __assign, __extends } 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) { __extends(TargetClusterCache, _super); function TargetClusterCache() { return _super.call(this, function (obj) { return "".concat(obj.BaseUrl, "-").concat(obj.Name); }) || this; } return TargetClusterCache; }(Cache)); export { TargetClusterCache }; var _targetCluster = new TargetClusterCache(); var TargetCluster = /** @class */ (function (_super) { __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, "BaseUrl", { get: function () { return this.connection.baseUrl; }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "Name", { get: function () { return this.get("Name"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "Prefix", { get: function () { return this.get("Prefix"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "Type", { get: function () { return this.get("Type"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "IsDefault", { get: function () { return this.get("IsDefault"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpClusters", { get: function () { return this.get("TpClusters"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclCCServers", { get: function () { return this.get("TpEclCCServers"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclServers", { get: function () { return this.get("TpEclServers"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclAgents", { get: function () { return this.get("TpEclAgents"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "TpEclSchedulers", { get: function () { return this.get("TpEclSchedulers"); }, enumerable: false, configurable: true }); Object.defineProperty(TargetCluster.prototype, "MachineInfoEx", { get: function () { return this.get("MachineInfoEx", []); }, enumerable: false, 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: false, configurable: true }); TargetCluster.attach = function (optsConnection, name, state) { var retVal = _targetCluster.get({ BaseUrl: optsConnection.baseUrl, Name: name }, function () { return new TargetCluster(optsConnection, name); }); if (state) { retVal.set(state); } return retVal; }; TargetCluster.prototype.fetchMachines = function (request) { var _this = this; if (request === void 0) { request = {}; } return this.machineConnection.GetTargetClusterInfo(__assign({ TargetClusters: { Item: ["".concat(this.Type, ":").concat(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) }; }; TargetCluster.prototype.fetchUsage = function () { return this.machineConnection.GetTargetClusterUsageEx([this.Name]); }; return TargetCluster; }(StateObject)); export { TargetCluster }; export function targetClusters(optsConnection) { var connection; if (optsConnection instanceof TopologyService) { connection = optsConnection; } else { connection = new TopologyService(optsConnection); } return connection.TpListTargetClusters({}).then(function (response) { return response.TargetClusters.TpClusterNameType.map(function (item) { return TargetCluster.attach(optsConnection, item.Name, item); }); }); } var _defaultTargetCluster = {}; export function defaultTargetCluster(optsConnection) { if (!_defaultTargetCluster[optsConnection.baseUrl]) { var connection = void 0; if (optsConnection instanceof TopologyService) { connection = optsConnection; } else { connection = new TopologyService(optsConnection); } _defaultTargetCluster[optsConnection.baseUrl] = connection.TpListTargetClusters({}).then(function (response) { var firstItem; var defaultItem; var hthorItem; response.TargetClusters.TpClusterNameType.forEach(function (item) { if (!firstItem) { firstItem = item; } if (!defaultItem && item.IsDefault === true) { defaultItem = item; } if (!hthorItem && item.Type === "hthor") { hthorItem = item; } }); var defItem = defaultItem || hthorItem || firstItem; return TargetCluster.attach(optsConnection, defItem.Name, defItem); }); } return _defaultTargetCluster[optsConnection.baseUrl]; } //# sourceMappingURL=targetCluster.js.map