teraslice-client-js 2.16.2 → 2.17.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.
- package/dist/src/executions.d.ts +1 -1
- package/dist/src/executions.d.ts.map +1 -1
- package/package.json +7 -4
- package/dist/test/assets-spec.d.ts +0 -2
- package/dist/test/assets-spec.d.ts.map +0 -1
- package/dist/test/assets-spec.js +0 -322
- package/dist/test/assets-spec.js.map +0 -1
- package/dist/test/client-spec.d.ts +0 -2
- package/dist/test/client-spec.d.ts.map +0 -1
- package/dist/test/client-spec.js +0 -374
- package/dist/test/client-spec.js.map +0 -1
- package/dist/test/cluster-spec.d.ts +0 -2
- package/dist/test/cluster-spec.d.ts.map +0 -1
- package/dist/test/cluster-spec.js +0 -143
- package/dist/test/cluster-spec.js.map +0 -1
- package/dist/test/ex-spec.d.ts +0 -2
- package/dist/test/ex-spec.d.ts.map +0 -1
- package/dist/test/ex-spec.js +0 -550
- package/dist/test/ex-spec.js.map +0 -1
- package/dist/test/executions-spec.d.ts +0 -2
- package/dist/test/executions-spec.d.ts.map +0 -1
- package/dist/test/executions-spec.js +0 -233
- package/dist/test/executions-spec.js.map +0 -1
- package/dist/test/job-spec.d.ts +0 -2
- package/dist/test/job-spec.d.ts.map +0 -1
- package/dist/test/job-spec.js +0 -837
- package/dist/test/job-spec.js.map +0 -1
- package/dist/test/jobs-spec.d.ts +0 -2
- package/dist/test/jobs-spec.d.ts.map +0 -1
- package/dist/test/jobs-spec.js +0 -241
- package/dist/test/jobs-spec.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/examples/cluster.js +0 -13
- package/examples/list.js +0 -16
- package/examples/submit.js +0 -48
- package/src/assets.ts +0 -99
- package/src/client.ts +0 -197
- package/src/cluster.ts +0 -48
- package/src/ex.ts +0 -223
- package/src/executions.ts +0 -82
- package/src/index.ts +0 -39
- package/src/interfaces.ts +0 -12
- package/src/job.ts +0 -260
- package/src/jobs.ts +0 -66
- package/test/assets-spec.ts +0 -376
- package/test/client-spec.ts +0 -416
- package/test/cluster-spec.ts +0 -167
- package/test/ex-spec.ts +0 -628
- package/test/executions-spec.ts +0 -260
- package/test/fixtures/test.txt +0 -1
- package/test/job-spec.ts +0 -947
- package/test/jobs-spec.ts +0 -272
- package/tsconfig.json +0 -12
package/dist/test/job-spec.js
DELETED
|
@@ -1,837 +0,0 @@
|
|
|
1
|
-
import nock from 'nock';
|
|
2
|
-
import { Teraslice } from '@terascope/types';
|
|
3
|
-
import Job from '../src/job.js';
|
|
4
|
-
describe('Teraslice Job', () => {
|
|
5
|
-
let scope;
|
|
6
|
-
const baseUrl = 'http://teraslice.example.dev/v1';
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
nock.cleanAll();
|
|
9
|
-
scope = nock(baseUrl);
|
|
10
|
-
});
|
|
11
|
-
const requestOptions = { headers: { 'Some-Header': 'yes' } };
|
|
12
|
-
const clusterState = {
|
|
13
|
-
'some-node-id': {
|
|
14
|
-
hostname: 'host',
|
|
15
|
-
pid: 111,
|
|
16
|
-
node_version: '10',
|
|
17
|
-
teraslice_version: 'fabled v1.0',
|
|
18
|
-
total: 2,
|
|
19
|
-
state: 'connected',
|
|
20
|
-
available: 3,
|
|
21
|
-
node_id: 'some-node-id',
|
|
22
|
-
active: [
|
|
23
|
-
{
|
|
24
|
-
job_id: 'some-job-id',
|
|
25
|
-
ex_id: 'some-ex-id',
|
|
26
|
-
worker_id: 'someId',
|
|
27
|
-
pid: 1324,
|
|
28
|
-
assignment: 'worker'
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
job_id: 'some-job-id',
|
|
32
|
-
ex_id: 'some-ex-id',
|
|
33
|
-
worker_id: 'someId',
|
|
34
|
-
pid: 1324,
|
|
35
|
-
assignment: 'worker'
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
'some-other-node-id': {
|
|
40
|
-
hostname: 'host',
|
|
41
|
-
pid: 222,
|
|
42
|
-
node_version: '10',
|
|
43
|
-
teraslice_version: 'fabled v1.0',
|
|
44
|
-
total: 2,
|
|
45
|
-
state: 'connected',
|
|
46
|
-
available: 3,
|
|
47
|
-
node_id: 'some-other-node-id',
|
|
48
|
-
active: [
|
|
49
|
-
{
|
|
50
|
-
job_id: 'some-job-id',
|
|
51
|
-
ex_id: 'some-ex-id',
|
|
52
|
-
worker_id: 'someId',
|
|
53
|
-
pid: 1324,
|
|
54
|
-
assignment: 'worker'
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
job_id: 'some-other-job-id',
|
|
58
|
-
ex_id: 'some-other-ex-id',
|
|
59
|
-
worker_id: 'someId',
|
|
60
|
-
pid: 1324,
|
|
61
|
-
assignment: 'worker'
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
job_id: 'some-other-job-id',
|
|
65
|
-
ex_id: 'some-other-ex-id',
|
|
66
|
-
worker_id: 'someId',
|
|
67
|
-
pid: 1324,
|
|
68
|
-
assignment: 'execution_controller'
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
const date = new Date().toISOString();
|
|
74
|
-
const executionResults = [
|
|
75
|
-
{
|
|
76
|
-
active: true,
|
|
77
|
-
analytics: false,
|
|
78
|
-
assets: [],
|
|
79
|
-
lifecycle: 'once',
|
|
80
|
-
max_retries: 3,
|
|
81
|
-
name: 'some_name',
|
|
82
|
-
apis: [],
|
|
83
|
-
operations: [{ _op: 'someOp' }],
|
|
84
|
-
probation_window: 3,
|
|
85
|
-
env_vars: {},
|
|
86
|
-
slicers: 1,
|
|
87
|
-
workers: 1,
|
|
88
|
-
metadata: {},
|
|
89
|
-
_created: date,
|
|
90
|
-
_updated: date,
|
|
91
|
-
_context: 'ex',
|
|
92
|
-
_status: Teraslice.ExecutionStatusEnum.running,
|
|
93
|
-
ex_id: '123456789',
|
|
94
|
-
job_id: '123456789',
|
|
95
|
-
slicer_hostname: 'hostname',
|
|
96
|
-
slicer_port: 5673,
|
|
97
|
-
_has_errors: false,
|
|
98
|
-
_slicer_stats: {},
|
|
99
|
-
_failureReason: '',
|
|
100
|
-
teraslice_version: 'v3.0.0'
|
|
101
|
-
},
|
|
102
|
-
];
|
|
103
|
-
describe('->id', () => {
|
|
104
|
-
describe('when constructed without a jobId', () => {
|
|
105
|
-
it('should throw an error', () => {
|
|
106
|
-
// @ts-expect-error
|
|
107
|
-
expect(() => new Job()).toThrow('Job requires jobId');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('when constructed with a invalid jobId', () => {
|
|
111
|
-
it('should throw an error', () => {
|
|
112
|
-
// @ts-expect-error
|
|
113
|
-
expect(() => new Job({}, { invalid: true })).toThrow('Job requires jobId to be a string');
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
describe('when constructed with a jobId', () => {
|
|
117
|
-
it('should return the jobId', () => {
|
|
118
|
-
const job = new Job({}, 'some-job-id');
|
|
119
|
-
expect(job.id()).toEqual('some-job-id');
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe('->slicer', () => {
|
|
124
|
-
describe('when called with nothing', () => {
|
|
125
|
-
beforeEach(() => {
|
|
126
|
-
scope.get('/jobs/some-job-id/slicer')
|
|
127
|
-
.reply(200, { id: 'example' });
|
|
128
|
-
});
|
|
129
|
-
it('should resolve json results from Teraslice', async () => {
|
|
130
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
131
|
-
const results = await job.slicer();
|
|
132
|
-
expect(results).toEqual({ id: 'example' });
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe('->controller', () => {
|
|
137
|
-
describe('when called with nothing', () => {
|
|
138
|
-
beforeEach(() => {
|
|
139
|
-
scope.get('/jobs/some-job-id/controller')
|
|
140
|
-
.reply(200, { id: 'example' });
|
|
141
|
-
});
|
|
142
|
-
it('should resolve json results from Teraslice', async () => {
|
|
143
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
144
|
-
const results = await job.controller();
|
|
145
|
-
expect(results).toEqual({ id: 'example' });
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
describe('when called with options', () => {
|
|
149
|
-
beforeEach(() => {
|
|
150
|
-
scope.get('/jobs/some-job-id/controller')
|
|
151
|
-
.matchHeader('Some-Header', 'yes')
|
|
152
|
-
.reply(200, { foo: 'bar' });
|
|
153
|
-
});
|
|
154
|
-
it('should resolve json results from Teraslice', async () => {
|
|
155
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
156
|
-
const results = await job.controller(requestOptions);
|
|
157
|
-
expect(results).toEqual({ foo: 'bar' });
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
const methodTestCases = [
|
|
162
|
-
'start',
|
|
163
|
-
'stop',
|
|
164
|
-
'pause',
|
|
165
|
-
'resume'
|
|
166
|
-
];
|
|
167
|
-
describe.each(methodTestCases)('->%s', (method) => {
|
|
168
|
-
describe('when called with nothing', () => {
|
|
169
|
-
beforeEach(() => {
|
|
170
|
-
scope.post(`/jobs/some-job-id/_${method}`)
|
|
171
|
-
.reply(200, { testMethod: method });
|
|
172
|
-
});
|
|
173
|
-
it('should resolve json results from Teraslice', async () => {
|
|
174
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
175
|
-
const results = await job[method]();
|
|
176
|
-
expect(results).toEqual({ testMethod: method });
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
describe('when called with a query', () => {
|
|
180
|
-
beforeEach(() => {
|
|
181
|
-
scope.post(`/jobs/some-job-id/_${method}`)
|
|
182
|
-
.query({ someParam: 'yes' })
|
|
183
|
-
.reply(200, { key: 'some-other-key' });
|
|
184
|
-
});
|
|
185
|
-
it('should resolve json results from Teraslice', async () => {
|
|
186
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
187
|
-
const results = await job[method]({ someParam: 'yes' });
|
|
188
|
-
expect(results).toEqual({ key: 'some-other-key' });
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
describe('when called with a query and options', () => {
|
|
192
|
-
beforeEach(() => {
|
|
193
|
-
scope.post(`/jobs/some-job-id/_${method}`)
|
|
194
|
-
.query({ foo: 'bar' })
|
|
195
|
-
.matchHeader('Some-Header', 'yes')
|
|
196
|
-
.reply(200, { key: 'some-random-key' });
|
|
197
|
-
});
|
|
198
|
-
it('should resolve json results from Teraslice', async () => {
|
|
199
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
200
|
-
const results = await job[method]({ foo: 'bar' }, requestOptions);
|
|
201
|
-
expect(results).toEqual({ key: 'some-random-key' });
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
describe('->start', () => {
|
|
206
|
-
describe('when the server returns deprecation warnings', () => {
|
|
207
|
-
const deprecationWarning = {
|
|
208
|
-
type: 'JobValidation',
|
|
209
|
-
reason: {
|
|
210
|
-
type: 'assetOperation',
|
|
211
|
-
kind: 'deprecation',
|
|
212
|
-
reason: {
|
|
213
|
-
_op: 'some-op',
|
|
214
|
-
field: 'old_field',
|
|
215
|
-
description: 'old_field is deprecated, use new_field instead',
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
const response = {
|
|
220
|
-
job_id: 'some-job-id',
|
|
221
|
-
warnings: [deprecationWarning],
|
|
222
|
-
};
|
|
223
|
-
beforeEach(() => {
|
|
224
|
-
scope.post('/jobs/some-job-id/_start')
|
|
225
|
-
.reply(200, response);
|
|
226
|
-
});
|
|
227
|
-
it('should return the response with warnings', async () => {
|
|
228
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
229
|
-
const result = await job.start();
|
|
230
|
-
expect(result.job_id).toEqual('some-job-id');
|
|
231
|
-
expect(result.warnings).toBeArrayOfSize(1);
|
|
232
|
-
expect(result.warnings[0]).toMatchObject(deprecationWarning);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
describe('->recover', () => {
|
|
237
|
-
describe('when called with nothing', () => {
|
|
238
|
-
beforeEach(() => {
|
|
239
|
-
scope.post('/jobs/some-other-job-id/_recover')
|
|
240
|
-
.reply(200, { job_id: 'some-other-job-id' });
|
|
241
|
-
});
|
|
242
|
-
it('should resolve json results from Teraslice', async () => {
|
|
243
|
-
const job = new Job({ baseUrl }, 'some-other-job-id');
|
|
244
|
-
const results = await job.recover();
|
|
245
|
-
expect(results).toEqual({ job_id: 'some-other-job-id' });
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
describe('when called with a query', () => {
|
|
249
|
-
beforeEach(() => {
|
|
250
|
-
scope.post('/jobs/foo-bar/_recover')
|
|
251
|
-
.query({ cleanup: 'errors' })
|
|
252
|
-
.reply(200, { job_id: 'foo-bar' });
|
|
253
|
-
});
|
|
254
|
-
it('should resolve json results from Teraslice', async () => {
|
|
255
|
-
const job = new Job({ baseUrl }, 'foo-bar');
|
|
256
|
-
const results = await job.recover({
|
|
257
|
-
cleanup: Teraslice.RecoveryCleanupType.errors
|
|
258
|
-
});
|
|
259
|
-
expect(results).toEqual({ job_id: 'foo-bar' });
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
describe('when called with a query and options', () => {
|
|
263
|
-
beforeEach(() => {
|
|
264
|
-
scope.post('/jobs/some-job-id/_recover')
|
|
265
|
-
.matchHeader('Some-Header', 'yes')
|
|
266
|
-
.query({ cleanup: 'errors' })
|
|
267
|
-
.reply(200, {
|
|
268
|
-
key: 'some-other-key'
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
it('should resolve json results from Teraslice', async () => {
|
|
272
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
273
|
-
const results = await job.recover({
|
|
274
|
-
cleanup: Teraslice.RecoveryCleanupType.errors
|
|
275
|
-
}, requestOptions);
|
|
276
|
-
expect(results).toEqual({
|
|
277
|
-
key: 'some-other-key'
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
describe('->recover with warnings', () => {
|
|
283
|
-
describe('when the server returns deprecation warnings', () => {
|
|
284
|
-
const deprecationWarning = {
|
|
285
|
-
type: 'JobValidation',
|
|
286
|
-
reason: {
|
|
287
|
-
type: 'assetAPIProperty',
|
|
288
|
-
kind: 'deprecation',
|
|
289
|
-
reason: {
|
|
290
|
-
api_name: 'some-api',
|
|
291
|
-
field: 'old_api_field',
|
|
292
|
-
description: 'old_api_field is deprecated, use new_api_field instead',
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
const response = {
|
|
297
|
-
job_id: 'some-other-job-id',
|
|
298
|
-
warnings: [deprecationWarning],
|
|
299
|
-
};
|
|
300
|
-
beforeEach(() => {
|
|
301
|
-
scope.post('/jobs/some-other-job-id/_recover')
|
|
302
|
-
.reply(200, response);
|
|
303
|
-
});
|
|
304
|
-
it('should return the response with warnings', async () => {
|
|
305
|
-
const job = new Job({ baseUrl }, 'some-other-job-id');
|
|
306
|
-
const result = await job.recover();
|
|
307
|
-
expect(result.job_id).toEqual('some-other-job-id');
|
|
308
|
-
expect(result.warnings).toBeArrayOfSize(1);
|
|
309
|
-
expect(result.warnings[0]).toMatchObject(deprecationWarning);
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
describe('->execution', () => {
|
|
314
|
-
const exJobId = executionResults[0].job_id;
|
|
315
|
-
describe('when called with nothing', () => {
|
|
316
|
-
beforeEach(() => {
|
|
317
|
-
scope.get(`/jobs/${exJobId}/ex`)
|
|
318
|
-
.reply(200, executionResults);
|
|
319
|
-
});
|
|
320
|
-
it('should resolve json results from Teraslice', async () => {
|
|
321
|
-
const job = new Job({ baseUrl }, exJobId);
|
|
322
|
-
const results = await job.execution();
|
|
323
|
-
expect(results).toEqual(executionResults);
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
describe('when called with options', () => {
|
|
327
|
-
beforeEach(() => {
|
|
328
|
-
scope.get(`/jobs/${exJobId}/ex`)
|
|
329
|
-
.matchHeader('Some-Header', 'yes')
|
|
330
|
-
.reply(200, executionResults);
|
|
331
|
-
});
|
|
332
|
-
it('should resolve json results from Teraslice', async () => {
|
|
333
|
-
const job = new Job({ baseUrl }, exJobId);
|
|
334
|
-
const results = await job.execution(requestOptions);
|
|
335
|
-
expect(results).toEqual(executionResults);
|
|
336
|
-
});
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
describe('->update', () => {
|
|
340
|
-
describe('when updating the whole config', () => {
|
|
341
|
-
const body = {
|
|
342
|
-
name: 'hello',
|
|
343
|
-
apis: [],
|
|
344
|
-
operations: [],
|
|
345
|
-
active: true,
|
|
346
|
-
analytics: false,
|
|
347
|
-
autorecover: false,
|
|
348
|
-
assets: [],
|
|
349
|
-
lifecycle: 'once',
|
|
350
|
-
max_retries: 0,
|
|
351
|
-
probation_window: 30000,
|
|
352
|
-
slicers: 1,
|
|
353
|
-
workers: 1,
|
|
354
|
-
env_vars: {},
|
|
355
|
-
_context: 'job',
|
|
356
|
-
job_id: 'some-job-id',
|
|
357
|
-
_created: 'hello',
|
|
358
|
-
_updated: 'hello'
|
|
359
|
-
};
|
|
360
|
-
beforeEach(() => {
|
|
361
|
-
scope.put('/jobs/some-job-id', body)
|
|
362
|
-
.reply(200, body);
|
|
363
|
-
});
|
|
364
|
-
it('should resolve the update job config', async () => {
|
|
365
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
366
|
-
const result = await job.update(body);
|
|
367
|
-
expect(result).toEqual(body);
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
describe('->updatePartial', () => {
|
|
372
|
-
describe('when updating a partial config', () => {
|
|
373
|
-
const body = {
|
|
374
|
-
name: 'hello',
|
|
375
|
-
apis: [],
|
|
376
|
-
operations: [],
|
|
377
|
-
active: true,
|
|
378
|
-
analytics: false,
|
|
379
|
-
autorecover: false,
|
|
380
|
-
assets: [],
|
|
381
|
-
lifecycle: 'once',
|
|
382
|
-
max_retries: 0,
|
|
383
|
-
probation_window: 30000,
|
|
384
|
-
slicers: 1,
|
|
385
|
-
workers: 1,
|
|
386
|
-
env_vars: {},
|
|
387
|
-
_context: 'job',
|
|
388
|
-
job_id: 'some-job-id',
|
|
389
|
-
_created: 'hello',
|
|
390
|
-
_updated: 'hello'
|
|
391
|
-
};
|
|
392
|
-
const expected = {
|
|
393
|
-
...body,
|
|
394
|
-
name: 'howdy'
|
|
395
|
-
};
|
|
396
|
-
beforeEach(() => {
|
|
397
|
-
scope.get('/jobs/some-job-id')
|
|
398
|
-
.reply(200, body);
|
|
399
|
-
scope.put('/jobs/some-job-id', expected)
|
|
400
|
-
.reply(200, expected);
|
|
401
|
-
});
|
|
402
|
-
it('should resolve the update job config', async () => {
|
|
403
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
404
|
-
const result = await job.updatePartial({ name: 'howdy' });
|
|
405
|
-
expect(result).toEqual(expected);
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
describe('->deleteJob', () => {
|
|
410
|
-
describe('when called', () => {
|
|
411
|
-
beforeEach(() => {
|
|
412
|
-
scope.delete('/jobs/some-other-job-id')
|
|
413
|
-
.reply(200, { job_id: 'some-other-job-id', _deleted: true });
|
|
414
|
-
});
|
|
415
|
-
it('should resolve json results from Teraslice', async () => {
|
|
416
|
-
const job = new Job({ baseUrl }, 'some-other-job-id');
|
|
417
|
-
const results = await job.deleteJob();
|
|
418
|
-
expect(results).toEqual({ job_id: 'some-other-job-id', _deleted: true });
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
|
-
describe('->exId', () => {
|
|
423
|
-
describe('when called with nothing', () => {
|
|
424
|
-
beforeEach(() => {
|
|
425
|
-
scope.get('/jobs/some-job-id/ex')
|
|
426
|
-
.reply(200, { ex_id: 'example-ex-id' });
|
|
427
|
-
});
|
|
428
|
-
it('should resolve json results from Teraslice', async () => {
|
|
429
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
430
|
-
const results = await job.exId();
|
|
431
|
-
expect(results).toEqual('example-ex-id');
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
describe('when called with options', () => {
|
|
435
|
-
beforeEach(() => {
|
|
436
|
-
scope.get('/jobs/some-job-id/ex')
|
|
437
|
-
.matchHeader('Some-Header', 'yes')
|
|
438
|
-
.reply(200, { ex_id: 'other-ex-id' });
|
|
439
|
-
});
|
|
440
|
-
it('should resolve json results from Teraslice', async () => {
|
|
441
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
442
|
-
const results = await job.exId(requestOptions);
|
|
443
|
-
expect(results).toEqual('other-ex-id');
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
describe('->status', () => {
|
|
448
|
-
describe('when called with nothing', () => {
|
|
449
|
-
beforeEach(() => {
|
|
450
|
-
scope.get('/jobs/some-job-id/ex')
|
|
451
|
-
.reply(200, {
|
|
452
|
-
ex_id: 'example-ex-id',
|
|
453
|
-
_status: 'example'
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
it('should resolve json results from Teraslice', async () => {
|
|
457
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
458
|
-
const results = await job.status();
|
|
459
|
-
expect(results).toEqual('example');
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
describe('when called with options', () => {
|
|
463
|
-
beforeEach(() => {
|
|
464
|
-
scope.get('/jobs/some-job-id/ex')
|
|
465
|
-
.matchHeader('Some-Header', 'yes')
|
|
466
|
-
.reply(200, {
|
|
467
|
-
ex_id: 'example-ex-id',
|
|
468
|
-
_status: 'other-status'
|
|
469
|
-
});
|
|
470
|
-
});
|
|
471
|
-
it('should resolve json results from Teraslice', async () => {
|
|
472
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
473
|
-
const results = await job.status(requestOptions);
|
|
474
|
-
expect(results).toEqual('other-status');
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
describe('->config', () => {
|
|
479
|
-
describe('when called with nothing', () => {
|
|
480
|
-
const data = {
|
|
481
|
-
job_id: 'example-job-id',
|
|
482
|
-
ex_id: 'example-ex-id',
|
|
483
|
-
example: 'job-spec'
|
|
484
|
-
};
|
|
485
|
-
beforeEach(() => {
|
|
486
|
-
scope.get('/jobs/example-job-id')
|
|
487
|
-
.reply(200, data);
|
|
488
|
-
});
|
|
489
|
-
it('should resolve json results from Teraslice', async () => {
|
|
490
|
-
const job = new Job({ baseUrl }, 'example-job-id');
|
|
491
|
-
const results = await job.config();
|
|
492
|
-
expect(results).toEqual(data);
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
describe('when called with with options', () => {
|
|
496
|
-
beforeEach(() => {
|
|
497
|
-
scope.get('/jobs/some-job-id')
|
|
498
|
-
.matchHeader('Some-Header', 'yes')
|
|
499
|
-
.reply(200, {
|
|
500
|
-
job_id: 'example-job-id',
|
|
501
|
-
ex_id: 'example-ex-id',
|
|
502
|
-
example: 'job-spec'
|
|
503
|
-
});
|
|
504
|
-
});
|
|
505
|
-
it('should resolve json results from Teraslice', async () => {
|
|
506
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
507
|
-
const results = await job.config(requestOptions);
|
|
508
|
-
expect(results).toEqual({
|
|
509
|
-
job_id: 'example-job-id',
|
|
510
|
-
ex_id: 'example-ex-id',
|
|
511
|
-
example: 'job-spec'
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
});
|
|
516
|
-
describe('->errors', () => {
|
|
517
|
-
describe('when called with nothing', () => {
|
|
518
|
-
beforeEach(() => {
|
|
519
|
-
scope.get('/jobs/some-job-id/errors')
|
|
520
|
-
.reply(200, [
|
|
521
|
-
{ error: 'example' },
|
|
522
|
-
{ error: 'example-2' }
|
|
523
|
-
]);
|
|
524
|
-
});
|
|
525
|
-
it('should resolve json results from Teraslice', async () => {
|
|
526
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
527
|
-
const results = await job.errors();
|
|
528
|
-
expect(results).toEqual([
|
|
529
|
-
{ error: 'example' },
|
|
530
|
-
{ error: 'example-2' }
|
|
531
|
-
]);
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
describe('->workers', () => {
|
|
536
|
-
const workerData = [];
|
|
537
|
-
const jobId = 'some-job-id';
|
|
538
|
-
for (const [nodeName, node] of Object.entries(clusterState)) {
|
|
539
|
-
// @ts-expect-error TODO: fixme
|
|
540
|
-
node.active.forEach((child) => {
|
|
541
|
-
if (child.assignment === 'worker' && child.job_id === jobId) {
|
|
542
|
-
child.node_id = nodeName;
|
|
543
|
-
workerData.push(child);
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
describe('when called and the state has workers', () => {
|
|
548
|
-
beforeEach(() => {
|
|
549
|
-
scope.get('/cluster/state')
|
|
550
|
-
.reply(200, clusterState);
|
|
551
|
-
});
|
|
552
|
-
it('should resolve json results from Teraslice', async () => {
|
|
553
|
-
const job = new Job({ baseUrl }, jobId);
|
|
554
|
-
const results = await job.workers();
|
|
555
|
-
expect(results).toEqual(workerData);
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
describe('when called and the state has workers (with headers)', () => {
|
|
559
|
-
beforeEach(() => {
|
|
560
|
-
scope.get('/cluster/state')
|
|
561
|
-
.matchHeader('Some-Header', 'yes')
|
|
562
|
-
.reply(200, clusterState);
|
|
563
|
-
});
|
|
564
|
-
it('should resolve json results from Teraslice', async () => {
|
|
565
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
566
|
-
const results = await job.workers(requestOptions);
|
|
567
|
-
expect(results).toEqual(workerData);
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
});
|
|
571
|
-
describe('->changeWorkers', () => {
|
|
572
|
-
const response = { message: 'Changed workers!' };
|
|
573
|
-
describe('when response returns a string', () => {
|
|
574
|
-
const oldStrResponse = 'hello';
|
|
575
|
-
beforeEach(() => {
|
|
576
|
-
scope.post('/jobs/some-job-id/_workers')
|
|
577
|
-
.query({ add: 2 })
|
|
578
|
-
.reply(200, oldStrResponse);
|
|
579
|
-
});
|
|
580
|
-
it('should resolve json results from Teraslice', async () => {
|
|
581
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
582
|
-
const results = await job.changeWorkers('add', 2);
|
|
583
|
-
expect(results).toEqual(oldStrResponse);
|
|
584
|
-
});
|
|
585
|
-
});
|
|
586
|
-
describe('when called with add and num', () => {
|
|
587
|
-
beforeEach(() => {
|
|
588
|
-
scope.post('/jobs/some-job-id/_workers')
|
|
589
|
-
.query({ add: 2 })
|
|
590
|
-
.reply(200, response);
|
|
591
|
-
});
|
|
592
|
-
it('should resolve json results from Teraslice', async () => {
|
|
593
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
594
|
-
const results = await job.changeWorkers('add', 2);
|
|
595
|
-
expect(results).toEqual(response);
|
|
596
|
-
});
|
|
597
|
-
});
|
|
598
|
-
describe('when called with remove and num', () => {
|
|
599
|
-
beforeEach(() => {
|
|
600
|
-
scope.post('/jobs/some-job-id/_workers')
|
|
601
|
-
.query({ remove: 2 })
|
|
602
|
-
.reply(200, response);
|
|
603
|
-
});
|
|
604
|
-
it('should resolve json results from Teraslice', async () => {
|
|
605
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
606
|
-
const results = await job.changeWorkers('remove', 2);
|
|
607
|
-
expect(results).toEqual(response);
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
describe('when called with total and num', () => {
|
|
611
|
-
beforeEach(() => {
|
|
612
|
-
scope.post('/jobs/some-job-id/_workers')
|
|
613
|
-
.query({ total: 2 })
|
|
614
|
-
.reply(200, response);
|
|
615
|
-
});
|
|
616
|
-
it('should resolve json results from Teraslice', async () => {
|
|
617
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
618
|
-
const results = await job.changeWorkers('total', 2);
|
|
619
|
-
expect(results).toEqual(response);
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
describe('when called with nothing', () => {
|
|
623
|
-
it('should reject with an error', async () => {
|
|
624
|
-
expect.hasAssertions();
|
|
625
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
626
|
-
try {
|
|
627
|
-
// @ts-expect-error
|
|
628
|
-
await job.changeWorkers();
|
|
629
|
-
}
|
|
630
|
-
catch (err) {
|
|
631
|
-
expect(err.message).toEqual('Change workers requires action and count');
|
|
632
|
-
}
|
|
633
|
-
});
|
|
634
|
-
});
|
|
635
|
-
describe('when called with an invalid action', () => {
|
|
636
|
-
it('should reject with an error', async () => {
|
|
637
|
-
expect.hasAssertions();
|
|
638
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
639
|
-
try {
|
|
640
|
-
// @ts-expect-error
|
|
641
|
-
await job.changeWorkers('invalid', 2);
|
|
642
|
-
}
|
|
643
|
-
catch (err) {
|
|
644
|
-
expect(err.message).toEqual('Change workers requires action to be one of add, remove, or total');
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
});
|
|
648
|
-
});
|
|
649
|
-
describe('->waitForStatus', () => {
|
|
650
|
-
describe('when called and it matches on the first try', () => {
|
|
651
|
-
beforeEach(() => {
|
|
652
|
-
scope.get('/jobs/some-job-id/ex')
|
|
653
|
-
.reply(200, {
|
|
654
|
-
ex_id: 'example-ex-id',
|
|
655
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
656
|
-
});
|
|
657
|
-
});
|
|
658
|
-
it('should resolve json results from Teraslice', async () => {
|
|
659
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
660
|
-
const results = await job.waitForStatus(Teraslice.ExecutionStatusEnum.running);
|
|
661
|
-
expect(results).toEqual(Teraslice.ExecutionStatusEnum.running);
|
|
662
|
-
});
|
|
663
|
-
});
|
|
664
|
-
describe('when called with status array and matches on the first try', () => {
|
|
665
|
-
beforeEach(() => {
|
|
666
|
-
scope.get('/jobs/some-job-id/ex')
|
|
667
|
-
.reply(200, {
|
|
668
|
-
ex_id: 'example-ex-id',
|
|
669
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
670
|
-
});
|
|
671
|
-
});
|
|
672
|
-
it('should resolve json results from Teraslice', async () => {
|
|
673
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
674
|
-
const results = await job.waitForStatus([
|
|
675
|
-
Teraslice.ExecutionStatusEnum.failing,
|
|
676
|
-
Teraslice.ExecutionStatusEnum.running
|
|
677
|
-
]);
|
|
678
|
-
expect(results).toEqual(Teraslice.ExecutionStatusEnum.running);
|
|
679
|
-
});
|
|
680
|
-
});
|
|
681
|
-
describe('when called and it matches on the first try (with headers)', () => {
|
|
682
|
-
const searchOptions = { headers: { 'Some-Header': 'yes' } };
|
|
683
|
-
beforeEach(() => {
|
|
684
|
-
scope.get('/jobs/some-job-id/ex')
|
|
685
|
-
.matchHeader('Some-Header', 'yes')
|
|
686
|
-
.reply(200, {
|
|
687
|
-
ex_id: 'example-ex-id',
|
|
688
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
689
|
-
});
|
|
690
|
-
});
|
|
691
|
-
it('should resolve json results from Teraslice', async () => {
|
|
692
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
693
|
-
const results = await job.waitForStatus(Teraslice.ExecutionStatusEnum.running, 1000, 0, searchOptions);
|
|
694
|
-
expect(results).toEqual(Teraslice.ExecutionStatusEnum.running);
|
|
695
|
-
});
|
|
696
|
-
});
|
|
697
|
-
describe('when called and it matches on the second try', () => {
|
|
698
|
-
beforeEach(() => {
|
|
699
|
-
scope.get('/jobs/some-job-id/ex')
|
|
700
|
-
.reply(200, {
|
|
701
|
-
ex_id: 'example-ex-id',
|
|
702
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
703
|
-
});
|
|
704
|
-
scope.get('/jobs/some-job-id/ex')
|
|
705
|
-
.reply(200, {
|
|
706
|
-
ex_id: 'example-ex-id',
|
|
707
|
-
_status: Teraslice.ExecutionStatusEnum.completed
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
it('should resolve json results from Teraslice', async () => {
|
|
711
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
712
|
-
const results = await job.waitForStatus(Teraslice.ExecutionStatusEnum.completed);
|
|
713
|
-
expect(results).toEqual(Teraslice.ExecutionStatusEnum.completed);
|
|
714
|
-
});
|
|
715
|
-
});
|
|
716
|
-
describe('when called with array of statuses and matches on the second try', () => {
|
|
717
|
-
beforeEach(() => {
|
|
718
|
-
scope.get('/jobs/some-job-id/ex')
|
|
719
|
-
.reply(200, {
|
|
720
|
-
ex_id: 'example-ex-id',
|
|
721
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
722
|
-
});
|
|
723
|
-
scope.get('/jobs/some-job-id/ex')
|
|
724
|
-
.reply(200, {
|
|
725
|
-
ex_id: 'example-ex-id',
|
|
726
|
-
_status: Teraslice.ExecutionStatusEnum.terminated
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
it('should resolve json results from Teraslice', async () => {
|
|
730
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
731
|
-
const results = await job.waitForStatus([
|
|
732
|
-
Teraslice.ExecutionStatusEnum.completed,
|
|
733
|
-
Teraslice.ExecutionStatusEnum.failed,
|
|
734
|
-
Teraslice.ExecutionStatusEnum.terminated
|
|
735
|
-
]);
|
|
736
|
-
expect(results).toEqual(Teraslice.ExecutionStatusEnum.terminated);
|
|
737
|
-
});
|
|
738
|
-
});
|
|
739
|
-
describe('when called and it never matches', () => {
|
|
740
|
-
beforeEach(() => {
|
|
741
|
-
scope.get('/jobs/some-job-id/ex')
|
|
742
|
-
.times(1)
|
|
743
|
-
.reply(200, {
|
|
744
|
-
ex_id: 'example-ex-id',
|
|
745
|
-
_status: Teraslice.ExecutionStatusEnum.initializing
|
|
746
|
-
});
|
|
747
|
-
scope.get('/jobs/some-job-id/ex')
|
|
748
|
-
.times(11)
|
|
749
|
-
.reply(200, {
|
|
750
|
-
ex_id: 'example-ex-id',
|
|
751
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
it('should reject with a timeout error', async () => {
|
|
755
|
-
expect.hasAssertions();
|
|
756
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
757
|
-
try {
|
|
758
|
-
await job.waitForStatus(Teraslice.ExecutionStatusEnum.completed, 100, 1000);
|
|
759
|
-
}
|
|
760
|
-
catch (err) {
|
|
761
|
-
expect(err.message).toEqual('Job status failed to change from status "running" to "completed" within 1000ms');
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
});
|
|
765
|
-
describe('when called with array of statuses and it never matches', () => {
|
|
766
|
-
beforeEach(() => {
|
|
767
|
-
scope.get('/jobs/some-job-id/ex')
|
|
768
|
-
.times(1)
|
|
769
|
-
.reply(200, {
|
|
770
|
-
ex_id: 'example-ex-id',
|
|
771
|
-
_status: Teraslice.ExecutionStatusEnum.initializing
|
|
772
|
-
});
|
|
773
|
-
scope.get('/jobs/some-job-id/ex')
|
|
774
|
-
.times(11)
|
|
775
|
-
.reply(200, {
|
|
776
|
-
ex_id: 'example-ex-id',
|
|
777
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
it('should reject with a timeout error', async () => {
|
|
781
|
-
expect.hasAssertions();
|
|
782
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
783
|
-
try {
|
|
784
|
-
await job.waitForStatus([
|
|
785
|
-
Teraslice.ExecutionStatusEnum.completed,
|
|
786
|
-
Teraslice.ExecutionStatusEnum.failed,
|
|
787
|
-
Teraslice.ExecutionStatusEnum.stopped
|
|
788
|
-
], 100, 1000);
|
|
789
|
-
}
|
|
790
|
-
catch (err) {
|
|
791
|
-
expect(err.message).toEqual('Job status failed to change from status "running" to "completed,failed,stopped" within 1000ms');
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
});
|
|
795
|
-
describe('when called and one request times out', () => {
|
|
796
|
-
beforeEach(() => {
|
|
797
|
-
scope.get('/jobs/some-job-id/ex')
|
|
798
|
-
.delay(1100)
|
|
799
|
-
.reply(200, {
|
|
800
|
-
ex_id: 'example-ex-id',
|
|
801
|
-
_status: Teraslice.ExecutionStatusEnum.initializing
|
|
802
|
-
});
|
|
803
|
-
scope.get('/jobs/some-job-id/ex')
|
|
804
|
-
.reply(200, {
|
|
805
|
-
ex_id: 'example-ex-id',
|
|
806
|
-
_status: Teraslice.ExecutionStatusEnum.running
|
|
807
|
-
});
|
|
808
|
-
});
|
|
809
|
-
it('should resolve with the correct status', async () => {
|
|
810
|
-
const job = new Job({ baseUrl }, 'some-job-id');
|
|
811
|
-
const status = await job.waitForStatus(Teraslice.ExecutionStatusEnum.running, 100, 1500);
|
|
812
|
-
expect(status).toEqual(Teraslice.ExecutionStatusEnum.running);
|
|
813
|
-
});
|
|
814
|
-
});
|
|
815
|
-
describe('when called and returns a terminal status', () => {
|
|
816
|
-
beforeEach(() => {
|
|
817
|
-
scope.get('/jobs/other-job-id/ex')
|
|
818
|
-
.reply(200, {
|
|
819
|
-
ex_id: 'example-ex-id',
|
|
820
|
-
_status: Teraslice.ExecutionStatusEnum.failed
|
|
821
|
-
});
|
|
822
|
-
});
|
|
823
|
-
it('should reject with a terminal status error', async () => {
|
|
824
|
-
expect.hasAssertions();
|
|
825
|
-
const job = new Job({ baseUrl }, 'other-job-id');
|
|
826
|
-
try {
|
|
827
|
-
await job.waitForStatus(Teraslice.ExecutionStatusEnum.completed, 100, 1000);
|
|
828
|
-
}
|
|
829
|
-
catch (err) {
|
|
830
|
-
const errMsg = 'Job cannot reach the target status, "completed", because it is in the terminal state, "failed"';
|
|
831
|
-
expect(err.message).toEqual(errMsg);
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
});
|
|
835
|
-
});
|
|
836
|
-
});
|
|
837
|
-
//# sourceMappingURL=job-spec.js.map
|