/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ /* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ package org.opensearch.indexmanagement.indexstatemanagement.validation import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase import org.opensearch.indexmanagement.indexstatemanagement.action.IndexPriorityAction import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.model.State import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate import org.opensearch.indexmanagement.waitFor import java.time.Instant import java.time.temporal.ChronoUnit import java.util.Locale class ValidateIndexPriorityIT : IndexStateManagementRestTestCase() { private val testIndexName = javaClass.simpleName.lowercase(Locale.ROOT) fun `test basic index priority`() { val indexName = "${testIndexName}_index_1" val policyID = "${testIndexName}_testPolicyName_1" val actionConfig = IndexPriorityAction(50, 0) val states = listOf(State(name = "SetPriorityState", actions = listOf(actionConfig), transitions = listOf())) val policy = Policy( id = policyID, description = "$testIndexName description", schemaVersion = 1L, lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), errorNotification = randomErrorNotification(), defaultState = states[0].name, states = states ) createPolicy(policy, policyID) createIndex(indexName, policyID) val managedIndexConfig = getExistingManagedIndexConfig(indexName) // Change the runJob start time so the job will trigger in 2 seconds updateManagedIndexConfigStartTime(managedIndexConfig) // ism policy initialized waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(indexName).policyID) } // change the runJob start time to change index priority updateManagedIndexConfigStartTime(managedIndexConfig) waitFor { assertEquals("Index did not set index_priority to ${actionConfig.indexPriority}", actionConfig.indexPriority, getIndexPrioritySetting(indexName)) } waitFor { val data = getExplainValidationResult(indexName) assertEquals( "Index Priority action validation status is PASSED.", Validate.ValidationStatus.PASSED, data.validationStatus ) } } }