@nsshunt/stsappframework 3.0.103 → 3.0.105
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/dist/authutilsnode.js +6 -7
- package/dist/authutilsnode.js.map +1 -1
- package/dist/influxdb/influxDBManager.js +16 -17
- package/dist/influxdb/influxDBManager.js.map +1 -1
- package/dist/influxdb/influxDBManagerAgent.js +9 -13
- package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
- package/dist/influxdb/influxDBManagerBase.js +2 -6
- package/dist/influxdb/influxDBManagerBase.js.map +1 -1
- package/dist/influxdb/influxDBManagerService.js +10 -14
- package/dist/influxdb/influxDBManagerService.js.map +1 -1
- package/dist/instrumentationsubscriber.js +11 -15
- package/dist/instrumentationsubscriber.js.map +1 -1
- package/dist/kafka/IMKafkaManager.js +2 -6
- package/dist/kafka/IMKafkaManager.js.map +1 -1
- package/dist/kafkatesting/produce.js +1 -5
- package/dist/kafkatesting/produce.js.map +1 -1
- package/dist/masterprocessbase.js +19 -20
- package/dist/masterprocessbase.js.map +1 -1
- package/dist/processbase.js +8 -10
- package/dist/processbase.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/singleprocessbase.js +3 -4
- package/dist/singleprocessbase.js.map +1 -1
- package/dist/tcpclient/app2.js +2 -2
- package/dist/tcpserver/appmaster.js +39 -16
- package/dist/tcpserver/appmaster.js.map +1 -1
- package/dist/workerprocessbase.js +3 -4
- package/dist/workerprocessbase.js.map +1 -1
- package/package.json +7 -7
- package/src/authutilsnode.ts +8 -10
- package/src/influxdb/influxDBManager.ts +16 -18
- package/src/influxdb/influxDBManagerAgent.ts +9 -11
- package/src/influxdb/influxDBManagerBase.ts +2 -4
- package/src/influxdb/influxDBManagerService.ts +10 -12
- package/src/instrumentationsubscriber.ts +11 -14
- package/src/kafka/IMKafkaManager.ts +2 -4
- package/src/kafkatesting/produce.ts +1 -3
- package/src/masterprocessbase.ts +32 -24
- package/src/processbase.ts +7 -11
- package/src/server.ts +1 -1
- package/src/singleprocessbase.ts +3 -5
- package/src/tcpclient/app2.ts +2 -2
- package/src/tcpserver/appmaster.ts +39 -17
- package/src/workerprocessbase.ts +3 -5
- package/types/authutilsnode.d.ts.map +1 -1
- package/types/influxdb/influxDBManager.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
- package/types/instrumentationsubscriber.d.ts.map +1 -1
- package/types/kafka/IMKafkaManager.d.ts.map +1 -1
- package/types/masterprocessbase.d.ts.map +1 -1
- package/types/processbase.d.ts +2 -2
- package/types/processbase.d.ts.map +1 -1
- package/types/singleprocessbase.d.ts.map +1 -1
- package/types/tcpserver/appmaster.d.ts.map +1 -1
- package/types/workerprocessbase.d.ts.map +1 -1
- package/src_new/authDefs.ts +0 -37
- package/src_new/authutilsnode.ts +0 -375
- package/src_new/commonTypes.ts +0 -239
- package/src_new/index.ts +0 -22
- package/src_new/influxdb/influxDBManager.ts +0 -972
- package/src_new/influxdb/influxDBManagerAgent.ts +0 -316
- package/src_new/influxdb/influxDBManagerBase.ts +0 -111
- package/src_new/influxdb/influxDBManagerService.ts +0 -375
- package/src_new/instrumentationsubscriber.ts +0 -286
- package/src_new/kafka/IMKafkaManager.ts +0 -154
- package/src_new/kafka/kafkaconsumer.ts +0 -82
- package/src_new/kafka/kafkamanager.ts +0 -186
- package/src_new/kafka/kafkaproducer.ts +0 -58
- package/src_new/kafkatesting/config.ts +0 -10
- package/src_new/kafkatesting/consume.ts +0 -116
- package/src_new/kafkatesting/produce.ts +0 -155
- package/src_new/masterprocessbase.ts +0 -590
- package/src_new/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_new/network.ts +0 -36
- package/src_new/processbase.ts +0 -413
- package/src_new/processoptions.ts +0 -164
- package/src_new/publishertransports/publishTransportDirect.ts +0 -45
- package/src_new/publishertransports/publishTransportUtils.ts +0 -53
- package/src_new/server.ts +0 -141
- package/src_new/serverprocessbase.ts +0 -393
- package/src_new/singleprocessbase.ts +0 -123
- package/src_new/socketIoServerHelper.ts +0 -177
- package/src_new/stscontrollerbase.ts +0 -15
- package/src_new/stslatencycontroller.ts +0 -27
- package/src_new/stslatencyroute.ts +0 -16
- package/src_new/stsrouterbase.ts +0 -22
- package/src_new/tcpclient/app.ts +0 -19
- package/src_new/tcpclient/app2.ts +0 -56
- package/src_new/tcpserver/app.ts +0 -11
- package/src_new/tcpserver/appConfig.ts +0 -65
- package/src_new/tcpserver/appmaster.ts +0 -522
- package/src_new/validation/errors.ts +0 -6
- package/src_new/webworkertesting/app.ts +0 -49
- package/src_new/webworkertesting/worker.ts +0 -24
- package/src_new/workerprocessbase.test.ts +0 -47
- package/src_new/workerprocessbase.ts +0 -187
- package/src_working/authDefs.ts +0 -37
- package/src_working/authutilsnode.ts +0 -373
- package/src_working/commonTypes.ts +0 -239
- package/src_working/index.ts +0 -22
- package/src_working/influxdb/influxDBManager.ts +0 -970
- package/src_working/influxdb/influxDBManagerAgent.ts +0 -314
- package/src_working/influxdb/influxDBManagerBase.ts +0 -109
- package/src_working/influxdb/influxDBManagerService.ts +0 -373
- package/src_working/instrumentationsubscriber.ts +0 -283
- package/src_working/kafka/IMKafkaManager.ts +0 -152
- package/src_working/kafka/kafkaconsumer.ts +0 -82
- package/src_working/kafka/kafkamanager.ts +0 -186
- package/src_working/kafka/kafkaproducer.ts +0 -58
- package/src_working/kafkatesting/config.ts +0 -10
- package/src_working/kafkatesting/consume.ts +0 -116
- package/src_working/kafkatesting/produce.ts +0 -153
- package/src_working/masterprocessbase.ts +0 -598
- package/src_working/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_working/network.ts +0 -36
- package/src_working/processbase.ts +0 -411
- package/src_working/processoptions.ts +0 -164
- package/src_working/publishertransports/publishTransportDirect.ts +0 -45
- package/src_working/publishertransports/publishTransportUtils.ts +0 -53
- package/src_working/server.ts +0 -141
- package/src_working/serverprocessbase.ts +0 -393
- package/src_working/singleprocessbase.ts +0 -121
- package/src_working/socketIoServerHelper.ts +0 -177
- package/src_working/stscontrollerbase.ts +0 -15
- package/src_working/stslatencycontroller.ts +0 -27
- package/src_working/stslatencyroute.ts +0 -16
- package/src_working/stsrouterbase.ts +0 -22
- package/src_working/tcpclient/app.ts +0 -19
- package/src_working/tcpclient/app2.ts +0 -56
- package/src_working/tcpserver/app.ts +0 -11
- package/src_working/tcpserver/appConfig.ts +0 -65
- package/src_working/tcpserver/appmaster.ts +0 -544
- package/src_working/validation/errors.ts +0 -6
- package/src_working/webworkertesting/app.ts +0 -49
- package/src_working/webworkertesting/worker.ts +0 -24
- package/src_working/workerprocessbase.test.ts +0 -47
- package/src_working/workerprocessbase.ts +0 -185
|
@@ -117,8 +117,6 @@ import { InfluxDBManagerBase } from './influxDBManagerBase'
|
|
|
117
117
|
import { IInfluxDBManagerOptions, InstrumentPayload } from './../commonTypes'
|
|
118
118
|
import { ISubscriptionPayload, ISubscriptionKey } from '@nsshunt/stssocketio-client'
|
|
119
119
|
|
|
120
|
-
import chalk from 'chalk';
|
|
121
|
-
|
|
122
120
|
const _logPrefix = 'InfluxDBManagerService:'
|
|
123
121
|
|
|
124
122
|
/*
|
|
@@ -181,7 +179,7 @@ data
|
|
|
181
179
|
|
|
182
180
|
return this.queryApi.collectRows(query)
|
|
183
181
|
} catch (error) {
|
|
184
|
-
console.error(
|
|
182
|
+
console.error(`${_logPrefix}#GetSTSCountGeneric: Error: [${error}]`.red);
|
|
185
183
|
}
|
|
186
184
|
}
|
|
187
185
|
|
|
@@ -197,7 +195,7 @@ data
|
|
|
197
195
|
|> difference()`;
|
|
198
196
|
return this.queryApi.collectRows(query)
|
|
199
197
|
} catch (error) {
|
|
200
|
-
console.error(
|
|
198
|
+
console.error(`${_logPrefix}#GetSTSHistoGeneric: Error: [${error}]`.red);
|
|
201
199
|
}
|
|
202
200
|
}
|
|
203
201
|
|
|
@@ -228,7 +226,7 @@ data
|
|
|
228
226
|
|
|
229
227
|
return this.queryApi.collectRows(query)
|
|
230
228
|
} catch (error) {
|
|
231
|
-
console.error(
|
|
229
|
+
console.error(`${_logPrefix}#GetSTSQuantileGeneric: Error: [${error}]`.red);
|
|
232
230
|
}
|
|
233
231
|
}
|
|
234
232
|
|
|
@@ -243,7 +241,7 @@ data
|
|
|
243
241
|
this.#GetSTSHistoGenericService(SERVICE_STATS_GLOBAL, '')],
|
|
244
242
|
[ ])
|
|
245
243
|
} catch (error) {
|
|
246
|
-
console.error(
|
|
244
|
+
console.error(`${_logPrefix}GetInfluxDBResultsRoot: Error: [${error}]`.red);
|
|
247
245
|
}
|
|
248
246
|
return {
|
|
249
247
|
subscriptionKey,
|
|
@@ -261,7 +259,7 @@ data
|
|
|
261
259
|
this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE, '')],
|
|
262
260
|
['serviceId'])
|
|
263
261
|
} catch (error) {
|
|
264
|
-
console.error(
|
|
262
|
+
console.error(`${_logPrefix}GetInfluxDBResultsService: Error: [${error}]`.red);
|
|
265
263
|
}
|
|
266
264
|
return {
|
|
267
265
|
subscriptionKey,
|
|
@@ -281,7 +279,7 @@ data
|
|
|
281
279
|
this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE, `and r["serviceId"] == "${serviceId}"`)],
|
|
282
280
|
['serviceId', 'serviceInstanceId'])
|
|
283
281
|
} catch (error) {
|
|
284
|
-
console.error(
|
|
282
|
+
console.error(`${_logPrefix}GetInfluxDBResultsServiceInstances: Error: [${error}]`.red);
|
|
285
283
|
}
|
|
286
284
|
return {
|
|
287
285
|
subscriptionKey,
|
|
@@ -300,7 +298,7 @@ data
|
|
|
300
298
|
this.#GetSTSHistoGenericService(SERVICE_STATS_BY_SERVICE_INSTANCE_PROCESS, `and r["serviceInstanceId"] == "${serviceInstanceId}"`)],
|
|
301
299
|
['serviceId', 'serviceInstanceId', 'serviceInstanceProcessId'])
|
|
302
300
|
} catch (error) {
|
|
303
|
-
console.error(
|
|
301
|
+
console.error(`${_logPrefix}GetInfluxDBResultsServiceInstance: Error: [${error}]`.red);
|
|
304
302
|
}
|
|
305
303
|
return {
|
|
306
304
|
subscriptionKey,
|
|
@@ -363,12 +361,12 @@ data
|
|
|
363
361
|
writeApi.writePoint(point);
|
|
364
362
|
return true;
|
|
365
363
|
} catch (error: any) {
|
|
366
|
-
console.error(
|
|
367
|
-
console.error(
|
|
364
|
+
console.error(`${_logPrefix}OutputInfluxDB: Could not write data point: [${error}]`.red);
|
|
365
|
+
console.error(`${JSON.stringify(instrumentPayload.context)}`.red);
|
|
368
366
|
return false;
|
|
369
367
|
}
|
|
370
368
|
} else {
|
|
371
|
-
console.error(
|
|
369
|
+
console.error(`${_logPrefix}OutputInfluxDBService: Could not write data point as writeClient is null`.red);
|
|
372
370
|
return false;
|
|
373
371
|
}
|
|
374
372
|
}
|
|
@@ -7,9 +7,6 @@ import { v4 as uuidv4 } from 'uuid';
|
|
|
7
7
|
|
|
8
8
|
import { $Options } from '@nsshunt/stsconfig'
|
|
9
9
|
import { STSOptionsBase } from '@nsshunt/stsutils';
|
|
10
|
-
|
|
11
|
-
import chalk from 'chalk';
|
|
12
|
-
|
|
13
10
|
const goptions = $Options()
|
|
14
11
|
|
|
15
12
|
declare interface IKafkaSubscription {
|
|
@@ -83,12 +80,12 @@ export class InstrumentationSubscriber extends STSOptionsBase {
|
|
|
83
80
|
const kafka = subscription.kafka;
|
|
84
81
|
if (kafka) {
|
|
85
82
|
// Un-Subscribe from this kafka topic
|
|
86
|
-
this.#Log(
|
|
83
|
+
this.#Log(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Starting`.yellow)
|
|
87
84
|
await kafka.kafkaConsumer?.Stop();
|
|
88
85
|
await kafka.kafkaConsumer?.Disconnect();
|
|
89
|
-
this.#Log(
|
|
86
|
+
this.#Log(`InstrumentationSubscriber:#UnSubscribeKafka(): Unsubscribe from Kafka topc: [${kafka.kafkaTopic}] Completed.`.yellow)
|
|
90
87
|
} else {
|
|
91
|
-
this.#Log(
|
|
88
|
+
this.#Log(`InstrumentationSubscriber:#UnSubscribeKafka(): Kafka details do not exist for this topc: [${JSON.stringify(subscription.subscriptionKey)}].`.magenta)
|
|
92
89
|
}
|
|
93
90
|
};
|
|
94
91
|
return unsubscribeKafka();
|
|
@@ -129,18 +126,18 @@ export class InstrumentationSubscriber extends STSOptionsBase {
|
|
|
129
126
|
} as IKafkaData
|
|
130
127
|
});
|
|
131
128
|
} else {
|
|
132
|
-
this.#Log(
|
|
129
|
+
this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}] and key: [${key}] do not match`.red);
|
|
133
130
|
}
|
|
134
131
|
} else {
|
|
135
|
-
this.#Log(
|
|
132
|
+
this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Invalid message format from Kafka data, topic: [${topic}], key: [${key}], value: [${value}]`.red);
|
|
136
133
|
}
|
|
137
134
|
} catch (error) {
|
|
138
|
-
this.#Log(
|
|
135
|
+
this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Error: [${error}]`.red);
|
|
139
136
|
}
|
|
140
137
|
});
|
|
141
|
-
this.#Log(
|
|
138
|
+
this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Subscribe to Kafka topc: [${kafka.kafkaTopic}] Completed`.yellow)
|
|
142
139
|
} else {
|
|
143
|
-
this.#Log(
|
|
140
|
+
this.#Log(`InstrumentationSubscriber:#SubscribeKafka(): Could not subscribe to Kafka topc, missing combinedKey for topic: [${JSON.stringify(subscription.subscriptionKey)}]`.magenta);
|
|
144
141
|
}
|
|
145
142
|
}
|
|
146
143
|
return kafkaSubscribe();
|
|
@@ -215,7 +212,7 @@ export class InstrumentationSubscriber extends STSOptionsBase {
|
|
|
215
212
|
}
|
|
216
213
|
}
|
|
217
214
|
} catch (error) {
|
|
218
|
-
this.#Log(
|
|
215
|
+
this.#Log(`InstrumentationSubscriber:#ExecuteSubscriptions(): Error: [${error}], [${JSON.stringify(retVal)}]`.red);
|
|
219
216
|
}
|
|
220
217
|
}
|
|
221
218
|
|
|
@@ -226,7 +223,7 @@ export class InstrumentationSubscriber extends STSOptionsBase {
|
|
|
226
223
|
}
|
|
227
224
|
if (this.#subscriptions[subscriptionKey.id]) {
|
|
228
225
|
// Subscription already exists - ignoring
|
|
229
|
-
this.#Log(
|
|
226
|
+
this.#Log(`InstrumentationSubscriber.Subscribe(): Subscription already exists: [${subscriptionKey.id}] - ignoring.`.magenta);
|
|
230
227
|
} else {
|
|
231
228
|
this.#subscriptions[subscriptionKey.id] = {
|
|
232
229
|
subscriptionKey,
|
|
@@ -253,7 +250,7 @@ export class InstrumentationSubscriber extends STSOptionsBase {
|
|
|
253
250
|
|
|
254
251
|
UnSubscribe(subscriptionKey: ISubscriptionKey) {
|
|
255
252
|
if (!this.#subscriptions[subscriptionKey.id]) {
|
|
256
|
-
this.#Log(
|
|
253
|
+
this.#Log(`UnSubscribe(): Warning, subscriptionKey.id: [${subscriptionKey.id}] does not exist within subscription records`.magenta);
|
|
257
254
|
} else {
|
|
258
255
|
if (subscriptionKey.topic.localeCompare(SubscriptionTopic.LogProcessing) === 0) {
|
|
259
256
|
this.#UnSubscribeKafka(this.#subscriptions[subscriptionKey.id]);
|
|
@@ -9,8 +9,6 @@ import { KafkaProducer } from './kafkaproducer'
|
|
|
9
9
|
import { JSONObject } from '@nsshunt/stsutils'
|
|
10
10
|
import { v4 as uuidv4 } from 'uuid';
|
|
11
11
|
|
|
12
|
-
import chalk from 'chalk';
|
|
13
|
-
|
|
14
12
|
import { $Options } from '@nsshunt/stsconfig'
|
|
15
13
|
const goptions = $Options()
|
|
16
14
|
|
|
@@ -71,7 +69,7 @@ export class IMKafkaManager {
|
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
71
|
} catch (error) {
|
|
74
|
-
console.error(
|
|
72
|
+
console.error(`${_logPrefix}#Terminate: Error: [${error}]`.red);
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
|
|
@@ -147,7 +145,7 @@ export class IMKafkaManager {
|
|
|
147
145
|
}
|
|
148
146
|
return true;
|
|
149
147
|
} catch (error: any) {
|
|
150
|
-
console.error(
|
|
148
|
+
console.error(`${_logPrefix}OutputLogs: Could not output log data to kafka: [${error}]`.red);
|
|
151
149
|
return false;
|
|
152
150
|
}
|
|
153
151
|
}
|
|
@@ -56,8 +56,6 @@ import { KafkaManager } from './../kafka/kafkamanager'
|
|
|
56
56
|
|
|
57
57
|
import 'colors'
|
|
58
58
|
|
|
59
|
-
import chalk from 'chalk';
|
|
60
|
-
|
|
61
59
|
async function Sleep(milliseconds = 1000) {
|
|
62
60
|
return new Promise(resolve => setTimeout(resolve, milliseconds))
|
|
63
61
|
}
|
|
@@ -94,7 +92,7 @@ const runme = async () => {
|
|
|
94
92
|
for (let i=0; i < count; i++) {
|
|
95
93
|
if (i % 100 === 0) console.log(i);
|
|
96
94
|
const retVal = await producer.SendMessages(TOPIC, [
|
|
97
|
-
{ key: 'key1', value:
|
|
95
|
+
{ key: 'key1', value: `hello world - ${i}`.green },
|
|
98
96
|
{ key: 'key2', value: 'hey hey! -2' },
|
|
99
97
|
{ key: 'key3', value: 'hey hey! -3' },
|
|
100
98
|
{ key: 'key4', value: 'hey hey! -4' },
|
package/src/masterprocessbase.ts
CHANGED
|
@@ -7,7 +7,9 @@ import axios from 'axios';
|
|
|
7
7
|
|
|
8
8
|
import cluster, { Worker } from 'node:cluster'
|
|
9
9
|
|
|
10
|
-
import
|
|
10
|
+
import os from 'os';
|
|
11
|
+
|
|
12
|
+
import colors from 'colors'
|
|
11
13
|
|
|
12
14
|
import express from 'express'
|
|
13
15
|
|
|
@@ -22,6 +24,7 @@ const goptions = $Options()
|
|
|
22
24
|
import debugModule from 'debug'
|
|
23
25
|
|
|
24
26
|
import { Gauge, GaugeTypes, InstrumentGaugeTelemetry, InstrumentGaugeOptions, InstrumentHistogramTelemetry } from '@nsshunt/stsinstrumentation'
|
|
27
|
+
import { GetFirstNetworkInterface } from './network'
|
|
25
28
|
|
|
26
29
|
import { ProcessOptions, STSServerType } from './processoptions'
|
|
27
30
|
import { ProcessBase } from './processbase';
|
|
@@ -29,6 +32,7 @@ import { IMasterProcessBase } from './commonTypes';
|
|
|
29
32
|
|
|
30
33
|
import { InstrumentDefinitions } from '@nsshunt/stspublisherserver'
|
|
31
34
|
import { IPCMessagePayload, IPCMessageCommand } from './commonTypes'
|
|
35
|
+
import { REQUEST_HEADER_FIELDS_TOO_LARGE } from "http-status-codes";
|
|
32
36
|
|
|
33
37
|
|
|
34
38
|
export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
@@ -186,15 +190,15 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
186
190
|
,httpsAgent: this.#httpsAgent
|
|
187
191
|
});
|
|
188
192
|
if (retVal.status !== 200) {
|
|
189
|
-
this.#debug(
|
|
193
|
+
this.#debug(`Error (MasterProcessBase:#GetLatency): Invalid response from server: [${retVal.status}]`.magenta);
|
|
190
194
|
return null;
|
|
191
195
|
}
|
|
192
196
|
return retVal.data.detail;
|
|
193
197
|
} catch (error: any) {
|
|
194
|
-
this.#debug(
|
|
195
|
-
this.#debug(
|
|
198
|
+
this.#debug(`Error (MasterProcessBase:#GetLatency:catch): [${error}]`.red);
|
|
199
|
+
this.#debug(` url: [${url}]`.red);
|
|
196
200
|
if (error.response && error.response.data) {
|
|
197
|
-
this.#debug(
|
|
201
|
+
this.#debug(` Details: [${JSON.stringify(error.response.data)}]`.red);
|
|
198
202
|
}
|
|
199
203
|
}
|
|
200
204
|
}
|
|
@@ -232,11 +236,11 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
232
236
|
worker.process.send( { command } );
|
|
233
237
|
return true;
|
|
234
238
|
} else {
|
|
235
|
-
this.LogEx(
|
|
239
|
+
this.LogEx(`Could not kill worker with id: [${id}]. The process does not exists`.red);
|
|
236
240
|
return false;
|
|
237
241
|
}
|
|
238
242
|
} else {
|
|
239
|
-
this.LogEx(
|
|
243
|
+
this.LogEx(`Could not kill worker with id: [${id}]. Worker does not exist within workers collection`.red);
|
|
240
244
|
return false;
|
|
241
245
|
}
|
|
242
246
|
}
|
|
@@ -338,7 +342,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
338
342
|
}
|
|
339
343
|
default : {
|
|
340
344
|
const errorMessage = `Could not process command: [${iPCMessagePayload.command}].`;
|
|
341
|
-
this.#debug(
|
|
345
|
+
this.#debug(` ${errorMessage}`.red);
|
|
342
346
|
throw new Error(errorMessage);
|
|
343
347
|
}
|
|
344
348
|
}
|
|
@@ -377,9 +381,9 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
377
381
|
// Only handle request/response message types here ...
|
|
378
382
|
if (payload.requestResponse) {
|
|
379
383
|
const iPCMessagePayload: IPCMessagePayload = payload as IPCMessagePayload;
|
|
380
|
-
this.#debug(
|
|
384
|
+
this.#debug(`Received message with id: [${iPCMessagePayload.id}] from worker: [${worker.process.pid}]. Details: [${JSON.stringify(iPCMessagePayload)}]`.yellow);
|
|
381
385
|
const response: IPCMessagePayload = await this.#processIPCCommand(iPCMessagePayload);
|
|
382
|
-
this.#debug(
|
|
386
|
+
this.#debug(`Sending response message with id: [${iPCMessagePayload.id}] to worker: [${worker.process.pid}]. Details: [${JSON.stringify(response)}]`.green);
|
|
383
387
|
worker.send(response);
|
|
384
388
|
} else {
|
|
385
389
|
this.#WorkerMessageEvent(payload);
|
|
@@ -443,21 +447,25 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
443
447
|
LogEx(`Worker process ${worker.process.pid} is online`);
|
|
444
448
|
});
|
|
445
449
|
|
|
446
|
-
cluster.on('exit', (worker, code, signal) =>
|
|
447
|
-
|
|
448
|
-
|
|
450
|
+
cluster.on('exit', (worker, code, signal) =>
|
|
451
|
+
{
|
|
452
|
+
if ((code !== null && code === 0) || (signal === 'SIGINT'))
|
|
453
|
+
{
|
|
454
|
+
LogEx(`Process ${worker.process.pid} terminated gracefully with code: ${code}, signal: ${signal}`.green);
|
|
449
455
|
this.DecWorkers();
|
|
450
|
-
} else if ((code !== null && code === 15) || (signal === 'SIGTERM'))
|
|
456
|
+
} else if ((code !== null && code === 15) || (signal === 'SIGTERM'))
|
|
457
|
+
{
|
|
451
458
|
this.DecWorkers();
|
|
452
|
-
LogEx(
|
|
459
|
+
LogEx(`Process ${worker.process.pid} terminated with code: ${code}, signal: ${signal}`.red);
|
|
453
460
|
} else {
|
|
454
461
|
this.DecWorkers();
|
|
455
|
-
LogEx(
|
|
456
|
-
LogEx(
|
|
457
|
-
LogEx(
|
|
458
|
-
LogEx(
|
|
459
|
-
if (goptions.respawnOnFail === true)
|
|
460
|
-
|
|
462
|
+
LogEx(`worker ${worker.process.pid} died`.red);
|
|
463
|
+
LogEx(`code: ${code}`.red);
|
|
464
|
+
LogEx(`signal: ${signal}`.red);
|
|
465
|
+
LogEx('process terminated in an error state'.red);
|
|
466
|
+
if (goptions.respawnOnFail === true)
|
|
467
|
+
{
|
|
468
|
+
LogEx(`Attemping to respawn worker`);
|
|
461
469
|
this.#SpawnWorker();
|
|
462
470
|
}
|
|
463
471
|
}
|
|
@@ -556,9 +564,9 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
556
564
|
{
|
|
557
565
|
if (code === 0)
|
|
558
566
|
{
|
|
559
|
-
LogEx(
|
|
567
|
+
LogEx(`Main Process: ${process.pid} terminated gracefully with code: ${code}`.green);
|
|
560
568
|
} else {
|
|
561
|
-
LogEx(
|
|
569
|
+
LogEx(`Main Process: ${process.pid} terminated with code: ${code}`.red);
|
|
562
570
|
}
|
|
563
571
|
});
|
|
564
572
|
|
|
@@ -570,7 +578,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
|
|
|
570
578
|
|
|
571
579
|
this.MasterStarted();
|
|
572
580
|
|
|
573
|
-
LogEx(
|
|
581
|
+
LogEx(`Master process:${process.pid} started`.green);
|
|
574
582
|
}
|
|
575
583
|
|
|
576
584
|
BroadcastDataToWorkers = (command: any, data: any) => {
|
package/src/processbase.ts
CHANGED
|
@@ -7,8 +7,6 @@ import colors from 'colors'
|
|
|
7
7
|
import si from 'systeminformation' // https://systeminformation.io/
|
|
8
8
|
import { GetFirstNetworkInterface } from './network'
|
|
9
9
|
|
|
10
|
-
import chalk from 'chalk';
|
|
11
|
-
|
|
12
10
|
import debugModule from 'debug'
|
|
13
11
|
const debug = debugModule(`proc:${process.pid}:processBase`);
|
|
14
12
|
|
|
@@ -78,12 +76,10 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
78
76
|
if (cluster.isPrimary)
|
|
79
77
|
{
|
|
80
78
|
prefix = 'M';
|
|
81
|
-
col =
|
|
82
|
-
//col = colors.bold.cyan; // chalk.bold.cyan;
|
|
79
|
+
col = colors.bold.cyan;
|
|
83
80
|
} else {
|
|
84
81
|
prefix = 'W';
|
|
85
|
-
col =
|
|
86
|
-
//col = colors.green; // chalk.green;
|
|
82
|
+
col = colors.green;
|
|
87
83
|
}
|
|
88
84
|
const msgEx = col(`${prefix}(${process.pid}) [${appName}]: ${msg}`);
|
|
89
85
|
debug(msgEx);
|
|
@@ -338,13 +334,13 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
338
334
|
try {
|
|
339
335
|
const retVal = await (this.accessLayer as PGAccessLayer).getResourceCount();
|
|
340
336
|
if (retVal.status !== StatusCodes.OK) {
|
|
341
|
-
this.LogEx(
|
|
337
|
+
this.LogEx(`Unable to get resources from the database. Is the database running? [${JSON.stringify(retVal)}]`.red);
|
|
342
338
|
exit(1);
|
|
343
339
|
} else {
|
|
344
|
-
this.LogEx(
|
|
340
|
+
this.LogEx(`Database connection successful. Resources: [${retVal.detail.count}]`.green);
|
|
345
341
|
}
|
|
346
342
|
} catch (error) {
|
|
347
|
-
this.LogEx(
|
|
343
|
+
this.LogEx(`Unable to get resources from the database. Is the database running? Error: [${error}]`.red);
|
|
348
344
|
exit(1);
|
|
349
345
|
}
|
|
350
346
|
})();
|
|
@@ -406,9 +402,9 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
|
|
|
406
402
|
GetSignalColour = (signal: any) => {
|
|
407
403
|
let msgcolor = null;
|
|
408
404
|
if (signal === 'SIGINT') {
|
|
409
|
-
msgcolor =
|
|
405
|
+
msgcolor = colors.yellow;
|
|
410
406
|
} else {
|
|
411
|
-
msgcolor =
|
|
407
|
+
msgcolor = colors.red;
|
|
412
408
|
}
|
|
413
409
|
return msgcolor;
|
|
414
410
|
};
|
package/src/server.ts
CHANGED
|
@@ -33,7 +33,7 @@ export class STSExpressServer
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
serverNetworkMiddleware.on(ServerNetworkMiddlewareEventName.UpdateInstrument_SERVER_NET_VAL, (data: ISocketRecord) => {
|
|
36
|
-
//console.log(
|
|
36
|
+
//console.log(`serverNetworkMiddleware: [${JSON.stringify(data)}]`.magenta)
|
|
37
37
|
stsApp.UpdateInstrument(Gauge.NETWORK_RX_GAUGE, {
|
|
38
38
|
Inc: data.requestBytesRead
|
|
39
39
|
} as InstrumentGaugeTelemetry);
|
package/src/singleprocessbase.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
import { $Options } from '@nsshunt/stsconfig'
|
|
3
3
|
const goptions = $Options()
|
|
4
4
|
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
|
|
7
5
|
import { Gauge, GaugeTypes, InstrumentGaugeOptions, InstrumentGaugeTelemetry } from '@nsshunt/stsinstrumentation'
|
|
8
6
|
|
|
9
7
|
import { ProcessOptions } from './processoptions'
|
|
@@ -99,9 +97,9 @@ export class SingleProcessBase extends ServerProcessBase implements ISingleProce
|
|
|
99
97
|
|
|
100
98
|
process.on('exit', (code) => {
|
|
101
99
|
if (code === 0) {
|
|
102
|
-
this.LogEx(
|
|
100
|
+
this.LogEx(`Main Process: ${process.pid} terminated gracefully with code: ${code}`.green);
|
|
103
101
|
} else {
|
|
104
|
-
this.LogEx(
|
|
102
|
+
this.LogEx(`Main Process: ${process.pid} terminated with code: ${code}`.red);
|
|
105
103
|
}
|
|
106
104
|
});
|
|
107
105
|
|
|
@@ -109,7 +107,7 @@ export class SingleProcessBase extends ServerProcessBase implements ISingleProce
|
|
|
109
107
|
|
|
110
108
|
this.ProcessStarted();
|
|
111
109
|
|
|
112
|
-
this.LogEx(
|
|
110
|
+
this.LogEx(`Main process:${process.pid} started`.green);
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
async TerminateApplication()
|
package/src/tcpclient/app2.ts
CHANGED
|
@@ -48,9 +48,9 @@ socket2.on('secureConnect', () => {
|
|
|
48
48
|
dosomework(socket2);
|
|
49
49
|
});
|
|
50
50
|
socket2.on('close', function(data: any) {
|
|
51
|
-
console.log(
|
|
51
|
+
console.log(`CLOSED: ${socket2.remoteAddress} ${socket2.remotePort}`.green);
|
|
52
52
|
});
|
|
53
53
|
socket2.on('data', function(data: any) {
|
|
54
|
-
console.log(
|
|
54
|
+
console.log(`DATA ${socket2.remoteAddress} ${socket2.remotePort} ${data}`.green);
|
|
55
55
|
});
|
|
56
56
|
*/
|
|
@@ -9,8 +9,6 @@ import { JSONObject } from '@nsshunt/stsutils';
|
|
|
9
9
|
import { MasterProcessBase } from './../masterprocessbase'
|
|
10
10
|
import { ProcessOptions } from './../processoptions'
|
|
11
11
|
|
|
12
|
-
import chalk from 'chalk';
|
|
13
|
-
|
|
14
12
|
// Colour codes
|
|
15
13
|
// ---------------------------------
|
|
16
14
|
// Red - Error
|
|
@@ -124,7 +122,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
124
122
|
// Update my currentTerm
|
|
125
123
|
this.#currentTerm = term;
|
|
126
124
|
// Return my yes vote
|
|
127
|
-
console.log(
|
|
125
|
+
console.log(`${message} - Vote Yes`.green)
|
|
128
126
|
callback(null, true); // YES vote
|
|
129
127
|
}
|
|
130
128
|
|
|
@@ -132,7 +130,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
132
130
|
// Log the fact that I have now voted for this currentTerm
|
|
133
131
|
this.#votedLog[term] = true;
|
|
134
132
|
// Return my yes vote
|
|
135
|
-
console.log(
|
|
133
|
+
console.log(`${message} - Vote No`.yellow)
|
|
136
134
|
callback(null, false); // NO vote
|
|
137
135
|
}
|
|
138
136
|
|
|
@@ -231,19 +229,19 @@ export class AppMaster extends MasterProcessBase
|
|
|
231
229
|
const retVal = this.#CheckMoreRecentTerm(term, lastLogItemTerm, lastLogItemIndex);
|
|
232
230
|
if (retVal.retVal === true) {
|
|
233
231
|
console.log(`${retVal.msg}`);
|
|
234
|
-
console.log(
|
|
232
|
+
console.log(`${this.#GetLogPrefix()}: New leader detected, Host: [${host}], Port: [${port}], while in CANDIDATE mode, reverting to FOLLOWER.`.magenta);
|
|
235
233
|
// This sending node is the leader so revert to follower
|
|
236
234
|
this.#currentTerm = term;
|
|
237
235
|
this.#ChangeState(AppMasterRAFTState.FOLLOWER);
|
|
238
236
|
} else {
|
|
239
237
|
console.log(`${retVal.msg}`);
|
|
240
|
-
console.log(
|
|
238
|
+
console.log(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`.magenta);
|
|
241
239
|
// Reject this RPC and continue in the CANDIDATE state
|
|
242
240
|
callback(null, false);
|
|
243
241
|
return;
|
|
244
242
|
}
|
|
245
243
|
} else if (this.#RAFTState.localeCompare(AppMasterRAFTState.LEADER) === 0) {
|
|
246
|
-
console.log(
|
|
244
|
+
console.log(`${this.#GetLogPrefix()}: appendEntry called while I am the current leader, rejecting RPC call.`.red);
|
|
247
245
|
// Reject this RPC and continue in the LEADER state
|
|
248
246
|
callback(null, false);
|
|
249
247
|
return;
|
|
@@ -260,7 +258,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
260
258
|
}
|
|
261
259
|
} else {
|
|
262
260
|
console.log(`${retVal.msg}`);
|
|
263
|
-
console.log(
|
|
261
|
+
console.log(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`.magenta);
|
|
264
262
|
// Reject this RPC and continue in the CANDIDATE state
|
|
265
263
|
callback(null, false);
|
|
266
264
|
return;
|
|
@@ -272,13 +270,13 @@ export class AppMaster extends MasterProcessBase
|
|
|
272
270
|
if (sentLeaderService) {
|
|
273
271
|
if (sentLeaderService.host.localeCompare(this.#leaderNode.host) !== 0 || sentLeaderService.port !== this.#leaderNode.port) {
|
|
274
272
|
this.#leaderNode = sentLeaderService;
|
|
275
|
-
console.log(
|
|
273
|
+
console.log(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`.white);
|
|
276
274
|
}
|
|
277
275
|
}
|
|
278
276
|
} else {
|
|
279
277
|
this.#leaderNode = this.#FindService(host, port);
|
|
280
278
|
if (this.#leaderNode) {
|
|
281
|
-
console.log(
|
|
279
|
+
console.log(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`.white);
|
|
282
280
|
}
|
|
283
281
|
}
|
|
284
282
|
|
|
@@ -311,6 +309,18 @@ export class AppMaster extends MasterProcessBase
|
|
|
311
309
|
};
|
|
312
310
|
|
|
313
311
|
const client = jayson.client.tls(options);
|
|
312
|
+
/*
|
|
313
|
+
client.on('tcp socket', (socket: tls.TLSSocket) => {
|
|
314
|
+
socket.setTimeout(200); //@@ config
|
|
315
|
+
socket.on('timeout', () => {
|
|
316
|
+
console.log('socket timeout');
|
|
317
|
+
socket.end();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
client.on('tcp error', (error: any) => {
|
|
321
|
+
console.log(`ERROR: [${error}]`.red);
|
|
322
|
+
});
|
|
323
|
+
*/
|
|
314
324
|
|
|
315
325
|
let lastLogItem: ILogItem;
|
|
316
326
|
if (this.#log.length > 0) {
|
|
@@ -325,7 +335,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
325
335
|
|
|
326
336
|
client.request('vote', [ this.#currentTerm, lastLogItem.term, lastLogItem.index ], (error: any, response: any) => {
|
|
327
337
|
if (error) {
|
|
328
|
-
//console.log(
|
|
338
|
+
//console.log(`vote attempt fail: [${JSON.stringify(options)}: ${error}]`.red);
|
|
329
339
|
} else {
|
|
330
340
|
// Log the result
|
|
331
341
|
if (response.result === true) {
|
|
@@ -343,6 +353,18 @@ export class AppMaster extends MasterProcessBase
|
|
|
343
353
|
};
|
|
344
354
|
|
|
345
355
|
const client = jayson.client.tls(options);
|
|
356
|
+
/*
|
|
357
|
+
client.on('tcp socket', (socket: tls.TLSSocket) => {
|
|
358
|
+
socket.setTimeout(200); //@@ config
|
|
359
|
+
socket.on('timeout', () => {
|
|
360
|
+
console.log('socket timeout');
|
|
361
|
+
socket.end();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
client.on('tcp error', (error: any) => {
|
|
365
|
+
console.log(`ERROR: [${error}]`.red);
|
|
366
|
+
});
|
|
367
|
+
*/
|
|
346
368
|
|
|
347
369
|
let lastLogItem: ILogItem;
|
|
348
370
|
if (this.#log.length > 0) {
|
|
@@ -357,7 +379,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
357
379
|
|
|
358
380
|
client.request('appendEntry', [ this.#thisService.host, this.#thisService.port, this.#currentTerm, lastLogItem.term, lastLogItem.index ], (error: any, response: any) => {
|
|
359
381
|
if (error) {
|
|
360
|
-
//console.log(
|
|
382
|
+
//console.log(`appendEntry attempt fail: [${JSON.stringify(options)}: ${error}]`.red);
|
|
361
383
|
} else {
|
|
362
384
|
this.#appendedEntries[this.#GetServiceKey(service)] = 1;
|
|
363
385
|
// Log the result
|
|
@@ -409,14 +431,14 @@ export class AppMaster extends MasterProcessBase
|
|
|
409
431
|
if (majority) {
|
|
410
432
|
this.#StartAppendEntries();
|
|
411
433
|
} else {
|
|
412
|
-
console.log(
|
|
434
|
+
console.log(`${this.#GetLogPrefix()}: Not enough response for valid cluster state.`.red);
|
|
413
435
|
}
|
|
414
436
|
}, this.#heartBeatTimeout);
|
|
415
437
|
}
|
|
416
438
|
|
|
417
439
|
#Promote = () => {
|
|
418
440
|
this.#ChangeState(AppMasterRAFTState.LEADER);
|
|
419
|
-
console.log(
|
|
441
|
+
console.log(`${this.#GetLogPrefix()}: New LEADER is elected: [${this.#GetSelfServiceKey()}]`.green);
|
|
420
442
|
// As leader, now start the regular pings
|
|
421
443
|
this.#StartAppendEntries();
|
|
422
444
|
}
|
|
@@ -470,7 +492,7 @@ export class AppMaster extends MasterProcessBase
|
|
|
470
492
|
// Log the result - Vote for myself
|
|
471
493
|
this.#votes[this.#GetSelfServiceKey()] = 1;
|
|
472
494
|
// Return my yes vote
|
|
473
|
-
console.log(
|
|
495
|
+
console.log(`${this.#GetLogPrefix()}: SELF VOTE: canidate currentTerm: [${this.#currentTerm}], vote YES`.green)
|
|
474
496
|
this.#CheckMajority();
|
|
475
497
|
} else {
|
|
476
498
|
// Send vote request
|
|
@@ -504,13 +526,13 @@ export class AppMaster extends MasterProcessBase
|
|
|
504
526
|
}
|
|
505
527
|
|
|
506
528
|
#StartRAFTService = async () => {
|
|
507
|
-
this.LogEx(
|
|
529
|
+
this.LogEx(`---[ RAFT Protocol Starting ]---`.green);
|
|
508
530
|
this.#server = await this.#SetupJSONRPCServer();
|
|
509
531
|
this.#StartElectionTimeout();
|
|
510
532
|
}
|
|
511
533
|
|
|
512
534
|
#ChangeState(newState: AppMasterRAFTState) {
|
|
513
|
-
this.LogEx(
|
|
535
|
+
this.LogEx(`${this.#GetLogPrefix()}: State Change, From: [${this.#RAFTState.toString()}] --> To: [${newState.toString()}]`.magenta);
|
|
514
536
|
this.#RAFTState = newState;
|
|
515
537
|
}
|
|
516
538
|
|