UNPKG

@hpcc-js/comms

Version:
159 lines 6.13 kB
import { __extends } from "tslib"; import { Cache, exists, StateObject } from "@hpcc-js/util"; import { TopologyService } from "../services/wsTopology"; import { TargetCluster } from "./targetCluster"; var TopologyCache = /** @class */ (function (_super) { __extends(TopologyCache, _super); function TopologyCache() { return _super.call(this, function (obj) { return obj.BaseUrl; }) || this; } return TopologyCache; }(Cache)); export { TopologyCache }; var _topology = new TopologyCache(); var Topology = /** @class */ (function (_super) { __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, "BaseUrl", { get: function () { return this.connection.baseUrl; }, enumerable: false, configurable: true }); Object.defineProperty(Topology.prototype, "properties", { // Accessors --- get: function () { return this.get(); }, enumerable: false, configurable: true }); Object.defineProperty(Topology.prototype, "TargetClusters", { get: function () { return this.get("TargetClusters"); }, enumerable: false, 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: false, configurable: true }); Object.defineProperty(Topology.prototype, "LogicalClusters", { get: function () { return this.get("LogicalClusters"); }, enumerable: false, configurable: true }); Object.defineProperty(Topology.prototype, "Services", { get: function () { return this.get("Services"); }, enumerable: false, configurable: true }); Topology.attach = function (optsConnection, state) { var retVal = _topology.get({ BaseUrl: optsConnection.baseUrl }, function () { return new Topology(optsConnection); }); if (state) { retVal.set(state); } return retVal; }; 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 "".concat(rootProtocol, "//").concat(ip, ":").concat(port, "/"); }); }; Topology.prototype.fetchTargetClusters = function () { var _this = this; return this.connection.TpTargetClusterQuery({ Type: "ROOT" }).then(function (response) { var _a, _b; _this.set({ TargetClusters: (_b = (_a = response.TpTargetClusters) === null || _a === void 0 ? void 0 : _a.TpTargetCluster) !== null && _b !== void 0 ? _b : [] }); return _this.CTargetClusters; }); }; Topology.prototype.fetchLogicalClusters = function (request) { var _this = this; if (request === void 0) { request = {}; } return this.connection.TpLogicalClusterQuery(request).then(function (response) { _this.set({ LogicalClusters: response.TpLogicalClusters.TpLogicalCluster }); return _this.LogicalClusters; }); }; Topology.prototype.fetchServices = function (request) { var _this = this; if (request === void 0) { request = {}; } return this.connection.TpServiceQuery(request).then(function (response) { _this.set({ Services: response.ServiceList }); return _this.Services; }); }; Topology.prototype.refresh = function (force) { var _this = this; if (force === void 0) { force = false; } if (!this._prevRefresh || force) { this._prevRefresh = Promise.all([this.fetchTargetClusters(), this.fetchLogicalClusters(), this.fetchServices()]).then(function () { return _this; }); } return this._prevRefresh; }; // 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