Skip to content

Commit

Permalink
Added specs and test for /_plugins/_transform.
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock committed Dec 10, 2024
1 parent c0237fb commit 7e43836
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- 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))
- Added `retry` support in `prologues` and `epilogues` ([#713](https://github.com/opensearch-project/opensearch-api-specification/pull/713))
- 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))
- Added response schema for `PUT` and `DELETE /_plugins/_transform/{id}` ([#722](https://github.com/opensearch-project/opensearch-api-specification/pull/716))

### Removed
- Removed unsupported `_common.mapping:SourceField`'s `mode` field and associated `_common.mapping:SourceFieldMode` enum ([#652](https://github.com/opensearch-project/opensearch-api-specification/pull/652))
Expand Down
26 changes: 16 additions & 10 deletions spec/namespaces/transforms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ paths:
requestBody:
$ref: '#/components/requestBodies/transforms.put'
responses:
'201':
$ref: '#/components/responses/transforms.put@201'
'200':
$ref: '#/components/responses/transforms.put@200'
delete:
Expand Down Expand Up @@ -120,17 +122,12 @@ components:
content:
application/json:
schema:
type: object
properties:
transform:
$ref: '../schemas/transforms._common.yaml#/components/schemas/Transform'
required:
- transform
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformRequest'
transforms.put:
content:
application/json:
schema:
$ref: '../schemas/transforms._common.yaml#/components/schemas/Transform'
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformRequest'
responses:
transforms.search@200:
content:
Expand All @@ -141,13 +138,22 @@ components:
content:
application/json:
schema:
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformEntity'
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformResponse'
transforms.put@200:
content:
application/json:
schema:
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformEntity'
transforms.delete@200: {}
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformResponse'
transforms.put@201:
content:
application/json:
schema:
$ref: '../schemas/transforms._common.yaml#/components/schemas/TransformResponse'
transforms.delete@200:
content:
application/json:
schema:
$ref: '../schemas/transforms._common.yaml#/components/schemas/DeleteTransformsResponse'
transforms.start@200:
content:
application/json:
Expand Down
89 changes: 74 additions & 15 deletions spec/schemas/transforms._common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ info:
version: 1.0.0
components:
schemas:
TransformEntity:
TransformRequest:
type: object
properties:
transform:
$ref: '#/components/schemas/Transform'
required:
- transform
TransformResponse:
type: object
properties:
_id:
type: string
_seqNo:
type: number
_primaryTerm:
type: number
$ref: '_common.yaml#/components/schemas/Id'
_primary_term:
type: integer
format: int64
_seq_no:
$ref: '_common.yaml#/components/schemas/SequenceNumber'
_version:
$ref: '_common.yaml#/components/schemas/VersionNumber'
transform:
$ref: '#/components/schemas/Transform'
TransformsResponse:
Expand All @@ -24,7 +34,54 @@ components:
transforms:
type: array
items:
$ref: '#/components/schemas/TransformEntity'
$ref: '#/components/schemas/TransformResponse'
DeleteTransformsResponse:
type: object
properties:
took:
type: integer
format: int64
errors:
type: boolean
items:
type: array
items:
type: object
properties:
delete:
$ref: '#/components/schemas/DeletedTransformResponse'
DeletedTransformResponse:
type: object
properties:
_index:
type: string
_id:
$ref: '_common.yaml#/components/schemas/Id'
_version:
$ref: '_common.yaml#/components/schemas/VersionNumber'
result:
type: string
forced_refresh:
type: boolean
_shards:
$ref: '_common.yaml#/components/schemas/ShardStatistics'
_primary_term:
type: integer
format: int64
_seq_no:
$ref: '_common.yaml#/components/schemas/SequenceNumber'
status:
type: number
required:
- _id
- _index
- _primary_term
- _seq_no
- _shards
- _version
- forced_refresh
- result
- status
Transform:
type: object
properties:
Expand All @@ -37,13 +94,13 @@ components:
schedule:
$ref: '#/components/schemas/Schedule'
metadata_id:
type: string
type: ['null', string]
updated_at:
type: string
type: number
enabled:
type: boolean
enabled_at:
type: number
type: ['null', number]
description:
type: string
source_index:
Expand All @@ -63,9 +120,9 @@ components:
items:
$ref: '#/components/schemas/GroupsConfigItem'
aggregations:
type: array
items:
$ref: '#/components/schemas/MetricsConfigItem'
type: object
additionalProperties:
$ref: '#/components/schemas/GroupsConfigItem'
ExplainResponse:
type: object
additionalProperties:
Expand All @@ -74,9 +131,11 @@ components:
type: object
properties:
metadata_id:
type: string
type: ['null', string]
transform_metadata:
$ref: '#/components/schemas/TransformMetadata'
oneOf:
- $ref: '#/components/schemas/TransformMetadata'
- type: 'null'
Preview:
type: object
properties:
Expand Down
93 changes: 93 additions & 0 deletions tests/default/transforms/transform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
$schema: ../../../json_schemas/test_story.schema.yaml

description: Test transform jobs.
prologues:
- path: /{index}/_doc
method: POST
parameters:
index: movies
refresh: true
request:
payload:
title: Beauty and the Beast
year: 91
status: [201]
epilogues:
- path: /_plugins/_transform/movies-to-films
method: DELETE
status: [200, 404]
- path: /movies
method: DELETE
status: [200, 404]
chapters:
- synopsis: Create a transform job.
id: transform
path: /_plugins/_transform/{id}
method: PUT
parameters:
id: movies-to-films
request:
payload:
transform:
enabled: false
description: A transform.
source_index: movies
target_index: films
data_selection_query:
match_all: {}
page_size: 10
groups:
- terms:
source_field: year
target_field: produced
schedule:
interval:
period: 1
unit: Minutes
start_time: 1602100553
response:
status: 201
output:
primary_term: payload._primary_term
seq_no: payload._seq_no
- synopsis: Update a transform job.
path: /_plugins/_transform/{id}
method: PUT
parameters:
id: movies-to-films
if_primary_term: ${transform.primary_term}
if_seq_no: ${transform.seq_no}
request:
payload:
transform:
enabled: false
description: A transform.
source_index: movies
target_index: films
data_selection_query:
match_all: {}
page_size: 10
groups:
- terms:
source_field: year
target_field: produced
schedule:
interval:
period: 1
unit: Minutes
start_time: 1602100553
response:
status: 200
- synopsis: Get transform jobs.
path: /_plugins/_transform
method: GET
- synopsis: Get a transform job.
path: /_plugins/_transform/{id}
method: GET
parameters:
id: movies-to-films
- synopsis: Delete a transform job.
path: /_plugins/_transform/{id}
method: DELETE
parameters:
id: movies-to-films
51 changes: 51 additions & 0 deletions tests/default/transforms/transform/explain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$schema: ../../../../json_schemas/test_story.schema.yaml

description: Test explaining a transform job.
prologues:
- path: /{index}/_doc
method: POST
parameters:
index: movies
refresh: true
request:
payload:
title: Beauty and the Beast
year: 91
status: [201]
- path: /_plugins/_transform/movies-to-films
method: PUT
request:
payload:
transform:
enabled: false
description: A transform.
source_index: movies
target_index: films
data_selection_query:
match_all: {}
page_size: 10
groups:
- terms:
source_field: year
target_field: produced
schedule:
interval:
period: 1
unit: Minutes
start_time: 1602100553
status: [201]
epilogues:
- path: /_plugins/_transform/movies-to-films
parameters:
force: true
method: DELETE
status: [200, 404]
- path: /movies
method: DELETE
status: [200, 404]
chapters:
- synopsis: Explain a transform job.
path: /_plugins/_transform/{id}/_explain
method: GET
parameters:
id: movies-to-films
51 changes: 51 additions & 0 deletions tests/default/transforms/transform/start.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$schema: ../../../../json_schemas/test_story.schema.yaml

description: Test starting a transform job.
prologues:
- path: /{index}/_doc
method: POST
parameters:
index: movies
refresh: true
request:
payload:
title: Beauty and the Beast
year: 91
status: [201]
- path: /_plugins/_transform/movies-to-films
method: PUT
request:
payload:
transform:
enabled: false
description: A transform.
source_index: movies
target_index: films
data_selection_query:
match_all: {}
page_size: 10
groups:
- terms:
source_field: year
target_field: produced
schedule:
interval:
period: 1
unit: Minutes
start_time: 1602100553
status: [201]
epilogues:
- path: /_plugins/_transform/movies-to-films
parameters:
force: true
method: DELETE
status: [200, 404]
- path: /movies
method: DELETE
status: [200, 404]
chapters:
- synopsis: Start a transform job.
path: /_plugins/_transform/{id}/_start
method: POST
parameters:
id: movies-to-films
Loading

0 comments on commit 7e43836

Please sign in to comment.