Skip to content

Commit

Permalink
feat(comms): implementing some methods for dfuWorkunit
Browse files Browse the repository at this point in the history
for use in ECL Watch DFU Workunit page, methods implemented include update, abort, delete, fetchXML

Signed-off-by: Jeremy Clements <Jeremy.Clements@lexisnexisrisk.com>
  • Loading branch information
jeclrsg committed Jun 20, 2023
1 parent db15791 commit 7adeb8f
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
53 changes: 52 additions & 1 deletion packages/comms/src/ecl/dfuWorkunit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Cache, IEvent, scopedLogger, StateCallback, StateEvents, StateObject, S
import { IConnection, IOptions } from "../connection";
import { ESPExceptions } from "../espConnection";
import { WsSMC } from "../services/wsSMC";
import { FileSpray, SprayFixedEx, FileSprayService, SprayVariableEx } from "../services/fileSpray";
import { FileSpray, FileSprayService, SprayFixedEx, SprayVariableEx, UpdateDFUWorkunitEx } from "../services/fileSpray";
import * as WsTopology from "../services/wsTopology";

const logger = scopedLogger("@hpcc-js/comms/dfuWorkunit.ts");
Expand Down Expand Up @@ -154,6 +154,21 @@ export class DFUWorkunit extends StateObject<UDFUWorkunitState, IDFUWorkunitStat
});
}

update(request: Partial<UpdateDFUWorkunitEx>): Promise<FileSpray.UpdateDFUWorkunitResponse> {
return this.connection.UpdateDFUWorkunitEx({
wu: {
JobName: request?.wu?.JobName ?? this.JobName,
isProtected: request?.wu?.isProtected ?? this.isProtected,
ID: this.ID,
State: this.State
},
ClusterOrig: this.ClusterName,
JobNameOrig: this.JobName,
isProtectedOrig: this.isProtected,
StateOrig: this.State
});
}

isComplete(): boolean {
switch (this.State) {
case States.Finished:
Expand Down Expand Up @@ -186,11 +201,23 @@ export class DFUWorkunit extends StateObject<UDFUWorkunitState, IDFUWorkunitStat
return !this.isComplete();
}

abort(): Promise<FileSpray.AbortDFUWorkunitResponse> {
return this.connection.AbortDFUWorkunit({ wuid: this.ID });
}

delete() {
return this.DFUWUAction(FileSpray.DFUWUActions.Delete);
}

async refresh(full: boolean = false): Promise<this> {
await this.GetDFUWorkunit();
return this;
}

fetchXML(callback?: void): Promise<FileSpray.DFUWUFileResponse> {
return this.DFUWUFile();
}

// Monitoring ---
protected _monitor(): void {
if (this.isComplete()) {
Expand All @@ -212,6 +239,30 @@ export class DFUWorkunit extends StateObject<UDFUWorkunitState, IDFUWorkunitStat
return retVal;
}

protected DFUWUFile(_request: Partial<FileSpray.DFUWUFileRequest> = {}): Promise<FileSpray.DFUWUFileResponse> {
return this.connection.DFUWUFile({
..._request, Wuid: this.ID
}).then(response => {
//TODO: additional processing?
return response;
}).catch((e: ESPExceptions) => {
return {} as FileSpray.DFUWUFileResponse;
});
}

protected DFUWUAction(actionType: FileSpray.DFUWUActions): Promise<FileSpray.DFUWorkunitsActionResponse> {
return this.connection.DFUWorkunitsAction({
wuids: { Item: [this.ID] },
Type: actionType
}).then((response) => {
if (actionType === FileSpray.DFUWUActions.Delete) return response;
return this.refresh().then(() => {
this._monitor();
return response;
});
});
}

// Events ---
on(eventID: DFUWorkunitEvents, propIDorCallback: StateCallback | keyof UDFUWorkunitState, callback?: StatePropCallback): this {
if (this.isCallback(propIDorCallback)) {
Expand Down
71 changes: 71 additions & 0 deletions packages/comms/src/services/fileSpray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,73 @@ export interface DesprayEx {
decrypt?: string;
}

export interface UpdateDFUWorkunitEx {
wu?: {
ID?: string;
DFUServerName?: string;
ClusterName?: string;
JobName?: string;
Queue?: string;
User?: string;
isProtected?: boolean;
Command?: number;
CommandMessage?: string;
PercentDone?: number;
SecsLeft?: number;
ProgressMessage?: string;
SummaryMessage?: string;
State?: number;
SourceLogicalName?: string;
SourceIP?: string;
SourceFilePath?: string;
SourceDali?: string;
SourceRecordSize?: number;
SourceFormat?: number;
RowTag?: string;
SourceNumParts?: number;
SourceDirectory?: string;
DestLogicalName?: string;
DestGroupName?: string;
DestDirectory?: string;
DestIP?: string;
DestFilePath?: string;
DestFormat?: number;
DestNumParts?: number;
DestRecordSize?: number;
Replicate?: boolean;
Overwrite?: boolean;
Compress?: boolean;
SourceCsvSeparate?: string;
SourceCsvQuote?: string;
SourceCsvTerminate?: string;
SourceCsvEscape?: string;
TimeStarted?: string;
TimeStopped?: string;
StateMessage?: string;
MonitorEventName?: string;
MonitorSub?: boolean;
MonitorShotLimit?: number;
SourceDiffKeyName?: string;
DestDiffKeyName?: string;
Archived?: boolean;
encrypt?: string;
decrypt?: string;
failIfNoSourceFile?: boolean;
recordStructurePresent?: boolean;
quotedTerminator?: boolean;
preserveCompression?: boolean;
expireDays?: number;
PreserveFileParts?: boolean;
FileAccessCost?: number;
KbPerSecAve?: number;
KbPerSec?: number;
};
ClusterOrig: string;
JobNameOrig: string;
isProtectedOrig: boolean;
StateOrig: number;
}

export class FileSprayService extends FileSprayServiceBase {

SprayFixedEx(request: SprayFixedEx): Promise<FileSpray.SprayFixedResponse> {
Expand All @@ -114,4 +181,8 @@ export class FileSprayService extends FileSprayServiceBase {
return this._connection.send("Despray", request);
}

UpdateDFUWorkunitEx(request: UpdateDFUWorkunitEx): Promise<FileSpray.UpdateDFUWorkunitResponse> {
return this._connection.send("UpdateDFUWorkunit", request, "json", false, undefined, "UpdateDFUWorkunitResponse");
}

}

0 comments on commit 7adeb8f

Please sign in to comment.