HDFS-17449. Fix ill-formed decommission host name and port pair triggers IndexOutOfBound error (#6691). Contributed by ConfX

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
ConfX 2024-04-06 16:08:09 +08:00 committed by GitHub
parent a1ae35e691
commit 73e6931ed0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -106,6 +106,10 @@ public void initOutOfServiceHosts(List<String> decommissionHostNameAndPorts,
for (String hostNameAndPort : decommissionHostNameAndPorts) { for (String hostNameAndPort : decommissionHostNameAndPorts) {
DatanodeAdminProperties dn = new DatanodeAdminProperties(); DatanodeAdminProperties dn = new DatanodeAdminProperties();
String[] hostAndPort = hostNameAndPort.split(":"); String[] hostAndPort = hostNameAndPort.split(":");
if (hostAndPort.length != 2) {
throw new IllegalArgumentException("The decommision host name and port format is "
+ "invalid. The format should be in <host>:<port>, not " + hostNameAndPort);
}
dn.setHostName(hostAndPort[0]); dn.setHostName(hostAndPort[0]);
dn.setPort(Integer.parseInt(hostAndPort[1])); dn.setPort(Integer.parseInt(hostAndPort[1]));
dn.setAdminState(AdminStates.DECOMMISSIONED); dn.setAdminState(AdminStates.DECOMMISSIONED);