-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Removed recursion from Explain Action to avoid stackoverflow in some situations (#419) * enabled by default integrated * Fix Test cases * Fix comments; set validation disabled by default * Rename validation_service to action_validation; Fix some detekt issues Signed-off-by: Joanne Wang <[email protected]> Signed-off-by: Petar Dzepina <[email protected]> Signed-off-by: Angie Zhang <[email protected]> Co-authored-by: Joanne Wang <[email protected]> Co-authored-by: Petar <[email protected]> Co-authored-by: Angie Zhang <[email protected]>
- Loading branch information
1 parent
8f78467
commit 57544c3
Showing
60 changed files
with
1,904 additions
and
50 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Validate.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,46 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.spi.indexstatemanagement | ||
|
||
import org.opensearch.cluster.service.ClusterService | ||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.common.io.stream.Writeable | ||
import org.opensearch.common.settings.Settings | ||
import org.opensearch.monitor.jvm.JvmService | ||
import java.util.Locale | ||
|
||
abstract class Validate( | ||
val settings: Settings, | ||
val clusterService: ClusterService, | ||
val jvmService: JvmService | ||
) { | ||
|
||
var validationStatus = ValidationStatus.PASSED | ||
var validationMessage: String? = "Starting Validation" | ||
|
||
abstract fun execute(indexName: String): Validate | ||
|
||
enum class ValidationStatus(val status: String) : Writeable { | ||
PASSED("passed"), | ||
RE_VALIDATING("re_validating"), | ||
FAILED("failed"); | ||
|
||
override fun toString(): String { | ||
return status | ||
} | ||
|
||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(status) | ||
} | ||
|
||
companion object { | ||
fun read(streamInput: StreamInput): ValidationStatus { | ||
return valueOf(streamInput.readString().uppercase(Locale.ROOT)) | ||
} | ||
} | ||
} | ||
} |
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
94 changes: 94 additions & 0 deletions
94
.../kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/model/ValidationResult.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,94 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.indexmanagement.spi.indexstatemanagement.model | ||
|
||
import org.opensearch.common.Strings | ||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.common.io.stream.Writeable | ||
import org.opensearch.common.xcontent.LoggingDeprecationHandler | ||
import org.opensearch.common.xcontent.NamedXContentRegistry | ||
import org.opensearch.common.xcontent.ToXContent | ||
import org.opensearch.common.xcontent.ToXContentFragment | ||
import org.opensearch.common.xcontent.XContentBuilder | ||
import org.opensearch.common.xcontent.XContentParser | ||
import org.opensearch.common.xcontent.XContentParserUtils | ||
import org.opensearch.common.xcontent.XContentType | ||
import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate | ||
import java.io.ByteArrayInputStream | ||
import java.nio.charset.StandardCharsets | ||
import java.util.Locale | ||
|
||
data class ValidationResult( | ||
val validationMessage: String, | ||
val validationStatus: Validate.ValidationStatus | ||
) : Writeable, ToXContentFragment { | ||
|
||
override fun writeTo(out: StreamOutput) { | ||
out.writeString(validationMessage) | ||
validationStatus.writeTo(out) | ||
} | ||
|
||
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { | ||
builder | ||
.field(VALIDATION_MESSAGE, validationMessage) | ||
.field(VALIDATION_STATUS, validationStatus.toString()) | ||
return builder | ||
} | ||
|
||
fun getMapValueString(): String { | ||
return Strings.toString(this, false, false) | ||
} | ||
|
||
companion object { | ||
const val VALIDATE = "validate" | ||
const val VALIDATION_MESSAGE = "validation_message" | ||
const val VALIDATION_STATUS = "validation_status" | ||
|
||
fun fromStreamInput(si: StreamInput): ValidationResult { | ||
val validationMessage: String? = si.readString() | ||
val validationStatus: Validate.ValidationStatus? = Validate.ValidationStatus.read(si) | ||
|
||
return ValidationResult( | ||
requireNotNull(validationMessage) { "$VALIDATION_MESSAGE is null" }, | ||
requireNotNull(validationStatus) { "$VALIDATION_STATUS is null" } | ||
) | ||
} | ||
|
||
fun fromManagedIndexMetaDataMap(map: Map<String, String?>): ValidationResult? { | ||
val stepJsonString = map[VALIDATE] | ||
return if (stepJsonString != null) { | ||
val inputStream = ByteArrayInputStream(stepJsonString.toByteArray(StandardCharsets.UTF_8)) | ||
val parser = XContentType.JSON.xContent().createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, inputStream) | ||
parser.nextToken() | ||
parse(parser) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
fun parse(xcp: XContentParser): ValidationResult { | ||
var validationMessage: String? = null | ||
var validationStatus: Validate.ValidationStatus? = null | ||
|
||
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) | ||
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { | ||
val fieldName = xcp.currentName() | ||
xcp.nextToken() | ||
|
||
when (fieldName) { | ||
VALIDATION_MESSAGE -> validationMessage = xcp.text() | ||
VALIDATION_STATUS -> validationStatus = Validate.ValidationStatus.valueOf(xcp.text().uppercase(Locale.ROOT)) | ||
} | ||
} | ||
|
||
return ValidationResult( | ||
requireNotNull(validationMessage) { "$VALIDATION_MESSAGE is null" }, | ||
requireNotNull(validationStatus) { "$VALIDATION_STATUS is null" } | ||
) | ||
} | ||
} | ||
} |
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.