teraslice 3.2.1 → 3.3.1

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 (108) hide show
  1. package/LICENSE +202 -0
  2. package/package.json +26 -30
  3. package/dist/src/interfaces.js +0 -12
  4. package/dist/src/lib/cluster/cluster_master.js +0 -246
  5. package/dist/src/lib/cluster/node_master.js +0 -355
  6. package/dist/src/lib/cluster/services/api.js +0 -663
  7. package/dist/src/lib/cluster/services/assets.js +0 -224
  8. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/index.js +0 -192
  9. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/interfaces.js +0 -2
  10. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/k8s.js +0 -419
  11. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/k8sDeploymentResource.js +0 -60
  12. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/k8sJobResource.js +0 -55
  13. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/k8sResource.js +0 -357
  14. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/k8sServiceResource.js +0 -37
  15. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/k8sState.js +0 -60
  16. package/dist/src/lib/cluster/services/cluster/backends/kubernetesV2/utils.js +0 -170
  17. package/dist/src/lib/cluster/services/cluster/backends/native/dispatch.js +0 -13
  18. package/dist/src/lib/cluster/services/cluster/backends/native/index.js +0 -526
  19. package/dist/src/lib/cluster/services/cluster/backends/native/messaging.js +0 -548
  20. package/dist/src/lib/cluster/services/cluster/backends/state-utils.js +0 -26
  21. package/dist/src/lib/cluster/services/cluster/index.js +0 -13
  22. package/dist/src/lib/cluster/services/execution.js +0 -435
  23. package/dist/src/lib/cluster/services/index.js +0 -6
  24. package/dist/src/lib/cluster/services/interfaces.js +0 -2
  25. package/dist/src/lib/cluster/services/jobs.js +0 -458
  26. package/dist/src/lib/config/default-sysconfig.js +0 -25
  27. package/dist/src/lib/config/index.js +0 -20
  28. package/dist/src/lib/config/schemas/system.js +0 -360
  29. package/dist/src/lib/storage/analytics.js +0 -86
  30. package/dist/src/lib/storage/assets.js +0 -401
  31. package/dist/src/lib/storage/backends/elasticsearch_store.js +0 -496
  32. package/dist/src/lib/storage/backends/mappings/analytics.js +0 -20
  33. package/dist/src/lib/storage/backends/mappings/asset.js +0 -32
  34. package/dist/src/lib/storage/backends/mappings/ex.js +0 -53
  35. package/dist/src/lib/storage/backends/mappings/job.js +0 -42
  36. package/dist/src/lib/storage/backends/mappings/state.js +0 -16
  37. package/dist/src/lib/storage/backends/s3_store.js +0 -237
  38. package/dist/src/lib/storage/execution.js +0 -302
  39. package/dist/src/lib/storage/index.js +0 -7
  40. package/dist/src/lib/storage/jobs.js +0 -81
  41. package/dist/src/lib/storage/state.js +0 -254
  42. package/dist/src/lib/utils/api_utils.js +0 -128
  43. package/dist/src/lib/utils/asset_utils.js +0 -94
  44. package/dist/src/lib/utils/date_utils.js +0 -52
  45. package/dist/src/lib/utils/encoding_utils.js +0 -27
  46. package/dist/src/lib/utils/events.js +0 -4
  47. package/dist/src/lib/utils/file_utils.js +0 -124
  48. package/dist/src/lib/utils/id_utils.js +0 -15
  49. package/dist/src/lib/utils/port_utils.js +0 -32
  50. package/dist/src/lib/workers/assets/index.js +0 -3
  51. package/dist/src/lib/workers/assets/loader-executable.js +0 -40
  52. package/dist/src/lib/workers/assets/loader.js +0 -73
  53. package/dist/src/lib/workers/assets/spawn.js +0 -55
  54. package/dist/src/lib/workers/context/execution-context.js +0 -12
  55. package/dist/src/lib/workers/context/terafoundation-context.js +0 -8
  56. package/dist/src/lib/workers/execution-controller/execution-analytics.js +0 -188
  57. package/dist/src/lib/workers/execution-controller/index.js +0 -1024
  58. package/dist/src/lib/workers/execution-controller/recovery.js +0 -151
  59. package/dist/src/lib/workers/execution-controller/scheduler.js +0 -390
  60. package/dist/src/lib/workers/execution-controller/slice-analytics.js +0 -96
  61. package/dist/src/lib/workers/helpers/job.js +0 -80
  62. package/dist/src/lib/workers/helpers/op-analytics.js +0 -22
  63. package/dist/src/lib/workers/helpers/terafoundation.js +0 -34
  64. package/dist/src/lib/workers/helpers/worker-shutdown.js +0 -147
  65. package/dist/src/lib/workers/metrics/index.js +0 -108
  66. package/dist/src/lib/workers/worker/index.js +0 -378
  67. package/dist/src/lib/workers/worker/slice.js +0 -122
  68. package/dist/test/config/schemas/system_schema-spec.js +0 -26
  69. package/dist/test/lib/cluster/services/cluster/backends/kubernetes/v2/k8s-v2-spec.js +0 -458
  70. package/dist/test/lib/cluster/services/cluster/backends/kubernetes/v2/k8sResource-v2-spec.js +0 -818
  71. package/dist/test/lib/cluster/services/cluster/backends/kubernetes/v2/k8sState-multicluster-v2-spec.js +0 -67
  72. package/dist/test/lib/cluster/services/cluster/backends/kubernetes/v2/k8sState-v2-spec.js +0 -84
  73. package/dist/test/lib/cluster/services/cluster/backends/kubernetes/v2/utils-v2-spec.js +0 -320
  74. package/dist/test/lib/cluster/services/cluster/backends/state-utils-spec.js +0 -37
  75. package/dist/test/node_master-spec.js +0 -194
  76. package/dist/test/services/api-spec.js +0 -79
  77. package/dist/test/services/assets-spec.js +0 -158
  78. package/dist/test/services/messaging-spec.js +0 -440
  79. package/dist/test/storage/assets_storage-spec.js +0 -95
  80. package/dist/test/storage/s3_store-spec.js +0 -149
  81. package/dist/test/test.config.js +0 -23
  82. package/dist/test/test.setup.js +0 -6
  83. package/dist/test/utils/api_utils-spec.js +0 -25
  84. package/dist/test/utils/asset_utils-spec.js +0 -141
  85. package/dist/test/utils/elastic_utils-spec.js +0 -25
  86. package/dist/test/workers/execution-controller/execution-controller-spec.js +0 -371
  87. package/dist/test/workers/execution-controller/execution-special-test-cases-spec.js +0 -519
  88. package/dist/test/workers/execution-controller/execution-test-cases-spec.js +0 -343
  89. package/dist/test/workers/execution-controller/recovery-spec.js +0 -160
  90. package/dist/test/workers/execution-controller/scheduler-spec.js +0 -249
  91. package/dist/test/workers/execution-controller/slice-analytics-spec.js +0 -121
  92. package/dist/test/workers/fixtures/ops/example-op/processor.js +0 -20
  93. package/dist/test/workers/fixtures/ops/example-op/schema.js +0 -19
  94. package/dist/test/workers/fixtures/ops/example-reader/fetcher.js +0 -20
  95. package/dist/test/workers/fixtures/ops/example-reader/schema.js +0 -41
  96. package/dist/test/workers/fixtures/ops/example-reader/slicer.js +0 -37
  97. package/dist/test/workers/fixtures/ops/new-op/processor.js +0 -29
  98. package/dist/test/workers/fixtures/ops/new-op/schema.js +0 -18
  99. package/dist/test/workers/fixtures/ops/new-reader/fetcher.js +0 -19
  100. package/dist/test/workers/fixtures/ops/new-reader/schema.js +0 -23
  101. package/dist/test/workers/fixtures/ops/new-reader/slicer.js +0 -13
  102. package/dist/test/workers/helpers/configs.js +0 -128
  103. package/dist/test/workers/helpers/execution-controller-helper.js +0 -49
  104. package/dist/test/workers/helpers/index.js +0 -5
  105. package/dist/test/workers/helpers/test-context.js +0 -210
  106. package/dist/test/workers/helpers/zip-directory.js +0 -25
  107. package/dist/test/workers/worker/slice-spec.js +0 -333
  108. package/dist/test/workers/worker/worker-spec.js +0 -356
@@ -1,548 +0,0 @@
1
- import { nanoid } from 'nanoid';
2
- import { pDelay, isFunction, isEmpty, get, toNumber, isKey, Queue } from '@terascope/core-utils';
3
- import { io as socketIOClient } from 'socket.io-client';
4
- import { Server as socketIOServer } from 'socket.io';
5
- import { isProcessAssignment, ProcessAssignment } from '../../../../../../interfaces.js';
6
- // messages send to cluster_master
7
- const clusterMasterMessages = {
8
- ipc: {
9
- 'process:SIGTERM': 'SIGTERM',
10
- 'process:SIGINT': 'SIGINT',
11
- },
12
- intraProcess: {
13
- 'network:disconnect': 'disconnect',
14
- 'network:error': 'error',
15
- },
16
- network: {
17
- 'node:online': 'node:online',
18
- 'node:state': 'node:state',
19
- 'execution:recovery:failed': 'execution:recovery:failed',
20
- 'execution:finished': 'execution:finished',
21
- 'cluster:analytics': 'cluster:analytics',
22
- 'execution:error:terminal': 'execution:error:terminal',
23
- 'assets:preloaded': 'assets:preloaded',
24
- 'assets:service:available': 'assets:service:available'
25
- }
26
- };
27
- const nodeMasterMessages = {
28
- ipc: {
29
- 'cluster:error:terminal': 'cluster:error:terminal',
30
- 'child:exit': 'exit'
31
- },
32
- intraProcess: {
33
- 'network:connect': 'connect',
34
- 'network:disconnect': 'disconnect',
35
- 'network:error': 'error',
36
- },
37
- network: {
38
- 'cluster:execution_controller:create': 'cluster:execution_controller:create',
39
- 'cluster:workers:create': 'cluster:workers:create',
40
- 'cluster:workers:remove': 'cluster:workers:remove',
41
- 'cluster:node:state': 'cluster:node:state',
42
- 'cluster:execution:stop': 'cluster:execution:stop',
43
- 'cluster:node:get_port': 'cluster:node:get_port',
44
- }
45
- };
46
- const assetServiceMessages = {
47
- ipc: {
48
- 'process:SIGTERM': 'SIGTERM',
49
- 'process:SIGINT': 'SIGINT',
50
- },
51
- network: {}
52
- };
53
- // messaging destination relative towards each process type
54
- export const routing = Object.freeze({
55
- cluster_master: {
56
- node_master: 'network',
57
- },
58
- node_master: {
59
- cluster_process: 'ipc',
60
- cluster_master: 'network',
61
- },
62
- assets_service: {
63
- cluster_master: 'ipc'
64
- }
65
- });
66
- export class Messaging {
67
- context;
68
- logger;
69
- events;
70
- configTimeout;
71
- networkLatencyBuffer;
72
- hostURL;
73
- messsagingOnline = false;
74
- messagingQueue = new Queue();
75
- childHookFn;
76
- config;
77
- self;
78
- selfMessages;
79
- processContext;
80
- functionMapping;
81
- io;
82
- constructor(context, logger, __io) {
83
- if (__io) {
84
- this.io = __io;
85
- }
86
- this.context = context;
87
- this.functionMapping = {};
88
- // processContext is set in _makeConfigurations
89
- this.config = this._makeConfigurations();
90
- const { hostURL } = this.config;
91
- this.hostURL = hostURL;
92
- this.configTimeout = context.sysconfig.teraslice.action_timeout;
93
- this.networkLatencyBuffer = context.sysconfig.teraslice.network_latency_buffer;
94
- this.self = this.config.assignment;
95
- this.events = context.apis.foundation.getSystemEvents();
96
- this.selfMessages = this._getMessages(this.self);
97
- this.logger = logger;
98
- // @ts-expect-error TODO: fixme
99
- this.childHookFn = null;
100
- this.logger.debug(`messaging service configuration for assignment ${this.config.assignment}`);
101
- // set a default listener the is used for forwarding/completing responses
102
- this.functionMapping['messaging:response'] = this._handleResponse.bind(this);
103
- this.processContext.on('messaging:response', this._handleResponse.bind(this));
104
- // all child processes need to set up a process listener on the 'message' event
105
- if (this.config.clients.ipcClient) {
106
- process.on('message', this._handleIpcMessages().bind(this));
107
- }
108
- else {
109
- this.processContext.on('online', (worker) => {
110
- this.logger.debug('worker process has come online');
111
- if (this.childHookFn) {
112
- this.childHookFn();
113
- }
114
- // @ts-expect-error
115
- const contextWorker = this.processContext.workers[worker.id];
116
- // don't double subscribe
117
- contextWorker.removeListener('message', this._handleWorkerMessage.bind(this));
118
- // set up a message handler on each child created, if a child is talking to cluster
119
- // then pass it on, else invoke process event handler on node_master
120
- contextWorker.on('message', this._handleWorkerMessage.bind(this));
121
- });
122
- }
123
- }
124
- _handleResponse(msgResponse) {
125
- // if msg has returned to source then emit it else pass it along
126
- if (msgResponse.__source === this.config.assignment) {
127
- this.logger.trace(`node message ${msgResponse.__msgId} has been processed`);
128
- // we are in the right spot, emit to complete the promise from send
129
- this.events.emit(msgResponse.__msgId, msgResponse);
130
- }
131
- else {
132
- this._forwardMessage(msgResponse);
133
- }
134
- }
135
- respond(incoming, outgoing) {
136
- const outgoingResponse = (outgoing && typeof outgoing === 'object') ? outgoing : {};
137
- if (incoming.__msgId) {
138
- outgoingResponse.__msgId = incoming.__msgId;
139
- }
140
- outgoingResponse.__source = incoming.__source;
141
- outgoingResponse.message = 'messaging:response';
142
- outgoingResponse.to = incoming.__source;
143
- return this.send(outgoingResponse);
144
- }
145
- _findAndSend(filterFn, msg, msgHookFn) {
146
- const childProcesses = this.context.cluster.workers;
147
- const children = Object.values(childProcesses).filter(filterFn);
148
- if (children.length === 0 && msg.response) {
149
- // if there are no child processes found and it needs a response, answer back so
150
- // that it does not hold for a long time
151
- this.respond(msg);
152
- }
153
- children.forEach((childProcess) => {
154
- if (msgHookFn)
155
- msgHookFn(childProcess);
156
- // @ts-expect-error
157
- if (childProcess.connected) {
158
- childProcess.send(msg);
159
- }
160
- else {
161
- this.logger.warn('cannot send message to process', msg);
162
- }
163
- });
164
- }
165
- _sendToProcesses(msg) {
166
- const msgExId = msg.ex_id || get(msg, 'payload.ex_id');
167
- if (msgExId) {
168
- // all processes that have the same assignment and exId
169
- const filterFn = (process) => {
170
- if (process.assignment !== msg.to)
171
- return false;
172
- if (process.ex_id !== msgExId)
173
- return false;
174
- return true;
175
- };
176
- this._findAndSend(filterFn, msg);
177
- }
178
- else {
179
- // all processes that have the same assignment
180
- const filterFn = (process) => process.assignment === msg.to;
181
- this._findAndSend(filterFn, msg);
182
- }
183
- }
184
- register(eventConfig) {
185
- const eventName = eventConfig.event;
186
- const { callback, identifier } = eventConfig;
187
- const selfHasEvent = Object.values(this.selfMessages)
188
- .some((type) => type[eventName] != null);
189
- if (!selfHasEvent) {
190
- throw new Error(`"${self}" cannot register for event, "${eventName}", in messaging module`);
191
- }
192
- if (this.selfMessages.ipc[eventName]) {
193
- const realKey = this.selfMessages.ipc[eventName];
194
- // this needs to be directly allocated so that IPC messaging can happen if
195
- // network was not instantiated
196
- this.processContext.on(realKey, callback);
197
- }
198
- else {
199
- // we attach events etc later when the connection is made, this is async
200
- // while others are sync registration
201
- let trueEventName = this.selfMessages.network[eventName];
202
- if (!trueEventName) {
203
- trueEventName = this.selfMessages.intraProcess[eventName];
204
- }
205
- if (identifier) {
206
- callback.__socketIdentifier = identifier;
207
- }
208
- this.functionMapping[trueEventName] = callback;
209
- }
210
- }
211
- _registerFns(socket) {
212
- for (const [key, func] of Object.entries(this.functionMapping)) {
213
- if (func.__socketIdentifier) {
214
- const wrappedFunc = (msg = {}) => {
215
- const identifier = func.__socketIdentifier;
216
- let id = msg[identifier];
217
- // if already set, extract value else set it on socket
218
- if (socket[identifier]) {
219
- id = socket[identifier];
220
- }
221
- else {
222
- socket[identifier] = id;
223
- }
224
- // if network host (slicer, cluster_master) and connection
225
- // or retry event, join room
226
- if (key === 'node:online') {
227
- const rooms = Object.keys(socket.rooms);
228
- const hasRoom = rooms.some((r) => r === id);
229
- if (!hasRoom) {
230
- this.logger.info(`joining room ${id}`);
231
- socket.join(id);
232
- }
233
- }
234
- // not all events have messages, if so then pass it, else just pass identifier
235
- if (msg) {
236
- func(msg, id, identifier);
237
- }
238
- else {
239
- func(id);
240
- }
241
- };
242
- socket.on(key, wrappedFunc);
243
- }
244
- else {
245
- this.logger.trace(`setting listener key ${key}`);
246
- socket.on(key, func);
247
- }
248
- }
249
- }
250
- _determinePathForMessage(messageSent) {
251
- const { to } = messageSent;
252
- let destinationType = undefined;
253
- if (isKey(routing, this.self) && isKey(routing[this.self], to)) {
254
- destinationType = routing[this.self][to];
255
- }
256
- // cluster_master has two types of connections to node_master, if it does not have a
257
- // address then its talking to its own node_master through ipc
258
- // TODO: reference self message, remove cluster_master specific code
259
- if (this.self === 'cluster_master' && !messageSent.address && (messageSent.message in clusterMasterMessages.ipc)) {
260
- destinationType = 'ipc';
261
- }
262
- if (destinationType === undefined) {
263
- throw new Error(`could not determine how to pass on message to: ${JSON.stringify(messageSent)}`);
264
- }
265
- return destinationType;
266
- }
267
- // join rooms before on connect to avoid race conditions
268
- _attachRoomsSocketIO() {
269
- if (!this.io)
270
- return;
271
- // middleware
272
- this.io.use((socket, next) => {
273
- const { node_id: nodeId, } = socket.handshake.query;
274
- if (nodeId) {
275
- this.logger.info(`node ${nodeId} joining room on connect`);
276
- socket.join(nodeId);
277
- }
278
- return next();
279
- });
280
- }
281
- _createIOServer(options) {
282
- const { server, port } = options;
283
- const opts = {
284
- path: '/native-clustering',
285
- pingTimeout: this.configTimeout,
286
- pingInterval: this.configTimeout + this.networkLatencyBuffer,
287
- perMessageDeflate: false,
288
- serveClient: false,
289
- };
290
- if (server) {
291
- this.io = new socketIOServer(server, opts);
292
- }
293
- else if (port) {
294
- this.io = new socketIOServer(opts);
295
- this.io.listen(port);
296
- }
297
- this._attachRoomsSocketIO();
298
- this.io.on('connection', (socket) => {
299
- this.logger.debug('a connection to cluster_master has been made');
300
- this._registerFns(socket);
301
- });
302
- }
303
- listen(options = {}) {
304
- const { query } = options;
305
- this.messsagingOnline = true;
306
- if (this.config.clients.networkClient) {
307
- // node_master, worker
308
- this.io = socketIOClient(this.hostURL, {
309
- forceNew: true,
310
- path: '/native-clustering',
311
- query
312
- });
313
- this._registerFns(this.io);
314
- if (this.self === 'node_master') {
315
- this.io.on('networkMessage', (networkMsg) => {
316
- const { message } = networkMsg;
317
- const func = this.functionMapping[message];
318
- if (func) {
319
- func(networkMsg);
320
- }
321
- else {
322
- // if no function is registered, it is meant to by passed along to child
323
- this._sendToProcesses(networkMsg);
324
- }
325
- });
326
- }
327
- this.logger.debug('client network connection is online');
328
- }
329
- else {
330
- // cluster_master and test processes
331
- this._createIOServer(options);
332
- }
333
- // TODO: message queuing will be used until formal process lifecycles are implemented
334
- while (this.messagingQueue.size() > 0) {
335
- const cachedMessages = this.messagingQueue.dequeue();
336
- // they are put in as a tuple, [realMsg, ipcMessage]
337
- this.processContext.emit(cachedMessages[0], cachedMessages[1]);
338
- }
339
- }
340
- broadcast(eventName, payload = {}) {
341
- this.logger.trace('broadcasting a network message', { eventName, payload });
342
- if (!payload.message) {
343
- payload.message = eventName;
344
- }
345
- this.io.emit('networkMessage', payload);
346
- }
347
- _forwardMessage(messageSent) {
348
- const messageType = this._determinePathForMessage(messageSent);
349
- if (messageType === 'network') {
350
- // worker and node_master communicate through broadcast to slicer/cluster_master
351
- if (this.self === 'node_master') {
352
- this.io.emit(messageSent.message, messageSent);
353
- }
354
- else if (this.self === 'cluster_master') {
355
- this.io.sockets.in(messageSent.address).emit('networkMessage', messageSent);
356
- }
357
- else {
358
- this.io.sockets.in(messageSent.address).emit(messageSent.message, messageSent);
359
- }
360
- }
361
- else if (this.self === 'node_master') {
362
- this._sendToProcesses(messageSent);
363
- }
364
- else if (this.processContext) {
365
- if (this.processContext.connected) {
366
- this.processContext.send(messageSent);
367
- }
368
- else {
369
- this.logger.warn('cannot send to process because it is not connected', messageSent);
370
- }
371
- }
372
- }
373
- send(messageSent) {
374
- if (!messageSent.__source) {
375
- messageSent.__source = this.self;
376
- }
377
- const needsReply = messageSent.response;
378
- if (!needsReply) {
379
- this._forwardMessage(messageSent);
380
- return Promise.resolve(true);
381
- }
382
- return new Promise((resolve, reject) => {
383
- let timer;
384
- const msgID = nanoid(8);
385
- const actionTimeout = messageSent.timeout || this.configTimeout;
386
- const messageTimeout = toNumber(actionTimeout) + this.networkLatencyBuffer;
387
- messageSent.__msgId = msgID;
388
- this.events.once(msgID, (nodeMasterData) => {
389
- clearTimeout(timer);
390
- if (nodeMasterData.error) {
391
- reject(new Error(`${nodeMasterData.error} occurred on node: ${nodeMasterData.__source}`));
392
- }
393
- else {
394
- resolve(nodeMasterData);
395
- }
396
- });
397
- this._forwardMessage(messageSent);
398
- timer = setTimeout(() => {
399
- // remove listener to prevent memory leaks
400
- this.events.removeAllListeners(msgID);
401
- reject(new Error(`timeout error while communicating with ${messageSent.to}, msg: ${messageSent.message}, data: ${JSON.stringify(messageSent)}`));
402
- }, messageTimeout);
403
- });
404
- }
405
- _makeConfigurations() {
406
- let host;
407
- let port;
408
- const options = {
409
- node_master: { networkClient: true, ipcClient: false },
410
- cluster_master: { networkClient: false, ipcClient: true },
411
- execution_controller: { networkClient: false, ipcClient: true },
412
- worker: { networkClient: true, ipcClient: true },
413
- assets_service: { networkClient: true, ipcClient: true }
414
- };
415
- // @ts-expect-error
416
- const env = this.context.__testingModule ? this.context.__testingModule.env : process.env;
417
- const processConfig = {};
418
- // @ts-expect-error
419
- const testProcess = this.context.__testingModule;
420
- const { assignment } = env;
421
- if (!isProcessAssignment(assignment)) {
422
- throw new Error(`assignment must be on of: ${Object.values(ProcessAssignment).toString()}. Received ${assignment}`);
423
- }
424
- processConfig.clients = options[assignment];
425
- if (processConfig.clients.ipcClient) {
426
- // all children of node_master
427
- this.processContext = testProcess ? testProcess : process;
428
- }
429
- else {
430
- // node_master
431
- this.processContext = this.context.cluster;
432
- }
433
- if (processConfig.clients.networkClient) {
434
- if (assignment === 'node_master' || assignment === 'assets_service') {
435
- host = this.context.sysconfig.teraslice.master_hostname;
436
- ({ port } = this.context.sysconfig.teraslice);
437
- }
438
- processConfig.hostURL = this._makeHostName(host, port);
439
- }
440
- processConfig.assignment = assignment;
441
- return processConfig;
442
- }
443
- _makeHostName(host, port, nameSpace) {
444
- let name;
445
- let hostname = host;
446
- if (!hostname.match(/http/)) {
447
- hostname = `http://${hostname}`;
448
- }
449
- const lastChar = hostname[hostname.length - 1];
450
- if (lastChar !== ':') {
451
- name = `${hostname}:${port}`;
452
- }
453
- else {
454
- name = hostname + port;
455
- }
456
- if (nameSpace) {
457
- return `${name}/${nameSpace}`;
458
- }
459
- return name;
460
- }
461
- _getMessages(type) {
462
- if (type === 'cluster_master')
463
- return clusterMasterMessages;
464
- if (type === 'node_master')
465
- return nodeMasterMessages;
466
- if (type === 'assets_service')
467
- return assetServiceMessages;
468
- return new Error(`could not find message model for type: ${type}`);
469
- }
470
- getHostUrl() {
471
- if (this.hostURL) {
472
- return this.hostURL;
473
- }
474
- return null;
475
- }
476
- getClientCounts() {
477
- if (this.io) {
478
- return this.io.eio.clientsCount;
479
- }
480
- // there are no connected clients because the network is not instantiated
481
- return 0;
482
- }
483
- listRooms() {
484
- const connected = get(this.io, 'sockets.connected', {});
485
- if (isEmpty(connected))
486
- return [];
487
- return Object.values(connected).flatMap((meta) => Object.keys(meta.rooms));
488
- }
489
- registerChildOnlineHook(fn) {
490
- this.childHookFn = fn;
491
- }
492
- _isExecutionStateQuery(msg) {
493
- const stateQuery = {
494
- 'cluster:execution:pause': 'cluster:execution:pause',
495
- 'cluster:execution:resume': 'cluster:execution:resume',
496
- 'cluster:slicer:analytics': 'cluster:slicer:analytics',
497
- };
498
- return (isKey(stateQuery, msg) && stateQuery[msg] !== undefined);
499
- }
500
- _emitIpcMessage(fn) {
501
- return (ipcMessage) => {
502
- const msg = ipcMessage.message;
503
- const realMsg = get(this.selfMessages, `ipc.${msg}`, null);
504
- if (realMsg) {
505
- fn(realMsg, ipcMessage);
506
- }
507
- else {
508
- this.logger.error(`process: ${self} has received a message: ${msg}, which is not registered in the messaging module`);
509
- }
510
- };
511
- }
512
- _handleIpcMessages() {
513
- if (this.self === 'execution_controller') {
514
- const checkAndEmit = (realMsg, ipcMessage) => {
515
- if (this.messsagingOnline || !this._isExecutionStateQuery(realMsg)) {
516
- this.processContext.emit(realMsg, ipcMessage);
517
- }
518
- else {
519
- this.messagingQueue.enqueue([realMsg, ipcMessage]);
520
- }
521
- };
522
- return this._emitIpcMessage(checkAndEmit);
523
- }
524
- // for everything else just emit the message
525
- const emitFn = (realMsg, ipcMessage) => this.processContext.emit(realMsg, ipcMessage);
526
- return this._emitIpcMessage(emitFn);
527
- }
528
- _handleWorkerMessage(ipcMessage) {
529
- if (ipcMessage.to === 'cluster_master') {
530
- this.logger.trace('network passing process message', ipcMessage.message, ipcMessage);
531
- this.send(ipcMessage);
532
- }
533
- else if (ipcMessage.to === 'node_master') {
534
- this.logger.trace('process message', ipcMessage.message, ipcMessage);
535
- this.processContext.emit(ipcMessage.message, ipcMessage);
536
- }
537
- else {
538
- this._sendToProcesses(ipcMessage);
539
- }
540
- }
541
- async shutdown() {
542
- if (this.io && isFunction(this.io.close)) {
543
- this.io.close();
544
- await pDelay(100);
545
- }
546
- }
547
- }
548
- //# sourceMappingURL=messaging.js.map
@@ -1,26 +0,0 @@
1
- import { cloneDeep } from '@terascope/core-utils';
2
- export function iterateState(clusterState, cb) {
3
- // I clone here, because the code below accidentally modifies clusterState.
4
- // Not sure if this is the best choice.
5
- const state = cloneDeep(clusterState);
6
- return Object.values(state)
7
- .filter((node) => node.state === 'connected')
8
- .flatMap((node) => {
9
- const workers = node.active.filter(cb);
10
- return workers.map((worker) => {
11
- worker.node_id = node.node_id;
12
- worker.hostname = node.hostname;
13
- return worker;
14
- });
15
- });
16
- }
17
- export function findAllSlicers(clusterState) {
18
- return iterateState(clusterState, (worker) => worker.assignment === 'execution_controller');
19
- }
20
- export function findWorkersByExecutionID(clusterState, exId) {
21
- return iterateState(clusterState, (worker) => worker.assignment === 'worker' && worker.ex_id === exId);
22
- }
23
- export function findSlicersByExecutionID(clusterState, exIdDict) {
24
- return iterateState(clusterState, (worker) => worker.assignment === 'execution_controller' && exIdDict[worker.ex_id]);
25
- }
26
- //# sourceMappingURL=state-utils.js.map
@@ -1,13 +0,0 @@
1
- import { NativeClustering } from './backends/native/index.js';
2
- import { KubernetesClusterBackendV2 } from './backends/kubernetesV2/index.js';
3
- export function makeClustering(context, { clusterMasterServer }) {
4
- const clusterType = context.sysconfig.teraslice.cluster_manager_type;
5
- if (clusterType === 'native') {
6
- return new NativeClustering(context, clusterMasterServer);
7
- }
8
- if (clusterType === 'kubernetesV2') {
9
- return new KubernetesClusterBackendV2(context, clusterMasterServer);
10
- }
11
- throw new Error(`unknown cluster service ${clusterType}, cannot find cluster module`);
12
- }
13
- //# sourceMappingURL=index.js.map