Skip to content

Commit

Permalink
Apply to StartTransformRequest
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Nov 26, 2024
1 parent ae9fa1b commit b5d4043
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@

package org.opensearch.indexmanagement.transform.action.start

import org.opensearch.action.ActionRequest
import org.opensearch.action.ActionRequestValidationException
import org.opensearch.action.ValidateActions.addValidationError
import org.opensearch.action.update.UpdateRequest
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import java.io.IOException

class StartTransformRequest : UpdateRequest {
class StartTransformRequest : ActionRequest {

val id: String
get() = field

@Throws(IOException::class)
constructor(sin: StreamInput) : super(sin)
constructor(sin: StreamInput) : super(sin) {
this.id = sin.readString()
}

constructor(id: String) {
super.id(id)
this.id = id
}

override fun validate(): ActionRequestValidationException? {
var validationException: ActionRequestValidationException? = null
if (super.id().isEmpty()) {
if (this.id.isEmpty()) {
validationException = addValidationError("id is missing", validationException)
}
return validationException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ constructor(
ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT,
)}",
)
val getRequest = GetRequest(INDEX_MANAGEMENT_INDEX, request.id())
val getRequest = GetRequest(INDEX_MANAGEMENT_INDEX, request.id)
val user = buildUser(client.threadPool().threadContext)
client.threadPool().threadContext.stashContext().use {
client.get(
Expand Down Expand Up @@ -117,7 +117,8 @@ constructor(
actionListener: ActionListener<AcknowledgedResponse>,
) {
val now = Instant.now().toEpochMilli()
request.index(INDEX_MANAGEMENT_INDEX).doc(
val updateReq = UpdateRequest(INDEX_MANAGEMENT_INDEX, request.id)
updateReq.doc(
mapOf(
Transform.TRANSFORM_TYPE to
mapOf(
Expand All @@ -127,7 +128,7 @@ constructor(
),
)
client.update(
request,
updateReq,
object : ActionListener<UpdateResponse> {
override fun onResponse(response: UpdateResponse) {
if (response.result == DocWriteResponse.Result.UPDATED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ class RequestTests : OpenSearchTestCase() {

fun `test start transform request`() {
val id = "some_id"
val req = StartTransformRequest(id).index(INDEX_MANAGEMENT_INDEX)
val req = UpdateRequest(INDEX_MANAGEMENT_INDEX, id)

val out = BytesStreamOutput().apply { req.writeTo(this) }
val streamedReq = StartTransformRequest(buildStreamInputForTransforms(out))

assertEquals(id, streamedReq.id())
assertEquals(id, streamedReq.id)
}

fun `test stop transform request`() {
Expand Down

0 comments on commit b5d4043

Please sign in to comment.