@hpcc-js/comms
Version:
hpcc-js - Communications
591 lines • 22.6 kB
JavaScript
import { __assign, __awaiter, __extends, __generator } from "tslib";
import { Cache, scopedLogger, StateObject } from "@hpcc-js/util";
import { FileSpray, FileSprayService } from "../services/fileSpray";
import * as WsTopology from "../services/wsTopology";
var logger = scopedLogger("@hpcc-js/comms/dfuWorkunit.ts");
var States;
(function (States) {
States[States["Unknown"] = 0] = "Unknown";
States[States["Scheduled"] = 1] = "Scheduled";
States[States["Queued"] = 2] = "Queued";
States[States["Started"] = 3] = "Started";
States[States["Aborted"] = 4] = "Aborted";
States[States["Failed"] = 5] = "Failed";
States[States["Finished"] = 6] = "Finished";
States[States["Monitoring"] = 7] = "Monitoring";
States[States["Aborting"] = 8] = "Aborting";
States[States["NotFound"] = 999] = "NotFound";
})(States || (States = {}));
var DFUWorkunitCache = /** @class */ (function (_super) {
__extends(DFUWorkunitCache, _super);
function DFUWorkunitCache() {
return _super.call(this, function (obj) {
return "".concat(obj.BaseUrl, "-").concat(obj.ID);
}) || this;
}
return DFUWorkunitCache;
}(Cache));
export { DFUWorkunitCache };
var _workunits = new DFUWorkunitCache();
var DFUWorkunit = /** @class */ (function (_super) {
__extends(DFUWorkunit, _super);
// --- --- ---
function DFUWorkunit(optsConnection, wuid) {
var _this = _super.call(this) || this;
_this.connection = new FileSprayService(optsConnection);
_this.topologyConnection = new WsTopology.TopologyService(optsConnection);
_this.clearState(wuid);
return _this;
}
Object.defineProperty(DFUWorkunit.prototype, "BaseUrl", {
get: function () { return this.connection.baseUrl; },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "properties", {
// Accessors ---
get: function () { return this.get(); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "ID", {
get: function () { return this.get("ID"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DFUServerName", {
get: function () { return this.get("DFUServerName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "ClusterName", {
get: function () { return this.get("ClusterName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "JobName", {
get: function () { return this.get("JobName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "Queue", {
get: function () { return this.get("Queue"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "User", {
get: function () { return this.get("User"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "isProtected", {
get: function () { return this.get("isProtected"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "Command", {
get: function () { return this.get("Command"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "CommandMessage", {
get: function () { return this.get("CommandMessage"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "PercentDone", {
get: function () { return this.get("PercentDone"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SecsLeft", {
get: function () { return this.get("SecsLeft"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "ProgressMessage", {
get: function () { return this.get("ProgressMessage"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SummaryMessage", {
get: function () { return this.get("SummaryMessage"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "State", {
get: function () { return this.get("State", States.Unknown); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceLogicalName", {
get: function () { return this.get("SourceLogicalName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceIP", {
get: function () { return this.get("SourceIP"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceFilePath", {
get: function () { return this.get("SourceFilePath"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceDali", {
get: function () { return this.get("SourceDali"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceRecordSize", {
get: function () { return this.get("SourceRecordSize"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceFormat", {
get: function () { return this.get("SourceFormat"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "RowTag", {
get: function () { return this.get("RowTag"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceNumParts", {
get: function () { return this.get("SourceNumParts"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceDirectory", {
get: function () { return this.get("SourceDirectory"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestLogicalName", {
get: function () { return this.get("DestLogicalName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestGroupName", {
get: function () { return this.get("DestGroupName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestDirectory", {
get: function () { return this.get("DestDirectory"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestIP", {
get: function () { return this.get("DestIP"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestFilePath", {
get: function () { return this.get("DestFilePath"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestFormat", {
get: function () { return this.get("DestFormat"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestNumParts", {
get: function () { return this.get("DestNumParts"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestRecordSize", {
get: function () { return this.get("DestRecordSize"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "Replicate", {
get: function () { return this.get("Replicate"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "Overwrite", {
get: function () { return this.get("Overwrite"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "Compress", {
get: function () { return this.get("Compress"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceCsvSeparate", {
get: function () { return this.get("SourceCsvSeparate"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceCsvQuote", {
get: function () { return this.get("SourceCsvQuote"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceCsvTerminate", {
get: function () { return this.get("SourceCsvTerminate"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceCsvEscape", {
get: function () { return this.get("SourceCsvEscape"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "TimeStarted", {
get: function () { return this.get("TimeStarted"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "TimeStopped", {
get: function () { return this.get("TimeStopped"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "StateMessage", {
get: function () { return this.get("StateMessage"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "MonitorEventName", {
get: function () { return this.get("MonitorEventName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "MonitorSub", {
get: function () { return this.get("MonitorSub"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "MonitorShotLimit", {
get: function () { return this.get("MonitorShotLimit"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "SourceDiffKeyName", {
get: function () { return this.get("SourceDiffKeyName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "DestDiffKeyName", {
get: function () { return this.get("DestDiffKeyName"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "Archived", {
get: function () { return this.get("Archived"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "encrypt", {
get: function () { return this.get("encrypt"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "decrypt", {
get: function () { return this.get("decrypt"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "failIfNoSourceFile", {
get: function () { return this.get("failIfNoSourceFile"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "recordStructurePresent", {
get: function () { return this.get("recordStructurePresent"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "quotedTerminator", {
get: function () { return this.get("quotedTerminator"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "preserveCompression", {
get: function () { return this.get("preserveCompression"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "expireDays", {
get: function () { return this.get("expireDays"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "PreserveFileParts", {
get: function () { return this.get("PreserveFileParts"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "FileAccessCost", {
get: function () { return this.get("FileAccessCost"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "KbPerSecAve", {
get: function () { return this.get("KbPerSecAve"); },
enumerable: false,
configurable: true
});
Object.defineProperty(DFUWorkunit.prototype, "KbPerSec", {
get: function () { return this.get("KbPerSec"); },
enumerable: false,
configurable: true
});
// Factories ---
DFUWorkunit.create = function (optsConnection, dfuServerQueue) {
var retVal = new DFUWorkunit(optsConnection);
return retVal.connection.CreateDFUWorkunit({ DFUServerQueue: dfuServerQueue }).then(function (response) {
_workunits.set(retVal);
retVal.set(response.result);
return retVal;
});
};
DFUWorkunit.attach = function (optsConnection, wuid, state) {
var retVal = _workunits.get({ BaseUrl: optsConnection.baseUrl, ID: wuid }, function () {
return new DFUWorkunit(optsConnection, wuid);
});
if (state) {
retVal.set(state);
}
return retVal;
};
DFUWorkunit.sprayFixed = function (server, request) {
var service = new FileSprayService(server);
return service.SprayFixedEx(__assign({}, request)).then(function (response) {
var wuid = response.wuid;
return service.GetDFUWorkunit({ wuid: wuid }).then(function (response) {
return DFUWorkunit.attach(server, wuid, response.result);
});
});
};
DFUWorkunit.sprayVariable = function (server, request) {
var service = new FileSprayService(server);
return service.SprayVariableEx(__assign({}, request)).then(function (response) {
var wuid = response.wuid;
return service.GetDFUWorkunit({ wuid: wuid }).then(function (response) {
return DFUWorkunit.attach(server, wuid, response.result);
});
});
};
DFUWorkunit.despray = function (server, request) {
var service = new FileSprayService(server);
return service.DesprayEx(__assign({}, request)).then(function (response) {
var wuid = response.wuid;
return service.GetDFUWorkunit({ wuid: wuid }).then(function (response) {
return DFUWorkunit.attach(server, wuid, response.result);
});
});
};
DFUWorkunit.prototype.update = function (request) {
var _a, _b, _c, _d;
return this.connection.UpdateDFUWorkunitEx({
wu: {
JobName: (_b = (_a = request === null || request === void 0 ? void 0 : request.wu) === null || _a === void 0 ? void 0 : _a.JobName) !== null && _b !== void 0 ? _b : this.JobName,
isProtected: (_d = (_c = request === null || request === void 0 ? void 0 : request.wu) === null || _c === void 0 ? void 0 : _c.isProtected) !== null && _d !== void 0 ? _d : this.isProtected,
ID: this.ID,
State: this.State
},
ClusterOrig: this.ClusterName,
JobNameOrig: this.JobName,
isProtectedOrig: this.isProtected,
StateOrig: this.State
});
};
DFUWorkunit.prototype.isComplete = function () {
switch (this.State) {
case States.Finished:
case States.Failed:
case States.Aborted:
case States.NotFound:
return true;
default:
}
return false;
};
DFUWorkunit.prototype.isFailed = function () {
if (this.isComplete() && this.State !== States.Finished) {
return true;
}
return false;
};
DFUWorkunit.prototype.isDeleted = function () {
switch (this.State) {
case States.NotFound:
return true;
default:
}
return false;
};
DFUWorkunit.prototype.isRunning = function () {
return !this.isComplete();
};
DFUWorkunit.prototype.abort = function () {
return this.connection.AbortDFUWorkunit({ wuid: this.ID });
};
DFUWorkunit.prototype.delete = function () {
var _this = this;
return this.DFUWUAction(FileSpray.DFUWUActions.Delete).then(function (response) {
return _this.refresh().then(function () {
_this._monitor();
return response;
});
});
};
DFUWorkunit.prototype.refresh = function () {
return __awaiter(this, arguments, void 0, function (full) {
if (full === void 0) { full = false; }
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.GetDFUWorkunit()];
case 1:
_a.sent();
return [2 /*return*/, this];
}
});
});
};
DFUWorkunit.prototype.fetchXML = function (callback) {
return this.DFUWUFile();
};
// Monitoring ---
DFUWorkunit.prototype._monitor = function () {
if (this.isComplete()) {
this._monitorTickCount = 0;
return;
}
_super.prototype._monitor.call(this);
};
DFUWorkunit.prototype._monitorTimeoutDuration = function () {
var retVal = _super.prototype._monitorTimeoutDuration.call(this);
if (this._monitorTickCount <= 1) { // Once
return 3000;
}
else if (this._monitorTickCount <= 5) { // Twice
return 6000;
}
else if (this._monitorTickCount <= 7) { // Twice
return 12000;
}
return retVal;
};
DFUWorkunit.prototype.DFUWUFile = function (_request) {
if (_request === void 0) { _request = {}; }
return this.connection.DFUWUFileEx(__assign(__assign({}, _request), { Wuid: this.ID })).then(function (response) {
//TODO: additional processing?
return response;
}).catch(function (e) {
return "";
});
};
DFUWorkunit.prototype.DFUWUAction = function (actionType) {
var _this = this;
return this.connection.DFUWorkunitsAction({
wuids: { Item: [this.ID] },
Type: actionType
}).then(function (response) {
if (actionType === FileSpray.DFUWUActions.Delete)
return response;
return _this.refresh().then(function () {
_this._monitor();
return response;
});
});
};
// Events ---
DFUWorkunit.prototype.on = function (eventID, propIDorCallback, callback) {
var _this = this;
if (this.isCallback(propIDorCallback)) {
switch (eventID) {
case "finished":
_super.prototype.on.call(this, "propChanged", "State", 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;
};
DFUWorkunit.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);
}
});
});
};
DFUWorkunit.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);
}
});
});
};
DFUWorkunit.prototype.clearState = function (wuid) {
this.clear({
ID: wuid,
State: States.Unknown
});
};
// FileSpray passthroughs ---
DFUWorkunit.prototype.GetDFUWorkunit = function (_request) {
var _this = this;
if (_request === void 0) { _request = {}; }
return this.connection.GetDFUWorkunit(__assign(__assign({}, _request), { wuid: this.ID })).then(function (response) {
_this.set(response.result);
return response;
}).catch(function (e) {
// deleted ---
var wuMissing = e.Exception.some(function (exception) {
if (exception.Code === 20080 || exception.Code === 20081) {
_this.clearState(_this.ID);
_this.set("State", States.NotFound);
return true;
}
return false;
});
if (!wuMissing) {
logger.warning("Unexpected ESP exception: ".concat(e.message));
throw e;
}
return {};
});
};
return DFUWorkunit;
}(StateObject));
export { DFUWorkunit };
//# sourceMappingURL=dfuWorkunit.js.map