Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-3877: JMX Bean RemotePeerBean should enclose IPV6 host in s… #1493

Closed
Closed
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 @@ -18,7 +18,9 @@

package org.apache.zookeeper.server.quorum;

import static org.apache.zookeeper.common.NetUtils.formatInetAddr;
import java.util.stream.Collectors;
import org.apache.zookeeper.common.NetUtils;
import org.apache.zookeeper.jmx.ZKMBeanInfo;

/**
Expand Down Expand Up @@ -47,22 +49,20 @@ public boolean isHidden() {
}

public String getQuorumAddress() {
return peer.addr.getAllAddresses().stream()
.map(address -> String.format("%s:%d", address.getHostString(), address.getPort()))
.collect(Collectors.joining("|"));
return peer.addr.getAllAddresses().stream().map(NetUtils::formatInetAddr)
.collect(Collectors.joining("|"));
}

public String getElectionAddress() {
return peer.electionAddr.getAllAddresses().stream()
.map(address -> String.format("%s:%d", address.getHostString(), address.getPort()))
.collect(Collectors.joining("|"));
return peer.electionAddr.getAllAddresses().stream().map(NetUtils::formatInetAddr)
.collect(Collectors.joining("|"));
}

public String getClientAddress() {
if (null == peer.clientAddr) {
return "";
}
return peer.clientAddr.getHostString() + ":" + peer.clientAddr.getPort();
return formatInetAddr(peer.clientAddr);
}

public String getLearnerType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,20 @@ public void testIsLeader() {
assertFalse(remotePeerBean.isLeader());
}

@Test
public void testHostPortReturnedWhenIPIsIPV6() {
QuorumPeer.QuorumServer quorumServerMock = mock(QuorumPeer.QuorumServer.class);
InetSocketAddress address = new InetSocketAddress("127::1", 2181);
MultipleAddresses multipleAddresses = new MultipleAddresses(address);
quorumServerMock.clientAddr = address;
quorumServerMock.electionAddr = multipleAddresses;
quorumServerMock.addr = multipleAddresses;
QuorumPeer peerMock = mock(QuorumPeer.class);
RemotePeerBean remotePeerBean = new RemotePeerBean(peerMock, quorumServerMock);
String expectedHostPort = "[127:0:0:0:0:0:0:1]:2181";
assertEquals(expectedHostPort, remotePeerBean.getClientAddress());
assertEquals(expectedHostPort, remotePeerBean.getElectionAddress());
assertEquals(expectedHostPort, remotePeerBean.getQuorumAddress());
}

}