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


##########
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:
   Fixed in 29b462e: `AggregatedLogsBlock.getApplicationLogURL()` now builds 
the NM address with `NetUtils.getHostPortString`, and takes the port after the 
last colon of the NM webapp address. 
`TestAggregatedLogsBlock#testApplicationLogUrlBracketsIPv6Host` covers it. The 
other `getHost() + ":"` builders do not go through `NodeId.fromString`, so they 
are left out of this PR.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
   



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