UNPKG

@hpcc-js/comms

Version:
105 lines 4.18 kB
import * as tslib_1 from "tslib"; import { exists, StateObject } from "@hpcc-js/util"; import { TopologyService } from "../services/wsTopology"; import { TargetCluster } from "./targetCluster"; var Topology = /** @class */ (function (_super) { tslib_1.__extends(Topology, _super); function Topology(optsConnection) { var _this = _super.call(this) || this; if (optsConnection instanceof TopologyService) { _this.connection = optsConnection; } else { _this.connection = new TopologyService(optsConnection); } return _this; } Object.defineProperty(Topology.prototype, "properties", { // Accessors --- get: function () { return this.get(); }, enumerable: true, configurable: true }); Object.defineProperty(Topology.prototype, "TargetClusters", { get: function () { return this.get("TargetClusters"); }, enumerable: true, configurable: true }); Object.defineProperty(Topology.prototype, "CTargetClusters", { get: function () { var _this = this; return this.TargetClusters.map(function (tc) { return TargetCluster.attach(_this.connection, tc.Name, tc); }); }, enumerable: true, configurable: true }); Topology.prototype.GetESPServiceBaseURL = function (type) { var _this = this; if (type === void 0) { type = ""; } return this.connection.TpServiceQuery({}).then(function (response) { var rootProtocol = _this.connection.protocol(); var ip = _this.connection.ip(); var port = rootProtocol === "https:" ? "18002" : "8002"; if (exists("ServiceList.TpEspServers.TpEspServer", response)) { for (var _i = 0, _a = response.ServiceList.TpEspServers.TpEspServer; _i < _a.length; _i++) { var item = _a[_i]; if (exists("TpBindings.TpBinding", item)) { for (var _b = 0, _c = item.TpBindings.TpBinding; _b < _c.length; _b++) { var binding = _c[_b]; if (binding.Service === type && binding.Protocol + ":" === rootProtocol) { port = binding.Port; } } } } } return rootProtocol + "//" + ip + ":" + port + "/"; }); }; Topology.prototype.fetchTargetClusters = function () { var _this = this; return this.connection.TpTargetClusterQuery({ Type: "ROOT" }).then(function (response) { _this.set({ TargetClusters: response.TpTargetClusters.TpTargetCluster }); return _this.CTargetClusters; }); }; Topology.prototype.refresh = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.fetchTargetClusters()]; case 1: _a.sent(); return [2 /*return*/, this]; } }); }); }; // Monitoring --- // Events --- Topology.prototype.on = function (eventID, propIDorCallback, callback) { if (this.isCallback(propIDorCallback)) { switch (eventID) { case "changed": _super.prototype.on.call(this, eventID, propIDorCallback); break; default: } } else { switch (eventID) { case "changed": _super.prototype.on.call(this, eventID, propIDorCallback, callback); break; default: } } this._monitor(); return this; }; return Topology; }(StateObject)); export { Topology }; //# sourceMappingURL=topology.js.map