Skip to content

Commit

Permalink
Merge pull request #4100 from jeclrsg/feat-comms-dfuworkunit-methods
Browse files Browse the repository at this point in the history
feat(comms): update, abort, delete methods for dfuWorkunit
  • Loading branch information
GordonSmith authored Jun 27, 2023
2 parents 727ecc6 + c826916 commit 3907a58
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 99 deletions.
57 changes: 54 additions & 3 deletions 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, UpdateDFUWorkunitEx } from "../services/fileSpray";
import * as WsTopology from "../services/wsTopology";

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

static sprayFixed(server: IOptions | IConnection, request: Partial<SprayFixedEx>): Promise<DFUWorkunit> {
static sprayFixed(server: IOptions | IConnection, request: Partial<FileSpray.SprayFixed>): Promise<DFUWorkunit> {
const service = new FileSprayService(server);
return service.SprayFixedEx({
...request
Expand All @@ -130,7 +130,7 @@ export class DFUWorkunit extends StateObject<UDFUWorkunitState, IDFUWorkunitStat
});
}

static sprayVariable(server: IOptions | IConnection, request: Partial<SprayVariableEx>): Promise<DFUWorkunit> {
static sprayVariable(server: IOptions | IConnection, request: Partial<FileSpray.SprayVariable>): Promise<DFUWorkunit> {
const service = new FileSprayService(server);
return service.SprayVariableEx({
...request
Expand All @@ -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
106 changes: 10 additions & 96 deletions packages/comms/src/services/fileSpray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,114 +4,28 @@ export {
FileSpray
};

export interface SprayFixedEx {
sourceIP?: string;
sourcePlane?: string;
sourcePath?: string;
srcxml?: string;
sourceFormat?: string;
sourceRecordSize?: number;
destGroup?: string;
destLogicalName?: string;
destNumParts?: number;
overwrite?: boolean;
replicate?: boolean;
ReplicateOffset?: number;
maxConnections?: number;
throttle?: number;
transferBufferSize?: number;
prefix?: string;
nosplit?: boolean;
norecover?: boolean;
compress?: boolean;
push?: boolean;
pull?: boolean;
noCommon?: boolean;
encrypt?: string;
decrypt?: string;
wrap?: boolean;
failIfNoSourceFile?: boolean;
recordStructurePresent?: boolean;
quotedTerminator?: boolean;
expireDays?: number;
DFUServerQueue?: string;
}

export interface SprayVariableEx {
sourceIP?: string;
sourcePlane?: string;
sourcePath?: string;
srcxml?: string;
sourceMaxRecordSize?: number;
sourceFormat?: number;
NoSourceCsvSeparator?: boolean;
sourceCsvSeparate?: string;
sourceCsvTerminate?: string;
sourceCsvQuote?: string;
sourceCsvEscape?: string;
sourceRowTag?: string;
destGroup?: string;
destLogicalName?: string;
overwrite?: boolean;
replicate?: boolean;
ReplicateOffset?: number;
maxConnections?: number;
throttle?: number;
transferBufferSize?: number;
prefix?: string;
nosplit?: boolean;
norecover?: boolean;
compress?: boolean;
push?: boolean;
pull?: boolean;
noCommon?: boolean;
encrypt?: string;
decrypt?: string;
failIfNoSourceFile?: boolean;
recordStructurePresent?: boolean;
quotedTerminator?: boolean;
sourceRowPath?: string;
isJSON?: boolean;
expireDays?: number;
DFUServerQueue?: string;
srcUsername?: string;
srcPassword?: string;
}
type UpdateDFUWorkunitMinusWU = Omit<FileSpray.UpdateDFUWorkunit, "wu">;
type UpdateDFUWorkunitWU = FileSpray.UpdateDFUWorkunit["wu"];

export interface DesprayEx {
destGroup?: string;
sourceLogicalName?: string;
destIP?: string;
destPath?: string;
destPlane?: string;
dstxml?: string;
overwrite?: boolean;
maxConnections?: number;
throttle?: number;
transferBufferSize?: number;
splitprefix?: string;
norecover?: boolean;
wrap?: boolean;
multiCopy?: boolean;
SingleConnection?: boolean;
DFUServerQueue?: string;
compress?: boolean;
encrypt?: string;
decrypt?: string;
export interface UpdateDFUWorkunitEx extends UpdateDFUWorkunitMinusWU {
wu?: Partial<UpdateDFUWorkunitWU>
}

export class FileSprayService extends FileSprayServiceBase {

SprayFixedEx(request: SprayFixedEx): Promise<FileSpray.SprayFixedResponse> {
SprayFixedEx(request: Partial<FileSpray.SprayFixed>): Promise<FileSpray.SprayFixedResponse> {
return this._connection.send("SprayFixed", request);
}

SprayVariableEx(request: SprayVariableEx): Promise<FileSpray.SprayResponse> {
SprayVariableEx(request: Partial<FileSpray.SprayVariable>): Promise<FileSpray.SprayResponse> {
return this._connection.send("SprayVariable", request, "json", false, null, "SprayResponse");
}

DesprayEx(request: DesprayEx): Promise<FileSpray.DesprayResponse> {
DesprayEx(request: Partial<FileSpray.Despray>): Promise<FileSpray.DesprayResponse> {
return this._connection.send("Despray", request);
}

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

0 comments on commit 3907a58

Please sign in to comment.