@hpcc-js/comms 2.102.1 → 2.102.2

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 (95) hide show
  1. package/LICENSE +43 -43
  2. package/README.md +50 -50
  3. package/dist/index.es6.js.map +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/dist/index.node.js.map +1 -1
  7. package/dist/index.node.min.js.map +1 -1
  8. package/package.json +5 -5
  9. package/src/__package__.ts +3 -3
  10. package/src/__tests__/dfuXRef.ts +22 -22
  11. package/src/__tests__/https.ts +69 -69
  12. package/src/__tests__/workunit.ts +35 -35
  13. package/src/clienttools/eclMeta.ts +506 -506
  14. package/src/clienttools/eclcc.ts +628 -628
  15. package/src/connection.ts +295 -295
  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 +195 -195
  20. package/src/ecl/machine.ts +63 -63
  21. package/src/ecl/query.ts +252 -252
  22. package/src/ecl/queryGraph.ts +813 -813
  23. package/src/ecl/resource.ts +39 -39
  24. package/src/ecl/result.ts +236 -236
  25. package/src/ecl/scope.ts +192 -192
  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 +1314 -1314
  32. package/src/ecl/xsdParser.ts +268 -268
  33. package/src/espConnection.ts +172 -172
  34. package/src/index-common.ts +41 -41
  35. package/src/index.node.ts +68 -68
  36. package/src/index.ts +3 -3
  37. package/src/pem/trustwave.ts +909 -909
  38. package/src/services/fileSpray.ts +48 -48
  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 +94 -94
  43. package/src/services/wsDFU.ts +34 -34
  44. package/src/services/wsDFUXRef.ts +308 -308
  45. package/src/services/wsDali.ts +40 -40
  46. package/src/services/wsEcl.ts +123 -123
  47. package/src/services/wsElk.ts +8 -8
  48. package/src/services/wsLogaccess.ts +263 -263
  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 +24 -24
  53. package/src/services/wsSasha.ts +7 -7
  54. package/src/services/wsStore.ts +230 -230
  55. package/src/services/wsTopology.ts +45 -45
  56. package/src/services/wsWorkunits.ts +160 -160
  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/WsCloud/v1/WsCloud.ts +38 -38
  61. package/src/services/wsdl/WsCloud/v1.02/WsCloud.ts +77 -77
  62. package/src/services/wsdl/WsDFUXRef/v1.02/WsDFUXRef.ts +224 -224
  63. package/src/services/wsdl/WsDali/v1.04/WsDali.ts +216 -216
  64. package/src/services/wsdl/WsDfu/v1.62/WsDfu.ts +1455 -1455
  65. package/src/services/wsdl/WsDfu/v1.63/WsDfu.ts +1465 -1465
  66. package/src/services/wsdl/WsDfu/v1.65/WsDfu.ts +1244 -1244
  67. package/src/services/wsdl/WsFileIO/v1.01/WsFileIO.ts +107 -107
  68. package/src/services/wsdl/WsPackageProcess/v1.04/WsPackageProcess.ts +519 -519
  69. package/src/services/wsdl/WsResources/v1.01/WsResources.ts +119 -119
  70. package/src/services/wsdl/WsSMC/v1.24/WsSMC.ts +665 -665
  71. package/src/services/wsdl/WsSMC/v1.27/WsSMC.ts +670 -670
  72. package/src/services/wsdl/WsTopology/v1.31/WsTopology.ts +856 -856
  73. package/src/services/wsdl/WsTopology/v1.32/WsTopology.ts +885 -885
  74. package/src/services/wsdl/WsWorkunits/v1.88/WsWorkunits.ts +2944 -2944
  75. package/src/services/wsdl/WsWorkunits/v1.94/WsWorkunits.ts +3072 -3072
  76. package/src/services/wsdl/WsWorkunits/v1.95/WsWorkunits.ts +3073 -3073
  77. package/src/services/wsdl/WsWorkunits/v1.97/WsWorkunits.ts +3134 -3134
  78. package/src/services/wsdl/WsWorkunits/v1.98/WsWorkunits.ts +3182 -3182
  79. package/src/services/wsdl/WsWorkunits/v1.99/WsWorkunits.ts +3162 -3162
  80. package/src/services/wsdl/WsWorkunits/v2/WsWorkunits.ts +3153 -3153
  81. package/src/services/wsdl/WsWorkunits/v2.02/WsWorkunits.ts +3157 -3157
  82. package/src/services/wsdl/ws_access/v1.16/ws_access.ts +1086 -1086
  83. package/src/services/wsdl/ws_access/v1.17/ws_access.ts +1023 -1023
  84. package/src/services/wsdl/ws_account/v1.05/ws_account.ts +111 -111
  85. package/src/services/wsdl/ws_account/v1.06/ws_account.ts +109 -109
  86. package/src/services/wsdl/ws_codesign/v1.1/ws_codesign.ts +100 -100
  87. package/src/services/wsdl/ws_elk/v1/ws_elk.ts +47 -47
  88. package/src/services/wsdl/ws_logaccess/v1/ws_logaccess.ts +83 -83
  89. package/src/services/wsdl/ws_logaccess/v1.02/ws_logaccess.ts +161 -161
  90. package/src/services/wsdl/ws_logaccess/v1.03/ws_logaccess.ts +190 -190
  91. package/src/services/wsdl/ws_logaccess/v1.04/ws_logaccess.ts +215 -215
  92. package/src/services/wsdl/ws_logaccess/v1.05/ws_logaccess.ts +219 -219
  93. package/src/services/wsdl/ws_logaccess/v1.08/ws_logaccess.ts +267 -267
  94. package/src/services/wsdl/ws_machine/v1.17/ws_machine.ts +567 -567
  95. package/src/services/wsdl/wsstore/v1.02/wsstore.ts +250 -250
package/src/ecl/store.ts CHANGED
@@ -1,154 +1,154 @@
1
- import { Cache, Dispatch, IObserverHandle, Message } from "@hpcc-js/util";
2
- import { IConnection, IOptions } from "../connection";
3
- import { StoreService } from "../services/wsStore";
4
-
5
- export class StoreCache extends Cache<{ BaseUrl: string, Name: string, UserSpecific: boolean, Namespace: string }, Store> {
6
- constructor() {
7
- super((obj) => {
8
- return `${obj.BaseUrl}-${obj.Name}:${obj.UserSpecific}-${obj.Namespace}`;
9
- });
10
- }
11
- }
12
- const _store = new StoreCache();
13
-
14
- export class ValueChangedMessage extends Message {
15
-
16
- constructor(readonly key: string, public value: any, public oldValue?: any) {
17
- super();
18
- }
19
-
20
- get canConflate(): boolean { return true; }
21
- conflate(other: ValueChangedMessage): boolean {
22
- if (this.key === other.key) {
23
- this.value = other.value;
24
- return true;
25
- }
26
- return false;
27
- }
28
-
29
- void(): boolean {
30
- return this.value === this.oldValue;
31
- }
32
- }
33
-
34
- export class Store {
35
- protected connection: StoreService;
36
- get BaseUrl() { return this.connection.baseUrl; }
37
- readonly Name: string;
38
- readonly UserSpecific: boolean;
39
- readonly Namespace: string;
40
-
41
- protected _dispatch = new Dispatch();
42
-
43
- static attach(optsConnection: IOptions | IConnection | StoreService, Name: string = "HPCCApps", Namespace: string, UserSpecific: boolean = true): Store {
44
- const retVal: Store = _store.get({ BaseUrl: optsConnection.baseUrl, Name, UserSpecific, Namespace }, () => {
45
- return new Store(optsConnection, Name, Namespace, UserSpecific);
46
- });
47
- return retVal;
48
- }
49
-
50
- protected constructor(optsConnection: IOptions | IConnection | StoreService, Name: string, Namespace: string, UserSpecific: boolean) {
51
- if (optsConnection instanceof StoreService) {
52
- this.connection = optsConnection;
53
- } else {
54
- this.connection = new StoreService(optsConnection);
55
- }
56
- this.Name = Name;
57
- this.UserSpecific = UserSpecific;
58
- this.Namespace = Namespace;
59
- }
60
-
61
- private _knownValues: { [key: string]: any } = {};
62
-
63
- protected create() {
64
- this.connection.CreateStore({ Name: this.Name, UserSpecific: this.UserSpecific, Type: "", Description: "" });
65
- }
66
-
67
- set(key: string, value: string, broadcast = true): Promise<void> {
68
- return this.connection.Set({
69
- StoreName: this.Name,
70
- UserSpecific: this.UserSpecific,
71
- Namespace: this.Namespace,
72
- Key: key,
73
- Value: value
74
- }).then(response => {
75
- const oldValue = this._knownValues[key];
76
- this._knownValues[key] = value;
77
- if (broadcast) {
78
- this._dispatch.post(new ValueChangedMessage(key, value, oldValue));
79
- }
80
- }).catch(e => {
81
- console.error(`Store.set("${key}", "${value}") failed:`, e);
82
- });
83
- }
84
-
85
- get(key: string, broadcast = true): Promise<string | undefined> {
86
- return this.connection.Fetch({
87
- StoreName: this.Name,
88
- UserSpecific: this.UserSpecific,
89
- Namespace: this.Namespace,
90
- Key: key
91
- }).then(response => {
92
- const oldValue = this._knownValues[key];
93
- this._knownValues[key] = response.Value;
94
- if (broadcast) {
95
- this._dispatch.post(new ValueChangedMessage(key, response.Value, oldValue));
96
- }
97
- return response.Value;
98
- }).catch(e => {
99
- console.error(`Store.get(${key}) failed:`, e);
100
- return undefined;
101
- });
102
- }
103
-
104
- getAll(broadcast = true): Promise<{ [key: string]: string }> {
105
- return this.connection.FetchAll({
106
- StoreName: this.Name,
107
- UserSpecific: this.UserSpecific,
108
- Namespace: this.Namespace
109
- }).then(response => {
110
- const retVal: { [key: string]: string } = {};
111
- const deletedValues = this._knownValues;
112
- this._knownValues = {};
113
- response.Pairs.Pair.forEach(pair => {
114
- const oldValue = this._knownValues[pair.Key];
115
- this._knownValues[pair.Key] = pair.Value;
116
- delete deletedValues[pair.Key];
117
- retVal[pair.Key] = pair.Value;
118
- if (broadcast) {
119
- this._dispatch.post(new ValueChangedMessage(pair.Key, pair.Value, oldValue));
120
- }
121
- });
122
- if (broadcast) {
123
- for (const key in deletedValues) {
124
- this._dispatch.post(new ValueChangedMessage(key, undefined, deletedValues[key]));
125
- }
126
- }
127
- return retVal;
128
- }).catch(e => {
129
- console.error("Store.getAll failed:", e);
130
- return {};
131
- });
132
- }
133
-
134
- delete(key: string, broadcast = true): Promise<void> {
135
- return this.connection.Delete({
136
- StoreName: this.Name,
137
- UserSpecific: this.UserSpecific,
138
- Namespace: this.Namespace,
139
- Key: key
140
- }).then(response => {
141
- const oldValue = this._knownValues[key];
142
- delete this._knownValues[key];
143
- if (broadcast) {
144
- this._dispatch.post(new ValueChangedMessage(key, undefined, oldValue));
145
- }
146
- }).catch(e => {
147
- console.error(`Store.delete(${key}) failed:`, e);
148
- });
149
- }
150
-
151
- monitor(callback: (messages: ValueChangedMessage[]) => void): IObserverHandle {
152
- return this._dispatch.attach(callback);
153
- }
154
- }
1
+ import { Cache, Dispatch, IObserverHandle, Message } from "@hpcc-js/util";
2
+ import { IConnection, IOptions } from "../connection";
3
+ import { StoreService } from "../services/wsStore";
4
+
5
+ export class StoreCache extends Cache<{ BaseUrl: string, Name: string, UserSpecific: boolean, Namespace: string }, Store> {
6
+ constructor() {
7
+ super((obj) => {
8
+ return `${obj.BaseUrl}-${obj.Name}:${obj.UserSpecific}-${obj.Namespace}`;
9
+ });
10
+ }
11
+ }
12
+ const _store = new StoreCache();
13
+
14
+ export class ValueChangedMessage extends Message {
15
+
16
+ constructor(readonly key: string, public value: any, public oldValue?: any) {
17
+ super();
18
+ }
19
+
20
+ get canConflate(): boolean { return true; }
21
+ conflate(other: ValueChangedMessage): boolean {
22
+ if (this.key === other.key) {
23
+ this.value = other.value;
24
+ return true;
25
+ }
26
+ return false;
27
+ }
28
+
29
+ void(): boolean {
30
+ return this.value === this.oldValue;
31
+ }
32
+ }
33
+
34
+ export class Store {
35
+ protected connection: StoreService;
36
+ get BaseUrl() { return this.connection.baseUrl; }
37
+ readonly Name: string;
38
+ readonly UserSpecific: boolean;
39
+ readonly Namespace: string;
40
+
41
+ protected _dispatch = new Dispatch();
42
+
43
+ static attach(optsConnection: IOptions | IConnection | StoreService, Name: string = "HPCCApps", Namespace: string, UserSpecific: boolean = true): Store {
44
+ const retVal: Store = _store.get({ BaseUrl: optsConnection.baseUrl, Name, UserSpecific, Namespace }, () => {
45
+ return new Store(optsConnection, Name, Namespace, UserSpecific);
46
+ });
47
+ return retVal;
48
+ }
49
+
50
+ protected constructor(optsConnection: IOptions | IConnection | StoreService, Name: string, Namespace: string, UserSpecific: boolean) {
51
+ if (optsConnection instanceof StoreService) {
52
+ this.connection = optsConnection;
53
+ } else {
54
+ this.connection = new StoreService(optsConnection);
55
+ }
56
+ this.Name = Name;
57
+ this.UserSpecific = UserSpecific;
58
+ this.Namespace = Namespace;
59
+ }
60
+
61
+ private _knownValues: { [key: string]: any } = {};
62
+
63
+ protected create() {
64
+ this.connection.CreateStore({ Name: this.Name, UserSpecific: this.UserSpecific, Type: "", Description: "" });
65
+ }
66
+
67
+ set(key: string, value: string, broadcast = true): Promise<void> {
68
+ return this.connection.Set({
69
+ StoreName: this.Name,
70
+ UserSpecific: this.UserSpecific,
71
+ Namespace: this.Namespace,
72
+ Key: key,
73
+ Value: value
74
+ }).then(response => {
75
+ const oldValue = this._knownValues[key];
76
+ this._knownValues[key] = value;
77
+ if (broadcast) {
78
+ this._dispatch.post(new ValueChangedMessage(key, value, oldValue));
79
+ }
80
+ }).catch(e => {
81
+ console.error(`Store.set("${key}", "${value}") failed:`, e);
82
+ });
83
+ }
84
+
85
+ get(key: string, broadcast = true): Promise<string | undefined> {
86
+ return this.connection.Fetch({
87
+ StoreName: this.Name,
88
+ UserSpecific: this.UserSpecific,
89
+ Namespace: this.Namespace,
90
+ Key: key
91
+ }).then(response => {
92
+ const oldValue = this._knownValues[key];
93
+ this._knownValues[key] = response.Value;
94
+ if (broadcast) {
95
+ this._dispatch.post(new ValueChangedMessage(key, response.Value, oldValue));
96
+ }
97
+ return response.Value;
98
+ }).catch(e => {
99
+ console.error(`Store.get(${key}) failed:`, e);
100
+ return undefined;
101
+ });
102
+ }
103
+
104
+ getAll(broadcast = true): Promise<{ [key: string]: string }> {
105
+ return this.connection.FetchAll({
106
+ StoreName: this.Name,
107
+ UserSpecific: this.UserSpecific,
108
+ Namespace: this.Namespace
109
+ }).then(response => {
110
+ const retVal: { [key: string]: string } = {};
111
+ const deletedValues = this._knownValues;
112
+ this._knownValues = {};
113
+ response.Pairs.Pair.forEach(pair => {
114
+ const oldValue = this._knownValues[pair.Key];
115
+ this._knownValues[pair.Key] = pair.Value;
116
+ delete deletedValues[pair.Key];
117
+ retVal[pair.Key] = pair.Value;
118
+ if (broadcast) {
119
+ this._dispatch.post(new ValueChangedMessage(pair.Key, pair.Value, oldValue));
120
+ }
121
+ });
122
+ if (broadcast) {
123
+ for (const key in deletedValues) {
124
+ this._dispatch.post(new ValueChangedMessage(key, undefined, deletedValues[key]));
125
+ }
126
+ }
127
+ return retVal;
128
+ }).catch(e => {
129
+ console.error("Store.getAll failed:", e);
130
+ return {};
131
+ });
132
+ }
133
+
134
+ delete(key: string, broadcast = true): Promise<void> {
135
+ return this.connection.Delete({
136
+ StoreName: this.Name,
137
+ UserSpecific: this.UserSpecific,
138
+ Namespace: this.Namespace,
139
+ Key: key
140
+ }).then(response => {
141
+ const oldValue = this._knownValues[key];
142
+ delete this._knownValues[key];
143
+ if (broadcast) {
144
+ this._dispatch.post(new ValueChangedMessage(key, undefined, oldValue));
145
+ }
146
+ }).catch(e => {
147
+ console.error(`Store.delete(${key}) failed:`, e);
148
+ });
149
+ }
150
+
151
+ monitor(callback: (messages: ValueChangedMessage[]) => void): IObserverHandle {
152
+ return this._dispatch.attach(callback);
153
+ }
154
+ }
@@ -1,149 +1,149 @@
1
- import { Cache, StateObject } from "@hpcc-js/util";
2
- import { IConnection, IOptions } from "../connection";
3
- import { WsMachine, WsMachineEx, MachineService } from "../services/wsMachine";
4
- import { TopologyService, WsTopology } from "../services/wsTopology";
5
- import { Machine } from "./machine";
6
-
7
- export class TargetClusterCache extends Cache<{ BaseUrl: string, Name: string }, TargetCluster> {
8
- constructor() {
9
- super((obj) => {
10
- return `${obj.BaseUrl}-${obj.Name}`;
11
- });
12
- }
13
- }
14
- const _targetCluster = new TargetClusterCache();
15
-
16
- export interface TpTargetClusterEx {
17
- MachineInfoEx: WsMachine.MachineInfoEx[];
18
- }
19
-
20
- export type UTargetClusterState = WsTopology.TpTargetCluster & WsTopology.TpClusterNameType & TpTargetClusterEx;
21
- export type ITargetClusterState = WsTopology.TpTargetCluster | WsTopology.TpClusterNameType | TpTargetClusterEx;
22
- export class TargetCluster extends StateObject<UTargetClusterState, ITargetClusterState> implements UTargetClusterState {
23
- protected connection: TopologyService;
24
- protected machineConnection: MachineService;
25
- get BaseUrl() { return this.connection.baseUrl; }
26
-
27
- get Name(): string { return this.get("Name"); }
28
- get Prefix(): string { return this.get("Prefix"); }
29
- get Type(): string { return this.get("Type"); }
30
- get IsDefault(): boolean { return this.get("IsDefault"); }
31
- get TpClusters(): WsTopology.TpClusters { return this.get("TpClusters"); }
32
- get TpEclCCServers(): WsTopology.TpEclCCServers { return this.get("TpEclCCServers"); }
33
- get TpEclServers(): WsTopology.TpEclServers { return this.get("TpEclServers"); }
34
- get TpEclAgents(): WsTopology.TpEclAgents { return this.get("TpEclAgents"); }
35
- get TpEclSchedulers(): WsTopology.TpEclSchedulers { return this.get("TpEclSchedulers"); }
36
- get MachineInfoEx(): WsMachine.MachineInfoEx[] { return this.get("MachineInfoEx", []); }
37
- get CMachineInfoEx(): Machine[] {
38
- return this.MachineInfoEx.map(machineInfoEx => Machine.attach(this.machineConnection, machineInfoEx.Address, machineInfoEx));
39
- }
40
-
41
- static attach(optsConnection: IOptions | IConnection | TopologyService, name: string, state?: ITargetClusterState): TargetCluster {
42
- const retVal: TargetCluster = _targetCluster.get({ BaseUrl: optsConnection.baseUrl, Name: name }, () => {
43
- return new TargetCluster(optsConnection, name);
44
- });
45
- if (state) {
46
- retVal.set(state);
47
- }
48
- return retVal;
49
- }
50
-
51
- protected constructor(optsConnection: IOptions | IConnection | TopologyService, name: string) {
52
- super();
53
- if (optsConnection instanceof TopologyService) {
54
- this.connection = optsConnection;
55
- this.machineConnection = new MachineService(optsConnection.connectionOptions());
56
- } else {
57
- this.connection = new TopologyService(optsConnection);
58
- this.machineConnection = new MachineService(optsConnection);
59
- }
60
- this.clear({
61
- Name: name
62
- });
63
- }
64
-
65
- fetchMachines(request: WsMachine.GetTargetClusterInfoRequest = {}): Promise<Machine[]> {
66
- return this.machineConnection.GetTargetClusterInfo({
67
- TargetClusters: {
68
- Item: [`${this.Type}:${this.Name}`]
69
- },
70
- ...request
71
- }).then(response => {
72
- const retVal: WsMachine.MachineInfoEx[] = [];
73
- for (const machineInfo of response.TargetClusterInfoList.TargetClusterInfo) {
74
- for (const machineInfoEx of machineInfo.Processes.MachineInfoEx) {
75
- retVal.push(machineInfoEx);
76
- }
77
- }
78
- this.set("MachineInfoEx", retVal);
79
- return this.CMachineInfoEx;
80
- });
81
- }
82
-
83
- machineStats(): { maxDisk: number; meanDisk: number } {
84
- let maxDisk = 0;
85
- let totalFree = 0;
86
- let total = 0;
87
- for (const machine of this.CMachineInfoEx) {
88
- for (const storageInfo of machine.Storage.StorageInfo) {
89
- totalFree += storageInfo.Available;
90
- total += storageInfo.Total;
91
- const usage = 1 - storageInfo.Available / storageInfo.Total;
92
- if (usage > maxDisk) {
93
- maxDisk = usage;
94
- }
95
- }
96
- }
97
- return {
98
- maxDisk,
99
- meanDisk: 1 - (total ? totalFree / total : 1)
100
- };
101
- }
102
-
103
- fetchUsage(): Promise<WsMachineEx.TargetClusterUsage[]> {
104
- return this.machineConnection.GetTargetClusterUsageEx([this.Name]);
105
- }
106
- }
107
-
108
- export function targetClusters(optsConnection: IOptions | IConnection | TopologyService): Promise<TargetCluster[]> {
109
- let connection: TopologyService;
110
- if (optsConnection instanceof TopologyService) {
111
- connection = optsConnection;
112
- } else {
113
- connection = new TopologyService(optsConnection);
114
- }
115
- return connection.TpListTargetClusters({}).then(response => {
116
- return response.TargetClusters.TpClusterNameType.map(item => TargetCluster.attach(optsConnection, item.Name, item));
117
- });
118
- }
119
-
120
- const _defaultTargetCluster: { [baseUrl: string]: Promise<TargetCluster> } = {};
121
- export function defaultTargetCluster(optsConnection: IOptions | IConnection | TopologyService): Promise<TargetCluster> {
122
- if (!_defaultTargetCluster[optsConnection.baseUrl]) {
123
- let connection: TopologyService;
124
- if (optsConnection instanceof TopologyService) {
125
- connection = optsConnection;
126
- } else {
127
- connection = new TopologyService(optsConnection);
128
- }
129
- _defaultTargetCluster[optsConnection.baseUrl] = connection.TpListTargetClusters({}).then(response => {
130
- let firstItem: WsTopology.TpClusterNameType;
131
- let defaultItem: WsTopology.TpClusterNameType;
132
- let hthorItem: WsTopology.TpClusterNameType;
133
- response.TargetClusters.TpClusterNameType.forEach(item => {
134
- if (!firstItem) {
135
- firstItem = item;
136
- }
137
- if (!defaultItem && item.IsDefault === true) {
138
- defaultItem = item;
139
- }
140
- if (!hthorItem && item.Type === "hthor") {
141
- hthorItem = item;
142
- }
143
- });
144
- const defItem = defaultItem || hthorItem || firstItem;
145
- return TargetCluster.attach(optsConnection, defItem.Name, defItem);
146
- });
147
- }
148
- return _defaultTargetCluster[optsConnection.baseUrl];
149
- }
1
+ import { Cache, StateObject } from "@hpcc-js/util";
2
+ import { IConnection, IOptions } from "../connection";
3
+ import { WsMachine, WsMachineEx, MachineService } from "../services/wsMachine";
4
+ import { TopologyService, WsTopology } from "../services/wsTopology";
5
+ import { Machine } from "./machine";
6
+
7
+ export class TargetClusterCache extends Cache<{ BaseUrl: string, Name: string }, TargetCluster> {
8
+ constructor() {
9
+ super((obj) => {
10
+ return `${obj.BaseUrl}-${obj.Name}`;
11
+ });
12
+ }
13
+ }
14
+ const _targetCluster = new TargetClusterCache();
15
+
16
+ export interface TpTargetClusterEx {
17
+ MachineInfoEx: WsMachine.MachineInfoEx[];
18
+ }
19
+
20
+ export type UTargetClusterState = WsTopology.TpTargetCluster & WsTopology.TpClusterNameType & TpTargetClusterEx;
21
+ export type ITargetClusterState = WsTopology.TpTargetCluster | WsTopology.TpClusterNameType | TpTargetClusterEx;
22
+ export class TargetCluster extends StateObject<UTargetClusterState, ITargetClusterState> implements UTargetClusterState {
23
+ protected connection: TopologyService;
24
+ protected machineConnection: MachineService;
25
+ get BaseUrl() { return this.connection.baseUrl; }
26
+
27
+ get Name(): string { return this.get("Name"); }
28
+ get Prefix(): string { return this.get("Prefix"); }
29
+ get Type(): string { return this.get("Type"); }
30
+ get IsDefault(): boolean { return this.get("IsDefault"); }
31
+ get TpClusters(): WsTopology.TpClusters { return this.get("TpClusters"); }
32
+ get TpEclCCServers(): WsTopology.TpEclCCServers { return this.get("TpEclCCServers"); }
33
+ get TpEclServers(): WsTopology.TpEclServers { return this.get("TpEclServers"); }
34
+ get TpEclAgents(): WsTopology.TpEclAgents { return this.get("TpEclAgents"); }
35
+ get TpEclSchedulers(): WsTopology.TpEclSchedulers { return this.get("TpEclSchedulers"); }
36
+ get MachineInfoEx(): WsMachine.MachineInfoEx[] { return this.get("MachineInfoEx", []); }
37
+ get CMachineInfoEx(): Machine[] {
38
+ return this.MachineInfoEx.map(machineInfoEx => Machine.attach(this.machineConnection, machineInfoEx.Address, machineInfoEx));
39
+ }
40
+
41
+ static attach(optsConnection: IOptions | IConnection | TopologyService, name: string, state?: ITargetClusterState): TargetCluster {
42
+ const retVal: TargetCluster = _targetCluster.get({ BaseUrl: optsConnection.baseUrl, Name: name }, () => {
43
+ return new TargetCluster(optsConnection, name);
44
+ });
45
+ if (state) {
46
+ retVal.set(state);
47
+ }
48
+ return retVal;
49
+ }
50
+
51
+ protected constructor(optsConnection: IOptions | IConnection | TopologyService, name: string) {
52
+ super();
53
+ if (optsConnection instanceof TopologyService) {
54
+ this.connection = optsConnection;
55
+ this.machineConnection = new MachineService(optsConnection.connectionOptions());
56
+ } else {
57
+ this.connection = new TopologyService(optsConnection);
58
+ this.machineConnection = new MachineService(optsConnection);
59
+ }
60
+ this.clear({
61
+ Name: name
62
+ });
63
+ }
64
+
65
+ fetchMachines(request: WsMachine.GetTargetClusterInfoRequest = {}): Promise<Machine[]> {
66
+ return this.machineConnection.GetTargetClusterInfo({
67
+ TargetClusters: {
68
+ Item: [`${this.Type}:${this.Name}`]
69
+ },
70
+ ...request
71
+ }).then(response => {
72
+ const retVal: WsMachine.MachineInfoEx[] = [];
73
+ for (const machineInfo of response.TargetClusterInfoList.TargetClusterInfo) {
74
+ for (const machineInfoEx of machineInfo.Processes.MachineInfoEx) {
75
+ retVal.push(machineInfoEx);
76
+ }
77
+ }
78
+ this.set("MachineInfoEx", retVal);
79
+ return this.CMachineInfoEx;
80
+ });
81
+ }
82
+
83
+ machineStats(): { maxDisk: number; meanDisk: number } {
84
+ let maxDisk = 0;
85
+ let totalFree = 0;
86
+ let total = 0;
87
+ for (const machine of this.CMachineInfoEx) {
88
+ for (const storageInfo of machine.Storage.StorageInfo) {
89
+ totalFree += storageInfo.Available;
90
+ total += storageInfo.Total;
91
+ const usage = 1 - storageInfo.Available / storageInfo.Total;
92
+ if (usage > maxDisk) {
93
+ maxDisk = usage;
94
+ }
95
+ }
96
+ }
97
+ return {
98
+ maxDisk,
99
+ meanDisk: 1 - (total ? totalFree / total : 1)
100
+ };
101
+ }
102
+
103
+ fetchUsage(): Promise<WsMachineEx.TargetClusterUsage[]> {
104
+ return this.machineConnection.GetTargetClusterUsageEx([this.Name]);
105
+ }
106
+ }
107
+
108
+ export function targetClusters(optsConnection: IOptions | IConnection | TopologyService): Promise<TargetCluster[]> {
109
+ let connection: TopologyService;
110
+ if (optsConnection instanceof TopologyService) {
111
+ connection = optsConnection;
112
+ } else {
113
+ connection = new TopologyService(optsConnection);
114
+ }
115
+ return connection.TpListTargetClusters({}).then(response => {
116
+ return response.TargetClusters.TpClusterNameType.map(item => TargetCluster.attach(optsConnection, item.Name, item));
117
+ });
118
+ }
119
+
120
+ const _defaultTargetCluster: { [baseUrl: string]: Promise<TargetCluster> } = {};
121
+ export function defaultTargetCluster(optsConnection: IOptions | IConnection | TopologyService): Promise<TargetCluster> {
122
+ if (!_defaultTargetCluster[optsConnection.baseUrl]) {
123
+ let connection: TopologyService;
124
+ if (optsConnection instanceof TopologyService) {
125
+ connection = optsConnection;
126
+ } else {
127
+ connection = new TopologyService(optsConnection);
128
+ }
129
+ _defaultTargetCluster[optsConnection.baseUrl] = connection.TpListTargetClusters({}).then(response => {
130
+ let firstItem: WsTopology.TpClusterNameType;
131
+ let defaultItem: WsTopology.TpClusterNameType;
132
+ let hthorItem: WsTopology.TpClusterNameType;
133
+ response.TargetClusters.TpClusterNameType.forEach(item => {
134
+ if (!firstItem) {
135
+ firstItem = item;
136
+ }
137
+ if (!defaultItem && item.IsDefault === true) {
138
+ defaultItem = item;
139
+ }
140
+ if (!hthorItem && item.Type === "hthor") {
141
+ hthorItem = item;
142
+ }
143
+ });
144
+ const defItem = defaultItem || hthorItem || firstItem;
145
+ return TargetCluster.attach(optsConnection, defItem.Name, defItem);
146
+ });
147
+ }
148
+ return _defaultTargetCluster[optsConnection.baseUrl];
149
+ }