diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerConfiguration.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerConfiguration.java index 77f0dfc2305a0..f3aa83672ed9c 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerConfiguration.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOzoneManagerConfiguration.java @@ -279,6 +279,45 @@ public void testWrongConfiguration() throws Exception { } } + /** + * A configuration with an empty node list while service ID is configured + * Should successfully start with no NPEs. + * @throws Exception + */ + @Test + public void testNoOMNodes() throws Exception { + String omServiceId = "om-service-test1"; + conf.set(OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY, omServiceId); + // Deliberately skip OZONE_OM_NODES_KEY and OZONE_OM_ADDRESS_KEY config + + // Should successfully start with no NPEs + startCluster(); + } + + /** + * A configuration with no OM addresses while service ID is configured. + * Should successfully start with no NPEs. + * @throws Exception + */ + @Test + public void testNoOMAddrs() throws Exception { + String omServiceId = "om-service-test1"; + + String omNode1Id = "omNode1"; + String omNode2Id = "omNode2"; + String omNode3Id = "omNode3"; + String omNodesKeyValue = omNode1Id + "," + omNode2Id + "," + omNode3Id; + String omNodesKey = OmUtils.addKeySuffixes( + OMConfigKeys.OZONE_OM_NODES_KEY, omServiceId); + + conf.set(OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY, omServiceId); + conf.set(omNodesKey, omNodesKeyValue); + // Deliberately skip OZONE_OM_ADDRESS_KEY config + + // Should successfully start with no NPEs + startCluster(); + } + /** * Test multiple OM service configuration. */ diff --git a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java index 48b095cfdb274..f7d1f114343e2 100644 --- a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java +++ b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OzoneManager.java @@ -622,6 +622,10 @@ private void loadOMHAConfigs(Configuration conf) { InetSocketAddress omAddress = OmUtils.getOmAddress(conf); int ratisPort = conf.getInt(OZONE_OM_RATIS_PORT_KEY, OZONE_OM_RATIS_PORT_DEFAULT); + // HDDS-2064: this.peerNodes would be null at this point because + // it is not initialized, we want to initialize it as an empty list + // to prevent NPE in OzoneManagerRatisServer#newOMRatisServer. + this.peerNodes = new ArrayList<>(); LOG.info("Configuration either no {} set. Falling back to the default " + "OM address {}", OZONE_OM_ADDRESS_KEY, omAddress);