teraslice-client-js 0.55.1 → 0.56.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/assets.d.ts +7 -6
- package/dist/src/assets.d.ts.map +1 -1
- package/dist/src/assets.js +15 -15
- package/dist/src/assets.js.map +1 -1
- package/dist/src/client.d.ts +1 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +14 -15
- package/dist/src/client.js.map +1 -1
- package/dist/src/cluster.d.ts +7 -7
- package/dist/src/cluster.d.ts.map +1 -1
- package/dist/src/cluster.js +2 -2
- package/dist/src/cluster.js.map +1 -1
- package/dist/src/ex.d.ts +14 -13
- package/dist/src/ex.d.ts.map +1 -1
- package/dist/src/ex.js +18 -17
- package/dist/src/ex.js.map +1 -1
- package/dist/src/executions.d.ts +6 -6
- package/dist/src/executions.d.ts.map +1 -1
- package/dist/src/executions.js +7 -7
- package/dist/src/executions.js.map +1 -1
- package/dist/src/interfaces.d.ts +1 -218
- package/dist/src/interfaces.d.ts.map +1 -1
- package/dist/src/interfaces.js +0 -20
- package/dist/src/interfaces.js.map +1 -1
- package/dist/src/job.d.ts +19 -19
- package/dist/src/job.d.ts.map +1 -1
- package/dist/src/job.js +23 -21
- package/dist/src/job.js.map +1 -1
- package/dist/src/jobs.d.ts +4 -4
- package/dist/src/jobs.d.ts.map +1 -1
- package/dist/src/jobs.js +3 -3
- package/dist/src/jobs.js.map +1 -1
- package/dist/test/assets-spec.js +2 -0
- package/dist/test/assets-spec.js.map +1 -1
- package/dist/test/cluster-spec.js +0 -2
- package/dist/test/cluster-spec.js.map +1 -1
- package/dist/test/ex-spec.js +25 -25
- package/dist/test/ex-spec.js.map +1 -1
- package/dist/test/job-spec.js +79 -52
- package/dist/test/job-spec.js.map +1 -1
- package/dist/test/jobs-spec.js +4 -4
- package/dist/test/jobs-spec.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/assets.ts +24 -19
- package/src/client.ts +9 -11
- package/src/cluster.ts +10 -16
- package/src/ex.ts +44 -54
- package/src/executions.ts +15 -21
- package/src/interfaces.ts +1 -334
- package/src/job.ts +65 -64
- package/src/jobs.ts +10 -14
- package/test/assets-spec.ts +6 -4
- package/test/cluster-spec.ts +0 -2
- package/test/ex-spec.ts +32 -32
- package/test/job-spec.ts +87 -61
- package/test/jobs-spec.ts +5 -5
package/src/interfaces.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClusterManagerType,
|
|
3
|
-
Assignment,
|
|
4
|
-
ValidatedJobConfig,
|
|
5
|
-
ExecutionConfig,
|
|
6
|
-
SliceRequest,
|
|
7
|
-
Omit,
|
|
8
|
-
Overwrite,
|
|
9
|
-
RecoveryCleanupType
|
|
10
|
-
} from '@terascope/job-components';
|
|
1
|
+
import { Omit } from '@terascope/utils';
|
|
11
2
|
import * as got from 'got';
|
|
12
3
|
|
|
13
4
|
export interface ClientConfig {
|
|
@@ -16,333 +7,9 @@ export interface ClientConfig {
|
|
|
16
7
|
apiVersion?: string;
|
|
17
8
|
timeout?: number;
|
|
18
9
|
}
|
|
19
|
-
// TODO: lockdown query parameter types
|
|
20
|
-
|
|
21
|
-
export interface APISearchParams {
|
|
22
|
-
size?: number;
|
|
23
|
-
from?: number;
|
|
24
|
-
sort?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface TxtSearchParams extends APISearchParams {
|
|
28
|
-
fields?: string | string[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type SearchJobStatus = '*' | ExecutionStatus;
|
|
32
|
-
|
|
33
|
-
export type JobListStatusQuery = SearchJobStatus | JobSearchParams;
|
|
34
|
-
|
|
35
|
-
export interface JobSearchParams extends APISearchParams {
|
|
36
|
-
status: SearchJobStatus;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type SearchQuery = APISearchParams & Record<string, any>;
|
|
40
10
|
|
|
41
11
|
export type RequestOptions = got.Options;
|
|
42
12
|
|
|
43
13
|
export type SearchOptions = Omit<got.Options, 'searchParams'>;
|
|
44
14
|
|
|
45
15
|
export type PostData = string | NodeJS.ReadableStream | Buffer;
|
|
46
|
-
|
|
47
|
-
export type TxtType = 'assets' | 'slicers' | 'ex' | 'jobs' | 'nodes' | 'workers';
|
|
48
|
-
|
|
49
|
-
export interface RootResponse {
|
|
50
|
-
arch: string;
|
|
51
|
-
clustering_type: ClusterManagerType;
|
|
52
|
-
name: string;
|
|
53
|
-
node_version: string;
|
|
54
|
-
platform: string;
|
|
55
|
-
teraslice_version: string;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface ErrorResponse {
|
|
59
|
-
error: number;
|
|
60
|
-
message: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface JobNativeProcess extends NativeProcess {
|
|
64
|
-
node_id: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface JobKubernetesProcess extends KubernetesProcess {
|
|
68
|
-
node_id: string;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export type JobProcesses = JobNativeProcess | JobKubernetesProcess;
|
|
72
|
-
|
|
73
|
-
export type WorkerJobProcesses = Overwrite<JobProcesses, { assignment: 'worker' }>;
|
|
74
|
-
|
|
75
|
-
/*
|
|
76
|
-
ASSETS
|
|
77
|
-
*/
|
|
78
|
-
export interface Asset {
|
|
79
|
-
_created: string;
|
|
80
|
-
version: string;
|
|
81
|
-
id: string;
|
|
82
|
-
name: string;
|
|
83
|
-
description?: string;
|
|
84
|
-
blob?: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface AssetStatusResponse {
|
|
88
|
-
available: boolean;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export type AssetIDResponse = {
|
|
92
|
-
_id: string;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/*
|
|
96
|
-
Cluster State Native
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
export interface NativeProcess {
|
|
100
|
-
worker_id: string;
|
|
101
|
-
assignment: Assignment;
|
|
102
|
-
pid: number;
|
|
103
|
-
ex_id?: string;
|
|
104
|
-
job_id?: string;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export interface BaseClusterState {
|
|
108
|
-
node_id: string;
|
|
109
|
-
hostname: string;
|
|
110
|
-
pid: number|'N/A';
|
|
111
|
-
node_version: string;
|
|
112
|
-
teraslice_version: string;
|
|
113
|
-
total: number|'N/A';
|
|
114
|
-
state: string;
|
|
115
|
-
available: number|'N/A';
|
|
116
|
-
active: any[];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface ClusterStateNodeNative extends BaseClusterState {
|
|
120
|
-
node_id: string;
|
|
121
|
-
hostname: string;
|
|
122
|
-
pid: number;
|
|
123
|
-
node_version: string;
|
|
124
|
-
teraslice_version: string;
|
|
125
|
-
total: number;
|
|
126
|
-
state: string;
|
|
127
|
-
available: number;
|
|
128
|
-
active: NativeProcess[];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface ClusterStateNative {
|
|
132
|
-
[key: string]: ClusterStateNodeNative;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/*
|
|
136
|
-
Cluster State Kubernetes
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
export interface KubernetesProcess {
|
|
140
|
-
worker_id: string;
|
|
141
|
-
assignment: Assignment;
|
|
142
|
-
pod_name: string;
|
|
143
|
-
ex_id: string;
|
|
144
|
-
job_id: string;
|
|
145
|
-
pod_ip: string;
|
|
146
|
-
assets: string[];
|
|
147
|
-
image: string;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface ClusterStateNodeKubernetes extends BaseClusterState {
|
|
151
|
-
node_id: string;
|
|
152
|
-
hostname: string;
|
|
153
|
-
pid: 'N/A';
|
|
154
|
-
node_version: 'N/A';
|
|
155
|
-
teraslice_version: 'N/A';
|
|
156
|
-
total: 'N/A';
|
|
157
|
-
state: 'connected';
|
|
158
|
-
available: 'N/A';
|
|
159
|
-
active: KubernetesProcess[];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export interface ClusterStateKubernetes {
|
|
163
|
-
[key: string]: ClusterStateNodeKubernetes;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export type ClusterState = ClusterStateNative | ClusterStateKubernetes;
|
|
167
|
-
export type ClusterProcess = NativeProcess | KubernetesProcess;
|
|
168
|
-
|
|
169
|
-
/*
|
|
170
|
-
Jobs
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
export interface JobConfiguration extends ValidatedJobConfig {
|
|
174
|
-
job_id: string;
|
|
175
|
-
_context: 'job';
|
|
176
|
-
_created: string;
|
|
177
|
-
_updated: string;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export interface JobIDResponse {
|
|
181
|
-
job_id: string;
|
|
182
|
-
ex_id?: string;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/*
|
|
186
|
-
Cluster Stats
|
|
187
|
-
*/
|
|
188
|
-
|
|
189
|
-
export interface SliceAccumulationStats {
|
|
190
|
-
processed: number;
|
|
191
|
-
failed: number;
|
|
192
|
-
queued: number;
|
|
193
|
-
job_duration: number;
|
|
194
|
-
workers_joined: number;
|
|
195
|
-
workers_disconnected: number;
|
|
196
|
-
workers_reconnected: number;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export interface ClusterStats {
|
|
200
|
-
controllers: SliceAccumulationStats;
|
|
201
|
-
slicer: SliceAccumulationStats;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/*
|
|
205
|
-
Execution Context
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
export enum ExecutionStatus {
|
|
209
|
-
pending = 'pending',
|
|
210
|
-
scheduling = 'scheduling',
|
|
211
|
-
initializing = 'initializing',
|
|
212
|
-
|
|
213
|
-
running = 'running',
|
|
214
|
-
recovering = 'recovering',
|
|
215
|
-
failing = 'failing',
|
|
216
|
-
paused = 'paused',
|
|
217
|
-
stopping = 'stopping',
|
|
218
|
-
|
|
219
|
-
completed = 'completed',
|
|
220
|
-
stopped = 'stopped',
|
|
221
|
-
rejected = 'rejected',
|
|
222
|
-
failed = 'failed',
|
|
223
|
-
terminated = 'terminated'
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export type ExecutionInitStatus =
|
|
227
|
-
ExecutionStatus.pending |
|
|
228
|
-
ExecutionStatus.scheduling |
|
|
229
|
-
ExecutionStatus.recovering;
|
|
230
|
-
|
|
231
|
-
export type ExecutionRunningStatus =
|
|
232
|
-
ExecutionStatus.recovering |
|
|
233
|
-
ExecutionStatus.running |
|
|
234
|
-
ExecutionStatus.failing |
|
|
235
|
-
ExecutionStatus.paused |
|
|
236
|
-
ExecutionStatus.stopping;
|
|
237
|
-
|
|
238
|
-
export type ExecutionTerminalStatus =
|
|
239
|
-
ExecutionStatus.completed |
|
|
240
|
-
ExecutionStatus.stopped |
|
|
241
|
-
ExecutionStatus.rejected |
|
|
242
|
-
ExecutionStatus.failed |
|
|
243
|
-
ExecutionStatus.terminated;
|
|
244
|
-
|
|
245
|
-
export interface SlicerAnalytics extends SliceAccumulationStats {
|
|
246
|
-
workers_available: number;
|
|
247
|
-
workers_active: number;
|
|
248
|
-
subslices: number;
|
|
249
|
-
slice_range_expansion: number;
|
|
250
|
-
slicers: number;
|
|
251
|
-
subslice_by_key: number;
|
|
252
|
-
started?: string;
|
|
253
|
-
queuing_complete?: string;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export interface Execution extends ExecutionConfig {
|
|
257
|
-
_context: 'ex';
|
|
258
|
-
_created: string;
|
|
259
|
-
_updated: string;
|
|
260
|
-
_status: ExecutionStatus;
|
|
261
|
-
_has_errors?: boolean;
|
|
262
|
-
_failureReason?: string;
|
|
263
|
-
_slicer_stats?: SlicerAnalytics;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Native Cluster => terminated, stats null
|
|
267
|
-
// failing, hasErrors, failureReason, slice stats
|
|
268
|
-
// failed, hasErrors, failureReason, slice stats
|
|
269
|
-
// teraminated, hasErrors, failureReason, slice stats
|
|
270
|
-
// completed, slice stats
|
|
271
|
-
// stopping/stopped, slice stats
|
|
272
|
-
|
|
273
|
-
export interface ExecutionIDResponse {
|
|
274
|
-
ex_id: string;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/*
|
|
278
|
-
* Lifecyle Response
|
|
279
|
-
*/
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Recover Job / Execution Options
|
|
283
|
-
*/
|
|
284
|
-
export interface RecoverQuery {
|
|
285
|
-
/** @deprecated use `cleanup_type` */
|
|
286
|
-
cleanup?: RecoveryCleanupType;
|
|
287
|
-
cleanup_type?: RecoveryCleanupType;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export interface PausedResponse {
|
|
291
|
-
status: ExecutionStatus.paused;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export interface ResumeResponse {
|
|
295
|
-
status: ExecutionStatus.running;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export interface StoppedResponse {
|
|
299
|
-
status: ExecutionStatus.stopped | ExecutionStatus.stopping;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export interface StopQuery {
|
|
303
|
-
timeout?: number;
|
|
304
|
-
blocking?: boolean;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export interface AssetUploadQuery {
|
|
308
|
-
blocking?: boolean;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/*
|
|
312
|
-
Worker changes Response
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
export type ChangeWorkerQueryParams = 'add' | 'remove' | 'total';
|
|
316
|
-
|
|
317
|
-
export interface ChangeWorkerResponse {
|
|
318
|
-
message: string;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/*
|
|
322
|
-
Slicer/Controller Response
|
|
323
|
-
*/
|
|
324
|
-
|
|
325
|
-
export interface SlicerStats extends SlicerAnalytics {
|
|
326
|
-
ex_id: string;
|
|
327
|
-
job_id: string;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export type ControllerState = SlicerStats[];
|
|
331
|
-
|
|
332
|
-
/*
|
|
333
|
-
Error Response
|
|
334
|
-
*/
|
|
335
|
-
|
|
336
|
-
export interface ErrorStateRecord {
|
|
337
|
-
ex_id: string;
|
|
338
|
-
slice_id: string;
|
|
339
|
-
slicer_id: string;
|
|
340
|
-
slicer_order: number;
|
|
341
|
-
request: SliceRequest;
|
|
342
|
-
state: 'error';
|
|
343
|
-
error: string;
|
|
344
|
-
_created: string;
|
|
345
|
-
_updated: string;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export type StateErrors = ErrorStateRecord[];
|
package/src/job.ts
CHANGED
|
@@ -1,36 +1,14 @@
|
|
|
1
1
|
import util from 'util';
|
|
2
2
|
import autoBind from 'auto-bind';
|
|
3
3
|
import {
|
|
4
|
-
pDelay,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Assignment,
|
|
9
|
-
toHumanTime,
|
|
10
|
-
JobConfig,
|
|
11
|
-
} from '@terascope/job-components';
|
|
4
|
+
pDelay, isString, toString,
|
|
5
|
+
TSError, toHumanTime,
|
|
6
|
+
} from '@terascope/utils';
|
|
7
|
+
import { Teraslice } from '@terascope/types';
|
|
12
8
|
import {
|
|
13
9
|
ClientConfig,
|
|
14
|
-
SearchQuery,
|
|
15
|
-
ExecutionStatus,
|
|
16
|
-
ChangeWorkerQueryParams,
|
|
17
|
-
ClusterState,
|
|
18
|
-
ClusterProcess,
|
|
19
|
-
ControllerState,
|
|
20
|
-
StateErrors,
|
|
21
|
-
WorkerJobProcesses,
|
|
22
10
|
SearchOptions,
|
|
23
|
-
|
|
24
|
-
RequestOptions,
|
|
25
|
-
ExecutionIDResponse,
|
|
26
|
-
RecoverQuery,
|
|
27
|
-
ResumeResponse,
|
|
28
|
-
StoppedResponse,
|
|
29
|
-
PausedResponse,
|
|
30
|
-
JobIDResponse,
|
|
31
|
-
StopQuery,
|
|
32
|
-
Execution,
|
|
33
|
-
JobConfiguration
|
|
11
|
+
RequestOptions
|
|
34
12
|
} from './interfaces';
|
|
35
13
|
import Client from './client';
|
|
36
14
|
|
|
@@ -41,7 +19,7 @@ import Client from './client';
|
|
|
41
19
|
* Depending on how usage of this API develops we may want to reconsider this.
|
|
42
20
|
*/
|
|
43
21
|
|
|
44
|
-
function _deprecateSlicerName(fn: () => Promise<
|
|
22
|
+
function _deprecateSlicerName(fn: () => Promise<Teraslice.ExecutionList>) {
|
|
45
23
|
const msg = 'api endpoints with /slicers are being deprecated in favor of the semantically correct term of /controllers';
|
|
46
24
|
return util.deprecate(fn, msg);
|
|
47
25
|
}
|
|
@@ -63,78 +41,92 @@ export default class Job extends Client {
|
|
|
63
41
|
|
|
64
42
|
id(): string { return this._jobId; }
|
|
65
43
|
|
|
66
|
-
async slicer(requestOptions: RequestOptions = {}): Promise<
|
|
44
|
+
async slicer(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionList> {
|
|
67
45
|
return this.get(`/jobs/${this._jobId}/slicer`, requestOptions);
|
|
68
46
|
}
|
|
69
47
|
|
|
70
|
-
async controller(requestOptions: RequestOptions = {}): Promise<
|
|
48
|
+
async controller(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionList> {
|
|
71
49
|
return this.get(`/jobs/${this._jobId}/controller`, requestOptions);
|
|
72
50
|
}
|
|
73
51
|
|
|
74
|
-
async start(
|
|
52
|
+
async start(
|
|
53
|
+
query?: Teraslice.SearchQuery,
|
|
54
|
+
searchOptions: SearchOptions = {}
|
|
55
|
+
): Promise<Teraslice.ApiJobCreateResponse> {
|
|
75
56
|
const options = this.makeOptions(query, searchOptions);
|
|
76
57
|
return this.post(`/jobs/${this._jobId}/_start`, null, options);
|
|
77
58
|
}
|
|
78
59
|
|
|
79
|
-
async stop(
|
|
60
|
+
async stop(
|
|
61
|
+
query?: Teraslice.StopQuery,
|
|
62
|
+
searchOptions: SearchOptions = {}
|
|
63
|
+
): Promise<Teraslice.ApiStoppedResponse> {
|
|
80
64
|
const options = this.makeOptions(query, searchOptions);
|
|
81
65
|
return this.post(`/jobs/${this._jobId}/_stop`, null, options);
|
|
82
66
|
}
|
|
83
67
|
|
|
84
|
-
async pause(
|
|
68
|
+
async pause(
|
|
69
|
+
query?: Teraslice.SearchQuery,
|
|
70
|
+
searchOptions: SearchOptions = {}
|
|
71
|
+
): Promise<Teraslice.ApiPausedResponse> {
|
|
85
72
|
const options = this.makeOptions(query, searchOptions);
|
|
86
73
|
return this.post(`/jobs/${this._jobId}/_pause`, null, options);
|
|
87
74
|
}
|
|
88
75
|
|
|
89
|
-
async resume(
|
|
76
|
+
async resume(
|
|
77
|
+
query?: Teraslice.SearchQuery,
|
|
78
|
+
searchOptions: SearchOptions = {}
|
|
79
|
+
): Promise<Teraslice.ApiResumeResponse> {
|
|
90
80
|
const options = this.makeOptions(query, searchOptions);
|
|
91
81
|
return this.post(`/jobs/${this._jobId}/_resume`, null, options);
|
|
92
82
|
}
|
|
93
83
|
|
|
94
84
|
async recover(
|
|
95
|
-
query: RecoverQuery = {},
|
|
85
|
+
query: Teraslice.RecoverQuery = {},
|
|
96
86
|
searchOptions: SearchOptions = {}
|
|
97
|
-
): Promise<
|
|
87
|
+
): Promise<Teraslice.ApiJobCreateResponse> {
|
|
98
88
|
const options = this.makeOptions(query, searchOptions);
|
|
99
89
|
return this.post(`/jobs/${this._jobId}/_recover`, null, options);
|
|
100
90
|
}
|
|
101
91
|
|
|
102
|
-
async update(jobSpec:
|
|
92
|
+
async update(jobSpec: Teraslice.JobRecord): Promise<Teraslice.JobRecord> {
|
|
103
93
|
return this.put(`/jobs/${this._jobId}`, jobSpec);
|
|
104
94
|
}
|
|
105
95
|
|
|
106
|
-
async updatePartial(
|
|
96
|
+
async updatePartial(
|
|
97
|
+
jobSpec: Partial<Teraslice.JobRecord>
|
|
98
|
+
): Promise<Teraslice.JobRecord> {
|
|
107
99
|
const current = await this.config();
|
|
108
|
-
const body:
|
|
100
|
+
const body: Teraslice.JobRecord = Object.assign({}, current, jobSpec);
|
|
109
101
|
return this.update(body);
|
|
110
102
|
}
|
|
111
103
|
|
|
112
|
-
async execution(requestOptions: RequestOptions = {}): Promise<
|
|
104
|
+
async execution(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionRecord> {
|
|
113
105
|
return this.get(`/jobs/${this._jobId}/ex`, requestOptions);
|
|
114
106
|
}
|
|
115
107
|
|
|
116
|
-
async exId(requestOptions: RequestOptions = {}): Promise<ExecutionIDResponse> {
|
|
108
|
+
async exId(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionIDResponse> {
|
|
117
109
|
const { ex_id: exId } = await this.get(`/jobs/${this._jobId}/ex`, requestOptions);
|
|
118
110
|
return exId;
|
|
119
111
|
}
|
|
120
112
|
|
|
121
|
-
async status(requestOptions: RequestOptions = {}): Promise<ExecutionStatus> {
|
|
113
|
+
async status(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionStatus> {
|
|
122
114
|
const { _status: status } = await this.get(`/jobs/${this._jobId}/ex`, requestOptions);
|
|
123
115
|
return status;
|
|
124
116
|
}
|
|
125
117
|
|
|
126
118
|
async waitForStatus(
|
|
127
|
-
target: ExecutionStatus[] | ExecutionStatus,
|
|
119
|
+
target: Teraslice.ExecutionStatus[] | Teraslice.ExecutionStatus,
|
|
128
120
|
intervalMs = 1000,
|
|
129
121
|
timeoutMs = 0,
|
|
130
122
|
requestOptions: RequestOptions = {}
|
|
131
|
-
): Promise<ExecutionStatus> {
|
|
123
|
+
): Promise<Teraslice.ExecutionStatus> {
|
|
132
124
|
const terminal = {
|
|
133
|
-
[
|
|
134
|
-
[
|
|
135
|
-
[
|
|
136
|
-
[
|
|
137
|
-
[
|
|
125
|
+
[Teraslice.ExecutionStatusEnum.terminated]: true,
|
|
126
|
+
[Teraslice.ExecutionStatusEnum.failed]: true,
|
|
127
|
+
[Teraslice.ExecutionStatusEnum.rejected]: true,
|
|
128
|
+
[Teraslice.ExecutionStatusEnum.completed]: true,
|
|
129
|
+
[Teraslice.ExecutionStatusEnum.stopped]: true,
|
|
138
130
|
};
|
|
139
131
|
|
|
140
132
|
const startTime = Date.now();
|
|
@@ -144,7 +136,7 @@ export default class Job extends Client {
|
|
|
144
136
|
}, requestOptions);
|
|
145
137
|
let exId: string;
|
|
146
138
|
|
|
147
|
-
const checkStatus = async (): Promise<ExecutionStatus> => {
|
|
139
|
+
const checkStatus = async (): Promise<Teraslice.ExecutionStatus> => {
|
|
148
140
|
let result;
|
|
149
141
|
try {
|
|
150
142
|
const ex = await this.get(`/jobs/${this._jobId}/ex`, options);
|
|
@@ -190,24 +182,27 @@ export default class Job extends Client {
|
|
|
190
182
|
return checkStatus();
|
|
191
183
|
}
|
|
192
184
|
|
|
193
|
-
async config(requestOptions: RequestOptions = {}): Promise<
|
|
185
|
+
async config(requestOptions: RequestOptions = {}): Promise<Teraslice.JobRecord> {
|
|
194
186
|
return this.get(`/jobs/${this._jobId}`, requestOptions);
|
|
195
187
|
}
|
|
196
188
|
|
|
197
|
-
async errors(
|
|
189
|
+
async errors(
|
|
190
|
+
query: Teraslice.SearchQuery = {},
|
|
191
|
+
searchOptions: SearchOptions = {}
|
|
192
|
+
): Promise<Teraslice.ErrorRecord[]> {
|
|
198
193
|
return this.get(`/jobs/${this._jobId}/errors`, this.makeOptions(query, searchOptions));
|
|
199
194
|
}
|
|
200
195
|
|
|
201
|
-
async workers(requestOptions: RequestOptions = {}): Promise<
|
|
202
|
-
const state: ClusterState = await this.get('/cluster/state', requestOptions);
|
|
203
|
-
return filterProcesses<
|
|
196
|
+
async workers(requestOptions: RequestOptions = {}): Promise<Teraslice.WorkerNode[]> {
|
|
197
|
+
const state: Teraslice.ClusterState = await this.get('/cluster/state', requestOptions);
|
|
198
|
+
return filterProcesses<Teraslice.WorkerNode>(state, this._jobId, 'worker');
|
|
204
199
|
}
|
|
205
200
|
|
|
206
201
|
async changeWorkers(
|
|
207
|
-
action: ChangeWorkerQueryParams,
|
|
202
|
+
action: Teraslice.ChangeWorkerQueryParams,
|
|
208
203
|
workerNum: number,
|
|
209
204
|
requestOptions: RequestOptions = {}
|
|
210
|
-
): Promise<ChangeWorkerResponse | string> {
|
|
205
|
+
): Promise<Teraslice.ChangeWorkerResponse | string> {
|
|
211
206
|
if (action == null || workerNum == null) {
|
|
212
207
|
throw new TSError('Change workers requires action and count', {
|
|
213
208
|
statusCode: 400
|
|
@@ -237,16 +232,22 @@ export default class Job extends Client {
|
|
|
237
232
|
}
|
|
238
233
|
}
|
|
239
234
|
|
|
240
|
-
function filterProcesses<T>(
|
|
235
|
+
function filterProcesses<T>(
|
|
236
|
+
state: Teraslice.ClusterState,
|
|
237
|
+
jobId: string,
|
|
238
|
+
type: Teraslice.Assignment
|
|
239
|
+
) {
|
|
241
240
|
const results: T[] = [];
|
|
242
241
|
|
|
243
242
|
for (const [, node] of Object.entries(state)) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
243
|
+
// TODO: fix this
|
|
244
|
+
node.active.forEach((child: any) => {
|
|
245
|
+
if (child.job_id) {
|
|
246
|
+
const { assignment, job_id: procJobId } = child;
|
|
247
|
+
if ((assignment && assignment === type) && (procJobId && procJobId === jobId)) {
|
|
248
|
+
const jobProcess = Object.assign({}, child, { node_id: node.node_id });
|
|
249
|
+
results.push(jobProcess);
|
|
250
|
+
}
|
|
250
251
|
}
|
|
251
252
|
});
|
|
252
253
|
}
|
package/src/jobs.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import { isString,
|
|
1
|
+
import { isString, TSError } from '@terascope/utils';
|
|
2
|
+
import { Teraslice } from '@terascope/types';
|
|
2
3
|
import autoBind from 'auto-bind';
|
|
3
4
|
import Client from './client';
|
|
4
5
|
import Job from './job';
|
|
5
|
-
import {
|
|
6
|
-
ClientConfig,
|
|
7
|
-
JobConfiguration,
|
|
8
|
-
SearchOptions,
|
|
9
|
-
JobSearchParams,
|
|
10
|
-
JobListStatusQuery,
|
|
11
|
-
JobIDResponse
|
|
12
|
-
} from './interfaces';
|
|
6
|
+
import { SearchOptions, ClientConfig } from './interfaces';
|
|
13
7
|
|
|
14
8
|
export default class Jobs extends Client {
|
|
15
9
|
constructor(config: ClientConfig) {
|
|
@@ -17,22 +11,24 @@ export default class Jobs extends Client {
|
|
|
17
11
|
autoBind(this);
|
|
18
12
|
}
|
|
19
13
|
|
|
20
|
-
async submit(jobSpec: JobConfig, shouldNotStart?: boolean): Promise<Job> {
|
|
14
|
+
async submit(jobSpec: Teraslice.JobConfig, shouldNotStart?: boolean): Promise<Job> {
|
|
21
15
|
if (!jobSpec) {
|
|
22
16
|
throw new TSError('Submit requires a jobSpec', {
|
|
23
17
|
statusCode: 400
|
|
24
18
|
});
|
|
25
19
|
}
|
|
26
|
-
|
|
20
|
+
|
|
21
|
+
const job: Teraslice.ApiJobCreateResponse = await this.post('/jobs', jobSpec, {
|
|
27
22
|
searchParams: { start: !shouldNotStart }
|
|
28
23
|
});
|
|
24
|
+
|
|
29
25
|
return this.wrap(job.job_id);
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
async list(
|
|
33
|
-
status?: JobListStatusQuery,
|
|
29
|
+
status?: Teraslice.JobListStatusQuery,
|
|
34
30
|
searchOptions: SearchOptions = {}
|
|
35
|
-
): Promise<
|
|
31
|
+
): Promise<Teraslice.JobRecord[]> {
|
|
36
32
|
const query = _parseListOptions(status);
|
|
37
33
|
return this.get('/jobs', this.makeOptions(query, searchOptions));
|
|
38
34
|
}
|
|
@@ -46,7 +42,7 @@ export default class Jobs extends Client {
|
|
|
46
42
|
}
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
function _parseListOptions(options?: JobListStatusQuery): JobSearchParams {
|
|
45
|
+
function _parseListOptions(options?: Teraslice.JobListStatusQuery): Teraslice.JobSearchParams {
|
|
50
46
|
// support legacy
|
|
51
47
|
if (!options) return { status: '*' };
|
|
52
48
|
if (isString(options)) return { status: options };
|
package/test/assets-spec.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import nock from 'nock';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
+
import { AssetRecord, AssetIDResponse } from '@terascope/types';
|
|
4
5
|
import Assets from '../src/assets';
|
|
5
|
-
import { AssetIDResponse, Asset } from '../src/interfaces';
|
|
6
6
|
|
|
7
7
|
describe('Teraslice Assets', () => {
|
|
8
8
|
let assets: Assets;
|
|
@@ -22,17 +22,19 @@ describe('Teraslice Assets', () => {
|
|
|
22
22
|
|
|
23
23
|
const date = new Date();
|
|
24
24
|
|
|
25
|
-
const assetVersion1:
|
|
25
|
+
const assetVersion1: AssetRecord = {
|
|
26
26
|
id: 'someId',
|
|
27
27
|
version: '1.0',
|
|
28
28
|
name: 'iAmAnAsset',
|
|
29
|
+
blob: '',
|
|
29
30
|
_created: date.toISOString()
|
|
30
31
|
};
|
|
31
32
|
|
|
32
|
-
const assetVersion2:
|
|
33
|
+
const assetVersion2: AssetRecord = {
|
|
33
34
|
id: 'someId',
|
|
34
35
|
version: '2.0',
|
|
35
36
|
name: 'iAmAnAsset',
|
|
37
|
+
blob: '',
|
|
36
38
|
_created: new Date(date.getTime() + 500000).toISOString()
|
|
37
39
|
};
|
|
38
40
|
|
|
@@ -83,7 +85,7 @@ describe('Teraslice Assets', () => {
|
|
|
83
85
|
});
|
|
84
86
|
|
|
85
87
|
describe('->list', () => {
|
|
86
|
-
const assetList:
|
|
88
|
+
const assetList: AssetRecord[] = [
|
|
87
89
|
assetVersion1,
|
|
88
90
|
assetVersion2
|
|
89
91
|
];
|
package/test/cluster-spec.ts
CHANGED
|
@@ -142,7 +142,6 @@ describe('Teraslice Cluster', () => {
|
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
it('should resolve the plain test results from Teraslice', async () => {
|
|
145
|
-
// @ts-expect-error TODO: fixme
|
|
146
145
|
const results = await cluster.txt('assets/assetName');
|
|
147
146
|
expect(results).toEqual('assets-txt-response');
|
|
148
147
|
});
|
|
@@ -158,7 +157,6 @@ describe('Teraslice Cluster', () => {
|
|
|
158
157
|
expect.hasAssertions();
|
|
159
158
|
const errMsg = '"invalid" is not a valid type. Must be one of ["assets","slicers","ex","jobs","nodes","workers"]';
|
|
160
159
|
try {
|
|
161
|
-
// @ts-expect-error
|
|
162
160
|
await cluster.txt('invalid');
|
|
163
161
|
} catch (err) {
|
|
164
162
|
expect(err.message).toEqual(errMsg);
|