@hpcc-js/comms
Version:
hpcc-js - Communications
1,280 lines • 60.3 kB
JavaScript
import { __assign, __awaiter, __extends, __generator } from "tslib";
import { Cache, deepMixinT, scopedLogger, StateObject, XMLNode } from "@hpcc-js/util";
import { format as d3Format } from "d3-format";
import { utcFormat, utcParse } from "d3-time-format";
import * as WsTopology from "../services/wsTopology";
import { WsWorkunits, WUStateID, WorkunitsService, WorkunitsServiceEx, WUUpdate } 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 d3FormatNum = d3Format(",");
function formatNum(num) {
if (num && !isNaN(+num)) {
return d3FormatNum(+num);
}
return num;
}
function safeDelete(obj, key, prop) {
if (obj[key] === undefined || obj[key][prop] === undefined)
return;
if (key === "__proto__" || key === "constructor" || key === "prototype")
return;
delete obj[key][prop];
}
var DEFINITION_LIST = "DefinitionList";
var definitionRegex = /([a-zA-Z]:)?(.*[\\\/])(.*)(\((\d+),(\d+)\))/;
export var PropertyType = ["Avg", "Min", "Max", "Delta", "StdDev"];
export var RelatedProperty = ["SkewMin", "SkewMax", "NodeMin", "NodeMax"];
var metricKeyRegex = /[A-Z][a-z]*/g;
function _splitMetric(fullLabel) {
// Related properties ---
for (var _i = 0, RelatedProperty_1 = RelatedProperty; _i < RelatedProperty_1.length; _i++) {
var relProp = RelatedProperty_1[_i];
var index = fullLabel.indexOf(relProp);
if (index === 0) {
var measure = "";
var label = fullLabel.slice(index + relProp.length);
return { measure: measure, ext: relProp, label: label };
}
}
// Primary properties ---
var labelParts = fullLabel.match(metricKeyRegex);
if (labelParts === null || labelParts === void 0 ? void 0 : labelParts.length) {
var measure = labelParts.shift();
var label = labelParts.join("");
for (var _a = 0, PropertyType_1 = PropertyType; _a < PropertyType_1.length; _a++) {
var ext = PropertyType_1[_a];
var index = label.indexOf(ext);
if (index === 0) {
label = label.slice(index + ext.length);
return { measure: measure, ext: ext, label: label };
}
}
// Not an aggregate property ---
return { measure: measure, ext: "", label: label };
}
// No match found ---
return { measure: "", ext: "", label: fullLabel };
}
var splitLabelCache = {};
export function splitMetric(key) {
var retVal = splitLabelCache[key];
if (!retVal) {
retVal = _splitMetric(key);
splitLabelCache[key] = retVal;
}
return retVal;
}
function formatValue(item, key) {
var _a, _b;
return (_b = (_a = item.__formattedProps) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : item[key];
}
function safeParseFloat(val) {
if (val === undefined)
return undefined;
var retVal = parseFloat(val);
return isNaN(retVal) ? undefined : retVal;
}
function formatValues(item, key, dedup) {
var keyParts = splitMetric(key);
if (!dedup[keyParts.measure]) {
dedup[keyParts.label] = true;
var avg = safeParseFloat(item["".concat(keyParts.measure, "Avg").concat(keyParts.label)]);
var min = safeParseFloat(item["".concat(keyParts.measure, "Min").concat(keyParts.label)]);
var max = safeParseFloat(item["".concat(keyParts.measure, "Max").concat(keyParts.label)]);
var stdDev = safeParseFloat(item["".concat(keyParts.measure, "StdDev").concat(keyParts.label)]);
var StdDevs = Math.max((avg - min) / stdDev, (max - avg) / stdDev);
return {
Key: "".concat(keyParts.measure).concat(keyParts.label),
Value: formatValue(item, "".concat(keyParts.measure).concat(keyParts.label)),
// Extended properties ---
Avg: formatValue(item, "".concat(keyParts.measure, "Avg").concat(keyParts.label)),
Min: formatValue(item, "".concat(keyParts.measure, "Min").concat(keyParts.label)),
Max: formatValue(item, "".concat(keyParts.measure, "Max").concat(keyParts.label)),
Delta: formatValue(item, "".concat(keyParts.measure, "Delta").concat(keyParts.label)),
StdDev: formatValue(item, "".concat(keyParts.measure, "StdDev").concat(keyParts.label)),
StdDevs: isNaN(StdDevs) ? undefined : StdDevs,
// Related properties ---
SkewMin: formatValue(item, "SkewMin".concat(keyParts.label)),
SkewMax: formatValue(item, "SkewMax".concat(keyParts.label)),
NodeMin: formatValue(item, "NodeMin".concat(keyParts.label)),
NodeMax: formatValue(item, "NodeMax".concat(keyParts.label))
};
}
return null;
}
var logger = scopedLogger("workunit.ts");
var WorkunitCache = /** @class */ (function (_super) {
__extends(WorkunitCache, _super);
function WorkunitCache() {
return _super.call(this, function (obj) {
return "".concat(obj.BaseUrl, "-").concat(obj.Wuid);
}) || this;
}
return WorkunitCache;
}(Cache));
export { WorkunitCache };
var _workunits = new WorkunitCache();
var Workunit = /** @class */ (function (_super) {
__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 WorkunitsService(optsConnection);
_this.topologyConnection = new WsTopology.TopologyService(optsConnection);
_this.clearState(wuid);
return _this;
}
Object.defineProperty(Workunit.prototype, "BaseUrl", {
get: function () { return this.connection.baseUrl; },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "properties", {
// Accessors ---
get: function () { return this.get(); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Wuid", {
get: function () { return this.get("Wuid"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Owner", {
get: function () { return this.get("Owner", ""); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Cluster", {
get: function () { return this.get("Cluster", ""); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Jobname", {
get: function () { return this.get("Jobname", ""); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Description", {
get: function () { return this.get("Description", ""); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ActionEx", {
get: function () { return this.get("ActionEx", ""); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "StateID", {
get: function () { return this.get("StateID", WUStateID.Unknown); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "State", {
get: function () { return this.get("State") || WUStateID[this.StateID]; },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Protected", {
get: function () { return this.get("Protected", false); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Exceptions", {
get: function () { return this.get("Exceptions", { ECLException: [] }); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ResultViews", {
get: function () { return this.get("ResultViews", { View: [] }); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ResultCount", {
get: function () { return this.get("ResultCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Results", {
get: function () { return this.get("Results", { ECLResult: [] }); },
enumerable: false,
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 Result.attach(_this.connection, _this.Wuid, eclResult, _this.ResultViews.View);
});
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "SequenceResults", {
get: function () {
var retVal = {};
this.CResults.forEach(function (result) {
retVal[result.Sequence] = result;
});
return retVal;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Timers", {
get: function () { return this.get("Timers", { ECLTimer: [] }); },
enumerable: false,
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: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "GraphCount", {
get: function () { return this.get("GraphCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Graphs", {
get: function () { return this.get("Graphs", { ECLGraph: [] }); },
enumerable: false,
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: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ThorLogList", {
get: function () { return this.get("ThorLogList"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ResourceURLCount", {
get: function () { return this.get("ResourceURLCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ResourceURLs", {
get: function () { return this.get("ResourceURLs", { URL: [] }); },
enumerable: false,
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: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "TotalClusterTime", {
get: function () { return this.get("TotalClusterTime", ""); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "DateTimeScheduled", {
get: function () { return this.get("DateTimeScheduled"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "IsPausing", {
get: function () { return this.get("IsPausing"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ThorLCR", {
get: function () { return this.get("ThorLCR"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ApplicationValues", {
get: function () { return this.get("ApplicationValues", { ApplicationValue: [] }); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "HasArchiveQuery", {
get: function () { return this.get("HasArchiveQuery"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "StateEx", {
get: function () { return this.get("StateEx"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "PriorityClass", {
get: function () { return this.get("PriorityClass"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "PriorityLevel", {
get: function () { return this.get("PriorityLevel"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Snapshot", {
get: function () { return this.get("Snapshot"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ResultLimit", {
get: function () { return this.get("ResultLimit"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "EventSchedule", {
get: function () { return this.get("EventSchedule"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Query", {
get: function () { return this.get("Query"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "HelpersCount", {
get: function () { return this.get("HelpersCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Helpers", {
get: function () { return this.get("Helpers", { ECLHelpFile: [] }); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "DebugValues", {
get: function () { return this.get("DebugValues"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "AllowedClusters", {
get: function () { return this.get("AllowedClusters"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ErrorCount", {
get: function () { return this.get("ErrorCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "WarningCount", {
get: function () { return this.get("WarningCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "InfoCount", {
get: function () { return this.get("InfoCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "AlertCount", {
get: function () { return this.get("AlertCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "SourceFileCount", {
get: function () { return this.get("SourceFileCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "SourceFiles", {
get: function () { return this.get("SourceFiles", { ECLSourceFile: [] }); },
enumerable: false,
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: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "VariableCount", {
get: function () { return this.get("VariableCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Variables", {
get: function () { return this.get("Variables", { ECLResult: [] }); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "TimerCount", {
get: function () { return this.get("TimerCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "HasDebugValue", {
get: function () { return this.get("HasDebugValue"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ApplicationValueCount", {
get: function () { return this.get("ApplicationValueCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "XmlParams", {
get: function () { return this.get("XmlParams"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "AccessFlag", {
get: function () { return this.get("AccessFlag"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ClusterFlag", {
get: function () { return this.get("ClusterFlag"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ResultViewCount", {
get: function () { return this.get("ResultViewCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "DebugValueCount", {
get: function () { return this.get("DebugValueCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "WorkflowCount", {
get: function () { return this.get("WorkflowCount", 0); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Archived", {
get: function () { return this.get("Archived"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "RoxieCluster", {
get: function () { return this.get("RoxieCluster"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "DebugState", {
get: function () { return this.get("DebugState", {}); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Queue", {
get: function () { return this.get("Queue"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Active", {
get: function () { return this.get("Active"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Action", {
get: function () { return this.get("Action"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Scope", {
get: function () { return this.get("Scope"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "AbortBy", {
get: function () { return this.get("AbortBy"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "AbortTime", {
get: function () { return this.get("AbortTime"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "Workflows", {
get: function () { return this.get("Workflows"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "TimingData", {
get: function () { return this.get("TimingData"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "HelpersDesc", {
get: function () { return this.get("HelpersDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "GraphsDesc", {
get: function () { return this.get("GraphsDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "SourceFilesDesc", {
get: function () { return this.get("SourceFilesDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ResultsDesc", {
get: function () { return this.get("ResultsDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "VariablesDesc", {
get: function () { return this.get("VariablesDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "TimersDesc", {
get: function () { return this.get("TimersDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "DebugValuesDesc", {
get: function () { return this.get("DebugValuesDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ApplicationValuesDesc", {
get: function () { return this.get("ApplicationValuesDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "WorkflowsDesc", {
get: function () { return this.get("WorkflowsDesc"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ServiceNames", {
get: function () { return this.get("ServiceNames"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "CompileCost", {
get: function () { return this.get("CompileCost"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ExecuteCost", {
get: function () { return this.get("ExecuteCost"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "FileAccessCost", {
get: function () { return this.get("FileAccessCost"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "NoAccess", {
get: function () { return this.get("NoAccess"); },
enumerable: false,
configurable: true
});
Object.defineProperty(Workunit.prototype, "ECLWUProcessList", {
get: function () { return this.get("ECLWUProcessList"); },
enumerable: false,
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({ BaseUrl: optsConnection.baseUrl, Wuid: wuid }, function () {
return new Workunit(optsConnection, wuid);
});
if (state) {
retVal.set(state);
}
return retVal;
};
Workunit.existsLocal = function (baseUrl, wuid) {
return _workunits.has({ BaseUrl: baseUrl, Wuid: wuid });
};
Workunit.submit = function (server, target, ecl, compileOnly) {
if (compileOnly === void 0) { compileOnly = false; }
return Workunit.create(server).then(function (wu) {
return wu.update({ QueryText: ecl });
}).then(function (wu) {
return compileOnly ? wu.submit(target, WUUpdate.Action.Compile) : wu.submit(target);
});
};
Workunit.compile = function (server, target, ecl) {
return Workunit.submit(server, target, ecl, true);
};
Workunit.query = function (server, opts) {
var wsWorkunits = new 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(__assign(__assign({}, request), {
Wuid: this.Wuid,
StateOrig: this.StateID,
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 = 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 === WUUpdate.Action.Debug) {
action = 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 === 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(WsWorkunits.ECLWUActions.SetToFailed);
};
Workunit.prototype.pause = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Pause);
};
Workunit.prototype.pauseNow = function () {
return this.WUAction(WsWorkunits.ECLWUActions.PauseNow);
};
Workunit.prototype.resume = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Resume);
};
Workunit.prototype.abort = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Abort);
};
Workunit.prototype.protect = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Protect);
};
Workunit.prototype.unprotect = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Unprotect);
};
Workunit.prototype.delete = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Delete);
};
Workunit.prototype.restore = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Restore);
};
Workunit.prototype.deschedule = function () {
return this.WUAction(WsWorkunits.ECLWUActions.Deschedule);
};
Workunit.prototype.reschedule = function () {
return this.WUAction(WsWorkunits.ECLWUActions.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.opts(), response.WUs.WU[0].WUID)
.refresh();
});
};
Workunit.prototype.refreshState = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.WUQuery()];
case 1:
_a.sent();
if (!(this.StateID === WUStateID.Compiled && !this.ActionEx && !this._submitAction)) return [3 /*break*/, 3];
return [4 /*yield*/, this.refreshInfo()];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/, this];
}
});
});
};
Workunit.prototype.refreshInfo = function (request) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.WUInfo(request)];
case 1:
_a.sent();
return [2 /*return*/, this];
}
});
});
};
Workunit.prototype.refreshDebug = function () {
return __awaiter(this, void 0, void 0, function () {
return __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 () {
return __awaiter(this, arguments, void 0, function (full, request) {
if (full === void 0) { full = false; }
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!full) return [3 /*break*/, 2];
return [4 /*yield*/, Promise.all([this.refreshInfo(request), 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.fetchArchive = function () {
return this.connection.WUFileEx({
Wuid: this.Wuid,
Type: "ArchiveQuery"
});
};
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.fetchQuery = function () {
var _this = this;
return this.WUInfo({ IncludeECL: true, TruncateEclTo64k: false }).then(function () {
return _this.Query;
});
};
Workunit.prototype.fetchHelpers = function () {
var _this = this;
return this.WUInfo({ IncludeHelpers: true }).then(function () {
var _a;
return ((_a = _this.Helpers) === null || _a === void 0 ? void 0 : _a.ECLHelpFile) || [];
});
};
Workunit.prototype.fetchAllowedClusters = function () {
var _this = this;
return this.WUInfo({ IncludeAllowedClusters: true }).then(function () {
var _a;
return ((_a = _this.AllowedClusters) === null || _a === void 0 ? void 0 : _a.AllowedCluster) || [];
});
};
Workunit.prototype.fetchTotalClusterTime = function () {
var _this = this;
return this.WUInfo({ IncludeTotalClusterTime: true }).then(function () {
return _this.TotalClusterTime;
});
};
Workunit.prototype.fetchServiceNames = function () {
var _this = this;
return this.WUInfo({ IncludeServiceNames: true }).then(function () {
var _a;
return (_a = _this.ServiceNames) === null || _a === void 0 ? void 0 : _a.Item;
});
};
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.normalizeDetails = function (meta, scopes) {
var _a, _b;
var columns = {
id: {
Measure: "label"
},
name: {
Measure: "label"
},
type: {
Measure: "label"
}
};
var data = [];
var _loop_1 = function (scope) {
var props = {};
var formattedProps = {};
if (scope && scope.Id && scope.Properties && scope.Properties.Property) {
var _loop_2 = function (key) {
var scopeProperty = scope.Properties.Property[key];
if (scopeProperty.Measure === "ns") {
scopeProperty.Measure = "s";
}
if (scopeProperty.Name === "Kind") {
var rawValue_1 = parseInt(scopeProperty.RawValue, 10);
scopeProperty.Formatted = (_a = meta.Activities.Activity.filter(function (a) { return a.Kind === rawValue_1; })[0].Name) !== null && _a !== void 0 ? _a : scopeProperty.RawValue;
}
columns[scopeProperty.Name] = __assign({}, scopeProperty);
safeDelete(columns, scopeProperty.Name, "RawValue");
safeDelete(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 "cost":
props[scopeProperty.Name] = +scopeProperty.RawValue / 1000000;
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;
}
formattedProps[scopeProperty.Name] = formatNum((_b = scopeProperty.Formatted) !== null && _b !== void 0 ? _b : props[scopeProperty.Name]);
};
for (var key in scope.Properties.Property) {
_loop_2(key);
}
// Other properties ---
}
var normalizedScope = __assign({ id: scope.Id, name: scope.ScopeName, type: scope.ScopeType, Kind: scope["Kind"], Label: scope["Label"], __formattedProps: formattedProps, __groupedProps: {}, __groupedRawProps: {}, __StdDevs: 0, __StdDevsSource: "" }, props);
if (normalizedScope[DEFINITION_LIST]) {
try {
var definitionList = JSON.parse(normalizedScope[DEFINITION_LIST].split("\\").join("\\\\"));
normalizedScope[DEFINITION_LIST] = [];
definitionList.forEach(function (definition, idx) {
var _a;
var matches = definition.match(definitionRegex);
if (matches) {
var filePath = ((_a = matches[1]) !== null && _a !== void 0 ? _a : "") + matches[2] + matches[3];
var line = parseInt(matches[5]);
var col = parseInt(matches[6]);
normalizedScope[DEFINITION_LIST].push({ filePath: filePath, line: line, col: col });
}
});
}
catch (e) {
logger.error("Unexpected \"DefinitionList\": ".concat(normalizedScope[DEFINITION_LIST]));
}
}
var dedup = {};
for (var key in normalizedScope) {
if (key.indexOf("__") !== 0) {
var row = formatValues(normalizedScope, key, dedup);
if (row) {
normalizedScope.__groupedProps[row.Key] = row;
if (!isNaN(row.StdDevs) && normalizedScope.__StdDevs < row.StdDevs) {
normalizedScope.__StdDevs = row.StdDevs;
normalizedScope.__StdDevsSource = row.Key;
}
}
}
}
data.push(normalizedScope);
};
for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
var scope = scopes_1[_i];
_loop_1(scope);
}
return {
meta: meta,
columns: columns,
data: data
};
};
Workunit.prototype.fetchDetailsNormalized = function (request) {
var _this = this;
if (request === void 0) { request = {}; }
return Promise.all([this.fetchDetailsMeta(), this.fetchDetailsRaw(request)]).then(function (promises) {
return _this.normalizeDetails(promises[0], promises[1]);
});
};
Workunit.prototype.fetchInfo = function (request) {
if (request === void 0) { request = {}; }
return this.WUInfo(request);
};
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", "function"]
},
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._monitorTimeoutDuration = function () {
var retVal = _super.prototype._monitorTimeoutDuration.call(this);
if (this._monitorTickCount <= 1) { // Once
return 1000;
}
else if (this._monitorTickCount <= 3) { // Twice
return 3000;
}
else if (this._monitorTickCount <= 5) { // Twice
return 5000;
}
else if (this._monitorTickCount <= 7) { // 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 _