AdyChechani commented on code in PR #10831:
URL: https://github.com/apache/ozone/pull/10831#discussion_r3668339002
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java:
##########
@@ -243,6 +243,52 @@ public static String getHostPortString(String host, int
port) {
return HostAndPort.fromParts(host, port).toString();
}
+ /**
+ * Parse a Ratis role string produced by
+ * {@code SCMRatisServerImpl.getRatisRoles()} into its constituent fields.
+ * The format is {@code [host]:port:ROLE:id:hostIP} where host and hostIP
+ * may be bracketed IPv6 literals.
+ *
+ * @param roleString the encoded role string
+ * @return a 5-element array: {host, port, role, id, hostIP}
+ */
+ public static String[] parseRatisRoleString(String roleString) {
+ // Parse from the right: the last field is hostIP (possibly bracketed),
+ // then id (uuid, no colons), then role (LEADER/FOLLOWER, no colons),
+ // and the remainder is host:port (which may be bracketed IPv6).
+ int idx = roleString.length();
+
+ // Field 5: hostIP — may be bracketed IPv6 like [2001:db8::1]
+ String hostIp;
+ if (idx > 0 && roleString.charAt(idx - 1) == ']') {
+ int bracket = roleString.lastIndexOf('[');
+ hostIp = roleString.substring(bracket + 1, idx - 1);
+ idx = bracket - 1; // skip the ':' before '['
+ } else {
+ int sep = roleString.lastIndexOf(':');
+ hostIp = roleString.substring(sep + 1);
+ idx = sep;
+ }
+
+ // Field 4: id (uuid or peer id, no colons)
+ int sep3 = roleString.lastIndexOf(':', idx - 1);
+ String id = roleString.substring(sep3 + 1, idx);
Review Comment:
the new changes use `Preconditions.checkArgument()`, which parses the Happy
path correctly and throws error on non-ratis strings
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]