Skip to content

Commit

Permalink
adding test case for aliased transform target index
Browse files Browse the repository at this point in the history
Signed-off-by: n-dohrmann <[email protected]>
  • Loading branch information
n-dohrmann committed Dec 6, 2023
1 parent 01bd3a2 commit ab17632
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ class TransformIndexer(
if (writeIndexMetadata == null) {
throw TransformIndexException("target_index [$targetIndex] is an alias but doesn't have write index")
}
val putMappingReq = PutMappingRequest(writeIndexMetadata?.index?.name).source(targetFieldMappings)
val putMappingReq = PutMappingRequest(writeIndexMetadata.index?.name).source(targetFieldMappings)
val mapResp: AcknowledgedResponse = client.admin().indices().suspendUntil {
putMapping(putMappingReq)
}
if (!mapResp.isAcknowledged) {
logger.error("Target index mapping request failed")
}
}

}

@Suppress("ThrowsCount", "RethrowCaughtException")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import org.opensearch.indexmanagement.waitFor
import org.opensearch.jobscheduler.spi.schedule.IntervalSchedule
import org.opensearch.rest.RestRequest
import org.opensearch.core.rest.RestStatus
import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_NUMBER_OF_REPLICAS
import org.opensearch.indexmanagement.indexstatemanagement.util.INDEX_NUMBER_OF_SHARDS
import org.opensearch.script.Script
import org.opensearch.script.ScriptType
import org.opensearch.search.aggregations.AggregationBuilders
Expand Down Expand Up @@ -1430,6 +1432,52 @@ class TransformRunnerIT : TransformRestTestCase() {
disableTransform(transform.id)
}

fun `test transform with wildcard, aliased target index`() {
validateSourceIndex("source-index")

// create alias
val indexAlias = "wildcard_index_alias"
val resolvedTargetIndex = "resolved_target_index"
val builtSettings = Settings.builder().let {
it.put(INDEX_NUMBER_OF_REPLICAS, 1)
it.put(INDEX_NUMBER_OF_SHARDS, 1)
it
}.build()
val aliases = "\"$indexAlias\": { \"is_write_index\": true }"
createIndex(resolvedTargetIndex, builtSettings, null, aliases)

refreshAllIndices()

val transform = Transform(
id = "id_18",
schemaVersion = 1L,
enabled = true,
enabledAt = Instant.now(),
updatedAt = Instant.now(),
jobSchedule = IntervalSchedule(Instant.now(), 1, ChronoUnit.MINUTES),
description = "test transform",
metadataId = null,
sourceIndex = "source-index",
targetIndex = indexAlias,
roles = emptyList(),
pageSize = 100,
groups = listOf(
Terms(sourceField = "store_and_fwd_flag", targetField = "flag")
)
).let { createTransform(it, it.id) }

updateTransformStartTime(transform)

waitFor { assertTrue("Target transform index was not created", indexExists(resolvedTargetIndex)) }

val metadata = waitFor {
val job = getTransform(transformId = transform.id)
assertNotNull("Transform job doesn't have metadata set", job.metadataId)
val transformMetadata = getTransformMetadata(job.metadataId!!)
assertEquals("Transform had not finished", TransformMetadata.Status.FINISHED, transformMetadata.status)
transformMetadata
}
}
private fun getStrictMappings(): String {
return """
"dynamic": "strict",
Expand Down

0 comments on commit ab17632

Please sign in to comment.