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,458 +0,0 @@
1
- import { TSError, uniq, cloneDeep, isEmpty, getTypeOf, isString, defaultsDeep, makeISODate } from '@terascope/core-utils';
2
- import { JobValidator, parseName } from '@terascope/job-components';
3
- import { makeLogger } from '../../workers/helpers/terafoundation.js';
4
- import { spawnAssetLoader } from '../../workers/assets/spawn.js';
5
- /**
6
- * New execution result
7
- * @typedef NewExecutionResult
8
- * @property {string} job_id
9
- * @property {string} ex_id
10
- */
11
- export class JobsService {
12
- context;
13
- jobValidator;
14
- logger;
15
- jobsStorage;
16
- executionStorage;
17
- executionService;
18
- constructor(context) {
19
- this.context = context;
20
- this.logger = makeLogger(context, 'jobs_service');
21
- this.jobValidator = new JobValidator(context);
22
- }
23
- async initialize() {
24
- this.logger.info('job service is initializing...');
25
- const { executionStorage, jobsStorage } = this.context.stores;
26
- if (jobsStorage == null || executionStorage == null) {
27
- throw new Error('Missing required stores');
28
- }
29
- const { executionService } = this.context.services;
30
- if (executionService == null) {
31
- throw new Error('Missing required services');
32
- }
33
- this.jobsStorage = jobsStorage;
34
- this.executionStorage = executionStorage;
35
- this.executionService = executionService;
36
- }
37
- /**
38
- * Validate the job spec
39
- *
40
- * @returns {Promise<import('@terascope/job-components').ValidatedJobConfig>}
41
- */
42
- async _validateJobSpec(jobSpec) {
43
- const parsedAssetJob = await this._ensureAssets(cloneDeep(jobSpec));
44
- const validJob = await this.jobValidator.validateConfig(parsedAssetJob);
45
- return validJob;
46
- }
47
- async submitJob(jobSpec, shouldRun) {
48
- // @ts-expect-error
49
- if (jobSpec.job_id) {
50
- throw new TSError('Job cannot include a job_id on submit', {
51
- statusCode: 422,
52
- });
53
- }
54
- this.addExternalPortsToJobSpec(jobSpec);
55
- const validJob = await this._validateJobSpec(jobSpec);
56
- // We don't create with the fully parsed validJob as it changes the asset names
57
- // to their asset id which we don't want stored as at the job level
58
- const job = await this.jobsStorage.create(jobSpec);
59
- if (!shouldRun) {
60
- return { job_id: job.job_id };
61
- }
62
- const jobRecord = Object.assign({}, jobSpec, validJob, {
63
- job_id: job.job_id
64
- });
65
- return this.executionService.createExecutionContext(jobRecord);
66
- }
67
- /**
68
- * Sets the `active` property on the job to `true` or `false`.
69
- * @param {string} jobId
70
- * @param {boolean} activeState
71
- */
72
- async setActiveState(jobId, activeState) {
73
- const job = await this.jobsStorage.get(jobId);
74
- if (activeState === true) {
75
- job.active = true;
76
- }
77
- else {
78
- job.active = false;
79
- }
80
- this.logger.info(`Setting jobId: ${jobId} to active: ${activeState}`);
81
- return this.updateJob(jobId, job);
82
- }
83
- async updateJob(jobId, jobSpec) {
84
- const originalJob = await this.jobsStorage.get(jobId);
85
- if (originalJob._deleted === true) {
86
- throw new TSError(`Job ${jobId} has been deleted and cannot be updated.`, {
87
- statusCode: 410
88
- });
89
- }
90
- // If job is switching from active to inactive job validation is skipped
91
- // This allows for old jobs that are missing required resources to be marked inactive
92
- if (originalJob.active !== false && jobSpec.active === false) {
93
- this.logger.info(`Skipping job validation to set jobId ${jobId} as _inactive`);
94
- }
95
- else {
96
- this.addExternalPortsToJobSpec(jobSpec);
97
- await this._validateJobSpec(jobSpec);
98
- }
99
- return this.jobsStorage.update(jobId, Object.assign({}, jobSpec, {
100
- _created: originalJob._created
101
- }));
102
- }
103
- /**
104
- * Start a Job
105
- *
106
- * @param {string} jobId
107
- * @returns {Promise<NewExecutionResult>}
108
- */
109
- async startJob(jobId) {
110
- const activeExecution = await this._getActiveExecution(jobId, true);
111
- // searching for an active execution, if there is then we reject
112
- if (activeExecution) {
113
- throw new TSError(`Job ${jobId} is currently running, cannot have the same job concurrently running`, {
114
- statusCode: 409
115
- });
116
- }
117
- const currentResources = await this.executionService.listResourcesForJobId(jobId);
118
- if (currentResources.length > 0) {
119
- const flattenedResources = currentResources.flat();
120
- const exIdsSet = new Set();
121
- for (const resource of flattenedResources) {
122
- if (resource.metadata.labels) {
123
- exIdsSet.add(resource.metadata.labels['teraslice.terascope.io/exId']);
124
- }
125
- }
126
- const exIdsArr = Array.from(exIdsSet);
127
- const exIdsString = exIdsArr.join(', ');
128
- throw new TSError(`There are orphaned resources for job: ${jobId}, exId: ${exIdsString}.
129
- Please wait for Kubernetes to clean up orphaned resources.`);
130
- }
131
- const jobSpec = await this.jobsStorage.get(jobId);
132
- if (jobSpec._deleted === true) {
133
- throw new TSError(`Job ${jobId} has been deleted and cannot be started.`, {
134
- statusCode: 410
135
- });
136
- }
137
- const validJob = await this._validateJobSpec(jobSpec);
138
- if (validJob.autorecover) {
139
- return this._recoverValidJob(validJob);
140
- }
141
- return this.executionService.createExecutionContext(validJob);
142
- }
143
- /**
144
- * Recover a job using the valid configuration
145
- *
146
- * @private
147
- * @param {import('@terascope/job-components').ValidatedJobConfig} validJob
148
- * @param {import('@terascope/job-components').RecoveryCleanupType} [cleanupType]
149
- * @returns {Promise<NewExecutionResult>}
150
- */
151
- async _recoverValidJob(validJob, cleanupType) {
152
- const recoverFrom = await this.getLatestExecution(validJob.job_id, undefined, true);
153
- // if there isn't an execution and autorecover is true
154
- // create a new execution else throw
155
- if (!recoverFrom) {
156
- if (validJob.autorecover) {
157
- return this.executionService.createExecutionContext(validJob);
158
- }
159
- throw new TSError(`Job ${validJob.job_id} is missing an execution to recover from`, {
160
- statusCode: 404
161
- });
162
- }
163
- if (validJob.slicers !== recoverFrom.slicers) {
164
- const changedFrom = `from ${recoverFrom.slicers} to ${validJob.slicers}`;
165
- this.logger.warn(`recovery for job ${recoverFrom.job_id} changed slicers ${changedFrom}`);
166
- }
167
- return this.executionService.recoverExecution(
168
- // apply the latest job config changes
169
- defaultsDeep({}, validJob, recoverFrom), cleanupType);
170
- }
171
- /**
172
- * Recover a job, applied the last changes to the prev execution
173
- *
174
- * @param {string} jobId
175
- * @param {import('@terascope/job-components').RecoveryCleanupType} [cleanupType]
176
- * @returns {Promise<NewExecutionResult>}
177
- */
178
- async recoverJob(jobId, cleanupType) {
179
- // we need to do validations since the job config could change between recovery
180
- const jobSpec = await this.jobsStorage.get(jobId);
181
- if (jobSpec._deleted === true) {
182
- throw new TSError(`Job ${jobId} has been deleted and cannot be recovered.`, {
183
- statusCode: 410
184
- });
185
- }
186
- const validJob = await this._validateJobSpec(jobSpec);
187
- return this._recoverValidJob(validJob, cleanupType);
188
- }
189
- async pauseJob(jobId) {
190
- const exId = await this.getLatestExecutionId(jobId);
191
- return this.executionService.pauseExecution(exId);
192
- }
193
- async resumeJob(jobId) {
194
- const exId = await this.getLatestExecutionId(jobId);
195
- return this.executionService.resumeExecution(exId);
196
- }
197
- async softDeleteJob(jobId) {
198
- const activeExecution = await this._getActiveExecution(jobId, true);
199
- // searching for an active execution, if there is then we reject
200
- if (activeExecution) {
201
- throw new TSError(`Job ${jobId} is currently running, cannot delete a running job.`, {
202
- statusCode: 409
203
- });
204
- }
205
- // This will return any orphaned resources in k8s clustering
206
- // or an empty array in native clustering
207
- const currentResources = await this.executionService.listResourcesForJobId(jobId);
208
- if (currentResources.length > 0) {
209
- const flattenedResources = currentResources.flat();
210
- const exIdsSet = new Set();
211
- for (const resource of flattenedResources) {
212
- if (resource.metadata.labels) {
213
- exIdsSet.add(resource.metadata.labels['teraslice.terascope.io/exId']);
214
- }
215
- }
216
- const exIdsArr = Array.from(exIdsSet);
217
- const exIdsString = exIdsArr.join(', ');
218
- this.logger.info(`There are orphaned resources for job: ${jobId}, exId: ${exIdsString}.\n`
219
- + 'Removing resources before job deletion.');
220
- await Promise.all(exIdsArr
221
- .map((exId) => this.executionService.stopExecution(exId, { force: true })));
222
- }
223
- const jobSpec = await this.jobsStorage.get(jobId);
224
- if (jobSpec._deleted === true) {
225
- throw new TSError(`Job ${jobId} has already been deleted.`, {
226
- statusCode: 410
227
- });
228
- }
229
- jobSpec._deleted = true;
230
- jobSpec._deleted_on = makeISODate();
231
- jobSpec.active = false;
232
- const executions = await this.getAllExecutions(jobId, undefined, true);
233
- for (const execution of executions) {
234
- await this.executionService.softDeleteExecutionContext(execution.ex_id);
235
- }
236
- return this.jobsStorage.update(jobId, jobSpec);
237
- }
238
- /**
239
- * Get all executions related to a jobId
240
- *
241
- * @param {string} jobId
242
- * @param {string} [query]
243
- * @param {boolean=false} [allowZeroResults]
244
- * @returns {Promise<import('@terascope/types').ExecutionConfig[]>}
245
- */
246
- async getAllExecutions(jobId, query, allowZeroResults = false) {
247
- if (!jobId || !isString(jobId)) {
248
- throw new TSError(`Invalid job id, got ${getTypeOf(jobId)}`);
249
- }
250
- const executions = await this.executionStorage.search(query || `job_id: "${jobId}"`, undefined, undefined, '_created:desc');
251
- if (!allowZeroResults && !executions.length) {
252
- throw new TSError(`No executions were found for job ${jobId}`, {
253
- statusCode: 404
254
- });
255
- }
256
- return executions;
257
- }
258
- /**
259
- * Get the latest execution
260
- *
261
- * @param {string} jobId
262
- * @param {string} [query]
263
- * @param {boolean=false} [allowZeroResults]
264
- * @returns {Promise<import('@terascope/types').ExecutionConfig>}
265
- */
266
- async getLatestExecution(jobId, query, allowZeroResults = false) {
267
- if (!jobId || !isString(jobId)) {
268
- throw new TSError(`Invalid job id, got ${getTypeOf(jobId)}`);
269
- }
270
- const ex = await this.executionStorage.search(query || `job_id: "${jobId}"`, undefined, 1, '_created:desc');
271
- if (!allowZeroResults && !ex.length) {
272
- throw new TSError(`No execution was found for job ${jobId}`, {
273
- statusCode: 404
274
- });
275
- }
276
- return ex[0];
277
- }
278
- /**
279
- * Get the job with the latest ex status
280
- *
281
- * @param {string} jobId
282
- * @param {string} [fields]
283
- * @returns {Promise<JobConfig>}
284
- */
285
- async getJobWithExInfo(jobId, fields) {
286
- if (!jobId || !isString(jobId)) {
287
- throw new TSError(`Invalid job id, got ${getTypeOf(jobId)}`);
288
- }
289
- const job = await this.jobsStorage.get(jobId);
290
- const ex = await this.executionStorage.search(`job_id: "${jobId}"`, undefined, 1, '_created:desc', fields || undefined);
291
- if (!ex.length || ex[0]._deleted === true) {
292
- job.ex = {};
293
- return job;
294
- }
295
- job.ex = ex[0];
296
- return job;
297
- }
298
- /**
299
- * Get a list of jobs with the latest ex status for each one
300
- *
301
- * @param {string} query
302
- * @param {number} from
303
- * @param {number} size
304
- * @param {string} sort
305
- * @param {string} [ex_fields]
306
- * @returns {Promise<JobConfig>}
307
- */
308
- async getJobsWithExInfo(query, from, size, sort, ex_fields) {
309
- const jobList = await this.jobsStorage.search(query, from, size, sort);
310
- const finalList = [];
311
- for (const job of jobList) {
312
- finalList.push(await this.getJobWithExInfo(job.job_id, ex_fields));
313
- }
314
- return finalList;
315
- }
316
- /**
317
- * Get the active execution
318
- *
319
- * @param {string} jobId
320
- * @param {boolean} [allowZeroResults]
321
- * @returns {Promise<import('@terascope/types').ExecutionConfig>}
322
- */
323
- async _getActiveExecution(jobId, allowZeroResults) {
324
- const statuses = this.executionStorage
325
- .getTerminalStatuses()
326
- .map((state) => ` _status:"${state}"`)
327
- .join(' OR ');
328
- const query = `job_id:"${jobId}" AND _context:ex NOT (${statuses.trim()})`;
329
- return this.getLatestExecution(jobId, query, allowZeroResults);
330
- }
331
- /**
332
- * Get the active execution
333
- *
334
- * @param {string} jobId
335
- * @returns {Promise<string>}
336
- */
337
- async _getActiveExecutionId(jobId) {
338
- const { ex_id } = await this._getActiveExecution(jobId);
339
- return ex_id;
340
- }
341
- async getLatestExecutionId(jobId) {
342
- const { ex_id } = await this.getLatestExecution(jobId);
343
- return ex_id;
344
- }
345
- async shutdown() {
346
- }
347
- async addWorkers(jobId, workerCount) {
348
- const exId = await this._getActiveExecutionId(jobId);
349
- return this.executionService.addWorkers(exId, workerCount);
350
- }
351
- async removeWorkers(jobId, workerCount) {
352
- const exId = await this._getActiveExecutionId(jobId);
353
- return this.executionService.removeWorkers(exId, workerCount);
354
- }
355
- async setWorkers(jobId, workerCount) {
356
- const exId = await this._getActiveExecutionId(jobId);
357
- return this.executionService.setWorkers(exId, workerCount);
358
- }
359
- async _ensureAssets(jobConfig) {
360
- const jobAssets = uniq(jobConfig.assets || []);
361
- if (isEmpty(jobAssets)) {
362
- return cloneDeep(jobConfig);
363
- }
364
- // convert asset references to their id's
365
- const assetIds = await spawnAssetLoader(jobAssets);
366
- if (!assetIds.length) {
367
- throw new Error(`no asset id's were found for assets: ${JSON.stringify(jobAssets)}`);
368
- }
369
- if (jobAssets.length !== assetIds.length) {
370
- throw new Error(`job specified ${jobAssets.length} assets: ${jobConfig.assets} but only ${assetIds.length} where found, assets: ${assetIds}`);
371
- }
372
- // need to normalize asset identifiers to their id form
373
- // but not mutate original job_spec
374
- const parsedAssetJob = cloneDeep(jobConfig);
375
- parsedAssetJob.assets = assetIds;
376
- const assetMapping = new Map();
377
- for (let i = 0; i < jobAssets.length; i++) {
378
- assetMapping.set(jobAssets[i], assetIds[i]);
379
- }
380
- this.adjustNamesByAsset(parsedAssetJob, assetMapping);
381
- return parsedAssetJob;
382
- }
383
- adjustNamesByAsset(jobConfig, dict) {
384
- jobConfig.operations = jobConfig.operations.map((op) => {
385
- if (op._api_name?.includes('@')) {
386
- const { name, assetIdentifier, tag } = parseName(op._api_name);
387
- const hashId = dict.get(assetIdentifier);
388
- if (!hashId) {
389
- throw new Error(`Invalid operation _api_name for _op: ${name}, could not find the hashID for asset identifier ${assetIdentifier}`);
390
- }
391
- let hashedName = `${name}@${hashId}`;
392
- if (tag) {
393
- hashedName = `${hashedName}:${tag}`;
394
- }
395
- op._api_name = hashedName;
396
- }
397
- if (op._op.includes('@')) {
398
- const { name, assetIdentifier } = parseName(op._op);
399
- const hashId = dict.get(assetIdentifier);
400
- if (!hashId) {
401
- throw new Error(`Invalid operation name for _op: ${name}, could not find the hashID for asset identifier ${assetIdentifier}`);
402
- }
403
- op._op = `${name}@${hashId}`;
404
- return op;
405
- }
406
- else {
407
- return op;
408
- }
409
- });
410
- if (jobConfig.apis) {
411
- jobConfig.apis = jobConfig.apis.map((api) => {
412
- if (api._name.includes('@')) {
413
- const { name, assetIdentifier, tag } = parseName(api._name);
414
- const hashId = dict.get(assetIdentifier);
415
- if (!hashId) {
416
- throw new Error(`Invalid api name for _name: ${name}, could not find the hashID for asset identifier ${assetIdentifier}`);
417
- }
418
- let hashedName = `${name}@${hashId}`;
419
- if (tag) {
420
- hashedName = `${hashedName}:${tag}`;
421
- }
422
- api._name = hashedName;
423
- return api;
424
- }
425
- else {
426
- return api;
427
- }
428
- });
429
- }
430
- }
431
- /**
432
- * Automatically add external_ports to jobSpec if needed.
433
- * This ensures that the Prometheus exporter server can be scraped.
434
- * Check if prom_metrics_enabled is true on jobSpec or teraslice config.
435
- * If so, add or update external_ports property with correct port.
436
- * @param {Partial<JobConfig>} jobSpec
437
- */
438
- addExternalPortsToJobSpec(jobSpec) {
439
- const { prom_metrics_enabled: enabledInTF, prom_metrics_port: tfPort } = this.context.sysconfig.terafoundation;
440
- const { prom_metrics_enabled: enabledInJob, prom_metrics_port: jobPort } = jobSpec;
441
- const portToUse = jobPort || tfPort;
442
- if (enabledInJob === true || (enabledInJob === undefined && enabledInTF)) {
443
- let portPresent = false;
444
- if (!jobSpec.external_ports) {
445
- jobSpec.external_ports = [];
446
- }
447
- for (const item of jobSpec.external_ports) {
448
- const currentPort = typeof item === 'number' ? item : item.port;
449
- if (currentPort === portToUse)
450
- portPresent = true;
451
- }
452
- if (!portPresent) {
453
- jobSpec.external_ports.push({ name: 'metrics', port: portToUse });
454
- }
455
- }
456
- }
457
- }
458
- //# sourceMappingURL=jobs.js.map
@@ -1,25 +0,0 @@
1
- function getConnectors() {
2
- const connectors = {
3
- 'elasticsearch-next': {
4
- default: {
5
- node: ['localhost:9200']
6
- }
7
- },
8
- kafka: {
9
- default: {
10
- brokers: ['localhost:9092']
11
- }
12
- }
13
- };
14
- return connectors;
15
- }
16
- export default {
17
- terafoundation: {
18
- connectors: getConnectors()
19
- },
20
- teraslice: {
21
- master: true,
22
- name: 'teracluster'
23
- }
24
- };
25
- //# sourceMappingURL=default-sysconfig.js.map
@@ -1,20 +0,0 @@
1
- import path from 'node:path';
2
- import { get } from '@terascope/core-utils';
3
- import { fileURLToPath } from 'node:url';
4
- import { configSchema } from './schemas/system.js';
5
- const filePath = fileURLToPath(new URL('.', import.meta.url));
6
- export function clusterName(configFile) {
7
- return get(configFile, 'teraslice.name', null);
8
- }
9
- export function getTerasliceConfig(sysconfig) {
10
- return Object.assign({
11
- name: 'teraslice',
12
- default_config_file: path.join(filePath, 'default-sysconfig.js'),
13
- config_schema: configSchema,
14
- cluster_name: clusterName,
15
- shutdownMessaging: false,
16
- start_workers: false,
17
- }, sysconfig);
18
- }
19
- export { configSchema, };
20
- //# sourceMappingURL=index.js.map