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.
Backport Issue opensearch-project#998 (opensearch-project#1067)
* Backport issue opensearch-project#998 to 2.x Signed-off-by: Joshua Au <[email protected]> * Issue651 tests (opensearch-project#1046) * Implemented filtering on the ISM eplain API Signed-off-by: Joshua Au <[email protected]> * Fixed tests for ExplainRequest Signed-off-by: Joshua Au <[email protected]> * Added filtering on query and metadata map Signed-off-by: Joshua Au <[email protected]> * Filtered on indexNames in metadata Signed-off-by: Joshua Au <[email protected]> * Fixed github workflow check errors Signed-off-by: Joshua Au <[email protected]> * Removed debugging comments Signed-off-by: Joshua Au <[email protected]> * Updated code styling to make more clear Signed-off-by: Joshua Au <[email protected]> * Refactored code to match suggestions Signed-off-by: Joshua Au <[email protected]> * Added test case for the ExplainFilter.byMetaData and parse methods Signed-off-by: Joshua Au <[email protected]> * Started implementation of explain filter IT Signed-off-by: Joshua Au <[email protected]> * Implemented test explain filter method Signed-off-by: Joshua Au <[email protected]> * Implemented explain filter test on failure Signed-off-by: Joshua Au <[email protected]> * Cleaned up log statements Signed-off-by: Joshua Au <[email protected]> * Added explain filter test for success Signed-off-by: Joshua Au <[email protected]> * Fixed lint errors Signed-off-by: Joshua Au <[email protected]> * Removed policy from index to fix flaky tests Signed-off-by: Joshua Au <[email protected]> --------- Signed-off-by: Joshua Au <[email protected]> Signed-off-by: bowenlan-amzn <[email protected]> Co-authored-by: bowenlan-amzn <[email protected]> * Fixed content type import Signed-off-by: Joshua Au <[email protected]> * Implemented filtering on the ISM eplain API (opensearch-project#998) * Implemented filtering on the ISM eplain API Signed-off-by: Joshua Au <[email protected]> * Fixed tests for ExplainRequest Signed-off-by: Joshua Au <[email protected]> * Added filtering on query and metadata map Signed-off-by: Joshua Au <[email protected]> * Filtered on indexNames in metadata Signed-off-by: Joshua Au <[email protected]> * Fixed github workflow check errors Signed-off-by: Joshua Au <[email protected]> * Removed debugging comments Signed-off-by: Joshua Au <[email protected]> * Updated code styling to make more clear Signed-off-by: Joshua Au <[email protected]> * Refactored code to match suggestions Signed-off-by: Joshua Au <[email protected]> --------- Signed-off-by: Joshua Au <[email protected]> Co-authored-by: bowenlan-amzn <[email protected]> * Issue651 tests (opensearch-project#1046) * Implemented filtering on the ISM eplain API Signed-off-by: Joshua Au <[email protected]> * Fixed tests for ExplainRequest Signed-off-by: Joshua Au <[email protected]> * Added filtering on query and metadata map Signed-off-by: Joshua Au <[email protected]> * Filtered on indexNames in metadata Signed-off-by: Joshua Au <[email protected]> * Fixed github workflow check errors Signed-off-by: Joshua Au <[email protected]> * Removed debugging comments Signed-off-by: Joshua Au <[email protected]> * Updated code styling to make more clear Signed-off-by: Joshua Au <[email protected]> * Refactored code to match suggestions Signed-off-by: Joshua Au <[email protected]> * Added test case for the ExplainFilter.byMetaData and parse methods Signed-off-by: Joshua Au <[email protected]> * Started implementation of explain filter IT Signed-off-by: Joshua Au <[email protected]> * Implemented test explain filter method Signed-off-by: Joshua Au <[email protected]> * Implemented explain filter test on failure Signed-off-by: Joshua Au <[email protected]> * Cleaned up log statements Signed-off-by: Joshua Au <[email protected]> * Added explain filter test for success Signed-off-by: Joshua Au <[email protected]> * Fixed lint errors Signed-off-by: Joshua Au <[email protected]> * Removed policy from index to fix flaky tests Signed-off-by: Joshua Au <[email protected]> --------- Signed-off-by: Joshua Au <[email protected]> Signed-off-by: bowenlan-amzn <[email protected]> Co-authored-by: bowenlan-amzn <[email protected]> * Backport explain filter tests * Sleep thread to allow jobs to finish Signed-off-by: Joshua Au <[email protected]> --------- Signed-off-by: Joshua Au <[email protected]> Signed-off-by: bowenlan-amzn <[email protected]> Co-authored-by: bowenlan-amzn <[email protected]>
- Loading branch information
1 parent
e5997e8
commit d65545a
Showing
12 changed files
with
536 additions
and
24 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/model/ExplainFilter.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,131 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.indexstatemanagement.model | ||
|
||
import org.opensearch.core.common.io.stream.StreamInput | ||
import org.opensearch.core.common.io.stream.StreamOutput | ||
import org.opensearch.core.common.io.stream.Writeable | ||
import org.opensearch.core.xcontent.ToXContent | ||
import org.opensearch.core.xcontent.ToXContentObject | ||
import org.opensearch.core.xcontent.XContentBuilder | ||
import org.opensearch.core.xcontent.XContentParser | ||
import org.opensearch.core.xcontent.XContentParser.Token | ||
import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken | ||
import org.opensearch.index.query.BoolQueryBuilder | ||
import org.opensearch.index.query.QueryBuilders | ||
import org.opensearch.indexmanagement.indexstatemanagement.util.MANAGED_INDEX_POLICY_ID_FIELD | ||
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData | ||
import java.io.IOException | ||
|
||
data class ExplainFilter( | ||
val policyID: String? = null, | ||
val state: String? = null, | ||
val actionType: String? = null, | ||
val failed: Boolean? = null | ||
) : ToXContentObject, Writeable { | ||
|
||
@Throws(IOException::class) | ||
constructor(sin: StreamInput) : this( | ||
policyID = sin.readOptionalString(), | ||
state = sin.readOptionalString(), | ||
actionType = sin.readOptionalString(), | ||
failed = sin.readOptionalBoolean() | ||
) | ||
|
||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
builder.startObject() | ||
builder.startObject(FILTER_FIELD) | ||
|
||
if (policyID != null) builder.field(POLICY_ID_FIELD, policyID) | ||
if (state != null) builder.field(STATE_FIELD, state) | ||
if (actionType != null) builder.field(ACTION_FIELD, actionType) | ||
if (failed != null) builder.field(FAILED_FIELD, failed) | ||
|
||
builder.endObject() | ||
return builder.endObject() | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
out.writeOptionalString(policyID) | ||
out.writeOptionalString(state) | ||
out.writeOptionalString(actionType) | ||
out.writeOptionalBoolean(failed) | ||
} | ||
|
||
fun byMetaData(metaData: ManagedIndexMetaData): Boolean { | ||
var isValid = true | ||
|
||
val stateMetaData = metaData.stateMetaData | ||
if (state != null && (stateMetaData == null || stateMetaData.name != state)) { | ||
isValid = false | ||
} | ||
|
||
val actionMetaData = metaData.actionMetaData | ||
if (actionType != null && (actionMetaData == null || actionMetaData.name != actionType)) { | ||
isValid = false | ||
} | ||
|
||
val retryInfoMetaData = metaData.policyRetryInfo | ||
val actionFailedNotValid = actionMetaData == null || actionMetaData.failed != failed | ||
val retryFailedNotValid = retryInfoMetaData == null || retryInfoMetaData.failed != failed | ||
if (failed != null && actionFailedNotValid && retryFailedNotValid) { | ||
isValid = false | ||
} | ||
|
||
return isValid | ||
} | ||
|
||
companion object { | ||
const val FILTER_FIELD = "filter" | ||
const val POLICY_ID_FIELD = "policy_id" | ||
const val STATE_FIELD = "state" | ||
const val ACTION_FIELD = "action_type" | ||
const val FAILED_FIELD = "failed" | ||
|
||
@JvmStatic | ||
@Throws(IOException::class) | ||
fun parse(xcp: XContentParser): ExplainFilter { | ||
var policyID: String? = null | ||
var state: String? = null | ||
var actionType: String? = null | ||
var failed: Boolean? = null | ||
|
||
ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) | ||
while (xcp.nextToken() != Token.END_OBJECT) { | ||
val fieldName = xcp.currentName() | ||
xcp.nextToken() | ||
|
||
when (fieldName) { | ||
FILTER_FIELD -> { | ||
ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp) | ||
while (xcp.nextToken() != Token.END_OBJECT) { | ||
val filter = xcp.currentName() | ||
xcp.nextToken() | ||
|
||
when (filter) { | ||
POLICY_ID_FIELD -> policyID = xcp.text() | ||
STATE_FIELD -> state = xcp.text() | ||
ACTION_FIELD -> actionType = xcp.text() | ||
FAILED_FIELD -> failed = xcp.booleanValue() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return ExplainFilter(policyID, state, actionType, failed) | ||
} | ||
} | ||
} | ||
|
||
fun BoolQueryBuilder.filterByPolicyID(explainFilter: ExplainFilter?): BoolQueryBuilder { | ||
if (explainFilter?.policyID != null) { | ||
this.filter(QueryBuilders.termsQuery(MANAGED_INDEX_POLICY_ID_FIELD, explainFilter.policyID)) | ||
} | ||
|
||
return this | ||
} |
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
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
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
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
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
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
Oops, something went wrong.