Skip to content

Commit dead9b4

Browse files
committed
HDDS-1384. TestBlockOutputStreamWithFailures is failing
Closes #750
1 parent 0af4011 commit dead9b4

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.hadoop.ozone;
1919

2020
import java.io.File;
21+
import java.net.ServerSocket;
2122
import java.util.ArrayList;
2223
import java.util.List;
2324
import java.util.Optional;
@@ -63,6 +64,7 @@
6364
import java.util.UUID;
6465
import java.util.concurrent.TimeUnit;
6566
import java.util.concurrent.TimeoutException;
67+
import java.util.concurrent.atomic.AtomicInteger;
6668

6769
import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_INTERVAL;
6870
import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.NodeState
@@ -388,6 +390,9 @@ private void setCAClient(CertificateClient client) {
388390
*/
389391
public static class Builder extends MiniOzoneCluster.Builder {
390392

393+
private static AtomicInteger lastUsedPort =
394+
new AtomicInteger(1000);
395+
391396
/**
392397
* Creates a new Builder.
393398
*
@@ -529,14 +534,16 @@ OzoneManager createOM()
529534
*/
530535
List<HddsDatanodeService> createHddsDatanodes(
531536
StorageContainerManager scm) throws IOException {
532-
configureHddsDatanodes();
533-
String scmAddress = scm.getDatanodeRpcAddress().getHostString() +
537+
538+
String scmAddress = scm.getDatanodeRpcAddress().getHostString() +
534539
":" + scm.getDatanodeRpcAddress().getPort();
535540
String[] args = new String[] {};
536541
conf.setStrings(ScmConfigKeys.OZONE_SCM_NAMES, scmAddress);
542+
537543
List<HddsDatanodeService> hddsDatanodes = new ArrayList<>();
538544
for (int i = 0; i < numOfDatanodes; i++) {
539545
OzoneConfiguration dnConf = new OzoneConfiguration(conf);
546+
configureHddsDatanodes(dnConf);
540547
String datanodeBaseDir = path + "/datanode-" + Integer.toString(i);
541548
Path metaDir = Paths.get(datanodeBaseDir, "meta");
542549
Path dataDir = Paths.get(datanodeBaseDir, "data", "containers");
@@ -563,10 +570,14 @@ List<HddsDatanodeService> createHddsDatanodes(
563570
}
564571

565572
private void configureSCM() {
566-
conf.set(ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY, "127.0.0.1:0");
567-
conf.set(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY, "127.0.0.1:0");
568-
conf.set(ScmConfigKeys.OZONE_SCM_DATANODE_ADDRESS_KEY, "127.0.0.1:0");
569-
conf.set(ScmConfigKeys.OZONE_SCM_HTTP_ADDRESS_KEY, "127.0.0.1:0");
573+
conf.set(ScmConfigKeys.OZONE_SCM_CLIENT_ADDRESS_KEY,
574+
"127.0.0.1:" + findPort());
575+
conf.set(ScmConfigKeys.OZONE_SCM_BLOCK_CLIENT_ADDRESS_KEY,
576+
"127.0.0.1:" + findPort());
577+
conf.set(ScmConfigKeys.OZONE_SCM_DATANODE_ADDRESS_KEY,
578+
"127.0.0.1:" + findPort());
579+
conf.set(ScmConfigKeys.OZONE_SCM_HTTP_ADDRESS_KEY,
580+
"127.0.0.1:" + findPort());
570581
conf.setInt(ScmConfigKeys.OZONE_SCM_HANDLER_COUNT_KEY, numOfScmHandlers);
571582
configureSCMheartbeat();
572583
}
@@ -597,19 +608,42 @@ private void configureSCMheartbeat() {
597608

598609

599610
private void configureOM() {
600-
conf.set(OMConfigKeys.OZONE_OM_ADDRESS_KEY, "127.0.0.1:0");
601-
conf.set(OMConfigKeys.OZONE_OM_HTTP_ADDRESS_KEY, "127.0.0.1:0");
611+
conf.set(OMConfigKeys.OZONE_OM_ADDRESS_KEY, "127.0.0.1:" + findPort());
612+
conf.set(OMConfigKeys.OZONE_OM_HTTP_ADDRESS_KEY,
613+
"127.0.0.1:" + findPort());
602614
conf.setInt(OMConfigKeys.OZONE_OM_HANDLER_COUNT_KEY, numOfOmHandlers);
603615
}
604616

605-
private void configureHddsDatanodes() {
606-
conf.set(ScmConfigKeys.HDDS_REST_HTTP_ADDRESS_KEY, "0.0.0.0:0");
607-
conf.set(HddsConfigKeys.HDDS_DATANODE_HTTP_ADDRESS_KEY, "0.0.0.0:0");
608-
conf.set(HDDS_DATANODE_PLUGINS_KEY,
617+
/**
618+
* Return an available TCP port if available.
619+
* <p>
620+
* As we have a static counter the port should be unique inside the JVM..
621+
*/
622+
private int findPort() {
623+
while (lastUsedPort.get() < 65536) {
624+
try {
625+
int nextPort = lastUsedPort.incrementAndGet();
626+
ServerSocket socket = new ServerSocket(nextPort);
627+
socket.close();
628+
return nextPort;
629+
} catch (IOException ex) {
630+
//port is not available, let's try the next one.
631+
continue;
632+
}
633+
}
634+
throw new RuntimeException("No available port");
635+
}
636+
637+
private void configureHddsDatanodes(OzoneConfiguration dnConf) {
638+
dnConf.set(ScmConfigKeys.HDDS_REST_HTTP_ADDRESS_KEY,
639+
"0.0.0.0:" + findPort());
640+
dnConf.set(HddsConfigKeys.HDDS_DATANODE_HTTP_ADDRESS_KEY,
641+
"0.0.0.0:" + findPort());
642+
dnConf.set(HDDS_DATANODE_PLUGINS_KEY,
609643
"org.apache.hadoop.ozone.web.OzoneHddsDatanodeService");
610-
conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT,
644+
dnConf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT,
611645
randomContainerPort);
612-
conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT,
646+
dnConf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT,
613647
randomContainerPort);
614648
}
615649

0 commit comments

Comments
 (0)