@hpcc-js/comms 3.15.2 → 3.15.4
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.
- package/LICENSE +43 -43
- package/README.md +50 -50
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/index.umd.cjs +1 -1
- package/dist/browser/index.umd.cjs.map +1 -1
- package/dist/node/index.cjs +10 -10
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.js +10 -10
- package/dist/node/index.js.map +3 -3
- package/package.json +7 -7
- package/src/__package__.ts +3 -3
- package/src/clienttools/eclMeta.ts +506 -506
- package/src/clienttools/eclcc.ts +628 -628
- package/src/connection.ts +288 -288
- package/src/ecl/activity.ts +82 -82
- package/src/ecl/dfuWorkunit.ts +363 -363
- package/src/ecl/graph.ts +196 -196
- package/src/ecl/logicalFile.ts +196 -196
- package/src/ecl/machine.ts +63 -63
- package/src/ecl/query.ts +265 -265
- package/src/ecl/queryGraph.ts +813 -813
- package/src/ecl/resource.ts +39 -39
- package/src/ecl/result.ts +245 -245
- package/src/ecl/scope.ts +188 -188
- package/src/ecl/sourceFile.ts +34 -34
- package/src/ecl/store.ts +154 -154
- package/src/ecl/targetCluster.ts +149 -149
- package/src/ecl/timer.ts +42 -42
- package/src/ecl/topology.ts +131 -131
- package/src/ecl/workunit.ts +1340 -1340
- package/src/ecl/xsdParser.ts +267 -267
- package/src/espConnection.ts +164 -164
- package/src/index.browser.ts +1 -1
- package/src/index.common.ts +40 -40
- package/src/index.node.ts +48 -48
- package/src/pem/trustwave.ts +909 -909
- package/src/services/fileSpray.ts +73 -73
- package/src/services/wsAccess.ts +8 -8
- package/src/services/wsAccount.ts +27 -27
- package/src/services/wsCloud.ts +73 -73
- package/src/services/wsCodesign.ts +18 -18
- package/src/services/wsDFU.ts +34 -34
- package/src/services/wsDFUXRef.ts +121 -121
- package/src/services/wsDali.ts +8 -8
- package/src/services/wsEcl.ts +123 -123
- package/src/services/wsElk.ts +8 -8
- package/src/services/wsLogaccess.ts +270 -267
- package/src/services/wsMachine.ts +89 -89
- package/src/services/wsPackageProcess.ts +8 -8
- package/src/services/wsResources.ts +8 -8
- package/src/services/wsSMC.ts +80 -80
- package/src/services/wsSasha.ts +7 -7
- package/src/services/wsStore.ts +32 -32
- package/src/services/wsTopology.ts +45 -45
- package/src/services/wsWorkunits.ts +151 -151
- package/src/services/wsdl/FileSpray/v1.23/FileSpray.ts +1008 -1008
- package/src/services/wsdl/FileSpray/v1.25/FileSpray.ts +1040 -1040
- package/src/services/wsdl/FileSpray/v1.26/FileSpray.ts +929 -929
- package/src/services/wsdl/FileSpray/v1.27/FileSpray.ts +930 -930
- package/src/services/wsdl/WsCloud/v1/WsCloud.ts +38 -38
- package/src/services/wsdl/WsCloud/v1.02/WsCloud.ts +77 -77
- package/src/services/wsdl/WsDFUXRef/v1.02/WsDFUXRef.ts +224 -224
- package/src/services/wsdl/WsDFUXRef/v1.04/WsDFUXRef.ts +227 -227
- package/src/services/wsdl/WsDali/v1.04/WsDali.ts +216 -216
- package/src/services/wsdl/WsDfu/v1.62/WsDfu.ts +1455 -1455
- package/src/services/wsdl/WsDfu/v1.63/WsDfu.ts +1465 -1465
- package/src/services/wsdl/WsDfu/v1.65/WsDfu.ts +1244 -1244
- package/src/services/wsdl/WsDfu/v1.66/WsDfu.ts +1267 -1267
- package/src/services/wsdl/WsDfu/v1.67/WsDfu.ts +1268 -1268
- package/src/services/wsdl/WsFileIO/v1.01/WsFileIO.ts +104 -104
- package/src/services/wsdl/WsPackageProcess/v1.04/WsPackageProcess.ts +519 -519
- package/src/services/wsdl/WsPackageProcess/v1.07/WsPackageProcess.ts +500 -500
- package/src/services/wsdl/WsResources/v1.01/WsResources.ts +119 -119
- package/src/services/wsdl/WsSMC/v1.24/WsSMC.ts +665 -665
- package/src/services/wsdl/WsSMC/v1.27/WsSMC.ts +591 -591
- package/src/services/wsdl/WsSMC/v1.28/WsSMC.ts +645 -645
- package/src/services/wsdl/WsSMC/v1.29/WsSMC.ts +660 -660
- package/src/services/wsdl/WsTopology/v1.31/WsTopology.ts +856 -856
- package/src/services/wsdl/WsTopology/v1.32/WsTopology.ts +786 -786
- package/src/services/wsdl/WsTopology/v1.33/WsTopology.ts +835 -835
- package/src/services/wsdl/WsWorkunits/v1.88/WsWorkunits.ts +2944 -2944
- package/src/services/wsdl/WsWorkunits/v1.94/WsWorkunits.ts +3072 -3072
- package/src/services/wsdl/WsWorkunits/v1.95/WsWorkunits.ts +3073 -3073
- package/src/services/wsdl/WsWorkunits/v1.97/WsWorkunits.ts +3134 -3134
- package/src/services/wsdl/WsWorkunits/v1.98/WsWorkunits.ts +3182 -3182
- package/src/services/wsdl/WsWorkunits/v1.99/WsWorkunits.ts +3162 -3162
- package/src/services/wsdl/WsWorkunits/v2/WsWorkunits.ts +3153 -3153
- package/src/services/wsdl/WsWorkunits/v2.02/WsWorkunits.ts +3162 -3162
- package/src/services/wsdl/WsWorkunits/v2.03/WsWorkunits.ts +3164 -3164
- package/src/services/wsdl/WsWorkunits/v2.04/WsWorkunits.ts +3171 -3171
- package/src/services/wsdl/ws_access/v1.16/ws_access.ts +1086 -1086
- package/src/services/wsdl/ws_access/v1.17/ws_access.ts +1023 -1023
- package/src/services/wsdl/ws_account/v1.05/ws_account.ts +111 -111
- package/src/services/wsdl/ws_account/v1.06/ws_account.ts +109 -109
- package/src/services/wsdl/ws_account/v1.07/ws_account.ts +114 -114
- package/src/services/wsdl/ws_codesign/v1.1/ws_codesign.ts +95 -95
- package/src/services/wsdl/ws_elk/v1/ws_elk.ts +47 -47
- package/src/services/wsdl/ws_logaccess/v1/ws_logaccess.ts +83 -83
- package/src/services/wsdl/ws_logaccess/v1.02/ws_logaccess.ts +161 -161
- package/src/services/wsdl/ws_logaccess/v1.03/ws_logaccess.ts +190 -190
- package/src/services/wsdl/ws_logaccess/v1.04/ws_logaccess.ts +215 -215
- package/src/services/wsdl/ws_logaccess/v1.05/ws_logaccess.ts +219 -219
- package/src/services/wsdl/ws_logaccess/v1.08/ws_logaccess.ts +267 -267
- package/src/services/wsdl/ws_machine/v1.17/ws_machine.ts +567 -567
- package/src/services/wsdl/ws_machine/v1.18/ws_machine.ts +497 -497
- package/src/services/wsdl/ws_machine/v1.19/ws_machine.ts +497 -497
- package/src/services/wsdl/wsstore/v1.02/wsstore.ts +239 -239
- package/types/services/wsLogaccess.d.ts +1 -0
package/src/ecl/query.ts
CHANGED
|
@@ -1,265 +1,265 @@
|
|
|
1
|
-
import { Cache, StateObject, scopedLogger, RecursivePartial } from "@hpcc-js/util";
|
|
2
|
-
import { format as d3Format } from "d3-format";
|
|
3
|
-
import { IConnection, IOptions } from "../connection.ts";
|
|
4
|
-
import { EclService, IWsEclRequest, IWsEclResponse, IWsEclResult } from "../services/wsEcl.ts";
|
|
5
|
-
import { WorkunitsService, WsWorkunits } from "../services/wsWorkunits.ts";
|
|
6
|
-
import { Topology } from "./topology.ts";
|
|
7
|
-
import { Workunit, IScope } from "./workunit.ts";
|
|
8
|
-
import { QueryGraph } from "./queryGraph.ts";
|
|
9
|
-
|
|
10
|
-
export { QueryGraph };
|
|
11
|
-
|
|
12
|
-
const logger = scopedLogger("@hpcc-js/comms/ecl/query.ts");
|
|
13
|
-
|
|
14
|
-
const siFormatter = d3Format("~s");
|
|
15
|
-
|
|
16
|
-
function isNumber(n) {
|
|
17
|
-
return !isNaN(parseFloat(n)) && !isNaN(n - 0);
|
|
18
|
-
}
|
|
19
|
-
export interface QueryEx extends WsWorkunits.WUQueryDetailsResponse {
|
|
20
|
-
BaseUrl: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class QueryCache extends Cache<QueryEx, Query> {
|
|
24
|
-
constructor() {
|
|
25
|
-
super((obj) => {
|
|
26
|
-
return Cache.hash([obj.QueryId, obj.QuerySet]);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const _queries = new QueryCache();
|
|
31
|
-
|
|
32
|
-
export class Query extends StateObject<QueryEx, QueryEx> implements QueryEx {
|
|
33
|
-
protected wsWorkunitsService: WorkunitsService;
|
|
34
|
-
get BaseUrl() { return this.wsWorkunitsService.baseUrl; }
|
|
35
|
-
protected topology: Topology;
|
|
36
|
-
protected _requestSchema: IWsEclRequest;
|
|
37
|
-
protected _responseSchema: IWsEclResponse;
|
|
38
|
-
|
|
39
|
-
get properties(): WsWorkunits.WUQueryDetailsResponse { return this.get(); }
|
|
40
|
-
get Exceptions(): WsWorkunits.Exceptions { return this.get("Exceptions"); }
|
|
41
|
-
get QueryId(): string { return this.get("QueryId"); }
|
|
42
|
-
get QuerySet(): string { return this.get("QuerySet"); }
|
|
43
|
-
get QueryName(): string { return this.get("QueryName"); }
|
|
44
|
-
get Wuid(): string { return this.get("Wuid"); }
|
|
45
|
-
get Dll(): string { return this.get("Dll"); }
|
|
46
|
-
get Suspended(): boolean { return this.get("Suspended"); }
|
|
47
|
-
get Activated(): boolean { return this.get("Activated"); }
|
|
48
|
-
get SuspendedBy(): string { return this.get("SuspendedBy"); }
|
|
49
|
-
get Clusters(): WsWorkunits.Clusters2 { return this.get("Clusters"); }
|
|
50
|
-
get PublishedBy(): string { return this.get("PublishedBy"); }
|
|
51
|
-
get Comment() { return this.get("Comment"); }
|
|
52
|
-
get LogicalFiles(): WsWorkunits.LogicalFiles { return this.get("LogicalFiles"); }
|
|
53
|
-
get SuperFiles(): WsWorkunits.SuperFiles { return this.get("SuperFiles"); }
|
|
54
|
-
get IsLibrary(): boolean { return this.get("IsLibrary"); }
|
|
55
|
-
get Priority(): string { return this.get("Priority"); }
|
|
56
|
-
get WUSnapShot(): string { return this.get("WUSnapShot"); }
|
|
57
|
-
get CompileTime(): string { return this.get("CompileTime"); }
|
|
58
|
-
get LibrariesUsed(): WsWorkunits.LibrariesUsed { return this.get("LibrariesUsed"); }
|
|
59
|
-
get CountGraphs(): number { return this.get("CountGraphs"); }
|
|
60
|
-
get ResourceURLCount(): number { return this.get("ResourceURLCount"); }
|
|
61
|
-
get WsEclAddresses(): WsWorkunits.WsEclAddresses { return this.get("WsEclAddresses"); }
|
|
62
|
-
get WUGraphs(): WsWorkunits.WUGraphs { return this.get("WUGraphs"); }
|
|
63
|
-
get WUTimers(): WsWorkunits.WUTimers { return this.get("WUTimers"); }
|
|
64
|
-
get PriorityID(): number { return this.get("PriorityID"); }
|
|
65
|
-
|
|
66
|
-
private constructor(optsConnection: IOptions | IConnection | WorkunitsService, querySet: string, queryID: string, queryDetails?: WsWorkunits.WUQueryDetailsResponse) {
|
|
67
|
-
super();
|
|
68
|
-
if (optsConnection instanceof WorkunitsService) {
|
|
69
|
-
this.wsWorkunitsService = optsConnection;
|
|
70
|
-
} else {
|
|
71
|
-
this.wsWorkunitsService = new WorkunitsService(optsConnection);
|
|
72
|
-
}
|
|
73
|
-
this.topology = Topology.attach(this.wsWorkunitsService.opts());
|
|
74
|
-
this.set({
|
|
75
|
-
QuerySet: querySet,
|
|
76
|
-
QueryId: queryID,
|
|
77
|
-
...queryDetails
|
|
78
|
-
} as QueryEx);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
static attach(optsConnection: IOptions | IConnection, querySet: string, queryId: string, state?: QueryEx): Query {
|
|
82
|
-
const retVal: Query = _queries.get({ BaseUrl: optsConnection.baseUrl, QuerySet: querySet, QueryId: queryId } as QueryEx, () => {
|
|
83
|
-
return new Query(optsConnection, querySet, queryId);
|
|
84
|
-
});
|
|
85
|
-
if (state) {
|
|
86
|
-
retVal.set(state);
|
|
87
|
-
}
|
|
88
|
-
return retVal;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private _eclService: Promise<EclService>;
|
|
92
|
-
protected async wsEclService(): Promise<EclService | undefined> {
|
|
93
|
-
if (!this._eclService) {
|
|
94
|
-
this._eclService = this.topology.fetchServices({}).then(services => {
|
|
95
|
-
for (const espServer of services?.TpEspServers?.TpEspServer ?? []) {
|
|
96
|
-
for (const binding of espServer?.TpBindings?.TpBinding ?? []) {
|
|
97
|
-
if (binding?.Service === "ws_ecl") {
|
|
98
|
-
const baseUrl = `${binding.Protocol}://${globalThis.location.hostname}:${binding.Port}`;
|
|
99
|
-
return new EclService({ baseUrl });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return undefined;
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return this._eclService;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
private async fetchDetails(): Promise<void> {
|
|
110
|
-
const queryDetails = await this.wsWorkunitsService.WUQueryDetails({
|
|
111
|
-
QuerySet: this.QuerySet,
|
|
112
|
-
QueryId: this.QueryId,
|
|
113
|
-
IncludeStateOnClusters: true,
|
|
114
|
-
IncludeSuperFiles: true,
|
|
115
|
-
IncludeWsEclAddresses: true,
|
|
116
|
-
CheckAllNodes: false
|
|
117
|
-
});
|
|
118
|
-
this.set({ ...queryDetails } as QueryEx);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
private async fetchRequestSchema(): Promise<void> {
|
|
122
|
-
const wsEclService = await this.wsEclService();
|
|
123
|
-
try {
|
|
124
|
-
this._requestSchema = await wsEclService?.requestJson(this.QuerySet, this.QueryId) ?? [];
|
|
125
|
-
} catch (e: any) {
|
|
126
|
-
// See: https://track.hpccsystems.com/browse/HPCC-29827
|
|
127
|
-
logger.debug(e.message ?? e);
|
|
128
|
-
this._requestSchema = [];
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private async fetchResponseSchema(): Promise<void> {
|
|
133
|
-
const wsEclService = await this.wsEclService();
|
|
134
|
-
try {
|
|
135
|
-
this._responseSchema = await wsEclService?.responseJson(this.QuerySet, this.QueryId) ?? {};
|
|
136
|
-
} catch (e: any) {
|
|
137
|
-
// See: https://track.hpccsystems.com/browse/HPCC-29827
|
|
138
|
-
logger.debug(e.message ?? e);
|
|
139
|
-
this._responseSchema = {};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
private async fetchSchema(): Promise<void> {
|
|
144
|
-
await Promise.all([this.fetchRequestSchema(), this.fetchResponseSchema()]);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
fetchSummaryStats() {
|
|
148
|
-
return this.wsWorkunitsService.WUQueryGetSummaryStats({ Target: this.QuerySet, QueryId: this.QueryId });
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
fetchGraph(GraphName: string = "", SubGraphId: string = ""): Promise<QueryGraph> {
|
|
152
|
-
return this.wsWorkunitsService.WUQueryGetGraph({ Target: this.QuerySet, QueryId: this.QueryId, GraphName, SubGraphId }).then(response => {
|
|
153
|
-
const graph = new QueryGraph();
|
|
154
|
-
let first = true;
|
|
155
|
-
for (const graphItem of response?.Graphs?.ECLGraphEx || []) {
|
|
156
|
-
if (first) {
|
|
157
|
-
graph.load(graphItem.Graph);
|
|
158
|
-
first = false;
|
|
159
|
-
} else {
|
|
160
|
-
graph.merge(graphItem.Graph);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return graph;
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
fetchDetailsNormalized(request: RecursivePartial<WsWorkunits.WUDetails> = {}): Promise<{ meta: WsWorkunits.WUDetailsMetaResponse | undefined, columns: { [id: string]: any } | undefined, data: IScope[] | undefined }> {
|
|
168
|
-
const wu = Workunit.attach(this.wsWorkunitsService, this.Wuid);
|
|
169
|
-
if (wu) {
|
|
170
|
-
return Promise.all([this.fetchGraph(), wu.fetchDetailsMeta(), wu.fetchDetailsRaw(request)]).then(promises => {
|
|
171
|
-
const graph = promises[0];
|
|
172
|
-
const meta = promises[1];
|
|
173
|
-
const metrics: WsWorkunits.Scope[] = promises[2];
|
|
174
|
-
const data = metrics.map(metric => {
|
|
175
|
-
const firstChar = metric.Id[0];
|
|
176
|
-
if (firstChar === "a" || firstChar === "e") {
|
|
177
|
-
const item = graph.idx[metric.Id.substring(1)];
|
|
178
|
-
if (!item) {
|
|
179
|
-
logger.debug(`Missing graph data for metric ID: ${metric.Id}`);
|
|
180
|
-
return metric;
|
|
181
|
-
}
|
|
182
|
-
const existingProperties = new Set(metric.Properties.Property.map(prop => prop.Name));
|
|
183
|
-
const newProperties: WsWorkunits.Property[] = [];
|
|
184
|
-
for (const key in item) {
|
|
185
|
-
const firstCharOfKey = key.charAt(0);
|
|
186
|
-
if (firstCharOfKey !== "_" &&
|
|
187
|
-
firstCharOfKey === firstCharOfKey.toUpperCase() &&
|
|
188
|
-
!existingProperties.has(key)) {
|
|
189
|
-
const value = item[key];
|
|
190
|
-
const valueType = typeof value;
|
|
191
|
-
if (valueType === "string" || valueType === "number" || valueType === "boolean") {
|
|
192
|
-
const isNum = isNumber(value);
|
|
193
|
-
let rawValue = isNum ? parseFloat(value as string) : value;
|
|
194
|
-
let formatted = value;
|
|
195
|
-
if (key.indexOf("Time") >= 0) {
|
|
196
|
-
rawValue = (rawValue as number) / 1000000000;
|
|
197
|
-
formatted = siFormatter(rawValue) + "s";
|
|
198
|
-
}
|
|
199
|
-
newProperties.push({
|
|
200
|
-
Name: key,
|
|
201
|
-
RawValue: rawValue as any,
|
|
202
|
-
Formatted: formatted
|
|
203
|
-
} as WsWorkunits.Property);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
if (newProperties.length > 0) {
|
|
208
|
-
metric.Properties.Property.push(...newProperties);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return metric;
|
|
212
|
-
});
|
|
213
|
-
return wu.normalizeDetails(meta, data);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
return Promise.resolve({ meta: undefined, columns: undefined, data: undefined });
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async submit(request: object): Promise<Array<{ [key: string]: object[] }>> {
|
|
220
|
-
const wsEclService = await this.wsEclService();
|
|
221
|
-
try {
|
|
222
|
-
return wsEclService?.submit(this.QuerySet, this.QueryId, request).then(results => {
|
|
223
|
-
for (const key in results) {
|
|
224
|
-
results[key] = results[key].Row;
|
|
225
|
-
}
|
|
226
|
-
return results;
|
|
227
|
-
}) ?? [];
|
|
228
|
-
} catch (e: any) {
|
|
229
|
-
// See: https://track.hpccsystems.com/browse/HPCC-29827
|
|
230
|
-
logger.debug(e.message ?? e);
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
async refresh(): Promise<this> {
|
|
236
|
-
await Promise.all([
|
|
237
|
-
this.fetchDetails(),
|
|
238
|
-
this.fetchSchema()
|
|
239
|
-
]);
|
|
240
|
-
return this;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
requestFields(): IWsEclRequest {
|
|
244
|
-
if (!this._requestSchema) return [];
|
|
245
|
-
return this._requestSchema;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
responseFields(): IWsEclResponse {
|
|
249
|
-
if (!this._responseSchema) return {};
|
|
250
|
-
return this._responseSchema;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
resultNames(): string[] {
|
|
254
|
-
const retVal: string[] = [];
|
|
255
|
-
for (const key in this.responseFields()) {
|
|
256
|
-
retVal.push(key);
|
|
257
|
-
}
|
|
258
|
-
return retVal;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
resultFields(resultName: string): IWsEclResult {
|
|
262
|
-
if (!this._responseSchema[resultName]) return [];
|
|
263
|
-
return this._responseSchema[resultName];
|
|
264
|
-
}
|
|
265
|
-
}
|
|
1
|
+
import { Cache, StateObject, scopedLogger, RecursivePartial } from "@hpcc-js/util";
|
|
2
|
+
import { format as d3Format } from "d3-format";
|
|
3
|
+
import { IConnection, IOptions } from "../connection.ts";
|
|
4
|
+
import { EclService, IWsEclRequest, IWsEclResponse, IWsEclResult } from "../services/wsEcl.ts";
|
|
5
|
+
import { WorkunitsService, WsWorkunits } from "../services/wsWorkunits.ts";
|
|
6
|
+
import { Topology } from "./topology.ts";
|
|
7
|
+
import { Workunit, IScope } from "./workunit.ts";
|
|
8
|
+
import { QueryGraph } from "./queryGraph.ts";
|
|
9
|
+
|
|
10
|
+
export { QueryGraph };
|
|
11
|
+
|
|
12
|
+
const logger = scopedLogger("@hpcc-js/comms/ecl/query.ts");
|
|
13
|
+
|
|
14
|
+
const siFormatter = d3Format("~s");
|
|
15
|
+
|
|
16
|
+
function isNumber(n) {
|
|
17
|
+
return !isNaN(parseFloat(n)) && !isNaN(n - 0);
|
|
18
|
+
}
|
|
19
|
+
export interface QueryEx extends WsWorkunits.WUQueryDetailsResponse {
|
|
20
|
+
BaseUrl: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class QueryCache extends Cache<QueryEx, Query> {
|
|
24
|
+
constructor() {
|
|
25
|
+
super((obj) => {
|
|
26
|
+
return Cache.hash([obj.QueryId, obj.QuerySet]);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const _queries = new QueryCache();
|
|
31
|
+
|
|
32
|
+
export class Query extends StateObject<QueryEx, QueryEx> implements QueryEx {
|
|
33
|
+
protected wsWorkunitsService: WorkunitsService;
|
|
34
|
+
get BaseUrl() { return this.wsWorkunitsService.baseUrl; }
|
|
35
|
+
protected topology: Topology;
|
|
36
|
+
protected _requestSchema: IWsEclRequest;
|
|
37
|
+
protected _responseSchema: IWsEclResponse;
|
|
38
|
+
|
|
39
|
+
get properties(): WsWorkunits.WUQueryDetailsResponse { return this.get(); }
|
|
40
|
+
get Exceptions(): WsWorkunits.Exceptions { return this.get("Exceptions"); }
|
|
41
|
+
get QueryId(): string { return this.get("QueryId"); }
|
|
42
|
+
get QuerySet(): string { return this.get("QuerySet"); }
|
|
43
|
+
get QueryName(): string { return this.get("QueryName"); }
|
|
44
|
+
get Wuid(): string { return this.get("Wuid"); }
|
|
45
|
+
get Dll(): string { return this.get("Dll"); }
|
|
46
|
+
get Suspended(): boolean { return this.get("Suspended"); }
|
|
47
|
+
get Activated(): boolean { return this.get("Activated"); }
|
|
48
|
+
get SuspendedBy(): string { return this.get("SuspendedBy"); }
|
|
49
|
+
get Clusters(): WsWorkunits.Clusters2 { return this.get("Clusters"); }
|
|
50
|
+
get PublishedBy(): string { return this.get("PublishedBy"); }
|
|
51
|
+
get Comment() { return this.get("Comment"); }
|
|
52
|
+
get LogicalFiles(): WsWorkunits.LogicalFiles { return this.get("LogicalFiles"); }
|
|
53
|
+
get SuperFiles(): WsWorkunits.SuperFiles { return this.get("SuperFiles"); }
|
|
54
|
+
get IsLibrary(): boolean { return this.get("IsLibrary"); }
|
|
55
|
+
get Priority(): string { return this.get("Priority"); }
|
|
56
|
+
get WUSnapShot(): string { return this.get("WUSnapShot"); }
|
|
57
|
+
get CompileTime(): string { return this.get("CompileTime"); }
|
|
58
|
+
get LibrariesUsed(): WsWorkunits.LibrariesUsed { return this.get("LibrariesUsed"); }
|
|
59
|
+
get CountGraphs(): number { return this.get("CountGraphs"); }
|
|
60
|
+
get ResourceURLCount(): number { return this.get("ResourceURLCount"); }
|
|
61
|
+
get WsEclAddresses(): WsWorkunits.WsEclAddresses { return this.get("WsEclAddresses"); }
|
|
62
|
+
get WUGraphs(): WsWorkunits.WUGraphs { return this.get("WUGraphs"); }
|
|
63
|
+
get WUTimers(): WsWorkunits.WUTimers { return this.get("WUTimers"); }
|
|
64
|
+
get PriorityID(): number { return this.get("PriorityID"); }
|
|
65
|
+
|
|
66
|
+
private constructor(optsConnection: IOptions | IConnection | WorkunitsService, querySet: string, queryID: string, queryDetails?: WsWorkunits.WUQueryDetailsResponse) {
|
|
67
|
+
super();
|
|
68
|
+
if (optsConnection instanceof WorkunitsService) {
|
|
69
|
+
this.wsWorkunitsService = optsConnection;
|
|
70
|
+
} else {
|
|
71
|
+
this.wsWorkunitsService = new WorkunitsService(optsConnection);
|
|
72
|
+
}
|
|
73
|
+
this.topology = Topology.attach(this.wsWorkunitsService.opts());
|
|
74
|
+
this.set({
|
|
75
|
+
QuerySet: querySet,
|
|
76
|
+
QueryId: queryID,
|
|
77
|
+
...queryDetails
|
|
78
|
+
} as QueryEx);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static attach(optsConnection: IOptions | IConnection, querySet: string, queryId: string, state?: QueryEx): Query {
|
|
82
|
+
const retVal: Query = _queries.get({ BaseUrl: optsConnection.baseUrl, QuerySet: querySet, QueryId: queryId } as QueryEx, () => {
|
|
83
|
+
return new Query(optsConnection, querySet, queryId);
|
|
84
|
+
});
|
|
85
|
+
if (state) {
|
|
86
|
+
retVal.set(state);
|
|
87
|
+
}
|
|
88
|
+
return retVal;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private _eclService: Promise<EclService>;
|
|
92
|
+
protected async wsEclService(): Promise<EclService | undefined> {
|
|
93
|
+
if (!this._eclService) {
|
|
94
|
+
this._eclService = this.topology.fetchServices({}).then(services => {
|
|
95
|
+
for (const espServer of services?.TpEspServers?.TpEspServer ?? []) {
|
|
96
|
+
for (const binding of espServer?.TpBindings?.TpBinding ?? []) {
|
|
97
|
+
if (binding?.Service === "ws_ecl") {
|
|
98
|
+
const baseUrl = `${binding.Protocol}://${globalThis.location.hostname}:${binding.Port}`;
|
|
99
|
+
return new EclService({ baseUrl });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return this._eclService;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private async fetchDetails(): Promise<void> {
|
|
110
|
+
const queryDetails = await this.wsWorkunitsService.WUQueryDetails({
|
|
111
|
+
QuerySet: this.QuerySet,
|
|
112
|
+
QueryId: this.QueryId,
|
|
113
|
+
IncludeStateOnClusters: true,
|
|
114
|
+
IncludeSuperFiles: true,
|
|
115
|
+
IncludeWsEclAddresses: true,
|
|
116
|
+
CheckAllNodes: false
|
|
117
|
+
});
|
|
118
|
+
this.set({ ...queryDetails } as QueryEx);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private async fetchRequestSchema(): Promise<void> {
|
|
122
|
+
const wsEclService = await this.wsEclService();
|
|
123
|
+
try {
|
|
124
|
+
this._requestSchema = await wsEclService?.requestJson(this.QuerySet, this.QueryId) ?? [];
|
|
125
|
+
} catch (e: any) {
|
|
126
|
+
// See: https://track.hpccsystems.com/browse/HPCC-29827
|
|
127
|
+
logger.debug(e.message ?? e);
|
|
128
|
+
this._requestSchema = [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private async fetchResponseSchema(): Promise<void> {
|
|
133
|
+
const wsEclService = await this.wsEclService();
|
|
134
|
+
try {
|
|
135
|
+
this._responseSchema = await wsEclService?.responseJson(this.QuerySet, this.QueryId) ?? {};
|
|
136
|
+
} catch (e: any) {
|
|
137
|
+
// See: https://track.hpccsystems.com/browse/HPCC-29827
|
|
138
|
+
logger.debug(e.message ?? e);
|
|
139
|
+
this._responseSchema = {};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private async fetchSchema(): Promise<void> {
|
|
144
|
+
await Promise.all([this.fetchRequestSchema(), this.fetchResponseSchema()]);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
fetchSummaryStats() {
|
|
148
|
+
return this.wsWorkunitsService.WUQueryGetSummaryStats({ Target: this.QuerySet, QueryId: this.QueryId });
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fetchGraph(GraphName: string = "", SubGraphId: string = ""): Promise<QueryGraph> {
|
|
152
|
+
return this.wsWorkunitsService.WUQueryGetGraph({ Target: this.QuerySet, QueryId: this.QueryId, GraphName, SubGraphId }).then(response => {
|
|
153
|
+
const graph = new QueryGraph();
|
|
154
|
+
let first = true;
|
|
155
|
+
for (const graphItem of response?.Graphs?.ECLGraphEx || []) {
|
|
156
|
+
if (first) {
|
|
157
|
+
graph.load(graphItem.Graph);
|
|
158
|
+
first = false;
|
|
159
|
+
} else {
|
|
160
|
+
graph.merge(graphItem.Graph);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return graph;
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fetchDetailsNormalized(request: RecursivePartial<WsWorkunits.WUDetails> = {}): Promise<{ meta: WsWorkunits.WUDetailsMetaResponse | undefined, columns: { [id: string]: any } | undefined, data: IScope[] | undefined }> {
|
|
168
|
+
const wu = Workunit.attach(this.wsWorkunitsService, this.Wuid);
|
|
169
|
+
if (wu) {
|
|
170
|
+
return Promise.all([this.fetchGraph(), wu.fetchDetailsMeta(), wu.fetchDetailsRaw(request)]).then(promises => {
|
|
171
|
+
const graph = promises[0];
|
|
172
|
+
const meta = promises[1];
|
|
173
|
+
const metrics: WsWorkunits.Scope[] = promises[2];
|
|
174
|
+
const data = metrics.map(metric => {
|
|
175
|
+
const firstChar = metric.Id[0];
|
|
176
|
+
if (firstChar === "a" || firstChar === "e") {
|
|
177
|
+
const item = graph.idx[metric.Id.substring(1)];
|
|
178
|
+
if (!item) {
|
|
179
|
+
logger.debug(`Missing graph data for metric ID: ${metric.Id}`);
|
|
180
|
+
return metric;
|
|
181
|
+
}
|
|
182
|
+
const existingProperties = new Set(metric.Properties.Property.map(prop => prop.Name));
|
|
183
|
+
const newProperties: WsWorkunits.Property[] = [];
|
|
184
|
+
for (const key in item) {
|
|
185
|
+
const firstCharOfKey = key.charAt(0);
|
|
186
|
+
if (firstCharOfKey !== "_" &&
|
|
187
|
+
firstCharOfKey === firstCharOfKey.toUpperCase() &&
|
|
188
|
+
!existingProperties.has(key)) {
|
|
189
|
+
const value = item[key];
|
|
190
|
+
const valueType = typeof value;
|
|
191
|
+
if (valueType === "string" || valueType === "number" || valueType === "boolean") {
|
|
192
|
+
const isNum = isNumber(value);
|
|
193
|
+
let rawValue = isNum ? parseFloat(value as string) : value;
|
|
194
|
+
let formatted = value;
|
|
195
|
+
if (key.indexOf("Time") >= 0) {
|
|
196
|
+
rawValue = (rawValue as number) / 1000000000;
|
|
197
|
+
formatted = siFormatter(rawValue) + "s";
|
|
198
|
+
}
|
|
199
|
+
newProperties.push({
|
|
200
|
+
Name: key,
|
|
201
|
+
RawValue: rawValue as any,
|
|
202
|
+
Formatted: formatted
|
|
203
|
+
} as WsWorkunits.Property);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (newProperties.length > 0) {
|
|
208
|
+
metric.Properties.Property.push(...newProperties);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return metric;
|
|
212
|
+
});
|
|
213
|
+
return wu.normalizeDetails(meta, data);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return Promise.resolve({ meta: undefined, columns: undefined, data: undefined });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async submit(request: object): Promise<Array<{ [key: string]: object[] }>> {
|
|
220
|
+
const wsEclService = await this.wsEclService();
|
|
221
|
+
try {
|
|
222
|
+
return wsEclService?.submit(this.QuerySet, this.QueryId, request).then(results => {
|
|
223
|
+
for (const key in results) {
|
|
224
|
+
results[key] = results[key].Row;
|
|
225
|
+
}
|
|
226
|
+
return results;
|
|
227
|
+
}) ?? [];
|
|
228
|
+
} catch (e: any) {
|
|
229
|
+
// See: https://track.hpccsystems.com/browse/HPCC-29827
|
|
230
|
+
logger.debug(e.message ?? e);
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async refresh(): Promise<this> {
|
|
236
|
+
await Promise.all([
|
|
237
|
+
this.fetchDetails(),
|
|
238
|
+
this.fetchSchema()
|
|
239
|
+
]);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
requestFields(): IWsEclRequest {
|
|
244
|
+
if (!this._requestSchema) return [];
|
|
245
|
+
return this._requestSchema;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
responseFields(): IWsEclResponse {
|
|
249
|
+
if (!this._responseSchema) return {};
|
|
250
|
+
return this._responseSchema;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
resultNames(): string[] {
|
|
254
|
+
const retVal: string[] = [];
|
|
255
|
+
for (const key in this.responseFields()) {
|
|
256
|
+
retVal.push(key);
|
|
257
|
+
}
|
|
258
|
+
return retVal;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
resultFields(resultName: string): IWsEclResult {
|
|
262
|
+
if (!this._responseSchema[resultName]) return [];
|
|
263
|
+
return this._responseSchema[resultName];
|
|
264
|
+
}
|
|
265
|
+
}
|