Skip to content

Commit 6341e87

Browse files
dblocknhtruong
andauthored
Added specs and tests for /_plugins/_transform. (#722)
Signed-off-by: dblock <[email protected]> Signed-off-by: Theo N. Truong <[email protected]> Co-authored-by: Theo N. Truong <[email protected]>
1 parent 2539457 commit 6341e87

File tree

7 files changed

+343
-51
lines changed

7 files changed

+343
-51
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3030
- Added schema for `/_plugins/_knn/stats`, `/_plugins/_knn/models/{model_id}`, `_train` and `_search` ([#704](https://github.com/opensearch-project/opensearch-api-specification/pull/704))
3131
- Added `retry` support in `prologues` and `epilogues` ([#713](https://github.com/opensearch-project/opensearch-api-specification/pull/713))
3232
- Added response schema for `DELETE /_plugins/_rollup/jobs/{id}`, `POST /_plugins/_rollup/jobs/{id}/_start` and `_stop` ([#716](https://github.com/opensearch-project/opensearch-api-specification/pull/716))
33+
- Added response schema for `PUT` and `DELETE /_plugins/_transform/{id}` ([#722](https://github.com/opensearch-project/opensearch-api-specification/pull/716))
3334
- Added response schema for `GET /_plugins/_knn/warmup/{index}` ([#717](https://github.com/opensearch-project/opensearch-api-specification/pull/717))
3435

3536
### Removed

spec/namespaces/transforms.yaml

+16-10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ paths:
4848
requestBody:
4949
$ref: '#/components/requestBodies/transforms.put'
5050
responses:
51+
'201':
52+
$ref: '#/components/responses/transforms.put@201'
5153
'200':
5254
$ref: '#/components/responses/transforms.put@200'
5355
delete:
@@ -120,17 +122,12 @@ components:
120122
content:
121123
application/json:
122124
schema:
123-
type: object
124-
properties:
125-
transform:
126-
$ref: '../schemas/transforms._common.yaml#/components/schemas/Transform'
127-
required:
128-
- transform
125+
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformRequest'
129126
transforms.put:
130127
content:
131128
application/json:
132129
schema:
133-
$ref: '../schemas/transforms._common.yaml#/components/schemas/Transform'
130+
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformRequest'
134131
responses:
135132
transforms.search@200:
136133
content:
@@ -141,13 +138,22 @@ components:
141138
content:
142139
application/json:
143140
schema:
144-
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformEntity'
141+
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformResponse'
145142
transforms.put@200:
146143
content:
147144
application/json:
148145
schema:
149-
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformEntity'
150-
transforms.delete@200: {}
146+
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformResponse'
147+
transforms.put@201:
148+
content:
149+
application/json:
150+
schema:
151+
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformResponse'
152+
transforms.delete@200:
153+
content:
154+
application/json:
155+
schema:
156+
$ref: '../schemas/transforms._common.yaml#/components/schemas/DeleteTransformsResponse'
151157
transforms.start@200:
152158
content:
153159
application/json:

spec/schemas/transforms._common.yaml

+78-41
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@ info:
55
version: 1.0.0
66
components:
77
schemas:
8-
TransformEntity:
8+
TransformRequest:
9+
type: object
10+
properties:
11+
transform:
12+
$ref: '#/components/schemas/Transform'
13+
required:
14+
- transform
15+
TransformResponse:
916
type: object
1017
properties:
1118
_id:
12-
type: string
13-
_seqNo:
14-
type: number
15-
_primaryTerm:
16-
type: number
19+
$ref: '_common.yaml#/components/schemas/Id'
20+
_primary_term:
21+
type: integer
22+
format: int64
23+
_seq_no:
24+
$ref: '_common.yaml#/components/schemas/SequenceNumber'
25+
_version:
26+
$ref: '_common.yaml#/components/schemas/VersionNumber'
1727
transform:
1828
$ref: '#/components/schemas/Transform'
1929
TransformsResponse:
@@ -24,7 +34,58 @@ components:
2434
transforms:
2535
type: array
2636
items:
27-
$ref: '#/components/schemas/TransformEntity'
37+
$ref: '#/components/schemas/TransformResponse'
38+
DeleteTransformsResponse:
39+
type: object
40+
properties:
41+
took:
42+
type: integer
43+
format: int64
44+
errors:
45+
type: boolean
46+
items:
47+
type: array
48+
items:
49+
$ref: '#/components/schemas/DeleteTransformResponseItem'
50+
DeleteTransformResponseItem:
51+
type: object
52+
properties:
53+
delete:
54+
$ref: '#/components/schemas/DeletedTransformResponse'
55+
DeletedTransformResponse:
56+
type: object
57+
properties:
58+
_type:
59+
$ref: '_common.yaml#/components/schemas/Type'
60+
_index:
61+
type: string
62+
_id:
63+
$ref: '_common.yaml#/components/schemas/Id'
64+
_version:
65+
$ref: '_common.yaml#/components/schemas/VersionNumber'
66+
result:
67+
type: string
68+
forced_refresh:
69+
type: boolean
70+
_shards:
71+
$ref: '_common.yaml#/components/schemas/ShardStatistics'
72+
_primary_term:
73+
type: integer
74+
format: int64
75+
_seq_no:
76+
$ref: '_common.yaml#/components/schemas/SequenceNumber'
77+
status:
78+
type: number
79+
required:
80+
- _id
81+
- _index
82+
- _primary_term
83+
- _seq_no
84+
- _shards
85+
- _version
86+
- forced_refresh
87+
- result
88+
- status
2889
Transform:
2990
type: object
3091
properties:
@@ -37,13 +98,13 @@ components:
3798
schedule:
3899
$ref: '#/components/schemas/Schedule'
39100
metadata_id:
40-
type: string
101+
type: ['null', string]
41102
updated_at:
42-
type: string
103+
type: number
43104
enabled:
44105
type: boolean
45106
enabled_at:
46-
type: number
107+
type: ['null', number]
47108
description:
48109
type: string
49110
source_index:
@@ -63,9 +124,9 @@ components:
63124
items:
64125
$ref: '#/components/schemas/GroupsConfigItem'
65126
aggregations:
66-
type: array
67-
items:
68-
$ref: '#/components/schemas/MetricsConfigItem'
127+
type: object
128+
additionalProperties:
129+
$ref: '#/components/schemas/GroupsConfigItem'
69130
ExplainResponse:
70131
type: object
71132
additionalProperties:
@@ -74,9 +135,11 @@ components:
74135
type: object
75136
properties:
76137
metadata_id:
77-
type: string
138+
type: ['null', string]
78139
transform_metadata:
79-
$ref: '#/components/schemas/TransformMetadata'
140+
oneOf:
141+
- $ref: '#/components/schemas/TransformMetadata'
142+
- type: 'null'
80143
Preview:
81144
type: object
82145
properties:
@@ -140,32 +203,6 @@ components:
140203
type: string
141204
target_field:
142205
type: string
143-
MetricsConfigItem:
144-
type: object
145-
properties:
146-
source_field:
147-
type: string
148-
target_field:
149-
type: string
150-
metrics:
151-
type: array
152-
items:
153-
$ref: '#/components/schemas/MetricsConfigMetrics'
154-
MetricsConfigMetrics:
155-
type: object
156-
properties:
157-
avg:
158-
type: object
159-
sum:
160-
type: object
161-
max:
162-
type: object
163-
min:
164-
type: object
165-
value_count:
166-
type: object
167-
minProperties: 1
168-
maxProperties: 1
169206
ContinuousStats:
170207
type: object
171208
properties:
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
$schema: ../../../json_schemas/test_story.schema.yaml
2+
3+
description: Test transform jobs.
4+
prologues:
5+
- path: /{index}/_doc
6+
method: POST
7+
parameters:
8+
index: movies
9+
refresh: true
10+
request:
11+
payload:
12+
title: Beauty and the Beast
13+
year: 91
14+
status: [201]
15+
epilogues:
16+
- path: /_plugins/_transform/movies-to-films
17+
method: DELETE
18+
status: [200, 404]
19+
- path: /movies
20+
method: DELETE
21+
status: [200, 404]
22+
chapters:
23+
- synopsis: Create a transform job.
24+
id: transform
25+
path: /_plugins/_transform/{id}
26+
method: PUT
27+
parameters:
28+
id: movies-to-films
29+
request:
30+
payload:
31+
transform:
32+
enabled: false
33+
description: A transform.
34+
source_index: movies
35+
target_index: films
36+
data_selection_query:
37+
match_all: {}
38+
page_size: 10
39+
groups:
40+
- terms:
41+
source_field: year
42+
target_field: produced
43+
schedule:
44+
interval:
45+
period: 1
46+
unit: Minutes
47+
start_time: 1602100553
48+
response:
49+
status: 201
50+
output:
51+
primary_term: payload._primary_term
52+
seq_no: payload._seq_no
53+
- synopsis: Update a transform job.
54+
path: /_plugins/_transform/{id}
55+
method: PUT
56+
parameters:
57+
id: movies-to-films
58+
if_primary_term: ${transform.primary_term}
59+
if_seq_no: ${transform.seq_no}
60+
request:
61+
payload:
62+
transform:
63+
enabled: false
64+
description: A transform.
65+
source_index: movies
66+
target_index: films
67+
data_selection_query:
68+
match_all: {}
69+
page_size: 10
70+
groups:
71+
- terms:
72+
source_field: year
73+
target_field: produced
74+
schedule:
75+
interval:
76+
period: 1
77+
unit: Minutes
78+
start_time: 1602100553
79+
response:
80+
status: 200
81+
- synopsis: Get transform jobs.
82+
path: /_plugins/_transform
83+
method: GET
84+
- synopsis: Get a transform job.
85+
path: /_plugins/_transform/{id}
86+
method: GET
87+
parameters:
88+
id: movies-to-films
89+
- synopsis: Delete a transform job.
90+
path: /_plugins/_transform/{id}
91+
method: DELETE
92+
parameters:
93+
id: movies-to-films
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
$schema: ../../../../json_schemas/test_story.schema.yaml
2+
3+
description: Test explaining a transform job.
4+
prologues:
5+
- path: /{index}/_doc
6+
method: POST
7+
parameters:
8+
index: movies
9+
refresh: true
10+
request:
11+
payload:
12+
title: Beauty and the Beast
13+
year: 91
14+
status: [201]
15+
- path: /_plugins/_transform/movies-to-films
16+
method: PUT
17+
request:
18+
payload:
19+
transform:
20+
enabled: false
21+
description: A transform.
22+
source_index: movies
23+
target_index: films
24+
data_selection_query:
25+
match_all: {}
26+
page_size: 10
27+
groups:
28+
- terms:
29+
source_field: year
30+
target_field: produced
31+
schedule:
32+
interval:
33+
period: 1
34+
unit: Minutes
35+
start_time: 1602100553
36+
status: [201]
37+
epilogues:
38+
- path: /_plugins/_transform/movies-to-films
39+
parameters:
40+
force: true
41+
method: DELETE
42+
status: [200, 404]
43+
- path: /movies
44+
method: DELETE
45+
status: [200, 404]
46+
chapters:
47+
- synopsis: Explain a transform job.
48+
path: /_plugins/_transform/{id}/_explain
49+
method: GET
50+
parameters:
51+
id: movies-to-films

0 commit comments

Comments
 (0)