teraslice 0.87.0 → 0.88.0

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 (69) hide show
  1. package/cluster-service.js +24 -18
  2. package/dist/src/index.js +42 -0
  3. package/package.json +11 -15
  4. package/service.js +4 -6
  5. package/worker-service.js +6 -6
  6. package/index.js +0 -21
  7. package/lib/cluster/cluster_master.js +0 -164
  8. package/lib/cluster/node_master.js +0 -393
  9. package/lib/cluster/services/api.js +0 -581
  10. package/lib/cluster/services/assets.js +0 -211
  11. package/lib/cluster/services/cluster/backends/kubernetes/deployments/worker.hbs +0 -86
  12. package/lib/cluster/services/cluster/backends/kubernetes/index.js +0 -225
  13. package/lib/cluster/services/cluster/backends/kubernetes/jobs/execution_controller.hbs +0 -69
  14. package/lib/cluster/services/cluster/backends/kubernetes/k8s.js +0 -450
  15. package/lib/cluster/services/cluster/backends/kubernetes/k8sResource.js +0 -443
  16. package/lib/cluster/services/cluster/backends/kubernetes/k8sState.js +0 -67
  17. package/lib/cluster/services/cluster/backends/kubernetes/utils.js +0 -58
  18. package/lib/cluster/services/cluster/backends/native/index.js +0 -611
  19. package/lib/cluster/services/cluster/backends/native/messaging.js +0 -563
  20. package/lib/cluster/services/cluster/backends/state-utils.js +0 -49
  21. package/lib/cluster/services/cluster/index.js +0 -15
  22. package/lib/cluster/services/execution.js +0 -459
  23. package/lib/cluster/services/jobs.js +0 -303
  24. package/lib/config/default-sysconfig.js +0 -47
  25. package/lib/config/index.js +0 -32
  26. package/lib/config/schemas/system.js +0 -333
  27. package/lib/processors/save_file/index.js +0 -9
  28. package/lib/processors/save_file/processor.js +0 -17
  29. package/lib/processors/save_file/schema.js +0 -17
  30. package/lib/processors/script.js +0 -130
  31. package/lib/processors/stdout/index.js +0 -9
  32. package/lib/processors/stdout/processor.js +0 -19
  33. package/lib/processors/stdout/schema.js +0 -18
  34. package/lib/storage/analytics.js +0 -106
  35. package/lib/storage/assets.js +0 -275
  36. package/lib/storage/backends/elasticsearch_store.js +0 -567
  37. package/lib/storage/backends/mappings/analytics.json +0 -49
  38. package/lib/storage/backends/mappings/asset.json +0 -40
  39. package/lib/storage/backends/mappings/ex.json +0 -55
  40. package/lib/storage/backends/mappings/job.json +0 -31
  41. package/lib/storage/backends/mappings/state.json +0 -37
  42. package/lib/storage/execution.js +0 -331
  43. package/lib/storage/index.js +0 -16
  44. package/lib/storage/jobs.js +0 -97
  45. package/lib/storage/state.js +0 -302
  46. package/lib/utils/api_utils.js +0 -173
  47. package/lib/utils/asset_utils.js +0 -117
  48. package/lib/utils/date_utils.js +0 -58
  49. package/lib/utils/encoding_utils.js +0 -29
  50. package/lib/utils/events.js +0 -7
  51. package/lib/utils/file_utils.js +0 -118
  52. package/lib/utils/id_utils.js +0 -19
  53. package/lib/utils/port_utils.js +0 -83
  54. package/lib/workers/assets/loader.js +0 -109
  55. package/lib/workers/assets/spawn.js +0 -78
  56. package/lib/workers/context/execution-context.js +0 -16
  57. package/lib/workers/context/terafoundation-context.js +0 -10
  58. package/lib/workers/execution-controller/execution-analytics.js +0 -211
  59. package/lib/workers/execution-controller/index.js +0 -1033
  60. package/lib/workers/execution-controller/recovery.js +0 -188
  61. package/lib/workers/execution-controller/scheduler.js +0 -461
  62. package/lib/workers/execution-controller/slice-analytics.js +0 -115
  63. package/lib/workers/helpers/job.js +0 -93
  64. package/lib/workers/helpers/op-analytics.js +0 -22
  65. package/lib/workers/helpers/terafoundation.js +0 -43
  66. package/lib/workers/helpers/worker-shutdown.js +0 -187
  67. package/lib/workers/metrics/index.js +0 -139
  68. package/lib/workers/worker/index.js +0 -344
  69. package/lib/workers/worker/slice.js +0 -143
@@ -1,31 +0,0 @@
1
- {
2
- "settings": {
3
- "index.number_of_shards": 5,
4
- "index.number_of_replicas": 1
5
- },
6
- "mappings": {
7
- "job": {
8
- "_all": {
9
- "enabled": false
10
- },
11
- "dynamic": false,
12
- "properties": {
13
- "active": {
14
- "type": "boolean"
15
- },
16
- "job_id": {
17
- "type": "keyword"
18
- },
19
- "_context": {
20
- "type": "keyword"
21
- },
22
- "_created": {
23
- "type": "date"
24
- },
25
- "_updated": {
26
- "type": "date"
27
- }
28
- }
29
- }
30
- }
31
- }
@@ -1,37 +0,0 @@
1
- {
2
- "template": "__state*",
3
- "mappings": {
4
- "state": {
5
- "_all": {
6
- "enabled": false
7
- },
8
- "dynamic": false,
9
- "properties": {
10
- "ex_id": {
11
- "type": "keyword"
12
- },
13
- "slice_id": {
14
- "type": "keyword"
15
- },
16
- "slicer_id": {
17
- "type": "keyword"
18
- },
19
- "slicer_order": {
20
- "type": "integer"
21
- },
22
- "state": {
23
- "type": "keyword"
24
- },
25
- "_created": {
26
- "type": "date"
27
- },
28
- "_updated": {
29
- "type": "date"
30
- },
31
- "error": {
32
- "type": "keyword"
33
- }
34
- }
35
- }
36
- }
37
- }
@@ -1,331 +0,0 @@
1
- 'use strict';
2
-
3
- const {
4
- TSError, includes, getTypeOf, makeISODate
5
- } = require('@terascope/utils');
6
- const { v4: uuid } = require('uuid');
7
- const { RecoveryCleanupType } = require('@terascope/job-components');
8
- const { makeLogger } = require('../workers/helpers/terafoundation');
9
- const elasticsearchBackend = require('./backends/elasticsearch_store');
10
-
11
- const INIT_STATUS = ['pending', 'scheduling', 'initializing'];
12
- const RUNNING_STATUS = ['recovering', 'running', 'failing', 'paused', 'stopping'];
13
- const TERMINAL_STATUS = ['completed', 'stopped', 'rejected', 'failed', 'terminated'];
14
-
15
- const VALID_STATUS = INIT_STATUS.concat(RUNNING_STATUS).concat(TERMINAL_STATUS);
16
-
17
- // Module to manager job states in Elasticsearch.
18
- // All functions in this module return promises that must be resolved to
19
- // get the final result.
20
- module.exports = async function executionStorage(context) {
21
- const logger = makeLogger(context, 'ex_storage');
22
- const config = context.sysconfig.teraslice;
23
- const jobType = 'ex';
24
- const indexName = `${config.name}__ex`;
25
-
26
- const backendConfig = {
27
- context,
28
- indexName,
29
- recordType: 'ex',
30
- idField: 'ex_id',
31
- fullResponse: false,
32
- logRecord: false,
33
- storageName: 'execution'
34
- };
35
-
36
- const backend = await elasticsearchBackend(backendConfig);
37
-
38
- async function getExecution(exId) {
39
- return backend.get(exId);
40
- }
41
-
42
- // encompasses all executions in either initialization or running statuses
43
- async function getActiveExecution(exId) {
44
- const str = getTerminalStatuses().map((state) => ` _status:${state} `).join('OR');
45
- const query = `ex_id:"${exId}" NOT (${str.trim()})`;
46
- const executions = await search(query, null, 1, '_created:desc');
47
- if (!executions.length) {
48
- throw new Error(`no active execution context was found for ex_id: ${exId}`, {
49
- statusCode: 404
50
- });
51
- }
52
- return executions[0];
53
- }
54
-
55
- async function search(query, from, size, sort, fields) {
56
- return backend.search(query, from, size, sort, fields);
57
- }
58
-
59
- async function create(record, status = 'pending') {
60
- if (!_isValidStatus(status)) {
61
- throw new Error(`Unknown status "${status}" on execution create`);
62
- }
63
- if (!record.job_id) {
64
- throw new Error('Missing job_id on execution create');
65
- }
66
-
67
- const date = makeISODate();
68
- const doc = Object.assign({}, record, {
69
- ex_id: uuid(),
70
- metadata: {},
71
- _status: status,
72
- _context: jobType,
73
- _created: date,
74
- _updated: date,
75
- _has_errors: false,
76
- _slicer_stats: {},
77
- _failureReason: ''
78
- });
79
-
80
- delete doc.slicer_port;
81
- delete doc.slicer_hostname;
82
-
83
- try {
84
- await backend.create(doc);
85
- } catch (err) {
86
- throw new TSError(err, {
87
- reason: 'Failure to create execution context'
88
- });
89
- }
90
- return doc;
91
- }
92
-
93
- async function updatePartial(exId, applyChanges) {
94
- return backend.updatePartial(exId, applyChanges);
95
- }
96
-
97
- /**
98
- * @typedef ExErrorMetadata
99
- * @property _has_errors {boolean}
100
- * @property _failureReason {string}
101
- * @property _slicer_stats {import(
102
- * '../workers/execution-controller/execution-analytics.js'
103
- * ).ExecutionStats}
104
- */
105
-
106
- /**
107
- * Format the execution error stats, primarly used for updating the
108
- * status.
109
- *
110
- * If no error message is passed, it will reset the _has_errors and _failureReason.
111
- * If execution stats is provided it will set the _slicer_stats
112
- *
113
- * @param stats {import(
114
- * '../workers/execution-controller/execution-analytics.js'
115
- * ).ExecutionStats=}
116
- * @param errMsg {string=}
117
- * @return {ExErrorMetadata}
118
- */
119
- function executionMetaData(stats, errMsg) {
120
- const errMetadata = {
121
- _has_errors: false,
122
- _failureReason: ''
123
- };
124
- const statsMetadata = {};
125
-
126
- if (errMsg) {
127
- errMetadata._has_errors = true;
128
- errMetadata._failureReason = errMsg;
129
- }
130
-
131
- if (stats) {
132
- statsMetadata._slicer_stats = Object.assign({}, stats);
133
- }
134
-
135
- return Object.assign({}, errMetadata, statsMetadata);
136
- }
137
-
138
- async function getMetadata(exId) {
139
- const ex = await getExecution(exId);
140
- return ex.metadata || {};
141
- }
142
-
143
- async function updateMetadata(exId, metadata = {}) {
144
- await backend.update(exId, {
145
- metadata,
146
- _updated: makeISODate()
147
- });
148
- }
149
-
150
- function _addMetadataFns() {
151
- if (!context.apis.executionContext) return;
152
- context.apis.executionContext.registerMetadataFns(
153
- { get: getMetadata, update: updateMetadata }
154
- );
155
- }
156
-
157
- async function getStatus(exId) {
158
- try {
159
- const result = await getExecution(exId);
160
- return result._status;
161
- } catch (err) {
162
- throw new TSError(err, {
163
- reason: `Cannot get execution status ${exId}`
164
- });
165
- }
166
- }
167
-
168
- // verify the current status to make sure it can be updated to the desired status
169
- async function verifyStatusUpdate(exId, desiredStatus) {
170
- if (!desiredStatus || !_isValidStatus(desiredStatus)) {
171
- throw new TSError(`Invalid Job status: "${desiredStatus}"`, {
172
- statusCode: 422
173
- });
174
- }
175
-
176
- const status = await getStatus(exId);
177
- _verifyStatus(status, desiredStatus);
178
- }
179
-
180
- function _verifyStatus(status, desiredStatus) {
181
- // when setting the same status to shouldn't throw an error
182
- if (desiredStatus === status) {
183
- return status;
184
- }
185
- // when the current status is running it cannot be set to an init status
186
- if (_isRunningStatus(status) && _isInitStatus(desiredStatus)) {
187
- throw new TSError(`Cannot update running job status of "${status}" to init status of "${desiredStatus}"`, {
188
- statusCode: 422
189
- });
190
- }
191
- // if it is set to stop but the execution finishes before it can stop
192
- // it is okay to set it to completed
193
- if (status === 'stopped' && desiredStatus === 'completed') {
194
- return status;
195
- }
196
- // when the status is a terminal status, it cannot be set to again
197
- if (_isTerminalStatus(status)) {
198
- throw new TSError(`Cannot update terminal job status of "${status}" to "${desiredStatus}"`, {
199
- statusCode: 422
200
- });
201
- }
202
-
203
- // otherwise allow the update
204
- return status;
205
- }
206
-
207
- /**
208
- * Set the status
209
- *
210
- * @param {string} exId
211
- * @param {string} status
212
- * @param {Partial<import('@terascope/job-components').ExecutionConfig>} body
213
- * @returns {Promise<import('@terascope/job-components').ExecutionConfig>}
214
- */
215
- async function setStatus(exId, status, body) {
216
- try {
217
- return await updatePartial(exId, (existing) => {
218
- _verifyStatus(existing._status, status);
219
- return Object.assign(existing, body, {
220
- _status: status,
221
- _updated: makeISODate()
222
- });
223
- });
224
- } catch (err) {
225
- throw new TSError(err, {
226
- statusCode: 422,
227
- reason: `Unable to set execution ${exId} status code to ${status}`
228
- });
229
- }
230
- }
231
-
232
- async function remove(exId) {
233
- return backend.remove(exId);
234
- }
235
-
236
- async function shutdown(forceShutdown) {
237
- logger.info('shutting down.');
238
- return backend.shutdown(forceShutdown);
239
- }
240
-
241
- function verifyClient() {
242
- return backend.verifyClient();
243
- }
244
-
245
- async function waitForClient() {
246
- return backend.waitForClient();
247
- }
248
-
249
- function getTerminalStatuses() {
250
- return TERMINAL_STATUS.slice();
251
- }
252
-
253
- function getRunningStatuses() {
254
- return RUNNING_STATUS.slice();
255
- }
256
-
257
- function getLivingStatuses() {
258
- return INIT_STATUS.concat(RUNNING_STATUS);
259
- }
260
-
261
- function _isValidStatus(status) {
262
- return includes(VALID_STATUS, status);
263
- }
264
-
265
- function _isRunningStatus(status) {
266
- return includes(RUNNING_STATUS, status);
267
- }
268
-
269
- function _isTerminalStatus(status) {
270
- return includes(TERMINAL_STATUS, status);
271
- }
272
-
273
- function _isInitStatus(status) {
274
- return includes(INIT_STATUS, status);
275
- }
276
-
277
- /**
278
- * @param {import('@terascope/job-components').ExecutionConfig} recoverFrom
279
- * @param {RecoveryCleanupType} [cleanupType]
280
- * @returns {Promise<import('@terascope/job-components').ExecutionConfig>}
281
- */
282
- async function createRecoveredExecution(recoverFrom, cleanupType) {
283
- if (!recoverFrom) {
284
- throw new Error(`Invalid execution given, got ${getTypeOf(recoverFrom)}`);
285
- }
286
- if (!recoverFrom.ex_id) {
287
- throw new Error('Unable to recover execution with missing ex_id');
288
- }
289
-
290
- const recoverFromId = recoverFrom.ex_id;
291
-
292
- const ex = Object.assign({}, recoverFrom);
293
- if (cleanupType && !RecoveryCleanupType[cleanupType]) {
294
- throw new Error(`Unknown cleanup type "${cleanupType}" to recover`);
295
- }
296
-
297
- ex.recovered_execution = recoverFromId;
298
-
299
- if (cleanupType) {
300
- ex.recovered_slice_type = cleanupType;
301
- } else if (ex.autorecover) {
302
- ex.recovered_slice_type = RecoveryCleanupType.pending;
303
- }
304
-
305
- return create(ex);
306
- }
307
-
308
- logger.info('execution storage initialized');
309
- _addMetadataFns(context);
310
- return {
311
- get: getExecution,
312
- search,
313
- create,
314
- updatePartial,
315
- remove,
316
- shutdown,
317
- createRecoveredExecution,
318
- getActiveExecution,
319
- getTerminalStatuses,
320
- getRunningStatuses,
321
- getLivingStatuses,
322
- setStatus,
323
- getStatus,
324
- getMetadata,
325
- updateMetadata,
326
- executionMetaData,
327
- verifyStatusUpdate,
328
- waitForClient,
329
- verifyClient,
330
- };
331
- };
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- const makeAnalyticsStore = require('./analytics');
4
- const makeAssetStore = require('./assets');
5
- const makeExStore = require('./execution');
6
- const makeJobStore = require('./jobs');
7
- const makeStateStore = require('./state');
8
-
9
- module.exports = {
10
- SliceState: makeStateStore.SliceState,
11
- makeAnalyticsStore,
12
- makeAssetStore,
13
- makeExStore,
14
- makeJobStore,
15
- makeStateStore,
16
- };
@@ -1,97 +0,0 @@
1
- 'use strict';
2
-
3
- const { v4: uuid } = require('uuid');
4
- const { TSError, makeISODate } = require('@terascope/utils');
5
- const { makeLogger } = require('../workers/helpers/terafoundation');
6
- const elasticsearchBackend = require('./backends/elasticsearch_store');
7
-
8
- // Module to manager job states in Elasticsearch.
9
- // All functions in this module return promises that must be resolved to
10
- // get the final result.
11
- module.exports = async function jobsStorage(context) {
12
- const logger = makeLogger(context, 'job_storage');
13
-
14
- const config = context.sysconfig.teraslice;
15
- const jobType = 'job';
16
- const indexName = `${config.name}__jobs`;
17
-
18
- const backendConfig = {
19
- context,
20
- indexName,
21
- recordType: 'job',
22
- idField: 'job_id',
23
- fullResponse: false,
24
- logRecord: false,
25
- storageName: 'jobs'
26
- };
27
-
28
- const backend = await elasticsearchBackend(backendConfig);
29
-
30
- async function getJob(jobId) {
31
- return backend.get(jobId);
32
- }
33
-
34
- async function search(query, from, size, sort, fields) {
35
- return backend.search(query, from, size, sort, fields);
36
- }
37
-
38
- async function create(record) {
39
- const date = makeISODate();
40
- const doc = Object.assign({}, record, {
41
- job_id: uuid(),
42
- _context: jobType,
43
- _created: date,
44
- _updated: date
45
- });
46
- try {
47
- await backend.create(doc);
48
- } catch (err) {
49
- throw new TSError(err, {
50
- reason: 'Failure to create job'
51
- });
52
- }
53
- return doc;
54
- }
55
-
56
- async function update(jobId, updateSpec) {
57
- // We want to save the whole job as it is posted, update api does partial doc updates
58
- return backend.indexWithId(jobId, Object.assign(
59
- {},
60
- updateSpec,
61
- {
62
- job_id: jobId,
63
- _context: jobType,
64
- _updated: makeISODate()
65
- }
66
- ));
67
- }
68
-
69
- async function remove(jobId) {
70
- return backend.remove(jobId);
71
- }
72
-
73
- async function shutdown(forceShutdown) {
74
- logger.info('shutting down.');
75
- return backend.shutdown(forceShutdown);
76
- }
77
-
78
- function verifyClient() {
79
- return backend.verifyClient();
80
- }
81
-
82
- async function waitForClient() {
83
- return backend.waitForClient();
84
- }
85
-
86
- logger.info('job storage initialized');
87
- return {
88
- get: getJob,
89
- search,
90
- create,
91
- update,
92
- remove,
93
- verifyClient,
94
- waitForClient,
95
- shutdown
96
- };
97
- };