forked from opensearch-project/index-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replica Count Validation when awareness replica balance is enabled (o…
…pensearch-project#429) (opensearch-project#463) * bump version to 2.2 (opensearch-project#446) Signed-off-by: Ashish Agrawal <[email protected]> * Replica Count validation when awareness replica balance is enabled Signed-off-by: Gaurav Bafna <[email protected]> * Addressing PR comments Signed-off-by: Gaurav Bafna <[email protected]> Signed-off-by: Ashish Agrawal <[email protected]> Signed-off-by: Gaurav Bafna <[email protected]> Co-authored-by: Ashish Agrawal <[email protected]> (cherry picked from commit f64c0c7) Co-authored-by: Gaurav Bafna <[email protected]>
- Loading branch information
1 parent
adfff8e
commit 2adc30f
Showing
2 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
.../kotlin/org/opensearch/indexmanagement/indexstatemanagement/action/IndexPolicyActionIT.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.indexstatemanagement.action | ||
|
||
import org.apache.http.entity.ContentType | ||
import org.apache.http.entity.StringEntity | ||
import org.junit.Assert | ||
import org.opensearch.client.ResponseException | ||
import org.opensearch.cluster.routing.allocation.AwarenessReplicaBalance | ||
import org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider | ||
import org.opensearch.indexmanagement.IndexManagementPlugin | ||
import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase | ||
import org.opensearch.indexmanagement.indexstatemanagement.model.Policy | ||
import org.opensearch.indexmanagement.indexstatemanagement.model.State | ||
import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification | ||
import org.opensearch.indexmanagement.indexstatemanagement.toJsonString | ||
import org.opensearch.indexmanagement.makeRequest | ||
import java.time.Instant | ||
import java.time.temporal.ChronoUnit | ||
import java.util.Locale | ||
|
||
class IndexPolicyActionIT : IndexStateManagementRestTestCase() { | ||
private val testIndexName = javaClass.simpleName.toLowerCase(Locale.ROOT) | ||
|
||
fun `test allocation aware replica count`() { | ||
val policyID = "${testIndexName}_testPolicyName_replica" | ||
var actionConfig = ReplicaCountAction(3, 0) | ||
var states = listOf(State(name = "ReplicaCountState", actions = listOf(actionConfig), transitions = listOf())) | ||
updateClusterSetting(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.key, "true") | ||
updateClusterSetting(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.key, "zone") | ||
|
||
// creates a dummy policy , so that ISM index gets initialized | ||
var policy = Policy( | ||
id = policyID, | ||
description = "$testIndexName description", | ||
schemaVersion = 1L, | ||
lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), | ||
errorNotification = randomErrorNotification(), | ||
defaultState = states[0].name, | ||
states = states | ||
) | ||
client().makeRequest( | ||
"PUT", | ||
"${IndexManagementPlugin.POLICY_BASE_URI}/init-index", | ||
emptyMap(), | ||
StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON) | ||
) | ||
|
||
updateClusterSetting(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.key + "zone.values", "a, b") | ||
|
||
// Valid replica count, shouldn't throw exception | ||
client().makeRequest( | ||
"PUT", | ||
"${IndexManagementPlugin.POLICY_BASE_URI}/$policyID", | ||
emptyMap(), | ||
StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON) | ||
) | ||
|
||
actionConfig = ReplicaCountAction(4, 0) | ||
states = listOf(State(name = "ReplicaCountState", actions = listOf(actionConfig), transitions = listOf())) | ||
policy = Policy( | ||
id = policyID, | ||
description = "$testIndexName description", | ||
schemaVersion = 1L, | ||
lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), | ||
errorNotification = randomErrorNotification(), | ||
defaultState = states[0].name, | ||
states = states | ||
) | ||
Assert.assertThrows( | ||
ResponseException::class.java | ||
) { | ||
client().makeRequest( | ||
"PUT", | ||
"${IndexManagementPlugin.POLICY_BASE_URI}/$policyID", | ||
emptyMap(), | ||
StringEntity(policy.toJsonString(), ContentType.APPLICATION_JSON) | ||
) | ||
} | ||
|
||
// clean up cluster settings | ||
updateClusterSetting(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.key, "true") | ||
updateClusterSetting(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.key, "") | ||
updateClusterSetting(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.key + "zone", "") | ||
} | ||
} |