This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Adds support for dynamically updatable search analyzers #290
Merged
setiah
merged 14 commits into
opendistro-for-elasticsearch:master
from
setiah:hotreload2
Sep 12, 2020
Merged
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
40db035
Squashed commit of the following:
4703b95
Refactoring - API renaming
ae21bd4
Response parsing changes
c68d4bc
Fixed multinode response parsing issue
2f494ab
Refactoring and logging
387095a
Fixing klint errors
2f790fc
Adding UTs to validate stream parsing
b41ebcb
CR comments, code refactoring and more UTs
6c33bb6
Merge branch 'master' into hotreload2
dbbaughe 33330d4
Integ test fixes by enforcing refresh during ingestion
f4c8465
CR comments - reading shardResponses as List from inputStream
71234c6
API path change and few minor tweaks
4115f97
misc changes
02db791
Reverting action name to follow the code convention
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
29 changes: 29 additions & 0 deletions
29
...opendistroforelasticsearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerAction.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,29 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.indexmanagement.refreshanalyzer | ||
|
||
import org.elasticsearch.action.ActionType | ||
import org.elasticsearch.common.io.stream.Writeable | ||
|
||
class RefreshSearchAnalyzerAction : ActionType<RefreshSearchAnalyzerResponse>(NAME, reader) { | ||
companion object { | ||
const val NAME = "indices:admin/refresh_search_analyzer" | ||
val INSTANCE = RefreshSearchAnalyzerAction() | ||
val reader = Writeable.Reader { inp -> RefreshSearchAnalyzerResponse(inp) } | ||
} | ||
|
||
override fun getResponseReader(): Writeable.Reader<RefreshSearchAnalyzerResponse> = reader | ||
} |
27 changes: 27 additions & 0 deletions
27
...pendistroforelasticsearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerRequest.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,27 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.indexmanagement.refreshanalyzer | ||
|
||
import org.elasticsearch.action.support.broadcast.BroadcastRequest | ||
import org.elasticsearch.common.io.stream.StreamInput | ||
import java.io.IOException | ||
|
||
class RefreshSearchAnalyzerRequest : BroadcastRequest<RefreshSearchAnalyzerRequest> { | ||
constructor(vararg indices: String) : super(*indices) | ||
|
||
@Throws(IOException::class) | ||
constructor(inp: StreamInput) : super(inp) | ||
} |
136 changes: 136 additions & 0 deletions
136
...endistroforelasticsearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerResponse.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,136 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.indexmanagement.refreshanalyzer | ||
|
||
import org.apache.logging.log4j.LogManager | ||
import org.elasticsearch.action.support.DefaultShardOperationFailedException | ||
import org.elasticsearch.action.support.broadcast.BroadcastResponse | ||
import org.elasticsearch.common.io.stream.StreamInput | ||
import org.elasticsearch.common.io.stream.StreamOutput | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser | ||
import org.elasticsearch.common.xcontent.ToXContent.Params | ||
import org.elasticsearch.common.xcontent.XContentBuilder | ||
import org.elasticsearch.rest.action.RestActions | ||
import java.io.IOException | ||
import java.util.function.Function | ||
|
||
class RefreshSearchAnalyzerResponse : BroadcastResponse { | ||
|
||
private var results: MutableMap<String, List<String>> = HashMap() | ||
private var shardFailures: MutableList<FailedShardDetails> = mutableListOf() | ||
private var temp: List<DefaultShardOperationFailedException> = mutableListOf() | ||
|
||
protected var logger = LogManager.getLogger(javaClass) | ||
|
||
@Throws(IOException::class) | ||
constructor(inp: StreamInput) : super(inp) { | ||
val resultSize: Int = inp.readVInt() | ||
for (i in 0..resultSize) { | ||
results.put(inp.readString(), inp.readStringArray().toList()) | ||
} | ||
|
||
val failureSize: Int = inp.readVInt() | ||
for (i in 0..failureSize) { | ||
shardFailures.add(FailedShardDetails(inp.readString(), inp.readInt(), inp.readString())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Make FailedShardDetails writeable and just pass in the streaminput/output There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I wanted to do some refactoring on this but couldn't get to it earlier. It's done now, the new version does not use this class now. |
||
} | ||
} | ||
|
||
constructor( | ||
totalShards: Int, | ||
successfulShards: Int, | ||
failedShards: Int, | ||
shardFailures: List<DefaultShardOperationFailedException>, | ||
results: MutableMap<String, List<String>> | ||
) : super( | ||
totalShards, successfulShards, failedShards, shardFailures | ||
) { | ||
this.results = results | ||
this.temp = shardFailures | ||
for (failure in shardFailures) { | ||
qreshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.shardFailures.add(FailedShardDetails(failure.index()!!, failure.shardId(), failure.reason())) | ||
} | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun toXContent(builder: XContentBuilder, params: Params?): XContentBuilder? { | ||
builder.startObject() | ||
RestActions.buildBroadcastShardsHeader(builder, params, totalShards, successfulShards, -1, failedShards, null) | ||
|
||
builder.startArray("_successful") | ||
for (index in results.keys) { | ||
builder.startObject() | ||
val reloadedAnalyzers: List<String> = results.get(index)!! | ||
builder.field("index", index) | ||
builder.startArray("refreshed_analyzers") | ||
for (analyzer in reloadedAnalyzers) { | ||
builder.value(analyzer) | ||
} | ||
builder.endArray() | ||
builder.endObject() | ||
} | ||
builder.endArray() | ||
|
||
builder.startArray("_failed") | ||
for (failure in shardFailures) { | ||
builder.startObject() | ||
qreshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
builder.field("index", failure.index) | ||
builder.field("shardId", failure.shardId) | ||
builder.field("failureReason", failure.failureReason) | ||
builder.endObject() | ||
} | ||
builder.endArray() | ||
|
||
builder.endObject() | ||
return builder | ||
} | ||
|
||
companion object { | ||
private val PARSER = ConstructingObjectParser<RefreshSearchAnalyzerResponse, Void>("refresh_search_analyzer", true, | ||
Function { arg: Array<Any> -> | ||
val response = arg[0] as RefreshSearchAnalyzerResponse | ||
RefreshSearchAnalyzerResponse(response.totalShards, response.successfulShards, response.failedShards, | ||
response.temp, response.results) | ||
}) | ||
|
||
init { | ||
declareBroadcastFields(PARSER) | ||
} | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
super.writeTo(out) | ||
|
||
out.writeVInt(results.size) | ||
for ((key, value) in results.entries) { | ||
out.writeString(key) | ||
out.writeStringArray(value.toTypedArray()) | ||
} | ||
|
||
out.writeVInt(shardFailures.size) | ||
for (failure in shardFailures) { | ||
out.writeString(failure.index) | ||
out.writeInt(failure.shardId) | ||
out.writeString(failure.failureReason) | ||
} | ||
} | ||
|
||
class FailedShardDetails(index: String, shardId: Int, failureReason: String) { | ||
val index = index | ||
val shardId = shardId | ||
val failureReason = failureReason | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...troforelasticsearch/indexmanagement/refreshanalyzer/RefreshSearchAnalyzerShardResponse.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,44 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.indexmanagement.refreshanalyzer | ||
|
||
import org.elasticsearch.action.support.broadcast.BroadcastShardResponse | ||
import org.elasticsearch.common.io.stream.StreamInput | ||
import org.elasticsearch.common.io.stream.StreamOutput | ||
import org.elasticsearch.index.shard.ShardId | ||
import java.io.IOException | ||
|
||
class RefreshSearchAnalyzerShardResponse : BroadcastShardResponse { | ||
var indexName: String | ||
var reloadedAnalyzers: List<String> | ||
|
||
constructor(`in`: StreamInput) : super(`in`) { | ||
qreshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
indexName = `in`.readString() | ||
reloadedAnalyzers = `in`.readStringArray().toList() | ||
} | ||
|
||
constructor(shardId: ShardId?, indexName: String, reloadedAnalyzers: List<String>) : super(shardId) { | ||
this.indexName = indexName | ||
this.reloadedAnalyzers = reloadedAnalyzers | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun writeTo(out: StreamOutput) { | ||
super.writeTo(out) | ||
out.writeString(indexName) | ||
out.writeStringArray(reloadedAnalyzers.toTypedArray()) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...distroforelasticsearch/indexmanagement/refreshanalyzer/RestRefreshSearchAnalyzerAction.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,60 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.indexmanagement.refreshanalyzer | ||
|
||
import com.amazon.opendistroforelasticsearch.indexmanagement.IndexManagementPlugin.Companion.ANALYZER_BASE_URI | ||
import org.elasticsearch.client.node.NodeClient | ||
import org.elasticsearch.common.Strings | ||
import org.elasticsearch.rest.BaseRestHandler | ||
import org.elasticsearch.rest.RestHandler.Route | ||
import org.elasticsearch.rest.RestRequest | ||
import org.elasticsearch.rest.RestRequest.Method.POST | ||
import org.elasticsearch.rest.action.RestToXContentListener | ||
import java.io.IOException | ||
|
||
class RestRefreshSearchAnalyzerAction : BaseRestHandler() { | ||
|
||
override fun getName(): String = "refresh_search_analyzer_action" | ||
|
||
override fun routes(): List<Route> { | ||
return listOf( | ||
Route(POST, REFRESH_SYNONYM_ANALYZER_URI) | ||
) | ||
} | ||
|
||
// TODO: Add indicesOptions? | ||
|
||
@Throws(IOException::class) | ||
@Suppress("SpreadOperator") | ||
override fun prepareRequest(request: RestRequest, client: NodeClient): RestChannelConsumer { | ||
val indices: Array<String>? = Strings.splitStringByCommaToArray(request.param("index")) | ||
|
||
if (indices.isNullOrEmpty()) { | ||
throw IllegalArgumentException("Missing indices") | ||
} | ||
|
||
val refreshSearchAnalyzerRequest: RefreshSearchAnalyzerRequest = RefreshSearchAnalyzerRequest() | ||
.indices(*indices) | ||
|
||
return RestChannelConsumer { channel -> | ||
client.execute(RefreshSearchAnalyzerAction.INSTANCE, refreshSearchAnalyzerRequest, RestToXContentListener(channel)) | ||
} | ||
} | ||
|
||
companion object { | ||
const val REFRESH_SYNONYM_ANALYZER_URI = "$ANALYZER_BASE_URI/refresh_search_analyzer/{index}" | ||
dbbaughe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a common pattern you saw elsewhere for reading off streaminput?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does this constructor only take the streaminput in the format outputted by
writeTo
? if so, you can changewriteTo
to do something like:and then here you can read the list and pass a class reference to the element of the list (assuming it's
Writeable
)You can find a similar example of this in the Monitor data class for Alerting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found this pattern in BroadcastResponse.java, although the one that Mohammad suggested looks to be a better way. I have modified it in my latest commit. Thanks for the suggestion Mo!