@hpcc-js/comms 3.15.4 → 3.15.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +50 -50
  3. package/dist/browser/index.js +1 -1
  4. package/dist/browser/index.js.map +1 -1
  5. package/dist/browser/index.umd.cjs +1 -1
  6. package/dist/browser/index.umd.cjs.map +1 -1
  7. package/dist/node/index.cjs +10 -10
  8. package/dist/node/index.cjs.map +4 -4
  9. package/dist/node/index.js +9 -9
  10. package/dist/node/index.js.map +4 -4
  11. package/package.json +7 -7
  12. package/src/__package__.ts +3 -3
  13. package/src/clienttools/eclMeta.ts +506 -506
  14. package/src/clienttools/eclcc.ts +628 -628
  15. package/src/connection.ts +288 -288
  16. package/src/ecl/activity.ts +82 -82
  17. package/src/ecl/dfuWorkunit.ts +363 -363
  18. package/src/ecl/graph.ts +196 -196
  19. package/src/ecl/logicalFile.ts +196 -196
  20. package/src/ecl/machine.ts +63 -63
  21. package/src/ecl/query.ts +265 -265
  22. package/src/ecl/queryGraph.ts +813 -813
  23. package/src/ecl/resource.ts +39 -39
  24. package/src/ecl/result.ts +245 -245
  25. package/src/ecl/scope.ts +188 -188
  26. package/src/ecl/sourceFile.ts +34 -34
  27. package/src/ecl/store.ts +154 -154
  28. package/src/ecl/targetCluster.ts +149 -149
  29. package/src/ecl/timer.ts +42 -42
  30. package/src/ecl/topology.ts +131 -131
  31. package/src/ecl/workunit.ts +1340 -1340
  32. package/src/ecl/xsdParser.ts +267 -267
  33. package/src/espConnection.ts +164 -164
  34. package/src/index.browser.ts +1 -1
  35. package/src/index.common.ts +40 -40
  36. package/src/index.node.ts +48 -48
  37. package/src/pem/trustwave.ts +909 -909
  38. package/src/services/fileSpray.ts +73 -73
  39. package/src/services/wsAccess.ts +8 -8
  40. package/src/services/wsAccount.ts +27 -27
  41. package/src/services/wsCloud.ts +73 -73
  42. package/src/services/wsCodesign.ts +18 -18
  43. package/src/services/wsDFU.ts +34 -34
  44. package/src/services/wsDFUXRef.ts +121 -121
  45. package/src/services/wsDali.ts +8 -8
  46. package/src/services/wsEcl.ts +123 -123
  47. package/src/services/wsElk.ts +8 -8
  48. package/src/services/wsLogaccess.ts +270 -270
  49. package/src/services/wsMachine.ts +89 -89
  50. package/src/services/wsPackageProcess.ts +8 -8
  51. package/src/services/wsResources.ts +8 -8
  52. package/src/services/wsSMC.ts +80 -80
  53. package/src/services/wsSasha.ts +7 -7
  54. package/src/services/wsStore.ts +32 -32
  55. package/src/services/wsTopology.ts +45 -45
  56. package/src/services/wsWorkunits.ts +151 -151
  57. package/src/services/wsdl/FileSpray/v1.23/FileSpray.ts +1008 -1008
  58. package/src/services/wsdl/FileSpray/v1.25/FileSpray.ts +1040 -1040
  59. package/src/services/wsdl/FileSpray/v1.26/FileSpray.ts +929 -929
  60. package/src/services/wsdl/FileSpray/v1.27/FileSpray.ts +930 -930
  61. package/src/services/wsdl/WsCloud/v1/WsCloud.ts +38 -38
  62. package/src/services/wsdl/WsCloud/v1.02/WsCloud.ts +77 -77
  63. package/src/services/wsdl/WsDFUXRef/v1.02/WsDFUXRef.ts +224 -224
  64. package/src/services/wsdl/WsDFUXRef/v1.04/WsDFUXRef.ts +228 -227
  65. package/src/services/wsdl/WsDali/v1.04/WsDali.ts +216 -216
  66. package/src/services/wsdl/WsDali/v1.07/WsDali.ts +72 -72
  67. package/src/services/wsdl/WsDfu/v1.62/WsDfu.ts +1455 -1455
  68. package/src/services/wsdl/WsDfu/v1.63/WsDfu.ts +1465 -1465
  69. package/src/services/wsdl/WsDfu/v1.65/WsDfu.ts +1244 -1244
  70. package/src/services/wsdl/WsDfu/v1.66/WsDfu.ts +1267 -1267
  71. package/src/services/wsdl/WsDfu/v1.67/WsDfu.ts +1268 -1268
  72. package/src/services/wsdl/WsDfu/v1.68/WsDfu.ts +1301 -0
  73. package/src/services/wsdl/WsESDLConfig/v1.5/WsESDLConfig.ts +366 -0
  74. package/src/services/wsdl/WsFileIO/v1.01/WsFileIO.ts +104 -104
  75. package/src/services/wsdl/WsPackageProcess/v1.04/WsPackageProcess.ts +519 -519
  76. package/src/services/wsdl/WsPackageProcess/v1.07/WsPackageProcess.ts +500 -500
  77. package/src/services/wsdl/WsPackageProcess/v1.08/WsPackageProcess.ts +503 -0
  78. package/src/services/wsdl/WsResources/v1.01/WsResources.ts +119 -119
  79. package/src/services/wsdl/WsSMC/v1.24/WsSMC.ts +665 -665
  80. package/src/services/wsdl/WsSMC/v1.27/WsSMC.ts +591 -591
  81. package/src/services/wsdl/WsSMC/v1.28/WsSMC.ts +645 -645
  82. package/src/services/wsdl/WsSMC/v1.29/WsSMC.ts +660 -660
  83. package/src/services/wsdl/WsSasha/v1.01/WsSasha.ts +18 -18
  84. package/src/services/wsdl/WsTopology/v1.31/WsTopology.ts +856 -856
  85. package/src/services/wsdl/WsTopology/v1.32/WsTopology.ts +786 -786
  86. package/src/services/wsdl/WsTopology/v1.33/WsTopology.ts +835 -835
  87. package/src/services/wsdl/WsWorkunits/v1.88/WsWorkunits.ts +2944 -2944
  88. package/src/services/wsdl/WsWorkunits/v1.94/WsWorkunits.ts +3072 -3072
  89. package/src/services/wsdl/WsWorkunits/v1.95/WsWorkunits.ts +3073 -3073
  90. package/src/services/wsdl/WsWorkunits/v1.97/WsWorkunits.ts +3134 -3134
  91. package/src/services/wsdl/WsWorkunits/v1.98/WsWorkunits.ts +3182 -3182
  92. package/src/services/wsdl/WsWorkunits/v1.99/WsWorkunits.ts +3162 -3162
  93. package/src/services/wsdl/WsWorkunits/v2/WsWorkunits.ts +3153 -3153
  94. package/src/services/wsdl/WsWorkunits/v2.02/WsWorkunits.ts +3162 -3162
  95. package/src/services/wsdl/WsWorkunits/v2.03/WsWorkunits.ts +3164 -3164
  96. package/src/services/wsdl/WsWorkunits/v2.04/WsWorkunits.ts +3171 -3171
  97. package/src/services/wsdl/WsWorkunits/v2.05/WsWorkunits.ts +3177 -0
  98. package/src/services/wsdl/ws_access/v1.16/ws_access.ts +1086 -1086
  99. package/src/services/wsdl/ws_access/v1.17/ws_access.ts +1023 -1023
  100. package/src/services/wsdl/ws_account/v1.05/ws_account.ts +111 -111
  101. package/src/services/wsdl/ws_account/v1.06/ws_account.ts +109 -109
  102. package/src/services/wsdl/ws_account/v1.07/ws_account.ts +114 -114
  103. package/src/services/wsdl/ws_codesign/v1.1/ws_codesign.ts +95 -95
  104. package/src/services/wsdl/ws_elk/v1/ws_elk.ts +47 -47
  105. package/src/services/wsdl/ws_logaccess/v1/ws_logaccess.ts +83 -83
  106. package/src/services/wsdl/ws_logaccess/v1.02/ws_logaccess.ts +161 -161
  107. package/src/services/wsdl/ws_logaccess/v1.03/ws_logaccess.ts +190 -190
  108. package/src/services/wsdl/ws_logaccess/v1.04/ws_logaccess.ts +215 -215
  109. package/src/services/wsdl/ws_logaccess/v1.05/ws_logaccess.ts +219 -219
  110. package/src/services/wsdl/ws_logaccess/v1.08/ws_logaccess.ts +267 -267
  111. package/src/services/wsdl/ws_machine/v1.17/ws_machine.ts +567 -567
  112. package/src/services/wsdl/ws_machine/v1.18/ws_machine.ts +497 -497
  113. package/src/services/wsdl/ws_machine/v1.19/ws_machine.ts +497 -497
  114. package/src/services/wsdl/wsstore/v1.02/wsstore.ts +239 -239
  115. package/types/services/wsPackageProcess.d.ts +1 -1
  116. package/types/services/wsWorkunits.d.ts +1 -1
  117. package/types/services/wsdl/FileSpray/v1.27/FileSpray.d.ts +506 -506
  118. package/types/services/wsdl/WsCloud/v1.02/WsCloud.d.ts +18 -18
  119. package/types/services/wsdl/WsDFUXRef/v1.04/WsDFUXRef.d.ts +58 -57
  120. package/types/services/wsdl/WsDali/v1.07/WsDali.d.ts +42 -42
  121. package/types/services/wsdl/WsPackageProcess/{v1.07 → v1.08}/WsPackageProcess.d.ts +121 -118
  122. package/types/services/wsdl/WsSasha/v1.01/WsSasha.d.ts +13 -13
  123. package/types/services/wsdl/WsTopology/v1.33/WsTopology.d.ts +360 -360
  124. package/types/services/wsdl/WsWorkunits/v2.05/WsWorkunits.d.ts +2571 -0
  125. package/types/services/wsdl/ws_access/v1.17/ws_access.d.ts +268 -268
  126. package/types/services/wsdl/ws_account/v1.07/ws_account.d.ts +34 -34
  127. package/types/services/wsdl/ws_codesign/v1.1/ws_codesign.d.ts +22 -22
  128. package/types/services/wsdl/ws_elk/v1/ws_elk.d.ts +12 -12
  129. package/types/services/wsdl/wsstore/v1.02/wsstore.d.ts +61 -61
  130. package/types/services/wsdl/WsWorkunits/v2.04/WsWorkunits.d.ts +0 -2565
@@ -1,364 +1,364 @@
1
- import { Cache, IEvent, scopedLogger, StateCallback, StateEvents, StateObject, StatePropCallback } from "@hpcc-js/util";
2
- import { IConnection, IOptions } from "../connection.ts";
3
- import { ESPExceptions } from "../espConnection.ts";
4
- import { WsSMC } from "../services/wsSMC.ts";
5
- import { FileSpray, FileSprayService, UpdateDFUWorkunitEx } from "../services/fileSpray.ts";
6
- import * as WsTopology from "../services/wsTopology.ts";
7
-
8
- const logger = scopedLogger("@hpcc-js/comms/dfuWorkunit.ts");
9
-
10
- enum States {
11
- Unknown = 0,
12
- Scheduled,
13
- Queued,
14
- Started,
15
- Aborted,
16
- Failed,
17
- Finished,
18
- Monitoring,
19
- Aborting,
20
- NotFound = 999
21
- }
22
-
23
- export class DFUWorkunitCache extends Cache<{ BaseUrl: string, ID: string }, DFUWorkunit> {
24
- constructor() {
25
- super((obj) => {
26
- return `${obj.BaseUrl}-${obj.ID}`;
27
- });
28
- }
29
- }
30
- const _workunits = new DFUWorkunitCache();
31
-
32
- export type DFUWorkunitEvents = "finished" | StateEvents;
33
- export type UDFUWorkunitState = FileSpray.DFUWorkunit;
34
- export type IDFUWorkunitState = FileSpray.DFUWorkunit | WsSMC.ActiveWorkunit;
35
- export class DFUWorkunit extends StateObject<UDFUWorkunitState, IDFUWorkunitState> implements FileSpray.DFUWorkunit {
36
- connection: FileSprayService;
37
- topologyConnection: WsTopology.TopologyService;
38
- get BaseUrl() { return this.connection.baseUrl; }
39
-
40
- // Accessors ---
41
- get properties(): FileSpray.DFUWorkunit { return this.get(); }
42
- get ID(): string { return this.get("ID"); }
43
- get DFUServerName(): string { return this.get("DFUServerName"); }
44
- get ClusterName(): string { return this.get("ClusterName"); }
45
- get JobName(): string { return this.get("JobName"); }
46
- get Queue(): string { return this.get("Queue"); }
47
- get User(): string { return this.get("User"); }
48
- get isProtected(): boolean { return this.get("isProtected"); }
49
- get Command(): number { return this.get("Command"); }
50
- get CommandMessage(): string { return this.get("CommandMessage"); }
51
- get PercentDone(): number { return this.get("PercentDone"); }
52
- get SecsLeft(): number { return this.get("SecsLeft"); }
53
- get ProgressMessage(): string { return this.get("ProgressMessage"); }
54
- get SummaryMessage(): string { return this.get("SummaryMessage"); }
55
- get State(): number { return this.get("State", States.Unknown); }
56
- get SourceLogicalName(): string { return this.get("SourceLogicalName"); }
57
- get SourceIP(): string { return this.get("SourceIP"); }
58
- get SourceFilePath(): string { return this.get("SourceFilePath"); }
59
- get SourceDali(): string { return this.get("SourceDali"); }
60
- get SourceRecordSize(): number { return this.get("SourceRecordSize"); }
61
- get SourceFormat(): number { return this.get("SourceFormat"); }
62
- get RowTag(): string { return this.get("RowTag"); }
63
- get SourceNumParts(): number { return this.get("SourceNumParts"); }
64
- get SourceDirectory(): string { return this.get("SourceDirectory"); }
65
- get DestLogicalName(): string { return this.get("DestLogicalName"); }
66
- get DestGroupName(): string { return this.get("DestGroupName"); }
67
- get DestDirectory(): string { return this.get("DestDirectory"); }
68
- get DestIP(): string { return this.get("DestIP"); }
69
- get DestFilePath(): string { return this.get("DestFilePath"); }
70
- get DestFormat(): number { return this.get("DestFormat"); }
71
- get DestNumParts(): number { return this.get("DestNumParts"); }
72
- get DestRecordSize(): number { return this.get("DestRecordSize"); }
73
- get Replicate(): boolean { return this.get("Replicate"); }
74
- get Overwrite(): boolean { return this.get("Overwrite"); }
75
- get Compress(): boolean { return this.get("Compress"); }
76
- get SourceCsvSeparate(): string { return this.get("SourceCsvSeparate"); }
77
- get SourceCsvQuote(): string { return this.get("SourceCsvQuote"); }
78
- get SourceCsvTerminate(): string { return this.get("SourceCsvTerminate"); }
79
- get SourceCsvEscape(): string { return this.get("SourceCsvEscape"); }
80
- get TimeStarted(): string { return this.get("TimeStarted"); }
81
- get TimeStopped(): string { return this.get("TimeStopped"); }
82
- get StateMessage(): string { return this.get("StateMessage"); }
83
- get MonitorEventName(): string { return this.get("MonitorEventName"); }
84
- get MonitorSub(): boolean { return this.get("MonitorSub"); }
85
- get MonitorShotLimit(): number { return this.get("MonitorShotLimit"); }
86
- get SourceDiffKeyName(): string { return this.get("SourceDiffKeyName"); }
87
- get DestDiffKeyName(): string { return this.get("DestDiffKeyName"); }
88
- get Archived(): boolean { return this.get("Archived"); }
89
- get encrypt(): string { return this.get("encrypt"); }
90
- get decrypt(): string { return this.get("decrypt"); }
91
- get failIfNoSourceFile(): boolean { return this.get("failIfNoSourceFile"); }
92
- get recordStructurePresent(): boolean { return this.get("recordStructurePresent"); }
93
- get quotedTerminator(): boolean { return this.get("quotedTerminator"); }
94
- get preserveCompression(): boolean { return this.get("preserveCompression"); }
95
- get expireDays(): number { return this.get("expireDays"); }
96
- get PreserveFileParts(): boolean { return this.get("PreserveFileParts"); }
97
- get FileAccessCost(): number { return this.get("FileAccessCost"); }
98
- get KbPerSecAve(): number { return this.get("KbPerSecAve"); }
99
- get KbPerSec(): number { return this.get("KbPerSec"); }
100
-
101
- // Factories ---
102
- static create(optsConnection: IOptions | IConnection, dfuServerQueue: string): Promise<DFUWorkunit> {
103
- const retVal: DFUWorkunit = new DFUWorkunit(optsConnection);
104
- return retVal.connection.CreateDFUWorkunit({ DFUServerQueue: dfuServerQueue }).then((response) => {
105
- _workunits.set(retVal);
106
- retVal.set(response.result);
107
- return retVal;
108
- });
109
- }
110
-
111
- static attach(optsConnection: IOptions | IConnection, wuid: string, state?: IDFUWorkunitState): DFUWorkunit {
112
- const retVal: DFUWorkunit = _workunits.get({ BaseUrl: optsConnection.baseUrl, ID: wuid }, () => {
113
- return new DFUWorkunit(optsConnection, wuid);
114
- });
115
- if (state) {
116
- retVal.set(state);
117
- }
118
- return retVal;
119
- }
120
-
121
- static sprayFixed(server: IOptions | IConnection, request: Partial<FileSpray.SprayFixed>): Promise<DFUWorkunit> {
122
- const service = new FileSprayService(server);
123
- return service.SprayFixedEx({
124
- ...request
125
- }).then(response => {
126
- const wuid = response.wuid;
127
- return service.GetDFUWorkunit({ wuid }).then(response => {
128
- return DFUWorkunit.attach(server, wuid, response.result);
129
- });
130
- });
131
- }
132
-
133
- static sprayVariable(server: IOptions | IConnection, request: Partial<FileSpray.SprayVariable>): Promise<DFUWorkunit> {
134
- const service = new FileSprayService(server);
135
- return service.SprayVariableEx({
136
- ...request
137
- }).then(response => {
138
- const wuid = response.wuid;
139
- return service.GetDFUWorkunit({ wuid }).then(response => {
140
- return DFUWorkunit.attach(server, wuid, response.result);
141
- });
142
- });
143
- }
144
-
145
- static despray(server: IOptions | IConnection, request: Partial<FileSpray.Despray>): Promise<DFUWorkunit> {
146
- const service = new FileSprayService(server);
147
- return service.DesprayEx({
148
- ...request
149
- }).then(response => {
150
- const wuid = response.wuid;
151
- return service.GetDFUWorkunit({ wuid }).then(response => {
152
- return DFUWorkunit.attach(server, wuid, response.result);
153
- });
154
- });
155
- }
156
-
157
- update(request: Partial<UpdateDFUWorkunitEx>): Promise<FileSpray.UpdateDFUWorkunitResponse> {
158
- return this.connection.UpdateDFUWorkunitEx({
159
- wu: {
160
- JobName: request?.wu?.JobName ?? this.JobName,
161
- isProtected: request?.wu?.isProtected ?? this.isProtected,
162
- ID: this.ID,
163
- State: this.State
164
- },
165
- ClusterOrig: this.ClusterName,
166
- JobNameOrig: this.JobName,
167
- isProtectedOrig: this.isProtected,
168
- StateOrig: this.State
169
- });
170
- }
171
-
172
- isComplete(): boolean {
173
- switch (this.State) {
174
- case States.Finished:
175
- case States.Failed:
176
- case States.Aborted:
177
- case States.NotFound:
178
- return true;
179
- default:
180
- }
181
- return false;
182
- }
183
-
184
- isFailed() {
185
- if (this.isComplete() && this.State !== States.Finished) {
186
- return true;
187
- }
188
- return false;
189
- }
190
-
191
- isDeleted() {
192
- switch (this.State) {
193
- case States.NotFound:
194
- return true;
195
- default:
196
- }
197
- return false;
198
- }
199
-
200
- isRunning(): boolean {
201
- return !this.isComplete();
202
- }
203
-
204
- abort(): Promise<FileSpray.AbortDFUWorkunitResponse> {
205
- return this.connection.AbortDFUWorkunit({ wuid: this.ID });
206
- }
207
-
208
- delete() {
209
- return this.DFUWUAction(FileSpray.DFUWUActions.Delete).then(response => {
210
- return this.refresh().then(() => {
211
- this._monitor();
212
- return response;
213
- });
214
- });
215
- }
216
-
217
- async refresh(full: boolean = false): Promise<this> {
218
- await this.GetDFUWorkunit();
219
- return this;
220
- }
221
-
222
- fetchXML(callback?: void): Promise<string> {
223
- return this.DFUWUFile();
224
- }
225
-
226
- // Monitoring ---
227
- protected _monitor(): void {
228
- if (this.isComplete()) {
229
- this._monitorTickCount = 0;
230
- return;
231
- }
232
- super._monitor();
233
- }
234
-
235
- protected _monitorTimeoutDuration(): number {
236
- const retVal = super._monitorTimeoutDuration();
237
- if (this._monitorTickCount <= 1) { // Once
238
- return 3000;
239
- } else if (this._monitorTickCount <= 5) { // Twice
240
- return 6000;
241
- } else if (this._monitorTickCount <= 7) { // Twice
242
- return 12000;
243
- }
244
- return retVal;
245
- }
246
-
247
- protected DFUWUFile(_request: Partial<FileSpray.DFUWUFileRequest> = {}): Promise<string> {
248
- return this.connection.DFUWUFileEx({
249
- ..._request, Wuid: this.ID
250
- }).then(response => {
251
- //TODO: additional processing?
252
- return response;
253
- }).catch((e: ESPExceptions) => {
254
- return "";
255
- });
256
- }
257
-
258
- protected DFUWUAction(actionType: FileSpray.DFUWUActions): Promise<FileSpray.DFUWorkunitsActionResponse> {
259
- return this.connection.DFUWorkunitsAction({
260
- wuids: { Item: [this.ID] },
261
- Type: actionType
262
- }).then((response) => {
263
- if (actionType === FileSpray.DFUWUActions.Delete) return response;
264
- return this.refresh().then(() => {
265
- this._monitor();
266
- return response;
267
- });
268
- });
269
- }
270
-
271
- // Events ---
272
- on(eventID: DFUWorkunitEvents, propIDorCallback: StateCallback | keyof UDFUWorkunitState, callback?: StatePropCallback): this {
273
- if (this.isCallback(propIDorCallback)) {
274
- switch (eventID) {
275
- case "finished":
276
- super.on("propChanged", "State", (changeInfo: IEvent) => {
277
- if (this.isComplete()) {
278
- propIDorCallback([changeInfo]);
279
- }
280
- });
281
- break;
282
- case "changed":
283
- super.on(eventID, propIDorCallback);
284
- break;
285
- default:
286
- }
287
- } else {
288
- switch (eventID) {
289
- case "changed":
290
- super.on(eventID, propIDorCallback, callback!);
291
- break;
292
- default:
293
- }
294
- }
295
- this._monitor();
296
- return this;
297
- }
298
-
299
- watchUntilComplete(callback?: StateCallback): Promise<this> {
300
- return new Promise((resolve, _) => {
301
- const watchHandle = this.watch((changes) => {
302
- if (callback) {
303
- callback(changes);
304
- }
305
- if (this.isComplete()) {
306
- watchHandle.release();
307
- resolve(this);
308
- }
309
- });
310
- });
311
- }
312
-
313
- watchUntilRunning(callback?: StateCallback): Promise<this> {
314
- return new Promise((resolve, _) => {
315
- const watchHandle = this.watch((changes) => {
316
- if (callback) {
317
- callback(changes);
318
- }
319
- if (this.isComplete() || this.isRunning()) {
320
- watchHandle.release();
321
- resolve(this);
322
- }
323
- });
324
- });
325
- }
326
-
327
- // --- --- ---
328
- protected constructor(optsConnection: IOptions | IConnection, wuid?: string) {
329
- super();
330
- this.connection = new FileSprayService(optsConnection);
331
- this.topologyConnection = new WsTopology.TopologyService(optsConnection);
332
- this.clearState(wuid);
333
- }
334
-
335
- clearState(wuid?: string) {
336
- this.clear({
337
- ID: wuid,
338
- State: States.Unknown
339
- });
340
- }
341
-
342
- // FileSpray passthroughs ---
343
- protected GetDFUWorkunit(_request: Partial<FileSpray.GetDFUWorkunit> = {}): Promise<FileSpray.GetDFUWorkunitResponse> {
344
- return this.connection.GetDFUWorkunit({ ..._request, wuid: this.ID }).then((response) => {
345
- this.set(response.result);
346
- return response;
347
- }).catch((e: ESPExceptions) => {
348
- // deleted ---
349
- const wuMissing = e.Exception.some((exception) => {
350
- if (exception.Code === 20080 || exception.Code === 20081) {
351
- this.clearState(this.ID);
352
- this.set("State", States.NotFound);
353
- return true;
354
- }
355
- return false;
356
- });
357
- if (!wuMissing) {
358
- logger.warning(`Unexpected ESP exception: ${e.message}`);
359
- throw e;
360
- }
361
- return {} as FileSpray.GetDFUWorkunitResponse;
362
- });
363
- }
1
+ import { Cache, IEvent, scopedLogger, StateCallback, StateEvents, StateObject, StatePropCallback } from "@hpcc-js/util";
2
+ import { IConnection, IOptions } from "../connection.ts";
3
+ import { ESPExceptions } from "../espConnection.ts";
4
+ import { WsSMC } from "../services/wsSMC.ts";
5
+ import { FileSpray, FileSprayService, UpdateDFUWorkunitEx } from "../services/fileSpray.ts";
6
+ import * as WsTopology from "../services/wsTopology.ts";
7
+
8
+ const logger = scopedLogger("@hpcc-js/comms/dfuWorkunit.ts");
9
+
10
+ enum States {
11
+ Unknown = 0,
12
+ Scheduled,
13
+ Queued,
14
+ Started,
15
+ Aborted,
16
+ Failed,
17
+ Finished,
18
+ Monitoring,
19
+ Aborting,
20
+ NotFound = 999
21
+ }
22
+
23
+ export class DFUWorkunitCache extends Cache<{ BaseUrl: string, ID: string }, DFUWorkunit> {
24
+ constructor() {
25
+ super((obj) => {
26
+ return `${obj.BaseUrl}-${obj.ID}`;
27
+ });
28
+ }
29
+ }
30
+ const _workunits = new DFUWorkunitCache();
31
+
32
+ export type DFUWorkunitEvents = "finished" | StateEvents;
33
+ export type UDFUWorkunitState = FileSpray.DFUWorkunit;
34
+ export type IDFUWorkunitState = FileSpray.DFUWorkunit | WsSMC.ActiveWorkunit;
35
+ export class DFUWorkunit extends StateObject<UDFUWorkunitState, IDFUWorkunitState> implements FileSpray.DFUWorkunit {
36
+ connection: FileSprayService;
37
+ topologyConnection: WsTopology.TopologyService;
38
+ get BaseUrl() { return this.connection.baseUrl; }
39
+
40
+ // Accessors ---
41
+ get properties(): FileSpray.DFUWorkunit { return this.get(); }
42
+ get ID(): string { return this.get("ID"); }
43
+ get DFUServerName(): string { return this.get("DFUServerName"); }
44
+ get ClusterName(): string { return this.get("ClusterName"); }
45
+ get JobName(): string { return this.get("JobName"); }
46
+ get Queue(): string { return this.get("Queue"); }
47
+ get User(): string { return this.get("User"); }
48
+ get isProtected(): boolean { return this.get("isProtected"); }
49
+ get Command(): number { return this.get("Command"); }
50
+ get CommandMessage(): string { return this.get("CommandMessage"); }
51
+ get PercentDone(): number { return this.get("PercentDone"); }
52
+ get SecsLeft(): number { return this.get("SecsLeft"); }
53
+ get ProgressMessage(): string { return this.get("ProgressMessage"); }
54
+ get SummaryMessage(): string { return this.get("SummaryMessage"); }
55
+ get State(): number { return this.get("State", States.Unknown); }
56
+ get SourceLogicalName(): string { return this.get("SourceLogicalName"); }
57
+ get SourceIP(): string { return this.get("SourceIP"); }
58
+ get SourceFilePath(): string { return this.get("SourceFilePath"); }
59
+ get SourceDali(): string { return this.get("SourceDali"); }
60
+ get SourceRecordSize(): number { return this.get("SourceRecordSize"); }
61
+ get SourceFormat(): number { return this.get("SourceFormat"); }
62
+ get RowTag(): string { return this.get("RowTag"); }
63
+ get SourceNumParts(): number { return this.get("SourceNumParts"); }
64
+ get SourceDirectory(): string { return this.get("SourceDirectory"); }
65
+ get DestLogicalName(): string { return this.get("DestLogicalName"); }
66
+ get DestGroupName(): string { return this.get("DestGroupName"); }
67
+ get DestDirectory(): string { return this.get("DestDirectory"); }
68
+ get DestIP(): string { return this.get("DestIP"); }
69
+ get DestFilePath(): string { return this.get("DestFilePath"); }
70
+ get DestFormat(): number { return this.get("DestFormat"); }
71
+ get DestNumParts(): number { return this.get("DestNumParts"); }
72
+ get DestRecordSize(): number { return this.get("DestRecordSize"); }
73
+ get Replicate(): boolean { return this.get("Replicate"); }
74
+ get Overwrite(): boolean { return this.get("Overwrite"); }
75
+ get Compress(): boolean { return this.get("Compress"); }
76
+ get SourceCsvSeparate(): string { return this.get("SourceCsvSeparate"); }
77
+ get SourceCsvQuote(): string { return this.get("SourceCsvQuote"); }
78
+ get SourceCsvTerminate(): string { return this.get("SourceCsvTerminate"); }
79
+ get SourceCsvEscape(): string { return this.get("SourceCsvEscape"); }
80
+ get TimeStarted(): string { return this.get("TimeStarted"); }
81
+ get TimeStopped(): string { return this.get("TimeStopped"); }
82
+ get StateMessage(): string { return this.get("StateMessage"); }
83
+ get MonitorEventName(): string { return this.get("MonitorEventName"); }
84
+ get MonitorSub(): boolean { return this.get("MonitorSub"); }
85
+ get MonitorShotLimit(): number { return this.get("MonitorShotLimit"); }
86
+ get SourceDiffKeyName(): string { return this.get("SourceDiffKeyName"); }
87
+ get DestDiffKeyName(): string { return this.get("DestDiffKeyName"); }
88
+ get Archived(): boolean { return this.get("Archived"); }
89
+ get encrypt(): string { return this.get("encrypt"); }
90
+ get decrypt(): string { return this.get("decrypt"); }
91
+ get failIfNoSourceFile(): boolean { return this.get("failIfNoSourceFile"); }
92
+ get recordStructurePresent(): boolean { return this.get("recordStructurePresent"); }
93
+ get quotedTerminator(): boolean { return this.get("quotedTerminator"); }
94
+ get preserveCompression(): boolean { return this.get("preserveCompression"); }
95
+ get expireDays(): number { return this.get("expireDays"); }
96
+ get PreserveFileParts(): boolean { return this.get("PreserveFileParts"); }
97
+ get FileAccessCost(): number { return this.get("FileAccessCost"); }
98
+ get KbPerSecAve(): number { return this.get("KbPerSecAve"); }
99
+ get KbPerSec(): number { return this.get("KbPerSec"); }
100
+
101
+ // Factories ---
102
+ static create(optsConnection: IOptions | IConnection, dfuServerQueue: string): Promise<DFUWorkunit> {
103
+ const retVal: DFUWorkunit = new DFUWorkunit(optsConnection);
104
+ return retVal.connection.CreateDFUWorkunit({ DFUServerQueue: dfuServerQueue }).then((response) => {
105
+ _workunits.set(retVal);
106
+ retVal.set(response.result);
107
+ return retVal;
108
+ });
109
+ }
110
+
111
+ static attach(optsConnection: IOptions | IConnection, wuid: string, state?: IDFUWorkunitState): DFUWorkunit {
112
+ const retVal: DFUWorkunit = _workunits.get({ BaseUrl: optsConnection.baseUrl, ID: wuid }, () => {
113
+ return new DFUWorkunit(optsConnection, wuid);
114
+ });
115
+ if (state) {
116
+ retVal.set(state);
117
+ }
118
+ return retVal;
119
+ }
120
+
121
+ static sprayFixed(server: IOptions | IConnection, request: Partial<FileSpray.SprayFixed>): Promise<DFUWorkunit> {
122
+ const service = new FileSprayService(server);
123
+ return service.SprayFixedEx({
124
+ ...request
125
+ }).then(response => {
126
+ const wuid = response.wuid;
127
+ return service.GetDFUWorkunit({ wuid }).then(response => {
128
+ return DFUWorkunit.attach(server, wuid, response.result);
129
+ });
130
+ });
131
+ }
132
+
133
+ static sprayVariable(server: IOptions | IConnection, request: Partial<FileSpray.SprayVariable>): Promise<DFUWorkunit> {
134
+ const service = new FileSprayService(server);
135
+ return service.SprayVariableEx({
136
+ ...request
137
+ }).then(response => {
138
+ const wuid = response.wuid;
139
+ return service.GetDFUWorkunit({ wuid }).then(response => {
140
+ return DFUWorkunit.attach(server, wuid, response.result);
141
+ });
142
+ });
143
+ }
144
+
145
+ static despray(server: IOptions | IConnection, request: Partial<FileSpray.Despray>): Promise<DFUWorkunit> {
146
+ const service = new FileSprayService(server);
147
+ return service.DesprayEx({
148
+ ...request
149
+ }).then(response => {
150
+ const wuid = response.wuid;
151
+ return service.GetDFUWorkunit({ wuid }).then(response => {
152
+ return DFUWorkunit.attach(server, wuid, response.result);
153
+ });
154
+ });
155
+ }
156
+
157
+ update(request: Partial<UpdateDFUWorkunitEx>): Promise<FileSpray.UpdateDFUWorkunitResponse> {
158
+ return this.connection.UpdateDFUWorkunitEx({
159
+ wu: {
160
+ JobName: request?.wu?.JobName ?? this.JobName,
161
+ isProtected: request?.wu?.isProtected ?? this.isProtected,
162
+ ID: this.ID,
163
+ State: this.State
164
+ },
165
+ ClusterOrig: this.ClusterName,
166
+ JobNameOrig: this.JobName,
167
+ isProtectedOrig: this.isProtected,
168
+ StateOrig: this.State
169
+ });
170
+ }
171
+
172
+ isComplete(): boolean {
173
+ switch (this.State) {
174
+ case States.Finished:
175
+ case States.Failed:
176
+ case States.Aborted:
177
+ case States.NotFound:
178
+ return true;
179
+ default:
180
+ }
181
+ return false;
182
+ }
183
+
184
+ isFailed() {
185
+ if (this.isComplete() && this.State !== States.Finished) {
186
+ return true;
187
+ }
188
+ return false;
189
+ }
190
+
191
+ isDeleted() {
192
+ switch (this.State) {
193
+ case States.NotFound:
194
+ return true;
195
+ default:
196
+ }
197
+ return false;
198
+ }
199
+
200
+ isRunning(): boolean {
201
+ return !this.isComplete();
202
+ }
203
+
204
+ abort(): Promise<FileSpray.AbortDFUWorkunitResponse> {
205
+ return this.connection.AbortDFUWorkunit({ wuid: this.ID });
206
+ }
207
+
208
+ delete() {
209
+ return this.DFUWUAction(FileSpray.DFUWUActions.Delete).then(response => {
210
+ return this.refresh().then(() => {
211
+ this._monitor();
212
+ return response;
213
+ });
214
+ });
215
+ }
216
+
217
+ async refresh(full: boolean = false): Promise<this> {
218
+ await this.GetDFUWorkunit();
219
+ return this;
220
+ }
221
+
222
+ fetchXML(callback?: void): Promise<string> {
223
+ return this.DFUWUFile();
224
+ }
225
+
226
+ // Monitoring ---
227
+ protected _monitor(): void {
228
+ if (this.isComplete()) {
229
+ this._monitorTickCount = 0;
230
+ return;
231
+ }
232
+ super._monitor();
233
+ }
234
+
235
+ protected _monitorTimeoutDuration(): number {
236
+ const retVal = super._monitorTimeoutDuration();
237
+ if (this._monitorTickCount <= 1) { // Once
238
+ return 3000;
239
+ } else if (this._monitorTickCount <= 5) { // Twice
240
+ return 6000;
241
+ } else if (this._monitorTickCount <= 7) { // Twice
242
+ return 12000;
243
+ }
244
+ return retVal;
245
+ }
246
+
247
+ protected DFUWUFile(_request: Partial<FileSpray.DFUWUFileRequest> = {}): Promise<string> {
248
+ return this.connection.DFUWUFileEx({
249
+ ..._request, Wuid: this.ID
250
+ }).then(response => {
251
+ //TODO: additional processing?
252
+ return response;
253
+ }).catch((e: ESPExceptions) => {
254
+ return "";
255
+ });
256
+ }
257
+
258
+ protected DFUWUAction(actionType: FileSpray.DFUWUActions): Promise<FileSpray.DFUWorkunitsActionResponse> {
259
+ return this.connection.DFUWorkunitsAction({
260
+ wuids: { Item: [this.ID] },
261
+ Type: actionType
262
+ }).then((response) => {
263
+ if (actionType === FileSpray.DFUWUActions.Delete) return response;
264
+ return this.refresh().then(() => {
265
+ this._monitor();
266
+ return response;
267
+ });
268
+ });
269
+ }
270
+
271
+ // Events ---
272
+ on(eventID: DFUWorkunitEvents, propIDorCallback: StateCallback | keyof UDFUWorkunitState, callback?: StatePropCallback): this {
273
+ if (this.isCallback(propIDorCallback)) {
274
+ switch (eventID) {
275
+ case "finished":
276
+ super.on("propChanged", "State", (changeInfo: IEvent) => {
277
+ if (this.isComplete()) {
278
+ propIDorCallback([changeInfo]);
279
+ }
280
+ });
281
+ break;
282
+ case "changed":
283
+ super.on(eventID, propIDorCallback);
284
+ break;
285
+ default:
286
+ }
287
+ } else {
288
+ switch (eventID) {
289
+ case "changed":
290
+ super.on(eventID, propIDorCallback, callback!);
291
+ break;
292
+ default:
293
+ }
294
+ }
295
+ this._monitor();
296
+ return this;
297
+ }
298
+
299
+ watchUntilComplete(callback?: StateCallback): Promise<this> {
300
+ return new Promise((resolve, _) => {
301
+ const watchHandle = this.watch((changes) => {
302
+ if (callback) {
303
+ callback(changes);
304
+ }
305
+ if (this.isComplete()) {
306
+ watchHandle.release();
307
+ resolve(this);
308
+ }
309
+ });
310
+ });
311
+ }
312
+
313
+ watchUntilRunning(callback?: StateCallback): Promise<this> {
314
+ return new Promise((resolve, _) => {
315
+ const watchHandle = this.watch((changes) => {
316
+ if (callback) {
317
+ callback(changes);
318
+ }
319
+ if (this.isComplete() || this.isRunning()) {
320
+ watchHandle.release();
321
+ resolve(this);
322
+ }
323
+ });
324
+ });
325
+ }
326
+
327
+ // --- --- ---
328
+ protected constructor(optsConnection: IOptions | IConnection, wuid?: string) {
329
+ super();
330
+ this.connection = new FileSprayService(optsConnection);
331
+ this.topologyConnection = new WsTopology.TopologyService(optsConnection);
332
+ this.clearState(wuid);
333
+ }
334
+
335
+ clearState(wuid?: string) {
336
+ this.clear({
337
+ ID: wuid,
338
+ State: States.Unknown
339
+ });
340
+ }
341
+
342
+ // FileSpray passthroughs ---
343
+ protected GetDFUWorkunit(_request: Partial<FileSpray.GetDFUWorkunit> = {}): Promise<FileSpray.GetDFUWorkunitResponse> {
344
+ return this.connection.GetDFUWorkunit({ ..._request, wuid: this.ID }).then((response) => {
345
+ this.set(response.result);
346
+ return response;
347
+ }).catch((e: ESPExceptions) => {
348
+ // deleted ---
349
+ const wuMissing = e.Exception.some((exception) => {
350
+ if (exception.Code === 20080 || exception.Code === 20081) {
351
+ this.clearState(this.ID);
352
+ this.set("State", States.NotFound);
353
+ return true;
354
+ }
355
+ return false;
356
+ });
357
+ if (!wuMissing) {
358
+ logger.warning(`Unexpected ESP exception: ${e.message}`);
359
+ throw e;
360
+ }
361
+ return {} as FileSpray.GetDFUWorkunitResponse;
362
+ });
363
+ }
364
364
  }