@nsshunt/stsappframework 3.0.94 → 3.0.95
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/package.json +1 -1
- package/src_new/authDefs.ts +37 -0
- package/src_new/authutilsnode.ts +375 -0
- package/src_new/commonTypes.ts +239 -0
- package/src_new/index.ts +22 -0
- package/src_new/influxdb/influxDBManager.ts +972 -0
- package/src_new/influxdb/influxDBManagerAgent.ts +316 -0
- package/src_new/influxdb/influxDBManagerBase.ts +111 -0
- package/src_new/influxdb/influxDBManagerService.ts +375 -0
- package/src_new/instrumentationsubscriber.ts +286 -0
- package/src_new/kafka/IMKafkaManager.ts +154 -0
- package/src_new/kafka/kafkaconsumer.ts +82 -0
- package/src_new/kafka/kafkamanager.ts +186 -0
- package/src_new/kafka/kafkaproducer.ts +58 -0
- package/src_new/kafkatesting/config.ts +10 -0
- package/src_new/kafkatesting/consume.ts +116 -0
- package/src_new/kafkatesting/produce.ts +155 -0
- package/src_new/masterprocessbase.ts +590 -0
- package/src_new/middleware/serverNetworkMiddleware.ts +240 -0
- package/src_new/network.ts +36 -0
- package/src_new/processbase.ts +413 -0
- package/src_new/processoptions.ts +164 -0
- package/src_new/publishertransports/publishTransportDirect.ts +45 -0
- package/src_new/publishertransports/publishTransportUtils.ts +53 -0
- package/src_new/server.ts +141 -0
- package/src_new/serverprocessbase.ts +393 -0
- package/src_new/singleprocessbase.ts +123 -0
- package/src_new/socketIoServerHelper.ts +177 -0
- package/src_new/stscontrollerbase.ts +15 -0
- package/src_new/stslatencycontroller.ts +27 -0
- package/src_new/stslatencyroute.ts +16 -0
- package/src_new/stsrouterbase.ts +22 -0
- package/src_new/tcpclient/app.ts +19 -0
- package/src_new/tcpclient/app2.ts +56 -0
- package/src_new/tcpserver/app.ts +11 -0
- package/src_new/tcpserver/appConfig.ts +65 -0
- package/src_new/tcpserver/appmaster.ts +522 -0
- package/src_new/validation/errors.ts +6 -0
- package/src_new/webworkertesting/app.ts +49 -0
- package/src_new/webworkertesting/worker.ts +24 -0
- package/src_new/workerprocessbase.test.ts +47 -0
- package/src_new/workerprocessbase.ts +187 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
+
import { IProcessBase } from './commonTypes';
|
|
3
|
+
|
|
4
|
+
export abstract class STSControllerBase
|
|
5
|
+
{
|
|
6
|
+
#stsApp: any;
|
|
7
|
+
|
|
8
|
+
constructor(stsApp: IProcessBase) {
|
|
9
|
+
this.#stsApp = stsApp;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get stsApp(): IProcessBase {
|
|
13
|
+
return this.#stsApp
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
+
import { StatusCodes } from 'http-status-codes'
|
|
3
|
+
import { STSControllerBase } from './stscontrollerbase'
|
|
4
|
+
import { IProcessBase } from './commonTypes'
|
|
5
|
+
|
|
6
|
+
export class STSLatencyController extends STSControllerBase
|
|
7
|
+
{
|
|
8
|
+
constructor(stsApp: IProcessBase) {
|
|
9
|
+
super(stsApp);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// curl http://localhost:3000/api/v1/latency/latency
|
|
13
|
+
async stslatency(req: any, res: any)
|
|
14
|
+
{
|
|
15
|
+
try {
|
|
16
|
+
const retVal = {
|
|
17
|
+
data: `Ping Completed At: ${Date.now()}`,
|
|
18
|
+
pid: process.pid,
|
|
19
|
+
ppid: process.ppid
|
|
20
|
+
};
|
|
21
|
+
return res.status(StatusCodes.OK).send(retVal);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.error(error);
|
|
24
|
+
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).send( { status: StatusCodes.INTERNAL_SERVER_ERROR, error: 'Operation was not successful', detail: error } );
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { STSRouterBase } from './stsrouterbase'
|
|
2
|
+
import { STSLatencyController } from './stslatencycontroller'
|
|
3
|
+
import { IProcessBase } from './commonTypes'
|
|
4
|
+
|
|
5
|
+
export class STSLatencyRoute extends STSRouterBase
|
|
6
|
+
{
|
|
7
|
+
constructor(stsApp: IProcessBase)
|
|
8
|
+
{
|
|
9
|
+
super(stsApp);
|
|
10
|
+
|
|
11
|
+
const latencyController = new STSLatencyController(stsApp);
|
|
12
|
+
const { stslatency } = latencyController;
|
|
13
|
+
|
|
14
|
+
this.router.get('/latency', stslatency.bind(latencyController)); // Create new test
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
+
import { Router } from 'express';
|
|
3
|
+
import { IProcessBase } from './commonTypes';
|
|
4
|
+
|
|
5
|
+
export abstract class STSRouterBase
|
|
6
|
+
{
|
|
7
|
+
#router: Router;
|
|
8
|
+
#stsApp: any;
|
|
9
|
+
|
|
10
|
+
constructor(stsApp: IProcessBase) {
|
|
11
|
+
this.#stsApp = stsApp;
|
|
12
|
+
this.#router = Router();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get router(): Router {
|
|
16
|
+
return this.#router;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get stsApp(): IProcessBase {
|
|
20
|
+
return this.#stsApp
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
|
|
2
|
+
import jayson from 'jayson'
|
|
3
|
+
|
|
4
|
+
// Read node's tls documentation for more information about these options:
|
|
5
|
+
// https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
|
|
6
|
+
const options: jayson.TcpClientOptions = {
|
|
7
|
+
port: 3003,
|
|
8
|
+
host: 'stscore.stsmda.org'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const client = jayson.client.tls(options);
|
|
12
|
+
|
|
13
|
+
// create a client
|
|
14
|
+
|
|
15
|
+
// invoke "add"
|
|
16
|
+
client.request('add', [1, 1], function(err: any, response: any) {
|
|
17
|
+
if(err) throw err;
|
|
18
|
+
console.log(response.result); // 2
|
|
19
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
+
import tls from 'tls';
|
|
3
|
+
import { Sleep } from '@nsshunt/stsutils'
|
|
4
|
+
|
|
5
|
+
import 'colors'
|
|
6
|
+
|
|
7
|
+
const options = {
|
|
8
|
+
port: 3003,
|
|
9
|
+
host: 'stscore.stsmda.org'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const done: boolean[] = [];
|
|
13
|
+
|
|
14
|
+
const dosomework = (socket: any, index: number) => {
|
|
15
|
+
console.log('Connected');
|
|
16
|
+
socket.write("Hello From Client " + JSON.stringify(socket.address()));
|
|
17
|
+
(async () => {
|
|
18
|
+
for (;;) {
|
|
19
|
+
const msg = `${new Date()}: Hello`;
|
|
20
|
+
console.log(`sending: [${msg}]`);
|
|
21
|
+
socket.write(msg);
|
|
22
|
+
await Sleep(1000);
|
|
23
|
+
if (done[index]) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (let i=0; i < 6; i++) {
|
|
31
|
+
const socket1 = tls.connect(options);
|
|
32
|
+
done[i] = false;
|
|
33
|
+
socket1.on('secureConnect', () => {
|
|
34
|
+
dosomework(socket1, i);
|
|
35
|
+
});
|
|
36
|
+
socket1.on('close', function(data: any) {
|
|
37
|
+
console.log(`CLOSED: ${socket1.remoteAddress} ${socket1.remotePort}`.yellow);
|
|
38
|
+
done[i]=true;
|
|
39
|
+
});
|
|
40
|
+
socket1.on('data', function(data: any) {
|
|
41
|
+
console.log(`DATA ${socket1.remoteAddress} ${socket1.remotePort} ${data}`.yellow);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
const socket2 = tls.connect(options);
|
|
47
|
+
socket2.on('secureConnect', () => {
|
|
48
|
+
dosomework(socket2);
|
|
49
|
+
});
|
|
50
|
+
socket2.on('close', function(data: any) {
|
|
51
|
+
console.log(chalk.green(`CLOSED: ${socket2.remoteAddress} ${socket2.remotePort}`));
|
|
52
|
+
});
|
|
53
|
+
socket2.on('data', function(data: any) {
|
|
54
|
+
console.log(chalk.green(`DATA ${socket2.remoteAddress} ${socket2.remotePort} ${data}`));
|
|
55
|
+
});
|
|
56
|
+
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ServiceConfigOptions } from './appConfig.js'
|
|
2
|
+
import { WorkerProcessBase } from '../index'
|
|
3
|
+
import { AppMaster } from './appmaster'
|
|
4
|
+
|
|
5
|
+
import cluster from 'cluster';
|
|
6
|
+
|
|
7
|
+
if (cluster.isPrimary) {
|
|
8
|
+
new AppMaster(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
|
|
9
|
+
} else {
|
|
10
|
+
new WorkerProcessBase(ServiceConfigOptions(true, cluster.isPrimary)).SetupServer();
|
|
11
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
|
|
3
|
+
import { $Options } from '@nsshunt/stsconfig'
|
|
4
|
+
const goptions = $Options()
|
|
5
|
+
|
|
6
|
+
import { ProcessOptions, STSServerType } from '../index'
|
|
7
|
+
|
|
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
|
+
|
|
26
|
+
export function ServiceConfigOptions(clusterMode: boolean, isMaster: boolean): ProcessOptions {
|
|
27
|
+
if (isMaster === true) {
|
|
28
|
+
const serviceInstanceId = uuidv4();
|
|
29
|
+
const data: ProcessOptions = {
|
|
30
|
+
serverType: STSServerType.TCPRAW_TLS,
|
|
31
|
+
|
|
32
|
+
clusterMode: clusterMode,
|
|
33
|
+
wssServer: false,
|
|
34
|
+
useLatency: false,
|
|
35
|
+
httpsServerKeyPath: goptions.httpsserverkeypath,
|
|
36
|
+
httpsServerCertificatePath: goptions.httpsservercertpath,
|
|
37
|
+
processExitOnTerminate: true,
|
|
38
|
+
serviceInstanceId: serviceInstanceId,
|
|
39
|
+
useDatabase: true,
|
|
40
|
+
|
|
41
|
+
isMaster: isMaster,
|
|
42
|
+
endpoint: goptions.rest01endpoint,
|
|
43
|
+
apiRoot: goptions.rest01apiroot,
|
|
44
|
+
listenPort: goptions.rest01hostport,
|
|
45
|
+
port: goptions.rest01port,
|
|
46
|
+
|
|
47
|
+
prometheusSupport: false,
|
|
48
|
+
prometheusClusterPort: goptions.rest01prometheusclusterport,
|
|
49
|
+
|
|
50
|
+
serviceName: goptions.rest01servicename,
|
|
51
|
+
serviceVersion: goptions.rest01serviceversion,
|
|
52
|
+
consoleLogging: true,
|
|
53
|
+
instrumentLogging: true,
|
|
54
|
+
|
|
55
|
+
instrumentationObservationInterval: goptions.instrumentationObservationInterval,
|
|
56
|
+
instrumentationTimeWindow: goptions.instrumentationTimeWindow,
|
|
57
|
+
|
|
58
|
+
useRedisAdaptor: false
|
|
59
|
+
}
|
|
60
|
+
return data;
|
|
61
|
+
} else {
|
|
62
|
+
const data: ProcessOptions = JSON.parse(process.env['STS_GSD_SII'] as string) as ProcessOptions;
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
}
|