You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by na...@apache.org on 2024/03/15 07:48:26 UTC

(ozone) branch master updated: HDDS-10440. Set new cluster ID and config instance in MiniOzoneCluster#build(). (#6325)

This is an automated email from the ASF dual-hosted git repository.

nanda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new f4ba2beaaa HDDS-10440. Set new cluster ID and config instance in MiniOzoneCluster#build(). (#6325)
f4ba2beaaa is described below

commit f4ba2beaaa6f303f6a0134de6226afea327c0ceb
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Fri Mar 15 08:48:20 2024 +0100

    HDDS-10440. Set new cluster ID and config instance in MiniOzoneCluster#build(). (#6325)
---
 .../apache/hadoop/ozone/MiniOzoneChaosCluster.java |  1 +
 .../org/apache/hadoop/fs/ozone/TestSafeMode.java   |  2 +-
 .../scm/node/TestDecommissionAndMaintenance.java   |  2 +-
 .../hadoop/hdds/upgrade/TestHDDSUpgrade.java       |  2 +-
 .../org/apache/hadoop/ozone/MiniOzoneCluster.java  | 19 +++++-------
 .../apache/hadoop/ozone/MiniOzoneClusterImpl.java  |  2 ++
 .../hadoop/ozone/MiniOzoneClusterProvider.java     | 34 ++++++++++------------
 .../hadoop/ozone/MiniOzoneHAClusterImpl.java       |  1 +
 8 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java b/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java
index f7f49fec3d..3c12bab432 100644
--- a/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java
+++ b/hadoop-ozone/fault-injection-test/mini-chaos-tests/src/test/java/org/apache/hadoop/ozone/MiniOzoneChaosCluster.java
@@ -309,6 +309,7 @@ public class MiniOzoneChaosCluster extends MiniOzoneHAClusterImpl {
       if (startDataNodes) {
         cluster.startHddsDatanodes();
       }
+      prepareForNextBuild();
       return cluster;
     }
   }
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestSafeMode.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestSafeMode.java
index ef46ec99d7..7668516901 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestSafeMode.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestSafeMode.java
@@ -62,7 +62,7 @@ class TestSafeMode {
   static void setup() {
     OzoneConfiguration conf = new OzoneConfiguration();
     clusterProvider = new MiniOzoneClusterProvider(
-        conf, MiniOzoneCluster.newBuilder(conf), 2);
+        MiniOzoneCluster.newBuilder(conf), 2);
   }
 
   @BeforeEach
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/node/TestDecommissionAndMaintenance.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/node/TestDecommissionAndMaintenance.java
index 5ebf9b56a8..3f7267b4fd 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/node/TestDecommissionAndMaintenance.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/node/TestDecommissionAndMaintenance.java
@@ -152,7 +152,7 @@ public class TestDecommissionAndMaintenance {
     MiniOzoneCluster.Builder builder = MiniOzoneCluster.newBuilder(conf)
         .setNumDatanodes(DATANODE_COUNT);
 
-    clusterProvider = new MiniOzoneClusterProvider(conf, builder, 7);
+    clusterProvider = new MiniOzoneClusterProvider(builder, 7);
   }
 
   @AfterAll
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/upgrade/TestHDDSUpgrade.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/upgrade/TestHDDSUpgrade.java
index 62e3b6321e..675570164d 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/upgrade/TestHDDSUpgrade.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/upgrade/TestHDDSUpgrade.java
@@ -178,7 +178,7 @@ public class TestHDDSUpgrade {
     // use multiple clusters, so its hard to know exactly how many will be
     // needed. This means the provider will create 1 extra cluster than needed
     // but that will not greatly affect runtimes.
-    clusterProvider = new MiniOzoneClusterProvider(conf, builder, 100);
+    clusterProvider = new MiniOzoneClusterProvider(builder, 100);
   }
 
   @AfterAll
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneCluster.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneCluster.java
index 9f689c6e0e..fcde2bed42 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneCluster.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneCluster.java
@@ -281,15 +281,17 @@ public interface MiniOzoneCluster extends AutoCloseable {
 
     protected Builder(OzoneConfiguration conf) {
       this.conf = conf;
-      setClusterId(UUID.randomUUID().toString());
+      setClusterId();
       // Use default SCM configurations if no override is provided.
       setSCMConfigurator(new SCMConfigurator());
       ExitUtils.disableSystemExit();
     }
 
-    public Builder setConf(OzoneConfiguration config) {
-      this.conf = config;
-      return this;
+    /** Prepare the builder for another call to {@link #build()}, avoiding conflict
+     * between the clusters created. */
+    protected void prepareForNextBuild() {
+      conf = new OzoneConfiguration(conf);
+      setClusterId();
     }
 
     public Builder setSCMConfigurator(SCMConfigurator configurator) {
@@ -297,13 +299,8 @@ public interface MiniOzoneCluster extends AutoCloseable {
       return this;
     }
 
-    /**
-     * Sets the cluster Id.
-     *
-     * @param id cluster Id
-     */
-    void setClusterId(String id) {
-      clusterId = id;
+    private void setClusterId() {
+      clusterId = UUID.randomUUID().toString();
       path = GenericTestUtils.getTempPath(
           MiniOzoneClusterImpl.class.getSimpleName() + "-" + clusterId);
     }
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java
index 6bc80cba15..72d6a29fce 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterImpl.java
@@ -545,6 +545,8 @@ public class MiniOzoneClusterImpl implements MiniOzoneCluster {
         if (startDataNodes) {
           cluster.startHddsDatanodes();
         }
+
+        prepareForNextBuild();
         return cluster;
       } catch (Exception ex) {
         stopOM(om);
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java
index cdd12ac841..618e2dd421 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneClusterProvider.java
@@ -17,14 +17,12 @@
  */
 package org.apache.hadoop.ozone;
 
-import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.UUID;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -49,10 +47,10 @@ import static java.util.concurrent.TimeUnit.SECONDS;
  * however shutting down the cluster in the background while the new cluster is
  * getting created will likely save about 10 seconds per test.
  *
- * To use this class, setup the Cluster Provider in a static method annotated
- * with @BeforeClass, eg:
- *
- *   @BeforeClass
+ * To use this class, set up the Cluster Provider in a static method annotated
+ * with {@code @BeforeAll}, eg:
+ * <pre>
+ *   &#64;BeforeAll
  *   public static void init() {
  *     OzoneConfiguration conf = new OzoneConfiguration();
  *     final int interval = 100;
@@ -71,29 +69,34 @@ import static java.util.concurrent.TimeUnit.SECONDS;
  *
  *     clusterProvider = new MiniOzoneClusterProvider(conf, builder, 5);
  *   }
+ * </pre>
  *
- * Ensure you shutdown the provider in a @AfterClass annotated method:
+ * Ensure you shut down the provider in an {@code @AfterAll} annotated method:
  *
- *   @AfterClass
+ * <pre>
+ *   &#64;AfterAll
  *   public static void shutdown() throws InterruptedException {
  *     if (clusterProvider != null) {
  *       clusterProvider.shutdown();
  *     }
  *   }
+ * </pre>
  *
- * Then in the @Before method, or in the test itself, obtain a cluster:
+ * Then in the {@code @BeforeEach} method, or in the test itself, obtain a cluster:
  *
- *   @Before
+ * <pre>
+ *   &#64;BeforeEach
  *   public void setUp() throws Exception {
  *     cluster = clusterProvider.provide();
  *   }
  *
- *   @After
+ *   &#64;AfterEach
  *   public void tearDown() throws InterruptedException, IOException {
  *     if (cluster != null) {
  *       clusterProvider.destroy(cluster);
  *     }
  *   }
+ * </pre>
  *
  *  This only works if the same config / builder object can be passed to each
  *  cluster in the test suite.
@@ -118,7 +121,6 @@ public class MiniOzoneClusterProvider {
   private final int clusterLimit;
   private int consumedClusterCount = 0;
 
-  private final OzoneConfiguration conf;
   private final MiniOzoneCluster.Builder builder;
   private final Thread createThread;
   private final Thread reapThread;
@@ -130,16 +132,13 @@ public class MiniOzoneClusterProvider {
       = new ArrayBlockingQueue<>(EXPIRED_LIMIT);
 
   /**
-   *
-   * @param conf The configuration to use when creating the cluster
    * @param builder A builder object with all cluster options set
    * @param clusterLimit The total number of clusters this provider should
    *                     create. If another is requested after this limit has
    *                     been reached, an exception will be thrown.
    */
-  public MiniOzoneClusterProvider(OzoneConfiguration conf,
+  public MiniOzoneClusterProvider(
       MiniOzoneCluster.Builder builder, int clusterLimit) {
-    this.conf = conf;
     this.builder = builder;
     this.clusterLimit = clusterLimit;
     createThread = createClusters();
@@ -214,9 +213,6 @@ public class MiniOzoneClusterProvider {
       while (!Thread.interrupted() && createdCount < clusterLimit) {
         MiniOzoneCluster cluster = null;
         try {
-          builder.setClusterId(UUID.randomUUID().toString());
-          builder.setConf(new OzoneConfiguration(conf));
-
           cluster = builder.build();
           cluster.waitForClusterToBeReady();
           createdCount++;
diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
index 8746e77c9e..16ef88177f 100644
--- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
+++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/MiniOzoneHAClusterImpl.java
@@ -437,6 +437,7 @@ public class MiniOzoneHAClusterImpl extends MiniOzoneClusterImpl {
       if (startDataNodes) {
         cluster.startHddsDatanodes();
       }
+      prepareForNextBuild();
       return cluster;
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org