-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extend cat api to get shards information for a specific index #18189
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
58b498f
extend cat api to get shards information for a specific index
kodjo-anipah 89946cf
add all possible shard states
kodjo-anipah 574059b
Merge branch 'master' into extend_cat_api_to_get_shards_info
kodjo-anipah 99a09c6
Merge branch 'master' into extend_cat_api_to_get_shards_info
kodjo-anipah c6349a4
add license header
kodjo-anipah 3e388c9
taking possible api changes into account
kodjo-anipah 775b3d7
enable jackson DeserializationFeature READ_UNKNOWN_ENUM_VALUES_USING_…
kodjo-anipah c3978bb
Merge branch 'master' into extend_cat_api_to_get_shards_info
kodjo-anipah ae4f044
manually map dto
kodjo-anipah 2bd429e
Merge branch 'master' into extend_cat_api_to_get_shards_info
kodjo-anipah d84cb1f
remove test
kodjo-anipah 78f3158
bit of refactoring & added integration test
kodjo-anipah 559dc70
move test
kodjo-anipah 8ac8309
deserialize ip as string
kodjo-anipah 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
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
71 changes: 71 additions & 0 deletions
71
graylog2-server/src/main/java/org/graylog2/indexer/indices/ShardsInfo.java
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,71 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.indexer.indices; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.commons.lang3.EnumUtils; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Locale; | ||
import java.util.function.Function; | ||
|
||
public record ShardsInfo(String index, int shard, ShardType shardType, State state, long docs, String store, InetAddress ip, String node ) { | ||
|
||
public static ShardsInfo create(JsonNode jsonNode) throws UnknownHostException { | ||
|
||
String index = jsonNode.get("index").asText(); | ||
int shard =jsonNode.get("shard").asInt(); | ||
|
||
String ipString = getValueOrDefault(jsonNode, "ip", JsonNode::asText, null); | ||
InetAddress ip = ipString != null ? InetAddress.getByName(ipString) : null; | ||
|
||
String store = getValueOrDefault(jsonNode, "store", JsonNode::asText, null); | ||
String node = getValueOrDefault(jsonNode, "node", JsonNode::asText, null); | ||
long docs = getValueOrDefault(jsonNode, "docs", JsonNode::asLong, 0L); | ||
|
||
State state = EnumUtils.getEnumIgnoreCase(State.class, jsonNode.get("state").asText(), State.UNKNOWN); | ||
ShardType shardType = ShardType.fromString(jsonNode.get("prirep").asText()); | ||
|
||
return new ShardsInfo(index, shard, shardType, state, docs, store, ip, node); | ||
} | ||
|
||
private static <T> T getValueOrDefault(JsonNode jsonNode, String nodeName, Function<JsonNode, T> valueConverter, T defaultValue) { | ||
return jsonNode.hasNonNull(nodeName) ? valueConverter.apply(jsonNode) : defaultValue; | ||
} | ||
|
||
public enum State { | ||
INITIALIZING, | ||
RELOCATING, | ||
UNASSIGNED, | ||
STARTED, | ||
UNKNOWN | ||
} | ||
|
||
public enum ShardType { | ||
PRIMARY, | ||
REPLICA, | ||
UNKNOWN; | ||
public static ShardType fromString(String value) { | ||
return switch (value.toLowerCase(Locale.ENGLISH)) { | ||
case "r" -> REPLICA; | ||
case "p" -> PRIMARY; | ||
default -> UNKNOWN; | ||
}; | ||
} | ||
} | ||
} |
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.
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.
I wonder if that's worth the complexity of having to handle UnknownHostException.
Couldn't we just return the string and let the consumer deal with potentially converting it?