teraslice 3.3.0 → 3.3.2

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 +25 -28
  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,128 +0,0 @@
1
- import path from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import { withoutNil } from '@terascope/core-utils';
4
- // @ts-expect-error
5
- import Chance from 'chance';
6
- import { newId } from '../../../src/lib/utils/id_utils.js';
7
- import { SEARCH_TEST_HOST } from '../../test.config.js';
8
- const dirname = path.dirname(fileURLToPath(import.meta.url));
9
- const opsPath = path.join(dirname, '..', 'fixtures', 'ops');
10
- const chance = new Chance();
11
- const newConfig = (options = {}) => {
12
- const { newOps } = options;
13
- let { operations } = options;
14
- if (operations == null) {
15
- if (newOps) {
16
- operations = [
17
- withoutNil({
18
- _op: path.join(opsPath, 'new-reader'),
19
- countPerSlicer: options.countPerSlicer
20
- }),
21
- withoutNil({
22
- _op: path.join(opsPath, 'new-op'),
23
- failOnSliceRetry: options.failOnSliceRetry || false
24
- }),
25
- {
26
- _op: 'noop'
27
- }
28
- ];
29
- }
30
- else {
31
- operations = [
32
- withoutNil({
33
- _op: path.join(opsPath, 'example-reader'),
34
- exampleProp: 321,
35
- updateMetadata: options.updateMetadata,
36
- errorAt: options.readerErrorAt,
37
- results: options.readerResults,
38
- slicerResults: options.slicerResults,
39
- slicerErrorAt: options.slicerErrorAt,
40
- slicerQueueLength: options.slicerQueueLength
41
- }),
42
- withoutNil({
43
- _op: path.join(opsPath, 'example-op'),
44
- exampleProp: 123,
45
- errorAt: options.opErrorAt,
46
- results: options.opResults
47
- })
48
- ];
49
- }
50
- }
51
- const { analytics = false, maxRetries = 0, slicerPort = 0, lifecycle = 'once', assets = [], workers = 1, slicers = 1, autorecover = false, recoveredExecution, recoveredSliceType, probationWindow = 5000, log_level } = options;
52
- return {
53
- name: chance.name({ middle: true }),
54
- slicers,
55
- workers,
56
- assets,
57
- analytics,
58
- lifecycle,
59
- max_retries: maxRetries,
60
- operations,
61
- autorecover,
62
- performance_metrics: false,
63
- recovered_execution: recoveredExecution,
64
- recovered_slice_type: recoveredSliceType,
65
- ex_id: newId('ex-id', true),
66
- job_id: newId('job-id', true),
67
- node_id: newId('node-id', true),
68
- slicer_port: slicerPort,
69
- slicer_hostname: 'localhost',
70
- probation_window: probationWindow,
71
- log_level
72
- };
73
- };
74
- const newSysConfig = (options) => {
75
- const { clusterName = 'test-teraslice-cluster', timeout = 3000, actionTimeout = 2000, shutdownTimeout = 4000, assetDir, clusterMasterPort, log_level_terafoundation = 'info', } = options;
76
- return {
77
- terafoundation: {
78
- log_level: log_level_terafoundation,
79
- connectors: {
80
- 'elasticsearch-next': {
81
- default: {
82
- node: [SEARCH_TEST_HOST],
83
- requestTimeout: timeout
84
- }
85
- }
86
- }
87
- },
88
- teraslice: {
89
- assets_directory: assetDir,
90
- shutdown_timeout: shutdownTimeout,
91
- action_timeout: actionTimeout,
92
- network_latency_buffer: 100,
93
- slicer_timeout: timeout,
94
- slicer_allocation_attempts: 3,
95
- node_state_interval: timeout,
96
- node_disconnect_timeout: timeout,
97
- worker_disconnect_timeout: timeout,
98
- analytics_rate: 100,
99
- name: clusterName,
100
- master_hostname: 'localhost',
101
- port: clusterMasterPort,
102
- index_settings: {
103
- analytics: {
104
- number_of_shards: 1,
105
- number_of_replicas: 0
106
- },
107
- assets: {
108
- number_of_shards: 1,
109
- number_of_replicas: 0
110
- },
111
- jobs: {
112
- number_of_shards: 1,
113
- number_of_replicas: 0
114
- },
115
- execution: {
116
- number_of_shards: 1,
117
- number_of_replicas: 0
118
- },
119
- state: {
120
- number_of_shards: 1,
121
- number_of_replicas: 0
122
- }
123
- }
124
- }
125
- };
126
- };
127
- export { opsPath, newConfig, newSysConfig };
128
- //# sourceMappingURL=configs.js.map
@@ -1,49 +0,0 @@
1
- import { pDelay, pDefer } from '@terascope/core-utils';
2
- export function makeShutdownEarlyFn({ exController, enabled = false }) {
3
- let shutdownErr = {
4
- message: 'Shutdown never triggered'
5
- };
6
- let alreadyCalled = false;
7
- const deferred = pDefer();
8
- const catchShutdown = async () => {
9
- if (alreadyCalled)
10
- return;
11
- alreadyCalled = true;
12
- shutdownErr.message = 'Shutdown trigger but did not error';
13
- try {
14
- await exController.shutdown();
15
- }
16
- catch (err) {
17
- shutdownErr = err;
18
- }
19
- deferred.resolve();
20
- };
21
- return {
22
- error: () => shutdownErr,
23
- wait: async () => {
24
- if (!enabled)
25
- return;
26
- await deferred.promise;
27
- },
28
- shutdown: async () => {
29
- if (!enabled)
30
- return;
31
- await pDelay(100);
32
- catchShutdown();
33
- await pDelay(100);
34
- }
35
- };
36
- }
37
- export function getTestCases(testCases) {
38
- const onlyCases = testCases.filter((ts) => ts[1].only);
39
- if (onlyCases.length > 0) {
40
- console.warn('[WARNING]: test cases includes a "only" property, make sure to remove this before committing');
41
- return onlyCases;
42
- }
43
- const cases = testCases.filter((ts) => !ts[1].only);
44
- if (cases.length !== testCases.length) {
45
- console.warn('[WARNING]: test cases includes a "skip" property, make sure to remove this before committing');
46
- }
47
- return cases;
48
- }
49
- //# sourceMappingURL=execution-controller-helper.js.map
@@ -1,5 +0,0 @@
1
- import { TestContext } from './test-context';
2
- import { newId } from '../../../src/lib/utils/id_utils.js';
3
- import { newConfig, newSysConfig, opsPath } from './configs';
4
- export { newConfig, opsPath, newId, newSysConfig, TestContext };
5
- //# sourceMappingURL=index.js.map
@@ -1,210 +0,0 @@
1
- import fs from 'fs-extra';
2
- import path from 'node:path';
3
- import { createTempDirSync, cleanupTempDirs } from 'jest-fixtures';
4
- import { newTestSlice } from '@terascope/job-components';
5
- import { get, pWhile } from '@terascope/core-utils';
6
- import { ClusterMaster } from '@terascope/teraslice-messaging';
7
- import { AssetsStorage, StateStorage, AnalyticsStorage, ExecutionStorage, JobsStorage } from '../../../src/lib/storage/index.js';
8
- import { initializeTestExecution } from '../../../src/lib/workers/helpers/job.js';
9
- import { makeTerafoundationContext } from '../../../src/lib/workers/context/terafoundation-context.js';
10
- import { makeExecutionContext } from '../../../src/lib/workers/context/execution-context.js';
11
- import { newId } from '../../../src/lib/utils/id_utils.js';
12
- import { findPort } from '../../../src/lib/utils/port_utils.js';
13
- import { newConfig, newSysConfig } from './configs.js';
14
- import { zipDirectory } from './zip-directory.js';
15
- import { TERASLICE_CLUSTER_NAME } from '../../test.config.js';
16
- const tmpAssetDir = createTempDirSync();
17
- const clusterName = `${TERASLICE_CLUSTER_NAME}`;
18
- export class TestContext {
19
- setupId;
20
- assetDir;
21
- sysconfig;
22
- config;
23
- context;
24
- clean = false;
25
- nodeId;
26
- exId;
27
- jobId;
28
- events;
29
- _cleanupFns = [];
30
- executionContext;
31
- assignment;
32
- clusterMaster;
33
- _stores = {};
34
- cleanups = {};
35
- constructor(options = {}) {
36
- const { clusterMasterPort, shutdownTimeout, actionTimeout, timeout, log_level_terafoundation } = options;
37
- this.setupId = newId('setup', true);
38
- this.assetDir = tmpAssetDir;
39
- this.sysconfig = newSysConfig({
40
- clusterName,
41
- assetDir: this.assetDir,
42
- clusterMasterPort,
43
- actionTimeout,
44
- timeout,
45
- shutdownTimeout,
46
- log_level_terafoundation
47
- });
48
- this.config = newConfig(options);
49
- this.cleanups[this.setupId] = () => this.cleanup();
50
- this.assignment = options.assignment || 'worker';
51
- }
52
- // make sure we cleanup if any test fails to cleanup properly
53
- async cleanupAll(withEs = false) {
54
- const count = Object.keys(this.cleanups).length;
55
- if (!count)
56
- return;
57
- const fns = Object.keys(this.cleanups).map(async (name) => {
58
- const fn = this.cleanups[name];
59
- try {
60
- await fn();
61
- }
62
- catch (err) {
63
- console.error(`Failed to cleanup ${name}`, err);
64
- }
65
- delete this.cleanups[name];
66
- });
67
- await Promise.all(fns);
68
- try {
69
- cleanupTempDirs();
70
- }
71
- catch (err) {
72
- console.error(err);
73
- }
74
- if (withEs && Object.keys(this._stores).length) {
75
- try {
76
- await Promise.all(Object.values(this._stores).map((store) => store.shutdown(true)));
77
- }
78
- catch (err) {
79
- console.error(err);
80
- }
81
- }
82
- }
83
- async waitForCleanup() {
84
- return pWhile(async () => !Object.keys(this.cleanups).length, {
85
- name: 'Test Context',
86
- timeoutMs: 3000
87
- });
88
- }
89
- async initialize(makeItReal = false, initOptions = {}) {
90
- this.context = await makeTerafoundationContext({ sysconfig: this.sysconfig });
91
- this.context.assignment = this.assignment;
92
- this.events = this.context.apis.foundation.getSystemEvents();
93
- if (makeItReal) {
94
- await Promise.all([
95
- this.addJobStore(),
96
- this.addExStore(),
97
- this.addStateStore()
98
- ]);
99
- const { ex } = await initializeTestExecution(Object.assign({
100
- context: this.context,
101
- config: this.config,
102
- stores: this._stores,
103
- }, initOptions));
104
- this.config = ex;
105
- }
106
- this.executionContext = await makeExecutionContext(this.context, this.config);
107
- // @ts-expect-error
108
- this.nodeId = this.executionContext.config.node_id;
109
- this.exId = this.executionContext.config.ex_id;
110
- this.jobId = this.executionContext.config.job_id;
111
- }
112
- get stores() {
113
- return this._stores;
114
- }
115
- async addClusterMaster() {
116
- if (this.clusterMaster)
117
- return this.clusterMaster;
118
- const port = await findPort();
119
- const networkLatencyBuffer = get(this.context, 'sysconfig.teraslice.network_latency_buffer');
120
- const actionTimeout = get(this.context, 'sysconfig.teraslice.action_timeout');
121
- const nodeDisconnectTimeout = get(this.context, 'sysconfig.teraslice.node_disconnect_timeout');
122
- this.clusterMaster = new ClusterMaster.Server({
123
- port,
124
- networkLatencyBuffer,
125
- actionTimeout,
126
- nodeDisconnectTimeout
127
- });
128
- await this.clusterMaster.start();
129
- this.context.sysconfig.teraslice.port = port;
130
- this.attachCleanup(() => this.clusterMaster.shutdown());
131
- return this.clusterMaster;
132
- }
133
- attachCleanup(fn) {
134
- this._cleanupFns.push(fn);
135
- }
136
- async saveAsset(assetDir, cleanup) {
137
- await this.addAssetStore();
138
- const exists = await fs.pathExists(assetDir);
139
- if (!exists) {
140
- const err = new Error(`Asset Directory ${assetDir} does not exist`);
141
- throw err;
142
- }
143
- const assetZip = await zipDirectory(assetDir);
144
- if (!this._stores.assetsStorage) {
145
- throw new Error('Assets storage is not setup');
146
- }
147
- const { assetId } = await this._stores.assetsStorage.save(assetZip);
148
- if (cleanup) {
149
- await fs.remove(path.join(this.assetDir, assetId));
150
- }
151
- return assetId;
152
- }
153
- async newSlice() {
154
- const sliceConfig = newTestSlice({ request: { example: 'slice-data' } });
155
- await this.addStateStore();
156
- await this._stores.stateStorage.createState(this.exId, sliceConfig, 'start');
157
- return sliceConfig;
158
- }
159
- async addAssetStore() {
160
- if (this._stores.assetsStorage) {
161
- return this._stores.assetsStorage;
162
- }
163
- this._stores.assetsStorage = new AssetsStorage(this.context);
164
- await this._stores.assetsStorage.initialize();
165
- delete this.context.apis.assets;
166
- return this._stores.assetsStorage;
167
- }
168
- async addStateStore() {
169
- if (this._stores.stateStorage) {
170
- return this._stores.stateStorage;
171
- }
172
- this._stores.stateStorage = new StateStorage(this.context);
173
- await this._stores.stateStorage.initialize();
174
- return this._stores.stateStorage;
175
- }
176
- async addAnalyticsStore() {
177
- if (this._stores.analyticsStorage) {
178
- return this._stores.analyticsStorage;
179
- }
180
- this._stores.analyticsStorage = new AnalyticsStorage(this.context);
181
- await this._stores.analyticsStorage.initialize();
182
- return this._stores.analyticsStorage;
183
- }
184
- async addJobStore() {
185
- if (this._stores.jobsStorage) {
186
- return this._stores.jobsStorage;
187
- }
188
- this._stores.jobsStorage = new JobsStorage(this.context);
189
- await this._stores.jobsStorage.initialize();
190
- return this._stores.jobsStorage;
191
- }
192
- async addExStore() {
193
- if (this._stores.executionStorage) {
194
- return this._stores.executionStorage;
195
- }
196
- this._stores.executionStorage = new ExecutionStorage(this.context);
197
- await this._stores.executionStorage.initialize();
198
- return this._stores.executionStorage;
199
- }
200
- async cleanup() {
201
- if (this.clean)
202
- return;
203
- await Promise.all(this._cleanupFns.map((fn) => fn()));
204
- this._cleanupFns.length = 0;
205
- this.events.removeAllListeners();
206
- delete this.cleanups[this.setupId];
207
- this.clean = true;
208
- }
209
- }
210
- //# sourceMappingURL=test-context.js.map
@@ -1,25 +0,0 @@
1
- import path from 'node:path';
2
- import { random } from '@terascope/core-utils';
3
- // @ts-expect-error
4
- import BufferStreams from 'bufferstreams';
5
- import archiver from 'archiver';
6
- import { newId } from '../../../src/lib/utils/id_utils.js';
7
- export function zipDirectory(dir) {
8
- return new Promise((resolve, reject) => {
9
- const archive = archiver('zip', { zlib: { level: 9 } });
10
- archive.append(JSON.stringify({
11
- name: path.basename(dir),
12
- version: `${random(0, 100)}.${random(0, 100)}.${random(0, 100)}`,
13
- someProp: newId()
14
- }, null, 4), { name: 'asset.json' });
15
- archive.pipe(new BufferStreams((err, buf) => {
16
- if (err) {
17
- reject(err);
18
- return;
19
- }
20
- resolve(buf);
21
- }));
22
- archive.directory(dir, 'asset').finalize();
23
- });
24
- }
25
- //# sourceMappingURL=zip-directory.js.map