@nsshunt/stsappframework 2.19.210 → 2.19.211

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.
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const appConfig_js_1 = require("./appConfig.js");
7
+ const appmaster_1 = require("./appmaster");
8
+ const cluster_1 = __importDefault(require("cluster"));
9
+ if (cluster_1.default.isPrimary) {
10
+ new appmaster_1.AppMaster((0, appConfig_js_1.ServiceConfigOptions)(cluster_1.default.isPrimary)).SetupServer();
11
+ }
12
+ else {
13
+ //new WorkerProcessBase(ServiceConfigOptions(cluster.isPrimary)).SetupServer();
14
+ }
15
+ //# sourceMappingURL=app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/tcpserver/app.ts"],"names":[],"mappings":";;;;;AAAA,iDAAqD;AAErD,2CAAuC;AAEvC,sDAA8B;AAE9B,IAAI,iBAAO,CAAC,SAAS,EAAE;IACnB,IAAI,qBAAS,CAAC,IAAA,mCAAoB,EAAC,iBAAO,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;CACxE;KAAM;IACH,+EAA+E;CAClF"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ServiceConfigOptions = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const stsconfig_1 = require("@nsshunt/stsconfig");
6
+ const goptions = (0, stsconfig_1.$Options)();
7
+ const index_1 = require("../index");
8
+ /*
9
+ // nid: `${goptions.rest01servicename} @ ${goptions.rest01serviceversion} | ${this.options.globalServiceData.serviceInstanceId} @ ${os.hostname()} ^ ${process.pid} @ ${(cluster.isMaster ? process.pid : process.ppid)}`,
10
+ // <serviceId> <serviceInstanceId> <serviceInstanceProcessId>
11
+ // <serviceName> <serviceVersion> <sid> <hostName> <pid> <ppid>
12
+ // << ............... Static Nid ............... >> << ............... Dynamic Nid ............... >>
13
+ // Note: The final nid will NOT contain the NID_SEPERATOR character. This will be replaced with the SEPERATOR character.
14
+ const Context = (isMaster, serviceInstanceId) => {
15
+ return {
16
+ nid: `\
17
+ ${goptions.rest01servicename}${ModelDelimeter.COMPONENT_SEPERATOR}${goptions.rest01serviceversion}\
18
+ ${ModelDelimeter.SEPERATOR}\
19
+ ${serviceInstanceId}${ModelDelimeter.COMPONENT_SEPERATOR}${os.hostname()}\
20
+ ${ModelDelimeter.NID_SEPERATOR}\
21
+ ${process.pid}${ModelDelimeter.COMPONENT_SEPERATOR}${(isMaster ? process.pid : process.ppid)}`
22
+ }
23
+ }
24
+ */
25
+ function ServiceConfigOptions(isMaster) {
26
+ if (isMaster === true) {
27
+ const serviceInstanceId = (0, uuid_1.v4)();
28
+ const data = {
29
+ serverType: index_1.STSServerType.TCPRAW_TLS,
30
+ wssServer: false,
31
+ useLatency: false,
32
+ httpsServerKeyPath: goptions.httpsserverkeypath,
33
+ httpsServerCertificatePath: goptions.httpsservercertpath,
34
+ processExitOnTerminate: true,
35
+ serviceInstanceId: serviceInstanceId,
36
+ useDatabase: true,
37
+ useInstrumentationWorkers: true,
38
+ isMaster: isMaster,
39
+ endpoint: goptions.rest01endpoint,
40
+ apiRoot: goptions.rest01apiroot,
41
+ listenPort: goptions.rest01hostport,
42
+ port: goptions.rest01port,
43
+ prometheusSupport: false,
44
+ prometheusClusterPort: goptions.rest01prometheusclusterport,
45
+ serviceName: goptions.rest01servicename,
46
+ serviceVersion: goptions.rest01serviceversion,
47
+ consoleLogging: true,
48
+ instrumentLogging: true,
49
+ instrumentationObservationInterval: goptions.instrumentationObservationInterval,
50
+ instrumentationTimeWindow: goptions.instrumentationTimeWindow,
51
+ useRedisAdaptor: false
52
+ };
53
+ return data;
54
+ }
55
+ else {
56
+ const data = JSON.parse(process.env['STS_GSD_SII']);
57
+ return data;
58
+ }
59
+ }
60
+ exports.ServiceConfigOptions = ServiceConfigOptions;
61
+ //# sourceMappingURL=appConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appConfig.js","sourceRoot":"","sources":["../../src/tcpserver/appConfig.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAGpC,kDAA6C;AAC7C,MAAM,QAAQ,GAAG,IAAA,oBAAQ,GAAE,CAAA;AAE3B,oCAAsE;AAEtE;;;;;;;;;;;;;;;;EAgBE;AAEF,SAAgB,oBAAoB,CAAC,QAAiB;IAClD,IAAI,QAAQ,KAAK,IAAI,EAAE;QACnB,MAAM,iBAAiB,GAAG,IAAA,SAAM,GAAE,CAAC;QACnC,MAAM,IAAI,GAAmB;YACzB,UAAU,EAAE,qBAAa,CAAC,UAAU;YAEpC,SAAS,EAAE,KAAK;YAChB,UAAU,EAAE,KAAK;YACjB,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB;YAC/C,0BAA0B,EAAE,QAAQ,CAAC,mBAAmB;YACxD,sBAAsB,EAAE,IAAI;YAC5B,iBAAiB,EAAE,iBAAiB;YACpC,WAAW,EAAE,IAAI;YACjB,yBAAyB,EAAE,IAAI;YAE/B,QAAQ,EAAE,QAAQ;YAClB,QAAQ,EAAE,QAAQ,CAAC,cAAc;YACjC,OAAO,EAAE,QAAQ,CAAC,aAAa;YAC/B,UAAU,EAAE,QAAQ,CAAC,cAAc;YACnC,IAAI,EAAE,QAAQ,CAAC,UAAU;YAEzB,iBAAiB,EAAE,KAAK;YACxB,qBAAqB,EAAE,QAAQ,CAAC,2BAA2B;YAE3D,WAAW,EAAE,QAAQ,CAAC,iBAAiB;YACvC,cAAc,EAAE,QAAQ,CAAC,oBAAoB;YAC7C,cAAc,EAAE,IAAI;YACpB,iBAAiB,EAAE,IAAI;YAEvB,kCAAkC,EAAE,QAAQ,CAAC,kCAAkC;YAC/E,yBAAyB,EAAE,QAAQ,CAAC,yBAAyB;YAE7D,eAAe,EAAE,KAAK;SACzB,CAAA;QACD,OAAO,IAAI,CAAC;KACf;SAAM;QACH,MAAM,IAAI,GAAmB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAW,CAAmB,CAAC;QAChG,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AAvCD,oDAuCC"}
@@ -0,0 +1,484 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AppMaster = exports.AppMasterRAFTState = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const jayson_1 = __importDefault(require("jayson"));
10
+ const masterprocessbase_1 = require("./../masterprocessbase");
11
+ // Colour codes
12
+ // ---------------------------------
13
+ // Red - Error
14
+ // Green - Vote YES
15
+ // Yellow - Vote No
16
+ // White - standard logging message
17
+ // Magenta - node state change
18
+ // Cyan - node term change
19
+ var AppMasterRAFTState;
20
+ (function (AppMasterRAFTState) {
21
+ AppMasterRAFTState["IDLE"] = "IDLE";
22
+ AppMasterRAFTState["FOLLOWER"] = "FOLLOWER";
23
+ AppMasterRAFTState["CANDIDATE"] = "CANDIDATE";
24
+ AppMasterRAFTState["LEADER"] = "LEADER";
25
+ })(AppMasterRAFTState = exports.AppMasterRAFTState || (exports.AppMasterRAFTState = {}));
26
+ class AppMaster extends masterprocessbase_1.MasterProcessBase {
27
+ #lastRequiredVotes = -1; // used for logging only
28
+ #lastVotes = -1; // used for logging only
29
+ #RAFTState;
30
+ #minElectionTimeout;
31
+ #maxElectionTimeout;
32
+ #electionTimeout;
33
+ #heartBeatTimeout;
34
+ #startRAFTProtocolTimeout;
35
+ #votes; // keyed by service key (host:port)
36
+ #services;
37
+ #thisService;
38
+ #canidateTimeout = null;
39
+ #appendEntriesTimeout = null;
40
+ #voteRegister = 0;
41
+ #server;
42
+ #serverPort;
43
+ #votedLog = {}; // keyed by term number
44
+ #appendedEntries = {};
45
+ #leaderNode = null;
46
+ #currentTerm;
47
+ #log;
48
+ #currentIndex = 0;
49
+ constructor(serviceConfig) {
50
+ super(serviceConfig);
51
+ this.#RAFTState = AppMasterRAFTState.IDLE;
52
+ this.#currentTerm = 0;
53
+ this.#votes = {};
54
+ this.#services = [{
55
+ host: "stscore.stsmda.org",
56
+ port: 3006
57
+ }, {
58
+ host: "stscore.stsmda.org",
59
+ port: 3007
60
+ }, {
61
+ host: "stscore.stsmda.org",
62
+ port: 3008
63
+ }];
64
+ this.#thisService = this.#services[parseInt(process.env.SERVICE_INDEX)]; // set self service
65
+ this.#serverPort = this.#thisService.port;
66
+ //this.#thisService = this.#services[0]; // set self service
67
+ this.#log = []; // Need to get from storage - volume, redis, etc.
68
+ // Set default config items
69
+ this.#minElectionTimeout = 1000; //@@ config
70
+ this.#maxElectionTimeout = 1200; //@@ config
71
+ this.#startRAFTProtocolTimeout = 2000; //@@ config
72
+ this.#electionTimeout = crypto_1.default.randomInt(this.#minElectionTimeout, this.#maxElectionTimeout);
73
+ this.#heartBeatTimeout = 750; //@@ config - also must be smaller than electionTimeout
74
+ }
75
+ #GetTLSOptions = () => {
76
+ return {
77
+ key: fs_1.default.readFileSync(this.options.httpsServerKeyPath),
78
+ cert: fs_1.default.readFileSync(this.options.httpsServerCertificatePath)
79
+ };
80
+ };
81
+ #SetupRPCServer = async (socket) => {
82
+ /*
83
+ console.log('CONNECTED: ' + socket.remoteAddress + ':' + socket.remotePort + ' ' + process.pid);
84
+
85
+ socket.on('close', function(data: any) {
86
+ console.log('CLOSED: ' + socket.remoteAddress + ' ' + socket.remotePort + ' ' + process.pid);
87
+ });
88
+
89
+ socket.on('data', function(data: any) {
90
+ console.log('DATA ' + socket.remoteAddress + ': ' + data);
91
+ });
92
+ */
93
+ };
94
+ #GetLogPrefix = () => {
95
+ return `${this.#thisService.host}:${this.#thisService.port}: currentTerm: [${this.#currentTerm}] index: [${this.#currentIndex}]: `;
96
+ };
97
+ #VoteYes = (callback, term, message) => {
98
+ // Log the fact that I have now voted for this currentTerm
99
+ this.#votedLog[term] = true;
100
+ // Update my currentTerm
101
+ this.#currentTerm = term;
102
+ // Return my yes vote
103
+ console.log(`${message} - Vote Yes`.green);
104
+ callback(null, true); // YES vote
105
+ };
106
+ #VoteNo = (callback, term, message) => {
107
+ // Log the fact that I have now voted for this currentTerm
108
+ this.#votedLog[term] = true;
109
+ // Return my yes vote
110
+ console.log(`${message} - Vote No`.grey);
111
+ callback(null, false); // NO vote
112
+ };
113
+ #FindService = (host, port) => {
114
+ let retService = null;
115
+ this.#services.forEach((service, index) => {
116
+ if (service.host.localeCompare(host) === 0 && service.port === port) {
117
+ retService = service;
118
+ return;
119
+ }
120
+ });
121
+ return retService;
122
+ };
123
+ #CheckMoreRecentTerm = (term, lastLogItemTerm, lastLogItemIndex) => {
124
+ // Check if the request to vote is newer than my current term
125
+ let msg = '';
126
+ let retVal;
127
+ if (term > this.#currentTerm) {
128
+ msg = `${this.#GetLogPrefix()}: canidate term: [${term}] greater than my currentTerm: [${this.#currentTerm}]`;
129
+ retVal = true;
130
+ }
131
+ else {
132
+ // Check if the request to vote is older than my current term
133
+ if (term === this.#currentTerm) {
134
+ if (lastLogItemIndex > this.#currentIndex) {
135
+ msg = `${this.#GetLogPrefix()}: canidate term: [${term}] the same as my currentTerm: [${this.#currentTerm}]. Canidate index: [${lastLogItemIndex}] greater than my index: [${this.#currentIndex}]`;
136
+ retVal = true;
137
+ }
138
+ else if (lastLogItemIndex === this.#currentIndex) {
139
+ msg = `${this.#GetLogPrefix()}: canidate term: [${term}] the same as my currentTerm: [${this.#currentTerm}]. Canidate index: [${lastLogItemIndex}] the same as my index: [${this.#currentIndex}]`;
140
+ retVal = true;
141
+ }
142
+ else {
143
+ msg = `${this.#GetLogPrefix()}: canidate term: [${term}] the same as my currentTerm: [${this.#currentTerm}]. Canidate index: [${lastLogItemIndex}] NOT greater than my index: [${this.#currentIndex}]`;
144
+ retVal = false;
145
+ }
146
+ }
147
+ else {
148
+ msg = `${this.#GetLogPrefix()}: canidate term: [${term}] less than my currentTerm: [${this.#currentTerm}]`;
149
+ retVal = false;
150
+ }
151
+ }
152
+ return {
153
+ msg,
154
+ retVal
155
+ };
156
+ };
157
+ #SetupJSONRPCServer = async () => {
158
+ const jaysonServer = new jayson_1.default.server();
159
+ jaysonServer.method("appendEntries", async (args, callback) => {
160
+ // Just received a message - reset my electionTimeout
161
+ this.#ResetElectionTimeout();
162
+ // Do something with this new log entry
163
+ // Needs to check if current, otherwise get old entries and duplicate
164
+ });
165
+ jaysonServer.method("vote", async (args, callback) => {
166
+ // Just received a message - reset my electionTimeout
167
+ this.#ResetElectionTimeout();
168
+ const term = args[0];
169
+ const lastLogItemTerm = args[1];
170
+ const lastLogItemIndex = args[2];
171
+ // Now determine whether this requestror gets my vote
172
+ // Check already voted
173
+ if (this.#votedLog[term]) {
174
+ this.#VoteNo(callback, term, `${this.#GetLogPrefix()}: Already voted - vote NO`);
175
+ return;
176
+ }
177
+ // Check if the request to vote is newer than my current term
178
+ const retVal = this.#CheckMoreRecentTerm(term, lastLogItemTerm, lastLogItemIndex);
179
+ if (retVal.retVal === true) {
180
+ this.#VoteYes(callback, term, retVal.msg);
181
+ }
182
+ else {
183
+ this.#VoteNo(callback, term, retVal.msg);
184
+ }
185
+ });
186
+ jaysonServer.method("appendEntry", async (args, callback) => {
187
+ // Just received a message - reset my electionTimeout
188
+ this.#ResetElectionTimeout();
189
+ const host = args[0];
190
+ const port = args[1];
191
+ const term = args[2];
192
+ const lastLogItemTerm = args[3];
193
+ const lastLogItemIndex = args[4];
194
+ if (this.#RAFTState.localeCompare(AppMasterRAFTState.CANDIDATE) === 0) {
195
+ const retVal = this.#CheckMoreRecentTerm(term, lastLogItemTerm, lastLogItemIndex);
196
+ if (retVal.retVal === true) {
197
+ console.log(`${retVal.msg}`);
198
+ console.log(`${this.#GetLogPrefix()}: New leader detected, Host: [${host}], Port: [${port}], while in CANDIDATE mode, reverting to FOLLOWER.`.magenta);
199
+ // This sending node is the leader so revert to follower
200
+ this.#currentTerm = term;
201
+ this.#ChangeState(AppMasterRAFTState.FOLLOWER);
202
+ }
203
+ else {
204
+ console.log(`${retVal.msg}`);
205
+ console.log(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`.magenta);
206
+ // Reject this RPC and continue in the CANDIDATE state
207
+ callback(null, false);
208
+ return;
209
+ }
210
+ }
211
+ else if (this.#RAFTState.localeCompare(AppMasterRAFTState.LEADER) === 0) {
212
+ console.log(`${this.#GetLogPrefix()}: appendEntry called while I am the current leader, rejecting RPC call.`.red);
213
+ // Reject this RPC and continue in the CANDIDATE state
214
+ callback(null, false);
215
+ return;
216
+ }
217
+ else {
218
+ // FOLLOWER
219
+ const retVal = this.#CheckMoreRecentTerm(term, lastLogItemTerm, lastLogItemIndex);
220
+ if (retVal.retVal === true) {
221
+ if (term > this.#currentTerm) {
222
+ console.log(`${retVal.msg}`);
223
+ this.#currentTerm = term;
224
+ }
225
+ }
226
+ else {
227
+ console.log(`${retVal.msg}`);
228
+ console.log(`${this.#GetLogPrefix()}: appendEntry called but log is older than my current state, Host: [${host}], Port: [${port}].`.magenta);
229
+ // Reject this RPC and continue in the CANDIDATE state
230
+ callback(null, false);
231
+ return;
232
+ }
233
+ }
234
+ if (this.#leaderNode) {
235
+ const sentLeaderService = this.#FindService(host, port);
236
+ if (sentLeaderService) {
237
+ if (sentLeaderService.host.localeCompare(this.#leaderNode.host) !== 0 || sentLeaderService.port !== this.#leaderNode.port) {
238
+ this.#leaderNode = sentLeaderService;
239
+ console.log(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`.yellow);
240
+ }
241
+ }
242
+ }
243
+ else {
244
+ this.#leaderNode = this.#FindService(host, port);
245
+ if (this.#leaderNode) {
246
+ console.log(`${this.#GetLogPrefix()}: Leader Service: Host:[${this.#leaderNode.host}] Port: [${this.#leaderNode.port}]`.yellow);
247
+ }
248
+ }
249
+ // Now update the log if only more recent
250
+ callback(null, true);
251
+ });
252
+ jaysonServer.method("ping", async function (args, callback) {
253
+ // do something, do nothing
254
+ console.log('server got ping');
255
+ callback();
256
+ });
257
+ const server = jaysonServer.tls(this.#GetTLSOptions());
258
+ server.on('secureConnection', this.#SetupRPCServer);
259
+ //server.listen(this.options.listenPort, () => { // 'stscore.stsmda.org'
260
+ server.listen(this.#serverPort, () => {
261
+ console.log('JSON RPC 2.0 Server is running on port ' + this.options.listenPort + '.');
262
+ }).on('listening', () => {
263
+ this.LogEx(`JSON RPC 2.0 live on ${this.options.endpoint}:${this.options.listenPort}${this.options.apiRoot}`);
264
+ });
265
+ return server;
266
+ };
267
+ #RequestVote = (service) => {
268
+ const options = {
269
+ port: service.port,
270
+ host: service.host
271
+ };
272
+ const client = jayson_1.default.client.tls(options);
273
+ /*
274
+ client.on('tcp socket', (socket: tls.TLSSocket) => {
275
+ socket.setTimeout(200); //@@ config
276
+ socket.on('timeout', () => {
277
+ console.log('socket timeout');
278
+ socket.end();
279
+ });
280
+ });
281
+ client.on('tcp error', (error: any) => {
282
+ console.log(`ERROR: [${error}]`.red);
283
+ });
284
+ */
285
+ let lastLogItem;
286
+ if (this.#log.length > 0) {
287
+ lastLogItem = this.#log[this.#log.length - 1];
288
+ }
289
+ else {
290
+ lastLogItem = {
291
+ term: 0,
292
+ index: 0,
293
+ data: null
294
+ };
295
+ }
296
+ client.request('vote', [this.#currentTerm, lastLogItem.term, lastLogItem.index], (error, response) => {
297
+ if (error) {
298
+ //console.log(`vote attempt fail: [${JSON.stringify(options)}: ${error}]`.red);
299
+ }
300
+ else {
301
+ // Log the result
302
+ if (response.result === true) {
303
+ this.#votes[this.#GetServiceKey(service)] = 1;
304
+ }
305
+ this.#CheckMajority();
306
+ }
307
+ });
308
+ };
309
+ #AppendEntry = (service) => {
310
+ const options = {
311
+ port: service.port,
312
+ host: service.host
313
+ };
314
+ const client = jayson_1.default.client.tls(options);
315
+ /*
316
+ client.on('tcp socket', (socket: tls.TLSSocket) => {
317
+ socket.setTimeout(200); //@@ config
318
+ socket.on('timeout', () => {
319
+ console.log('socket timeout');
320
+ socket.end();
321
+ });
322
+ });
323
+ client.on('tcp error', (error: any) => {
324
+ console.log(`ERROR: [${error}]`.red);
325
+ });
326
+ */
327
+ let lastLogItem;
328
+ if (this.#log.length > 0) {
329
+ lastLogItem = this.#log[this.#log.length - 1];
330
+ }
331
+ else {
332
+ lastLogItem = {
333
+ term: 0,
334
+ index: 0,
335
+ data: null
336
+ };
337
+ }
338
+ client.request('appendEntry', [this.#thisService.host, this.#thisService.port, this.#currentTerm, lastLogItem.term, lastLogItem.index], (error, response) => {
339
+ if (error) {
340
+ //console.log(`appendEntry attempt fail: [${JSON.stringify(options)}: ${error}]`.red);
341
+ }
342
+ else {
343
+ this.#appendedEntries[this.#GetServiceKey(service)] = 1;
344
+ // Log the result
345
+ /*
346
+ if (response.result === true) {
347
+ this.#votes[this.#GetServiceKey(service)] = 1;
348
+ }
349
+ */
350
+ }
351
+ });
352
+ };
353
+ #AppendEntries = () => {
354
+ // Reset all appendEntries for this iteration
355
+ this.#appendedEntries = {};
356
+ // Reset all votes
357
+ this.#services.forEach((service, index) => {
358
+ this.#appendedEntries[this.#GetServiceKey(service)] = 0;
359
+ });
360
+ // Request vote for all other services - include my logs current item
361
+ this.#services.forEach((service, index) => {
362
+ if (service.host.localeCompare(this.#thisService.host) === 0 && service.port === this.#thisService.port) {
363
+ // Myself
364
+ this.#ResetElectionTimeout();
365
+ this.#appendedEntries[this.#GetSelfServiceKey()] = 1;
366
+ }
367
+ else {
368
+ // Send vote request
369
+ this.#AppendEntry(service);
370
+ }
371
+ });
372
+ };
373
+ #GetServiceKey = (service) => {
374
+ return `${service.host}:${service.port}`;
375
+ };
376
+ #GetSelfServiceKey = () => {
377
+ return this.#GetServiceKey(this.#thisService);
378
+ };
379
+ // set interval ???
380
+ #StartAppendEntries = () => {
381
+ this.#AppendEntries();
382
+ this.#appendEntriesTimeout = setTimeout(() => {
383
+ // Now check if we still have majority
384
+ const majority = this.#CheckMajorityWithCollection(this.#appendedEntries);
385
+ if (majority) {
386
+ this.#StartAppendEntries();
387
+ }
388
+ else {
389
+ console.log(`${this.#GetLogPrefix()}: Not enough response for valid cluster state.`.red);
390
+ }
391
+ }, this.#heartBeatTimeout);
392
+ };
393
+ #Promote = () => {
394
+ this.#ChangeState(AppMasterRAFTState.LEADER);
395
+ console.log(`${this.#GetLogPrefix()}: New LEADER is elected: [${this.#GetSelfServiceKey()}]`.green);
396
+ // As leader, now start the regular pings
397
+ this.#StartAppendEntries();
398
+ };
399
+ #CheckMajority = () => {
400
+ if (this.#CheckMajorityWithCollection(this.#votes)) {
401
+ this.#Promote();
402
+ }
403
+ };
404
+ #CheckMajorityWithCollection = (col) => {
405
+ let votes = 0;
406
+ for (const [key, val] of Object.entries(col)) {
407
+ votes += val;
408
+ }
409
+ const requiredVotes = Math.floor(this.#services.length / 2) + 1;
410
+ if (requiredVotes !== this.#lastRequiredVotes || votes !== this.#lastVotes) {
411
+ console.log(`${this.#GetLogPrefix()}votes: [${votes} need: [${requiredVotes}]`.cyan);
412
+ this.#lastRequiredVotes = requiredVotes;
413
+ this.#lastVotes = votes;
414
+ }
415
+ return votes >= requiredVotes;
416
+ };
417
+ #StartCanidateVote = () => {
418
+ // Get the election timeout going again
419
+ this.#StartElectionTimeout();
420
+ console.log(`${this.#GetLogPrefix()}: Start CANDIDATE vote`.yellow);
421
+ // Start in the CANDIDATE state
422
+ this.#ChangeState(AppMasterRAFTState.CANDIDATE);
423
+ // Reset votes
424
+ this.#votes = {};
425
+ // Reset all votes from all service instances
426
+ this.#services.forEach((service, index) => {
427
+ this.#votes[this.#GetServiceKey(service)] = 0;
428
+ });
429
+ // Start a new term
430
+ this.#currentTerm++;
431
+ // Request vote for all other services - include my logs current item
432
+ this.#services.forEach((service, index) => {
433
+ if (service.host.localeCompare(this.#thisService.host) === 0 && service.port === this.#thisService.port) {
434
+ // Log the fact that I have now voted for this term
435
+ this.#votedLog[this.#currentTerm] = true;
436
+ // Log the result - Vote for myself
437
+ this.#votes[this.#GetSelfServiceKey()] = 1;
438
+ // Return my yes vote
439
+ console.log(`${this.#GetLogPrefix()}: SELF VOTE: canidate currentTerm: [${this.#currentTerm}], vote YES`.green);
440
+ this.#CheckMajority();
441
+ }
442
+ else {
443
+ // Send vote request
444
+ this.#RequestVote(service);
445
+ }
446
+ });
447
+ };
448
+ #ReceiveVoteRequest = () => {
449
+ // Check if the request term and meta-data is more recent than me
450
+ // If request more recent ...
451
+ this.#voteRegister = 1;
452
+ // Send vote back to requestor
453
+ };
454
+ #ResetElectionTimeout = () => {
455
+ if (this.#canidateTimeout) {
456
+ clearTimeout(this.#canidateTimeout);
457
+ }
458
+ this.#StartElectionTimeout();
459
+ };
460
+ #StartElectionTimeout = () => {
461
+ if (this.#canidateTimeout) {
462
+ clearTimeout(this.#canidateTimeout);
463
+ }
464
+ this.#canidateTimeout = setTimeout(() => {
465
+ this.#StartCanidateVote();
466
+ }, this.#electionTimeout).unref();
467
+ };
468
+ #StartRAFTService = async () => {
469
+ this.LogEx(`---[ RAFT Protocol Starting ]---`.green);
470
+ this.#server = await this.#SetupJSONRPCServer();
471
+ this.#StartElectionTimeout();
472
+ };
473
+ #ChangeState(newState) {
474
+ this.LogEx(`${this.#GetLogPrefix()}: State Change, From: [${this.#RAFTState.toString()}] --> To: [${newState.toString()}]`.green);
475
+ this.#RAFTState = newState;
476
+ }
477
+ MasterStarted() {
478
+ setTimeout(() => {
479
+ this.#StartRAFTService();
480
+ }, this.#startRAFTProtocolTimeout).unref();
481
+ }
482
+ }
483
+ exports.AppMaster = AppMaster;
484
+ //# sourceMappingURL=appmaster.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appmaster.js","sourceRoot":"","sources":["../../src/tcpserver/appmaster.ts"],"names":[],"mappings":";;;;;;AAA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iB,EAAE,CAAC;QAC7B,CAAC,EAAE,IAAI,CAAC,yBAAyB,CAAC,CAAC,KAAK,EAAE,CAAC;IAC/C,CAAC;CACJ;AAxfD,8BAwfC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsshunt/stsappframework",
3
- "version": "2.19.210",
3
+ "version": "2.19.211",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/index.d.ts",
package/run1.sh ADDED
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+ # openssl req -nodes -new -x509 -keyout server.key -out server.cert
3
+ clear; \
4
+ export STS_PROJ_ROOT=./..; \
5
+ STSENVFILE=$STS_PROJ_ROOT/stsglobalresources/.env \
6
+ DB_SCRIPT_FOLDER=$STS_PROJ_ROOT/stsglobalresources/db-scripts \
7
+ REST01_PORT=3003 \
8
+ REST01_HOST_PORT=3003 \
9
+ REST01_SERVICE_NAME="STSRest01-3003" \
10
+ REST01_API_IDENTIFIER="https://stsmda.com.au/stsrest01api/v1.0/" \
11
+ REST01_ENDPOINT="https://stsrest.stsmda.org" \
12
+ MAX_CPU=4 \
13
+ AS_ENDPOINT=https://stscore.stsmda.org \
14
+ AS_HOST_PORT=3002 \
15
+ AS_PORT=3002 \
16
+ DB_HOST=localhost \
17
+ DB_PORT=5432 \
18
+ DB_PASSWORD=postgres \
19
+ HTTPS_SERVER_KEY_PATH=/etc/letsencrypt/live/stsmda.org/privkey.pem \
20
+ HTTPS_SERVER_CERT_PATH=/etc/letsencrypt/live/stsmda.org/fullchain.pem \
21
+ DEBUG=zzproc* \
22
+ PUBLISH_DEBUG=false \
23
+ UV_THREADPOOL_SIZE=64 \
24
+ SERVICE_INDEX=0 \
25
+ node dist/tcpserver/app;
package/run2.sh ADDED
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+ # openssl req -nodes -new -x509 -keyout server.key -out server.cert
3
+ clear; \
4
+ export STS_PROJ_ROOT=./..; \
5
+ STSENVFILE=$STS_PROJ_ROOT/stsglobalresources/.env \
6
+ DB_SCRIPT_FOLDER=$STS_PROJ_ROOT/stsglobalresources/db-scripts \
7
+ REST01_PORT=3003 \
8
+ REST01_HOST_PORT=3003 \
9
+ REST01_SERVICE_NAME="STSRest01-3003" \
10
+ REST01_API_IDENTIFIER="https://stsmda.com.au/stsrest01api/v1.0/" \
11
+ REST01_ENDPOINT="https://stsrest.stsmda.org" \
12
+ MAX_CPU=4 \
13
+ AS_ENDPOINT=https://stscore.stsmda.org \
14
+ AS_HOST_PORT=3002 \
15
+ AS_PORT=3002 \
16
+ DB_HOST=localhost \
17
+ DB_PORT=5432 \
18
+ DB_PASSWORD=postgres \
19
+ HTTPS_SERVER_KEY_PATH=/etc/letsencrypt/live/stsmda.org/privkey.pem \
20
+ HTTPS_SERVER_CERT_PATH=/etc/letsencrypt/live/stsmda.org/fullchain.pem \
21
+ DEBUG=zzproc* \
22
+ PUBLISH_DEBUG=false \
23
+ UV_THREADPOOL_SIZE=64 \
24
+ SERVICE_INDEX=1 \
25
+ node dist/tcpserver/app;