teraslice-client-js 0.55.0 → 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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teraslice-client-js",
|
|
3
3
|
"displayName": "Teraslice Client (JavaScript)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.56.0",
|
|
5
5
|
"description": "A Node.js client for teraslice jobs, assets, and cluster references.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"elasticsearch",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"test:watch": "ts-scripts test --watch . --"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@terascope/
|
|
34
|
+
"@terascope/types": "^0.14.0",
|
|
35
|
+
"@terascope/utils": "^0.55.0",
|
|
35
36
|
"auto-bind": "^4.0.0",
|
|
36
37
|
"got": "^11.8.3"
|
|
37
38
|
},
|
package/src/assets.ts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import { TSError, isEmpty, isString } from '@terascope/
|
|
1
|
+
import { TSError, isEmpty, isString } from '@terascope/utils';
|
|
2
|
+
import { Teraslice } from '@terascope/types';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import autoBind from 'auto-bind';
|
|
4
5
|
import Client from './client';
|
|
5
|
-
import {
|
|
6
|
-
SearchQuery,
|
|
7
|
-
PostData,
|
|
8
|
-
AssetIDResponse,
|
|
9
|
-
SearchOptions,
|
|
10
|
-
AssetUploadQuery,
|
|
11
|
-
TxtSearchParams,
|
|
12
|
-
ClientConfig,
|
|
13
|
-
Asset
|
|
14
|
-
} from './interfaces';
|
|
6
|
+
import { PostData, SearchOptions, ClientConfig } from './interfaces';
|
|
15
7
|
|
|
16
8
|
export default class Assets extends Client {
|
|
17
9
|
constructor(config: ClientConfig) {
|
|
@@ -19,7 +11,10 @@ export default class Assets extends Client {
|
|
|
19
11
|
autoBind(this);
|
|
20
12
|
}
|
|
21
13
|
|
|
22
|
-
async upload(
|
|
14
|
+
async upload(
|
|
15
|
+
data: PostData,
|
|
16
|
+
query: Teraslice.AssetUploadQuery = {}
|
|
17
|
+
): Promise<Teraslice.AssetIDResponse> {
|
|
23
18
|
if (isEmpty(data)) {
|
|
24
19
|
throw new TSError('Asset stream must not be empty', {
|
|
25
20
|
statusCode: 400
|
|
@@ -29,28 +24,37 @@ export default class Assets extends Client {
|
|
|
29
24
|
const results = await this.post('/assets', data, {
|
|
30
25
|
searchParams: query as Record<string, any>
|
|
31
26
|
});
|
|
27
|
+
|
|
32
28
|
return this.parse(results);
|
|
33
29
|
}
|
|
34
30
|
|
|
35
|
-
async remove(
|
|
31
|
+
async remove(
|
|
32
|
+
id: string,
|
|
33
|
+
searchOptions: SearchOptions = {}
|
|
34
|
+
): Promise<Teraslice.AssetIDResponse> {
|
|
36
35
|
if (isEmpty(id)) {
|
|
37
36
|
throw new TSError('Asset delete requires a ID', {
|
|
38
37
|
statusCode: 400
|
|
39
38
|
});
|
|
40
39
|
}
|
|
40
|
+
|
|
41
41
|
const results = await this.delete(`/assets/${id}`, searchOptions);
|
|
42
42
|
return this.parse(results);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async list(
|
|
46
|
-
query: SearchQuery = {},
|
|
46
|
+
query: Teraslice.SearchQuery = {},
|
|
47
47
|
searchOptions: SearchOptions = {}
|
|
48
|
-
): Promise<
|
|
48
|
+
): Promise<Teraslice.AssetRecord[]> {
|
|
49
49
|
const options = { ...searchOptions, searchParams: query };
|
|
50
50
|
return this.get('/assets', options);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
async getAsset(
|
|
53
|
+
async getAsset(
|
|
54
|
+
name: string,
|
|
55
|
+
version = '',
|
|
56
|
+
searchOptions: SearchOptions = {}
|
|
57
|
+
): Promise<Teraslice.AssetRecord[]> {
|
|
54
58
|
if (!name || !isString(name)) {
|
|
55
59
|
throw new TSError('Name is required, and must be of type string', {
|
|
56
60
|
statusCode: 400
|
|
@@ -62,14 +66,15 @@ export default class Assets extends Client {
|
|
|
62
66
|
});
|
|
63
67
|
}
|
|
64
68
|
|
|
65
|
-
const
|
|
66
|
-
|
|
69
|
+
const assetUrl = path.join('/assets', name, version);
|
|
70
|
+
|
|
71
|
+
return this.get(assetUrl, searchOptions);
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
async txt(
|
|
70
75
|
name = '',
|
|
71
76
|
version = '',
|
|
72
|
-
query: TxtSearchParams = {},
|
|
77
|
+
query: Teraslice.TxtSearchParams = {},
|
|
73
78
|
searchOptions: SearchOptions = {}
|
|
74
79
|
): Promise<string> {
|
|
75
80
|
if (name && !isString(name)) {
|
package/src/client.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isString,
|
|
3
|
-
|
|
4
|
-
isPlainObject,
|
|
5
|
-
isTest,
|
|
6
|
-
trimStart,
|
|
7
|
-
tryParseJSON,
|
|
2
|
+
isString, TSError, isPlainObject,
|
|
3
|
+
isTest, trimStart, tryParseJSON,
|
|
8
4
|
withoutNil,
|
|
9
|
-
} from '@terascope/
|
|
5
|
+
} from '@terascope/utils';
|
|
10
6
|
import { STATUS_CODES } from 'http';
|
|
11
7
|
import { URL } from 'url';
|
|
12
8
|
import got, { Got } from 'got';
|
|
@@ -45,7 +41,7 @@ export default class Client {
|
|
|
45
41
|
return this._makeRequest<T>('get', endpoint, options);
|
|
46
42
|
}
|
|
47
43
|
|
|
48
|
-
async post<T = any>(endpoint: string, data
|
|
44
|
+
async post<T = any>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<T> {
|
|
49
45
|
return this._makeRequest<T>('post', endpoint, options, data);
|
|
50
46
|
}
|
|
51
47
|
|
|
@@ -109,7 +105,6 @@ export default class Client {
|
|
|
109
105
|
return tryParseJSON(results);
|
|
110
106
|
}
|
|
111
107
|
|
|
112
|
-
// TODO: make better types for this
|
|
113
108
|
protected makeOptions(
|
|
114
109
|
searchParams: Record<string, any>|undefined, options: RequestOptions | SearchOptions
|
|
115
110
|
): RequestOptions {
|
|
@@ -164,15 +159,18 @@ interface OldErrorOutput extends TSError {
|
|
|
164
159
|
|
|
165
160
|
function makeErrorFromResponse(response: any): OldErrorOutput {
|
|
166
161
|
const { statusCode } = response;
|
|
167
|
-
const
|
|
162
|
+
const parsedError = getErrorFromResponse(response);
|
|
168
163
|
const {
|
|
169
164
|
message = STATUS_CODES[statusCode],
|
|
170
165
|
code = statusCode
|
|
171
|
-
} =
|
|
166
|
+
} = parsedError;
|
|
167
|
+
|
|
172
168
|
const error: Partial<OldErrorOutput> = new Error(message);
|
|
169
|
+
|
|
173
170
|
error.error = code; // for legacy support
|
|
174
171
|
error.code = code;
|
|
175
172
|
error.statusCode = code;
|
|
173
|
+
|
|
176
174
|
return error as OldErrorOutput;
|
|
177
175
|
}
|
|
178
176
|
|
package/src/cluster.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import { startsWith } from '@terascope/
|
|
1
|
+
import { startsWith } from '@terascope/utils';
|
|
2
|
+
import { Teraslice } from '@terascope/types';
|
|
2
3
|
import util from 'util';
|
|
3
4
|
import autoBind from 'auto-bind';
|
|
4
5
|
import Client from './client';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
RootResponse,
|
|
8
|
-
ClusterState,
|
|
9
|
-
ClusterStats,
|
|
10
|
-
ControllerState
|
|
11
|
-
} from './interfaces';
|
|
12
|
-
|
|
13
|
-
function _deprecateSlicerName(fn: () => Promise<ControllerState>) {
|
|
6
|
+
|
|
7
|
+
function _deprecateSlicerName(fn: () => Promise<Teraslice.ExecutionList>) {
|
|
14
8
|
const msg = 'api endpoints with /slicers are being deprecated in favor of the semantically correct term of /controllers';
|
|
15
9
|
return util.deprecate(fn, msg);
|
|
16
10
|
}
|
|
@@ -22,27 +16,27 @@ export default class Cluster extends Client {
|
|
|
22
16
|
autoBind(this);
|
|
23
17
|
}
|
|
24
18
|
|
|
25
|
-
async info(): Promise<
|
|
19
|
+
async info(): Promise<Teraslice.ApiRootResponse> {
|
|
26
20
|
return this.get('/');
|
|
27
21
|
}
|
|
28
22
|
|
|
29
|
-
async state(): Promise<ClusterState> {
|
|
23
|
+
async state(): Promise<Teraslice.ClusterState> {
|
|
30
24
|
return this.get('/cluster/state');
|
|
31
25
|
}
|
|
32
26
|
|
|
33
|
-
async stats(): Promise<ClusterStats> {
|
|
27
|
+
async stats(): Promise<Teraslice.ClusterStats> {
|
|
34
28
|
return this.get('/cluster/stats');
|
|
35
29
|
}
|
|
36
30
|
|
|
37
|
-
async slicers(): Promise<
|
|
31
|
+
async slicers(): Promise<Teraslice.ExecutionList> {
|
|
38
32
|
return this.get('/cluster/slicers');
|
|
39
33
|
}
|
|
40
34
|
|
|
41
|
-
async controllers(): Promise<
|
|
35
|
+
async controllers(): Promise<Teraslice.ExecutionList> {
|
|
42
36
|
return this.get('/cluster/controllers');
|
|
43
37
|
}
|
|
44
38
|
|
|
45
|
-
async txt(type:
|
|
39
|
+
async txt(type: string): Promise<string> {
|
|
46
40
|
const validTypes = ['assets', 'slicers', 'ex', 'jobs', 'nodes', 'workers'];
|
|
47
41
|
const isValid = validTypes.some((validType) => startsWith(type, validType));
|
|
48
42
|
if (!isValid) {
|
package/src/ex.ts
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isString,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Assignment,
|
|
7
|
-
toHumanTime
|
|
8
|
-
} from '@terascope/job-components';
|
|
2
|
+
isString, TSError, toString,
|
|
3
|
+
pDelay, toHumanTime
|
|
4
|
+
} from '@terascope/utils';
|
|
5
|
+
import { Teraslice } from '@terascope/types';
|
|
9
6
|
import autoBind from 'auto-bind';
|
|
10
7
|
import Client from './client';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
ClientConfig,
|
|
14
|
-
SearchQuery,
|
|
15
|
-
SearchOptions,
|
|
16
|
-
PausedResponse,
|
|
17
|
-
StoppedResponse,
|
|
18
|
-
StopQuery,
|
|
19
|
-
Execution,
|
|
20
|
-
ResumeResponse,
|
|
21
|
-
ExecutionStatus,
|
|
22
|
-
StateErrors,
|
|
23
|
-
RequestOptions,
|
|
24
|
-
RecoverQuery,
|
|
25
|
-
ControllerState,
|
|
26
|
-
ClusterState,
|
|
27
|
-
WorkerJobProcesses,
|
|
28
|
-
ClusterProcess,
|
|
29
|
-
ChangeWorkerResponse,
|
|
30
|
-
ChangeWorkerQueryParams,
|
|
31
|
-
JobIDResponse
|
|
32
|
-
} from './interfaces';
|
|
8
|
+
import { ClientConfig, SearchOptions, RequestOptions } from './interfaces';
|
|
33
9
|
|
|
34
10
|
export default class Ex extends Client {
|
|
35
11
|
private readonly _exId: string;
|
|
@@ -45,27 +21,36 @@ export default class Ex extends Client {
|
|
|
45
21
|
|
|
46
22
|
id(): string { return this._exId; }
|
|
47
23
|
|
|
48
|
-
async stop(
|
|
24
|
+
async stop(
|
|
25
|
+
query?: Teraslice.StopQuery,
|
|
26
|
+
searchOptions: SearchOptions = {}
|
|
27
|
+
): Promise<Teraslice.ApiStoppedResponse> {
|
|
49
28
|
const options = this.makeOptions(query, searchOptions);
|
|
50
29
|
return this.post(`/ex/${this._exId}/_stop`, null, options);
|
|
51
30
|
}
|
|
52
31
|
|
|
53
|
-
async pause(
|
|
32
|
+
async pause(
|
|
33
|
+
query?: Teraslice.SearchQuery,
|
|
34
|
+
searchOptions: SearchOptions = {}
|
|
35
|
+
): Promise<Teraslice.ApiPausedResponse> {
|
|
54
36
|
const options = this.makeOptions(query, searchOptions);
|
|
55
37
|
return this.post(`/ex/${this._exId}/_pause`, null, options);
|
|
56
38
|
}
|
|
57
39
|
|
|
58
|
-
async resume(
|
|
40
|
+
async resume(
|
|
41
|
+
query?: Teraslice.SearchQuery,
|
|
42
|
+
searchOptions: SearchOptions = {}
|
|
43
|
+
): Promise<Teraslice.ApiResumeResponse> {
|
|
59
44
|
const options = this.makeOptions(query, searchOptions);
|
|
60
45
|
return this.post(`/ex/${this._exId}/_resume`, null, options);
|
|
61
46
|
}
|
|
62
47
|
|
|
63
48
|
async recover(
|
|
64
|
-
query: RecoverQuery = {},
|
|
49
|
+
query: Teraslice.RecoverQuery = {},
|
|
65
50
|
searchOptions: SearchOptions = {}
|
|
66
51
|
): Promise<Ex> {
|
|
67
52
|
const options = this.makeOptions(query, searchOptions);
|
|
68
|
-
const result:
|
|
53
|
+
const result: Teraslice.ApiJobCreateResponse = await this.post(`/ex/${this._exId}/_recover`, null, options);
|
|
69
54
|
|
|
70
55
|
// support older version of teraslice
|
|
71
56
|
if (!result.ex_id) {
|
|
@@ -76,39 +61,39 @@ export default class Ex extends Client {
|
|
|
76
61
|
return new Ex(this._config, result.ex_id);
|
|
77
62
|
}
|
|
78
63
|
|
|
79
|
-
async status(requestOptions?: RequestOptions): Promise<ExecutionStatus> {
|
|
64
|
+
async status(requestOptions?: RequestOptions): Promise<Teraslice.ExecutionStatus> {
|
|
80
65
|
const { _status: status } = await this.config(requestOptions);
|
|
81
66
|
return status;
|
|
82
67
|
}
|
|
83
68
|
|
|
84
|
-
async slicer(requestOptions: RequestOptions = {}): Promise<
|
|
69
|
+
async slicer(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionList> {
|
|
85
70
|
return this.get(`/ex/${this._exId}/slicer`, requestOptions);
|
|
86
71
|
}
|
|
87
72
|
|
|
88
|
-
async controller(requestOptions: RequestOptions = {}): Promise<
|
|
73
|
+
async controller(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionList> {
|
|
89
74
|
return this.get(`/ex/${this._exId}/controller`, requestOptions);
|
|
90
75
|
}
|
|
91
76
|
|
|
92
|
-
async config(requestOptions: RequestOptions = {}): Promise<
|
|
77
|
+
async config(requestOptions: RequestOptions = {}): Promise<Teraslice.ExecutionRecord> {
|
|
93
78
|
return this.get(`/ex/${this._exId}`, requestOptions);
|
|
94
79
|
}
|
|
95
80
|
|
|
96
|
-
async workers(requestOptions: RequestOptions = {}): Promise<
|
|
97
|
-
const state: ClusterState = await this.get('/cluster/state', requestOptions);
|
|
98
|
-
return filterProcesses<
|
|
81
|
+
async workers(requestOptions: RequestOptions = {}): Promise<Teraslice.WorkerNode[]> {
|
|
82
|
+
const state: Teraslice.ClusterState = await this.get('/cluster/state', requestOptions);
|
|
83
|
+
return filterProcesses<Teraslice.WorkerNode>(state, this._exId, 'worker');
|
|
99
84
|
}
|
|
100
85
|
|
|
101
|
-
async errors(options?: SearchQuery): Promise<
|
|
86
|
+
async errors(options?: Teraslice.SearchQuery): Promise<Teraslice.ErrorRecord[]> {
|
|
102
87
|
return this.get(`/ex/${this._exId}/errors`, {
|
|
103
88
|
searchParams: options,
|
|
104
89
|
} as SearchOptions);
|
|
105
90
|
}
|
|
106
91
|
|
|
107
92
|
async changeWorkers(
|
|
108
|
-
action: ChangeWorkerQueryParams,
|
|
93
|
+
action: Teraslice.ChangeWorkerQueryParams,
|
|
109
94
|
workerNum: number,
|
|
110
95
|
requestOptions: RequestOptions = {}
|
|
111
|
-
): Promise<ChangeWorkerResponse | string> {
|
|
96
|
+
): Promise<Teraslice.ChangeWorkerResponse | string> {
|
|
112
97
|
if (action == null || workerNum == null) {
|
|
113
98
|
throw new TSError('Change workers requires action and count', {
|
|
114
99
|
statusCode: 400
|
|
@@ -138,17 +123,17 @@ export default class Ex extends Client {
|
|
|
138
123
|
}
|
|
139
124
|
|
|
140
125
|
async waitForStatus(
|
|
141
|
-
target: ExecutionStatus,
|
|
126
|
+
target: Teraslice.ExecutionStatus,
|
|
142
127
|
intervalMs = 1000,
|
|
143
128
|
timeoutMs = 0,
|
|
144
129
|
requestOptions: RequestOptions = {}
|
|
145
|
-
): Promise<ExecutionStatus> {
|
|
130
|
+
): Promise<Teraslice.ExecutionStatus> {
|
|
146
131
|
const terminal = {
|
|
147
|
-
[
|
|
148
|
-
[
|
|
149
|
-
[
|
|
150
|
-
[
|
|
151
|
-
[
|
|
132
|
+
[Teraslice.ExecutionStatusEnum.terminated]: true,
|
|
133
|
+
[Teraslice.ExecutionStatusEnum.failed]: true,
|
|
134
|
+
[Teraslice.ExecutionStatusEnum.rejected]: true,
|
|
135
|
+
[Teraslice.ExecutionStatusEnum.completed]: true,
|
|
136
|
+
[Teraslice.ExecutionStatusEnum.stopped]: true,
|
|
152
137
|
};
|
|
153
138
|
|
|
154
139
|
const startTime = Date.now();
|
|
@@ -157,7 +142,7 @@ export default class Ex extends Client {
|
|
|
157
142
|
timeout: intervalMs < 1000 ? 1000 : intervalMs,
|
|
158
143
|
}, requestOptions);
|
|
159
144
|
|
|
160
|
-
const checkStatus = async (): Promise<ExecutionStatus> => {
|
|
145
|
+
const checkStatus = async (): Promise<Teraslice.ExecutionStatus> => {
|
|
161
146
|
let result;
|
|
162
147
|
try {
|
|
163
148
|
result = await this.status(options);
|
|
@@ -212,11 +197,16 @@ function validateExId(exId?: string) {
|
|
|
212
197
|
}
|
|
213
198
|
}
|
|
214
199
|
|
|
215
|
-
function filterProcesses<T>(
|
|
200
|
+
function filterProcesses<T>(
|
|
201
|
+
state: Teraslice.ClusterState,
|
|
202
|
+
exId: string,
|
|
203
|
+
type: Teraslice.Assignment
|
|
204
|
+
) {
|
|
216
205
|
const results: T[] = [];
|
|
217
206
|
|
|
218
207
|
for (const node of Object.values(state)) {
|
|
219
|
-
|
|
208
|
+
// TODO: fixme
|
|
209
|
+
node.active.forEach((child: any) => {
|
|
220
210
|
const { assignment, ex_id: procExId } = child;
|
|
221
211
|
if ((assignment && assignment === type) && (procExId && procExId === exId)) {
|
|
222
212
|
const jobProcess = Object.assign({}, child, { node_id: node.node_id });
|
package/src/executions.ts
CHANGED
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
isString,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TSError,
|
|
6
|
-
unset
|
|
7
|
-
} from '@terascope/job-components';
|
|
2
|
+
isString, isPlainObject, TSError, unset
|
|
3
|
+
} from '@terascope/utils';
|
|
4
|
+
import { Teraslice } from '@terascope/types';
|
|
8
5
|
import autoBind from 'auto-bind';
|
|
9
6
|
import Client from './client';
|
|
10
7
|
import Ex from './ex';
|
|
11
8
|
|
|
12
|
-
import {
|
|
13
|
-
ClientConfig,
|
|
14
|
-
SearchQuery,
|
|
15
|
-
SearchOptions,
|
|
16
|
-
StateErrors,
|
|
17
|
-
Execution,
|
|
18
|
-
JobIDResponse,
|
|
19
|
-
} from './interfaces';
|
|
9
|
+
import { ClientConfig, SearchOptions } from './interfaces';
|
|
20
10
|
|
|
21
|
-
type ListOptions = undefined | string | SearchQuery;
|
|
11
|
+
type ListOptions = undefined | string | Teraslice.SearchQuery;
|
|
22
12
|
|
|
23
13
|
export default class Executions extends Client {
|
|
24
14
|
constructor(config: ClientConfig) {
|
|
@@ -29,13 +19,13 @@ export default class Executions extends Client {
|
|
|
29
19
|
/**
|
|
30
20
|
* Similar to jobs.submit but returns an instance of Ex not a Job
|
|
31
21
|
*/
|
|
32
|
-
async submit(jobSpec: JobConfig, shouldNotStart?: boolean): Promise<Ex> {
|
|
22
|
+
async submit(jobSpec: Teraslice.JobConfig, shouldNotStart?: boolean): Promise<Ex> {
|
|
33
23
|
if (!jobSpec) {
|
|
34
24
|
throw new TSError('Submit requires a jobSpec', {
|
|
35
25
|
statusCode: 400
|
|
36
26
|
});
|
|
37
27
|
}
|
|
38
|
-
const job:
|
|
28
|
+
const job: Teraslice.ApiJobCreateResponse = await this.post('/jobs', jobSpec, {
|
|
39
29
|
searchParams: { start: !shouldNotStart }
|
|
40
30
|
});
|
|
41
31
|
// support older version of teraslice
|
|
@@ -43,16 +33,20 @@ export default class Executions extends Client {
|
|
|
43
33
|
const { ex_id: exId } = await this.get(`/jobs/${job.job_id}/ex`);
|
|
44
34
|
return this.wrap(exId);
|
|
45
35
|
}
|
|
36
|
+
|
|
46
37
|
return this.wrap(job.ex_id);
|
|
47
38
|
}
|
|
48
39
|
|
|
49
|
-
async list(options?: ListOptions): Promise<
|
|
40
|
+
async list(options?: ListOptions): Promise<Teraslice.ExecutionRecord[]> {
|
|
50
41
|
const query = _parseListOptions(options);
|
|
51
42
|
return this.get('/ex', { searchParams: query } as SearchOptions);
|
|
52
43
|
}
|
|
53
44
|
|
|
54
|
-
async errors(
|
|
55
|
-
|
|
45
|
+
async errors(
|
|
46
|
+
exId?: string | Teraslice.SearchQuery,
|
|
47
|
+
opts?: Teraslice.SearchQuery
|
|
48
|
+
): Promise<Teraslice.ErrorRecord[]> {
|
|
49
|
+
const options: Teraslice.SearchQuery = {};
|
|
56
50
|
if (isString(exId)) {
|
|
57
51
|
if (isPlainObject(opts)) {
|
|
58
52
|
options.searchParams = opts;
|
|
@@ -77,7 +71,7 @@ export default class Executions extends Client {
|
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
function _parseListOptions(options: ListOptions): SearchQuery {
|
|
74
|
+
function _parseListOptions(options: ListOptions): Teraslice.SearchQuery {
|
|
81
75
|
// support legacy
|
|
82
76
|
if (!options) return {};
|
|
83
77
|
if (isString(options)) {
|