UNPKG

@hpcc-js/comms

Version:
1,302 lines (1,301 loc) 50.6 kB
import * as tslib_1 from "tslib"; import { Cache, deepMixinT, scopedLogger, StateObject, XMLNode } from "@hpcc-js/util"; import { utcFormat, utcParse } from "d3-time-format"; import * as WsTopology from "../services/wsTopology"; import * as WsWorkunits from "../services/wsWorkunits"; import { createGraph, createXGMMLGraph, ECLGraph, GraphCache } from "./graph"; import { Resource } from "./resource"; import { Result, ResultCache } from "./result"; import { Scope } from "./scope"; import { SourceFile } from "./sourceFile"; import { Timer } from "./timer"; var formatter = utcFormat("%Y-%m-%dT%H:%M:%S.%LZ"); var parser = utcParse("%Y-%m-%dT%H:%M:%S.%LZ"); var logger = scopedLogger("workunit.ts"); var WUStateID = WsWorkunits.WUStateID; var WorkunitCache = /** @class */ (function (_super) { tslib_1.__extends(WorkunitCache, _super); function WorkunitCache() { return _super.call(this, function (obj) { return obj.Wuid; }) || this; } return WorkunitCache; }(Cache)); export { WorkunitCache }; var _workunits = new WorkunitCache(); var Workunit = /** @class */ (function (_super) { tslib_1.__extends(Workunit, _super); // --- --- --- function Workunit(optsConnection, wuid) { var _this = _super.call(this) || this; _this._debugMode = false; _this._resultCache = new ResultCache(); _this._graphCache = new GraphCache(); _this.connection = new WsWorkunits.WorkunitsService(optsConnection); _this.topologyConnection = new WsTopology.TopologyService(optsConnection); _this.clearState(wuid); return _this; } Object.defineProperty(Workunit.prototype, "properties", { // Accessors --- get: function () { return this.get(); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Wuid", { get: function () { return this.get("Wuid"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Owner", { get: function () { return this.get("Owner", ""); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Cluster", { get: function () { return this.get("Cluster", ""); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Jobname", { get: function () { return this.get("Jobname", ""); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Description", { get: function () { return this.get("Description", ""); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ActionEx", { get: function () { return this.get("ActionEx", ""); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "StateID", { get: function () { return this.get("StateID", WsWorkunits.WUStateID.Unknown); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "State", { get: function () { return this.get("State") || WsWorkunits.WUStateID[this.StateID]; }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Protected", { get: function () { return this.get("Protected", false); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Exceptions", { get: function () { return this.get("Exceptions", { ECLException: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ResultViews", { get: function () { return this.get("ResultViews", []); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ResultCount", { get: function () { return this.get("ResultCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Results", { get: function () { return this.get("Results", { ECLResult: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "CResults", { get: function () { var _this = this; return this.Results.ECLResult.map(function (eclResult) { return _this._resultCache.get(eclResult, function () { return new Result(_this.connection, _this.Wuid, eclResult, _this.ResultViews); }); }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "SequenceResults", { get: function () { var retVal = {}; this.CResults.forEach(function (result) { retVal[result.Sequence] = result; }); return retVal; }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Timers", { get: function () { return this.get("Timers", { ECLTimer: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "CTimers", { get: function () { var _this = this; return this.Timers.ECLTimer.map(function (eclTimer) { return new Timer(_this.connection, _this.Wuid, eclTimer); }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "GraphCount", { get: function () { return this.get("GraphCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Graphs", { get: function () { return this.get("Graphs", { ECLGraph: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "CGraphs", { get: function () { var _this = this; return this.Graphs.ECLGraph.map(function (eclGraph) { return _this._graphCache.get(eclGraph, function () { return new ECLGraph(_this, eclGraph, _this.CTimers); }); }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ThorLogList", { get: function () { return this.get("ThorLogList"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ResourceURLCount", { get: function () { return this.get("ResourceURLCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ResourceURLs", { get: function () { return this.get("ResourceURLs", { URL: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "CResourceURLs", { get: function () { var _this = this; return this.ResourceURLs.URL.map(function (url) { return new Resource(_this, url); }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "TotalClusterTime", { get: function () { return this.get("TotalClusterTime", ""); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "DateTimeScheduled", { get: function () { return this.get("DateTimeScheduled"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "IsPausing", { get: function () { return this.get("IsPausing"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ThorLCR", { get: function () { return this.get("ThorLCR"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ApplicationValues", { get: function () { return this.get("ApplicationValues", { ApplicationValue: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "HasArchiveQuery", { get: function () { return this.get("HasArchiveQuery"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "StateEx", { get: function () { return this.get("StateEx"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "PriorityClass", { get: function () { return this.get("PriorityClass"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "PriorityLevel", { get: function () { return this.get("PriorityLevel"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Snapshot", { get: function () { return this.get("Snapshot"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ResultLimit", { get: function () { return this.get("ResultLimit"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "EventSchedule", { get: function () { return this.get("EventSchedule"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "HaveSubGraphTimings", { get: function () { return this.get("HaveSubGraphTimings"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Query", { get: function () { return this.get("Query"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "HelpersCount", { get: function () { return this.get("HelpersCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Helpers", { get: function () { return this.get("Helpers", { ECLHelpFile: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "DebugValues", { get: function () { return this.get("DebugValues"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "AllowedClusters", { get: function () { return this.get("AllowedClusters"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ErrorCount", { get: function () { return this.get("ErrorCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "WarningCount", { get: function () { return this.get("WarningCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "InfoCount", { get: function () { return this.get("InfoCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "AlertCount", { get: function () { return this.get("AlertCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "SourceFileCount", { get: function () { return this.get("SourceFileCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "SourceFiles", { get: function () { return this.get("SourceFiles", { ECLSourceFile: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "CSourceFiles", { get: function () { var _this = this; return this.SourceFiles.ECLSourceFile.map(function (eclSourceFile) { return new SourceFile(_this.connection, _this.Wuid, eclSourceFile); }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "VariableCount", { get: function () { return this.get("VariableCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Variables", { get: function () { return this.get("Variables", { ECLResult: [] }); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "TimerCount", { get: function () { return this.get("TimerCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "HasDebugValue", { get: function () { return this.get("HasDebugValue"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ApplicationValueCount", { get: function () { return this.get("ApplicationValueCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "XmlParams", { get: function () { return this.get("XmlParams"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "AccessFlag", { get: function () { return this.get("AccessFlag"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ClusterFlag", { get: function () { return this.get("ClusterFlag"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ResultViewCount", { get: function () { return this.get("ResultViewCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "DebugValueCount", { get: function () { return this.get("DebugValueCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "WorkflowCount", { get: function () { return this.get("WorkflowCount", 0); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Archived", { get: function () { return this.get("Archived"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "RoxieCluster", { get: function () { return this.get("RoxieCluster"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "DebugState", { get: function () { return this.get("DebugState", {}); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Queue", { get: function () { return this.get("Queue"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Active", { get: function () { return this.get("Active"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Action", { get: function () { return this.get("Action"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Scope", { get: function () { return this.get("Scope"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "AbortBy", { get: function () { return this.get("AbortBy"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "AbortTime", { get: function () { return this.get("AbortTime"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "Workflows", { get: function () { return this.get("Workflows"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "TimingData", { get: function () { return this.get("TimingData"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "HelpersDesc", { get: function () { return this.get("HelpersDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "GraphsDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "SourceFilesDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ResultsDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "VariablesDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "TimersDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "DebugValuesDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "ApplicationValuesDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); Object.defineProperty(Workunit.prototype, "WorkflowsDesc", { get: function () { return this.get("GraphsDesc"); }, enumerable: true, configurable: true }); // Factories --- Workunit.create = function (optsConnection) { var retVal = new Workunit(optsConnection); return retVal.connection.WUCreate().then(function (response) { _workunits.set(retVal); retVal.set(response.Workunit); return retVal; }); }; Workunit.attach = function (optsConnection, wuid, state) { var retVal = _workunits.get({ Wuid: wuid }, function () { return new Workunit(optsConnection, wuid); }); if (state) { retVal.set(state); } return retVal; }; Workunit.existsLocal = function (wuid) { return _workunits.has({ Wuid: wuid }); }; Workunit.submit = function (server, target, ecl) { return Workunit.create(server).then(function (wu) { return wu.update({ QueryText: ecl }); }).then(function (wu) { return wu.submit(target); }); }; Workunit.query = function (server, opts) { var wsWorkunits = new WsWorkunits.WorkunitsService(server); return wsWorkunits.WUQuery(opts).then(function (response) { return response.Workunits.ECLWorkunit.map(function (wu) { return Workunit.attach(server, wu.Wuid, wu); }); }); }; Workunit.prototype.clearState = function (wuid) { this.clear({ Wuid: wuid, StateID: WUStateID.Unknown }); }; Workunit.prototype.update = function (request) { var _this = this; return this.connection.WUUpdate(tslib_1.__assign({}, request, { Wuid: this.Wuid, StateOrig: this.State, JobnameOrig: this.Jobname, DescriptionOrig: this.Description, ProtectedOrig: this.Protected, ClusterOrig: this.Cluster })).then(function (response) { _this.set(response.Workunit); return _this; }); }; Workunit.prototype.submit = function (_cluster, action, resultLimit) { var _this = this; if (action === void 0) { action = WsWorkunits.WUUpdate.Action.Run; } var clusterPromise; if (_cluster !== void 0) { clusterPromise = Promise.resolve(_cluster); } else { clusterPromise = this.topologyConnection.DefaultTpLogicalClusterQuery().then(function (response) { return response.Name; }); } this._debugMode = false; if (action === WsWorkunits.WUUpdate.Action.Debug) { action = WsWorkunits.WUUpdate.Action.Run; this._debugMode = true; } return clusterPromise.then(function (cluster) { return _this.connection.WUUpdate({ Wuid: _this.Wuid, Action: action, ResultLimit: resultLimit, DebugValues: { DebugValue: [ { Name: "Debug", Value: _this._debugMode ? "1" : "" } ] } }).then(function (response) { _this.set(response.Workunit); _this._submitAction = action; return _this.connection.WUSubmit({ Wuid: _this.Wuid, Cluster: cluster }); }); }).then(function () { return _this; }); }; Workunit.prototype.isComplete = function () { switch (this.StateID) { case WUStateID.Compiled: return this.ActionEx === "compile" || this._submitAction === WsWorkunits.WUUpdate.Action.Compile; case WUStateID.Completed: case WUStateID.Failed: case WUStateID.Aborted: case WUStateID.NotFound: return true; default: } return false; }; Workunit.prototype.isFailed = function () { switch (this.StateID) { case WUStateID.Aborted: case WUStateID.Failed: return true; default: } return false; }; Workunit.prototype.isDeleted = function () { switch (this.StateID) { case WUStateID.NotFound: return true; default: } return false; }; Workunit.prototype.isDebugging = function () { switch (this.StateID) { case WUStateID.DebugPaused: case WUStateID.DebugRunning: return true; default: } return this._debugMode; }; Workunit.prototype.isRunning = function () { switch (this.StateID) { case WUStateID.Compiled: case WUStateID.Running: case WUStateID.Aborting: case WUStateID.Blocked: case WUStateID.DebugPaused: case WUStateID.DebugRunning: return true; default: } return false; }; Workunit.prototype.setToFailed = function () { return this.WUAction("SetToFailed"); }; Workunit.prototype.pause = function () { return this.WUAction("Pause"); }; Workunit.prototype.pauseNow = function () { return this.WUAction("PauseNow"); }; Workunit.prototype.resume = function () { return this.WUAction("Resume"); }; Workunit.prototype.abort = function () { return this.WUAction("Abort"); }; Workunit.prototype.delete = function () { return this.WUAction("Delete"); }; Workunit.prototype.restore = function () { return this.WUAction("Restore"); }; Workunit.prototype.deschedule = function () { return this.WUAction("Deschedule"); }; Workunit.prototype.reschedule = function () { return this.WUAction("Reschedule"); }; Workunit.prototype.resubmit = function () { var _this = this; return this.WUResubmit({ CloneWorkunit: false, ResetWorkflow: false }).then(function () { _this.clearState(_this.Wuid); return _this.refresh().then(function () { _this._monitor(); return _this; }); }); }; Workunit.prototype.clone = function () { var _this = this; return this.WUResubmit({ CloneWorkunit: true, ResetWorkflow: false }).then(function (response) { return Workunit.attach(_this.connection.connection(), response.WUs.WU[0].WUID) .refresh(); }); }; Workunit.prototype.refreshState = 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.WUQuery()]; case 1: _a.sent(); return [2 /*return*/, this]; } }); }); }; Workunit.prototype.refreshInfo = 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.WUInfo()]; case 1: _a.sent(); return [2 /*return*/, this]; } }); }); }; Workunit.prototype.refreshDebug = 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.debugStatus()]; case 1: _a.sent(); return [2 /*return*/, this]; } }); }); }; Workunit.prototype.refresh = function (full) { if (full === void 0) { full = false; } return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: if (!full) return [3 /*break*/, 2]; return [4 /*yield*/, Promise.all([this.refreshInfo(), this.refreshDebug()])]; case 1: _a.sent(); return [3 /*break*/, 4]; case 2: return [4 /*yield*/, this.refreshState()]; case 3: _a.sent(); _a.label = 4; case 4: return [2 /*return*/, this]; } }); }); }; Workunit.prototype.eclExceptions = function () { return this.Exceptions.ECLException; }; Workunit.prototype.fetchECLExceptions = function () { var _this = this; return this.WUInfo({ IncludeExceptions: true }).then(function () { return _this.eclExceptions(); }); }; Workunit.prototype.fetchResults = function () { var _this = this; return this.WUInfo({ IncludeResults: true }).then(function () { return _this.CResults; }); }; Workunit.prototype.fetchGraphs = function () { var _this = this; return this.WUInfo({ IncludeGraphs: true }).then(function () { return _this.CGraphs; }); }; Workunit.prototype.fetchDetailsMeta = function (request) { if (request === void 0) { request = {}; } return this.WUDetailsMeta(request); }; Workunit.prototype.fetchDetailsRaw = function (request) { if (request === void 0) { request = {}; } return this.WUDetails(request).then(function (response) { return response.Scopes.Scope; }); }; Workunit.prototype.fetchDetailsNormalized = function (request) { if (request === void 0) { request = {}; } return Promise.all([this.fetchDetailsMeta(), this.fetchDetailsRaw(request)]).then(function (promises) { var meta = promises[0]; var scopes = promises[1]; var columns = { id: { Measure: "label" }, name: { Measure: "label" }, type: { Measure: "label" } }; var data = []; for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) { var scope = scopes_1[_i]; var props = {}; if (scope && scope.Id && scope.Properties && scope.Properties.Property) { for (var key in scope.Properties.Property) { var scopeProperty = scope.Properties.Property[key]; if (scopeProperty.Measure === "ns") { scopeProperty.Measure = "s"; } columns[scopeProperty.Name] = tslib_1.__assign({}, scopeProperty); delete columns[scopeProperty.Name].RawValue; delete columns[scopeProperty.Name].Formatted; switch (scopeProperty.Measure) { case "bool": props[scopeProperty.Name] = !!+scopeProperty.RawValue; break; case "sz": props[scopeProperty.Name] = +scopeProperty.RawValue; break; case "s": props[scopeProperty.Name] = +scopeProperty.RawValue / 1000000000; break; case "ns": props[scopeProperty.Name] = +scopeProperty.RawValue; break; case "ts": props[scopeProperty.Name] = new Date(+scopeProperty.RawValue / 1000).toISOString(); break; case "cnt": props[scopeProperty.Name] = +scopeProperty.RawValue; break; case "cpu": case "skw": case "node": case "ppm": case "ip": case "cy": case "en": case "txt": case "id": case "fname": default: props[scopeProperty.Name] = scopeProperty.RawValue; } } data.push(tslib_1.__assign({ id: scope.Id, name: scope.ScopeName, type: scope.ScopeType }, props)); } } return { meta: meta, columns: columns, data: data }; }); }; Workunit.prototype.fetchDetails = function (request) { var _this = this; if (request === void 0) { request = {}; } return this.WUDetails(request).then(function (response) { return response.Scopes.Scope.map(function (rawScope) { return new Scope(_this, rawScope); }); }); }; Workunit.prototype.fetchDetailsHierarchy = function (request) { var _this = this; if (request === void 0) { request = {}; } return this.WUDetails(request).then(function (response) { var retVal = []; // Recreate Scope Hierarchy and dedup --- var scopeMap = {}; response.Scopes.Scope.forEach(function (rawScope) { if (scopeMap[rawScope.ScopeName]) { scopeMap[rawScope.ScopeName].update(rawScope); return null; } else { var scope = new Scope(_this, rawScope); scopeMap[scope.ScopeName] = scope; return scope; } }); for (var key in scopeMap) { if (scopeMap.hasOwnProperty(key)) { var scope = scopeMap[key]; var parentScopeID = scope.parentScope(); if (parentScopeID && scopeMap[parentScopeID]) { scopeMap[parentScopeID].children().push(scope); } else { retVal.push(scope); } } } return retVal; }); }; Workunit.prototype.fetchGraphDetails = function (graphIDs, rootTypes) { if (graphIDs === void 0) { graphIDs = []; } return this.fetchDetails({ ScopeFilter: { MaxDepth: 999999, Ids: graphIDs, ScopeTypes: rootTypes }, NestedFilter: { Depth: 999999, ScopeTypes: ["graph", "subgraph", "activity", "edge"] }, PropertiesToReturn: { AllStatistics: true, AllAttributes: true, AllHints: true, AllProperties: true, AllScopes: true }, ScopeOptions: { IncludeId: true, IncludeScope: true, IncludeScopeType: true }, PropertyOptions: { IncludeName: true, IncludeRawValue: true, IncludeFormatted: true, IncludeMeasure: true, IncludeCreator: false, IncludeCreatorType: false } }); }; Workunit.prototype.fetchScopeGraphs = function (graphIDs) { if (graphIDs === void 0) { graphIDs = []; } return this.fetchGraphDetails(graphIDs, ["graph"]).then(function (scopes) { return createGraph(scopes); }); }; Workunit.prototype.fetchTimeElapsed = function () { return this.fetchDetails({ ScopeFilter: { PropertyFilters: { PropertyFilter: [{ Name: "TimeElapsed" }] } } }).then(function (scopes) { var scopeInfo = {}; scopes.forEach(function (scope) { scopeInfo[scope.ScopeName] = scopeInfo[scope.ScopeName] || { scope: scope.ScopeName, start: null, elapsed: null, finish: null }; scope.CAttributes.forEach(function (attr) { if (attr.Name === "TimeElapsed") { scopeInfo[scope.ScopeName].elapsed = +attr.RawValue; } else if (attr.Measure === "ts" && attr.Name.indexOf("Started") >= 0) { scopeInfo[scope.ScopeName].start = attr.Formatted; } }); }); // Workaround duplicate scope responses var retVal = []; for (var key in scopeInfo) { var scope = scopeInfo[key]; if (scope.start && scope.elapsed) { var endTime = parser(scope.start); endTime.setMilliseconds(endTime.getMilliseconds() + scope.elapsed / 1000000); scope.finish = formatter(endTime); retVal.push(scope); } } retVal.sort(function (l, r) { if (l.start < r.start) return -1; if (l.start > r.start) return 1; return 0; }); return retVal; }); }; // Monitoring --- Workunit.prototype._monitor = function () { if (this.isComplete()) { this._monitorTickCount = 0; return; } _super.prototype._monitor.call(this); }; Workunit.prototype._monitorTimeoutDuraction = function () { var retVal = _super.prototype._monitorTimeoutDuraction.call(this); if (this._monitorTickCount <= 1) { // Once return 0; } else if (this._monitorTickCount <= 3) { // Twice return 500; } else if (this._monitorTickCount <= 5) { // Twice return 1000; } else if (this._monitorTickCount <= 7) { // Twice return 3000; } else if (this._monitorTickCount <= 9) { // Twice return 5000; } else if (this._monitorTickCount <= 11) { // Twice return 10000; } return retVal; }; // Events --- Workunit.prototype.on = function (eventID, propIDorCallback, callback) { var _this = this; if (this.isCallback(propIDorCallback)) { switch (eventID) { case "completed": _super.prototype.on.call(this, "propChanged", "StateID", function (changeInfo) { if (_this.isComplete()) { propIDorCallback([changeInfo]); } }); break; 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; }; Workunit.prototype.watchUntilComplete = function (callback) { var _this = this; return new Promise(function (resolve, _) { var watchHandle = _this.watch(function (changes) { if (callback) { callback(changes); } if (_this.isComplete()) { watchHandle.release(); resolve(_this); } }); }); }; Workunit.prototype.watchUntilRunning = function (callback) { var _this = this; return new Promise(function (resolve, _) { var watchHandle = _this.watch(function (changes) { if (callback) { callback(changes); } if (_this.isComplete() || _this.isRunning()) { watchHandle.release(); resolve(_this); } }); }); }; // WsWorkunits passthroughs --- Workunit.prototype.WUQuery = function (_request) { var _this = this; if (_request === void 0) { _request = {}; } return this.connection.WUQuery(tslib_1.__assign({}, _request, { Wuid: this.Wuid })).then(function (response) { _this.set(response.Workunits.ECLWorkunit[0]); return response; }).catch(function (e) { // deleted --- var wuMissing = e.Exception.some(function (exception) { if (exception.Code === 20081) { _this.clearState(_this.Wuid); _this.set("StateID", WUStateID.NotFound); return true; } return false; }); if (!wuMissing) { logger.warning("Unexpected exception: "); throw e; } return {}; }); }; Workunit.prototype.WUCreate = function () { var _this = this; return this.connection.WUCreate().then(function (response) { _this.set(response.Workunit); _workunits.set(_this); return response; }); }; Workunit.prototype.WUInfo = function (_request) { var _this = this; if (_request === void 0) { _request = {}; } var includeResults = _request.IncludeResults || _request.IncludeResultsViewNames; return this.connection.WUInfo(tslib_1.__assign({}, _request, { Wuid: this.Wuid, IncludeResults: includeResults, IncludeResultsViewNames: includeResults, SuppressResultSchemas: false })).then(function (response) { if (response.Workunit.ResourceURLCount) { response.Workunit.ResourceURLCount = response.Workunit.ResourceURLCount - 1; } if (response.Workunit.ResourceURLs && response.Workunit.ResourceURLs.URL) { response.Workunit.ResourceURLs.URL = response.Workunit.ResourceURLs.URL.filter(function (_, idx) { return idx > 0; }); } _this.set(response.Workunit); _this.set({ ResultViews: includeResults ? response.ResultViews : [], HelpersCount: response.Workunit.Helpers && response.Workunit.Helpers.ECLHelpFile ? response.Workunit.Helpers.ECLHelpFile.length : 0 }); return response; }).catch(function (e) { // deleted --- var wuMissing = e.Exception.some(function (exception) { if (exception.Code === 20080) { _this.clearState(_this.Wuid); _this.set("StateID", WUStateID.NotFound); return true; } return false; }); if (!wuMissing) { logger.warning("Unexpected exception: "); throw e; } return {}; }); }; Workunit.prototype.WUResubmit = function (request) { return this.connection.WUResubmit(deepMixinT({}, request, { Wuids: [this.Wuid] })); }; Workunit.prototype.WUDetailsMeta = function (request) { return this.connection.WUDetailsMeta(request); }; Workunit.prototype.WUDetails = function (request) { return this.connection.WUDetails(deepMixinT({ ScopeFilter: { MaxDepth: 9999 }, ScopeOptions: { IncludeMatchedScopesInResults: true, IncludeScope: true, IncludeId: false, IncludeScopeType: false }, PropertyOptions: { IncludeName: true, IncludeRawValue: false, IncludeFormatted: true, IncludeMeasure: true, IncludeCreator: false, IncludeCreatorType: false } }, request, { WUID: this.Wuid })).then(function (response) { return deepMixinT({ Scopes: { Scope: [] } }, response); }); }; Workunit.prototype.WUAction = function (actionType) { var _this = this; return this.connection.WUAction({ Wuids: [this.Wuid], WUActionType: actionType }).then(function (response) { return _this.refresh().then(function () { _this._monitor(); return response; }); }); }; Workunit.prototype.WUCDebug = function (command, opts) { if (opts === void 0) { opts = {}; } var optsStr = ""; for (var key in opts) { if (opts.hasOwnProperty(key)) { optsStr += " " + key + "='" + opts[key] + "'"; } } return this.connection.WUCDebug({ Wuid: this.Wuid, Command: "<debug:" + command + " uid='" + this.Wuid + "'" + optsStr + "/>" }).then(function (response) { return response; }); }; Workunit.prototype.debug = function (command, opts) { if (!this.isDebugging()) { return Promise.resolve(new XMLNode(command)); } return this.WUCDebug(command, opts).then(function (response) { var retVal = response.children(command); if (retVal.length) { return retVal[0]; } return new XMLNode(command); }).catch(function (_) { logger.error(_); return Promise.resolve(new XMLNode(command)); }); }; Workunit.prototype.debugStatus = function () { var _this = this; if (!this.isDebugging()) { return Promise.resolve({ DebugState: { state: "unknown" } }); } return this.debug("status").then(function (response) { var debugState = tslib_1.__assign({}, _this.DebugState, response.$); _this.set({ DebugState: debugState }); return response; }); }; Workunit.prototype.debugContinue = function (mode) { if (mode === void 0) { mode = ""; } return this.debug("continue", { mode: mode }); }; Workunit.prototype.debugStep = function (mode) { return this.debug("step", { mode: mode }); }; Workunit.prototype.debugPause = function () { return this.debug("interrupt"); }; Workunit.prototype.debugQuit = function () { return this.debug("quit"); }; Workunit.prototype.debugDeleteAllBreakpoints = function () { return this.debug("delete", { idx: 0 }); }; Workunit.prototype.debugBreakpointResponseParser = function (rootNode) { return rootNode.children().map(function (childNode) { if (childNode.name === "break") { return childNode.$; } }); }; Workunit.prototype.debugBreakpointAdd = function (id, mode, action) { var _this = this; return this.debug("breakpoint", { id: id, mode: mode, action: action }).then(function (rootNode) { return _this.debugBreakpointResponseParser(rootNode); }); }; Workunit.prototype.debugBreakpointList = function () { var _this = this; return this.debug("list").then(function (rootNode) { return _this.debugBreakpointResponseParser(rootNode); }); }; Workunit.prototype.debugGraph = function () { var _this = this; if (this._debugAllGraph && this.DebugState["_prevGraphSequenceNum"] === this.DebugState["graphSequenceNum"]) { return Promise.resolve(this._debugAllGraph); } return this.debug("graph", { name: "all" }).then(function (response) { _this.DebugState["_prevGraphSequenceNum"] = _this.DebugState["graphSequenceNum"]; _this._debugAllGraph = createXGMMLGraph(_this.Wuid, response); return _this._debugAllGraph; }); }; Workunit.prototype.debugBreakpointValid = function (path) { return this.debugGraph().then(function (graph) { return breakpointLocations(graph, path); }); }; Workunit.prototype.debugPrint = function (edgeID, startRow, numRows) { if (startRow === void 0) { startRow = 0; } if (numRows === void 0) { numRows = 10; } return this.debug("print", { edgeID: edgeID, startRow: startRow, numRows: numRows }).then(function (response) { return response.children().map(function (rowNode) { var retVal = {}; rowNode.children().forEach(function (cellNode) { retVal[cellNode.name] = cellNode.content; }); return retVal; }); }); }; return Workunit; }(StateObject)); export { Workunit }; var ATTR_DEFINITION = "definition"; function hasECLDefinition(vertex) { return vertex._[ATTR_DEFINITION] !== undefined; } function getECLDefinition(vertex) { var match = /([a-z]:\\(?:[-\w\.\d]+\\)*(?:[-\w\.\d]+)?|(?:\/[\w\.\-]+)+)\((\d*),(\d*)\)/.exec(vertex._[ATTR_DEFINITION]); if (match) { var _file = match[1], _row = match[2], _col = match[3]; _file.replace("/./", "/"); return { id: vertex._["id"], file: _file, line: +_row,