Skip to content

Commit

Permalink
transform role name to lower case to avoid confusion
Browse files Browse the repository at this point in the history
Signed-off-by: Yaliang Wu <ylwu@amazon.com>
  • Loading branch information
ylwu-amzn committed Jun 14, 2022
1 parent 836be1f commit 5101c9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
Expand Down Expand Up @@ -571,10 +572,12 @@ private static Map<String, DiscoveryNodeRole> rolesToMap(final Stream<DiscoveryN
private static Map<String, DiscoveryNodeRole> roleMap = rolesToMap(DiscoveryNodeRole.BUILT_IN_ROLES.stream());

public static DiscoveryNodeRole getRoleFromRoleName(final String roleName) {
if (roleMap.containsKey(roleName)) {
return roleMap.get(roleName);
//As we are supporting dynamic role, should make role name case-insensitive to avoid confusion of role name like "Data"/"DATA"
String lowerCasedRoleName = Objects.requireNonNull(roleName).toLowerCase(Locale.ROOT);
if (roleMap.containsKey(lowerCasedRoleName)) {
return roleMap.get(lowerCasedRoleName);
}
return new DiscoveryNodeRole.DynamicRole(roleName, roleName, false);
return new DiscoveryNodeRole.DynamicRole(lowerCasedRoleName, lowerCasedRoleName, false);
}

public static Set<DiscoveryNodeRole> getPossibleRoles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ private DiscoveryNodeRole(
) {
this.isKnownRole = isKnownRole;
this.isDynamicRole = isDynamicRole;
this.roleName = Objects.requireNonNull(roleName);
//As we are supporting dynamic role, should make role name case-insensitive to avoid confusion of role name like "Data"/"DATA"
this.roleName = Objects.requireNonNull(roleName).toLowerCase(Locale.ROOT);
this.roleNameAbbreviation = Objects.requireNonNull(roleNameAbbreviation);
this.canContainData = canContainData;
}
Expand Down

0 comments on commit 5101c9a

Please sign in to comment.