diff --git a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java index 660b1131ff9..5895ecc12b3 100644 --- a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java +++ b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/StorageContainerManager.java @@ -1595,12 +1595,9 @@ public void start() throws IOException { setStartTime(); - if (SCMHAUtils.isSCMHAEnabled(configuration) && getScmHAManager().getRatisServer().getLeaderId() != null) { - scmHAMetricsUpdate(getScmHAManager().getRatisServer().getLeaderId().toString()); - } else { - // At this point leader is not known - scmHAMetricsUpdate(null); - } + RaftPeerId leaderId = SCMHAUtils.isSCMHAEnabled(configuration) + ? getScmHAManager().getRatisServer().getLeaderId() : null; + scmHAMetricsUpdate(Objects.toString(leaderId, null)); if (scmCertificateClient != null) { // In case root CA certificate is rotated during this SCM is offline 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 feb313c6c98..3594996856a 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 @@ -145,7 +145,7 @@ public class MiniOzoneClusterImpl implements MiniOzoneCluster { private CertificateClient caClient; private final Set clients = ConcurrentHashMap.newKeySet(); private SecretKeyClient secretKeyClient; - private static volatile MockedStatic mockDNStatic; + private static MockedStatic mockDNStatic = Mockito.mockStatic(HddsDatanodeService.class); /** * Creates a new MiniOzoneCluster with Recon. @@ -571,16 +571,6 @@ private void setSecretKeyClient(SecretKeyClient client) { this.secretKeyClient = client; } - public static void mockDatanode() { - if (mockDNStatic == null) { - synchronized (MiniOzoneClusterImpl.class) { - if (mockDNStatic == null) { - mockDNStatic = Mockito.mockStatic(HddsDatanodeService.class); - } - } - } - } - private static void stopDatanodes( Collection hddsDatanodes) { if (!hddsDatanodes.isEmpty()) { @@ -877,7 +867,6 @@ protected Gateway createS3G() { */ protected List createHddsDatanodes() throws IOException { - mockDatanode(); List hddsDatanodes = new ArrayList<>(); // Override default datanode initial and current version if necessary