Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.DatanodeDetails.Port;
Expand Down Expand Up @@ -217,7 +218,7 @@ static String getClientRpcAddress(DatanodeDetails details) throws IOException {
throw new IOException(String.format("host: %s(%s) %s port not found",
details.getHostName(), details.getIpAddress(), Port.Name.CLIENT_RPC.name()));
}
return details.getIpAddress() + ":" + port.getValue();
return HddsUtils.getHostPortString(details.getIpAddress(), port.getValue());
}

/**
Expand All @@ -237,7 +238,7 @@ public static String getDatanodeHostAndIp(HddsProtos.DatanodeDetailsProto nodePr
.findFirst()
.orElse(HDDS_DATANODE_CLIENT_PORT_DEFAULT); // Default port if not found

String addressPort = ipAddress + ":" + port;
String addressPort = HddsUtils.getHostPortString(ipAddress, port);
if (hostname != null && !hostname.isEmpty() && !hostname.equals(ipAddress)) {
return hostname + " (" + addressPort + ")";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.DatanodeDetails.Port;
Expand Down Expand Up @@ -102,7 +103,7 @@ public static List<String> getAllOperableNodesClientRpcAddress(
}
Port port = details.getPort(Port.Name.CLIENT_RPC);
if (port != null) {
addresses.add(details.getIpAddress() + ":" + port.getValue());
addresses.add(HddsUtils.getHostPortString(details.getIpAddress(), port.getValue()));
} else {
System.out.printf("host: %s(%s) %s port not found",
details.getHostName(), details.getIpAddress(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.apache.hadoop.net.NetUtils;
import org.junit.jupiter.api.Test;

/**
Expand Down Expand Up @@ -97,6 +99,18 @@ public void testGetClientRpcAddress() throws IOException {
DiskBalancerSubCommandUtil.getClientRpcAddress(details));
}

@Test
public void testGetClientRpcAddressWithIpv6() throws IOException {
DatanodeDetails details = DatanodeDetails.getFromProtoBuf(
buildNode(DN_UUID, "nodename", "2001:db8::5", HDDS_DATANODE_CLIENT_PORT_DEFAULT).getNodeID());

String address = DiskBalancerSubCommandUtil.getClientRpcAddress(details);

assertEquals("[2001:db8::5]:" + HDDS_DATANODE_CLIENT_PORT_DEFAULT, address);
assertEquals(new InetSocketAddress("2001:db8::5", HDDS_DATANODE_CLIENT_PORT_DEFAULT),
NetUtils.createSocketAddr(address));
}

@Test
public void testGetDatanodeHostAndIp() {
HddsProtos.DatanodeDetailsProto nodeProto = buildNode(
Expand All @@ -110,6 +124,16 @@ public void testGetDatanodeHostAndIp() {
DiskBalancerSubCommandUtil.getDatanodeHostAndIp(nodeProto));
}

@Test
public void testGetDatanodeHostAndIpWithIpv6() {
HddsProtos.DatanodeDetailsProto nodeProto = buildNode(
DN_UUID, "ozone-datanode-2.ozone_default", "2001:db8::5", HDDS_DATANODE_CLIENT_PORT_DEFAULT).getNodeID();

assertEquals(
"ozone-datanode-2.ozone_default ([2001:db8::5]:" + HDDS_DATANODE_CLIENT_PORT_DEFAULT + ")",
DiskBalancerSubCommandUtil.getDatanodeHostAndIp(nodeProto));
}

@Test
public void testNormalizeNodeIds() {
List<String> normalized = DiskBalancerSubCommandUtil.normalizeNodeIds(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.ozone.admin.reconfig;

import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DATANODE_CLIENT_PORT_DEFAULT;
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeOperationalState.IN_SERVICE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.junit.jupiter.api.Test;

/**
* Unit tests for {@link ReconfigureSubCommandUtil}.
*/
public class TestReconfigureSubCommandUtil {

@Test
public void testGetAllOperableNodesClientRpcAddress() throws IOException {
ScmClient scmClient = mock(ScmClient.class);
when(scmClient.queryNode(IN_SERVICE, null, HddsProtos.QueryScope.CLUSTER, "")).thenReturn(Arrays.asList(
buildNode("10.140.95.199", HddsProtos.NodeState.HEALTHY),
buildNode("2001:db8::5", HddsProtos.NodeState.HEALTHY),
buildNode("2001:db8::6", HddsProtos.NodeState.DEAD)));

assertThat(ReconfigureSubCommandUtil.getAllOperableNodesClientRpcAddress(scmClient)).containsExactly(
"10.140.95.199:" + HDDS_DATANODE_CLIENT_PORT_DEFAULT,
"[2001:db8::5]:" + HDDS_DATANODE_CLIENT_PORT_DEFAULT);
}

private static HddsProtos.Node buildNode(String ipAddress, HddsProtos.NodeState state) {
HddsProtos.DatanodeDetailsProto dnd = HddsProtos.DatanodeDetailsProto.newBuilder()
.setUuid(UUID.randomUUID().toString())
.setHostName("nodename")
.setIpAddress(ipAddress)
.addPorts(HddsProtos.Port.newBuilder()
.setName(DatanodeDetails.Port.Name.CLIENT_RPC.name())
.setValue(HDDS_DATANODE_CLIENT_PORT_DEFAULT)
.build())
.build();
return HddsProtos.Node.newBuilder().setNodeID(dnd).addNodeStates(state).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected List<OMProxyInfo<T>> initOmProxiesFromConfigs(ConfigurationSource conf
if (hostAddr.isPresent()) {
int port = hostport
.orElse(config.getObject(GrpcOmTransport.GrpcOmTransportConfig.class).getPort());
String rpcAddrStr = hostAddr.get() + ":" + port;
String rpcAddrStr = HddsUtils.getHostPortString(hostAddr.get(), port);
omProxies.add(OMProxyInfo.newInstance(createOMProxy(), omSvcId, nodeId, rpcAddrStr));
} else {
LOG.error("expected host address not defined for: {}", rpcAddrKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public String getHost(OzoneConfiguration conf, Component component) {
String protocol = policy.isHttpsEnabled() ? HTTPS_SCHEME : HTTP_SCHEME;

if (component.getHostname() != null) {
return protocol + "://" + component.getHostname() + ":" + component.getPort();
return protocol + "://" + HddsUtils.getHostPortString(component.getHostname(), component.getPort());
}

String address = getComponentAddress(conf, component.getName(), policy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,17 @@ public void testFallbackToIpv6RpcAddress() {
assertEquals("http://[2001:db8::2]:" + OMConfigKeys.OZONE_OM_HTTP_BIND_PORT_DEFAULT,
command.getHost(conf, new Component(Type.OM, null)));
}

@Test
public void testDatanodeIpv6Hostname() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OzoneConfigKeys.OZONE_HTTP_POLICY_KEY, "HTTP_ONLY");

BaseInsightSubCommand command = new BaseInsightSubCommand();

assertEquals("http://[2001:db8::3]:9882",
command.getHost(conf, new Component(Type.DATANODE, null, "2001:db8::3", 9882)));
assertEquals("http://dn-host:9882",
command.getHost(conf, new Component(Type.DATANODE, null, "dn-host", 9882)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hadoop.ozone.protocolPB;

import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_TRANSPORT_CLASS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
Expand Down Expand Up @@ -91,4 +92,15 @@ public void testStartStop() throws Exception {
client.shutdown();
}
}

@Test
public void testStartStopWithIpv6OmAddress() throws Exception {
OzoneConfiguration ipv6Conf = new OzoneConfiguration(conf);
ipv6Conf.set(OZONE_OM_ADDRESS_KEY, "[2001:db8::10]:9862");
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();

// the constructor starts the transport
GrpcOmTransport client = new GrpcOmTransport(ipv6Conf, ugi, "");
client.shutdown();
}
}
Loading