Copilot commented on code in PR #8955:
URL: https://github.com/apache/hadoop/pull/8955#discussion_r4495627509


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/NodeId.java:
##########
@@ -116,17 +117,25 @@ public int compareTo(NodeId other) {
   @Public
   @Stable
   public static NodeId fromString(String nodeIdStr) {
-    String[] parts = nodeIdStr.split(":");
-    if (parts.length != 2) {
+    // The port is always present, so the last colon separates it even when
+    // the host is an IPv6 literal, as in toString(). [ipv6]:port is accepted 
too.
+    int sep = nodeIdStr.lastIndexOf(':');
+    String host = nodeIdStr.substring(0, Math.max(sep, 0)).trim();
+    boolean bracketed = host.length() > 1 && host.startsWith("[") && 
host.endsWith("]");
+    if (bracketed) {
+      host = host.substring(1, host.length() - 1);
+    }
+    boolean ipv6 = host.contains(":");
+    // A bracketed host or a host with a colon must be an IPv6 literal.
+    if (sep < 0 || ((bracketed || ipv6) && !(ipv6 && 
InetAddresses.isInetAddress(host)))) {
       throw new IllegalArgumentException("Invalid NodeId [" + nodeIdStr
           + "]. Expected host:port");
     }
+    String port = nodeIdStr.substring(sep + 1);
     try {
-      NodeId nodeId =
-          NodeId.newInstance(parts[0].trim(), Integer.parseInt(parts[1]));
-      return nodeId;
+      return NodeId.newInstance(host, Integer.parseInt(port));

Review Comment:
   This now returns an IPv6 host without brackets, but 
`AggregatedLogsBlock.getApplicationLogURL()` still builds the NM URL as 
`NodeId.fromString(nodeId).getHost() + ":" + httpPort`. For a node such as 
`2001:db8::21:8041`, that produces `http://2001:db8::21:8042/...`, which is not 
a valid URI authority, so the aggregated-log page remains broken for the IPv6 
case this change is intended to fix. Format the host/port with 
`NetUtils.getHostPortString` (and update equivalent URL-building callers) 
before constructing the URL.



-- 
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]

Reply via email to