diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/recon/ReconConfigKeys.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/recon/ReconConfigKeys.java index 47d3b00dd565..3571d39bc8a2 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/recon/ReconConfigKeys.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/recon/ReconConfigKeys.java @@ -44,6 +44,9 @@ private ReconConfigKeys() { // Fully qualified heatmap provider implementation class name key. public static final String OZONE_RECON_HEATMAP_PROVIDER_KEY = "ozone.recon.heatmap.provider"; + public static final String OZONE_RECON_HEATMAP_ENABLE_KEY = + "ozone.recon.heatmap.enable"; + public static final boolean OZONE_RECON_HEATMAP_ENABLE_DEFAULT = false; public static final String OZONE_RECON_ADDRESS_DEFAULT = "0.0.0.0:9891"; public static final String OZONE_RECON_HTTP_ADDRESS_KEY = diff --git a/hadoop-hdds/common/src/main/resources/ozone-default.xml b/hadoop-hdds/common/src/main/resources/ozone-default.xml index f90fea4908b3..280ce927532f 100644 --- a/hadoop-hdds/common/src/main/resources/ozone-default.xml +++ b/hadoop-hdds/common/src/main/resources/ozone-default.xml @@ -3735,6 +3735,17 @@ + + ozone.recon.heatmap.enable + false + OZONE, RECON + + To enable/disable recon heatmap feature. Along with this config, user must also provide the implementation + of "org.apache.hadoop.ozone.recon.heatmap.IHeatMapProvider" interface and configure in + "ozone.recon.heatmap.provider" configuration. + + + ozone.fs.datastream.enabled false diff --git a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/FeatureProvider.java b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/FeatureProvider.java index 7696b3992593..60d701d18b82 100644 --- a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/FeatureProvider.java +++ b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/FeatureProvider.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.stream.Collectors; +import static org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_ENABLE_DEFAULT; +import static org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_ENABLE_KEY; import static org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_PROVIDER_KEY; /** @@ -34,7 +36,7 @@ */ @Singleton public final class FeatureProvider { - private static EnumMap featureSupportMap = + private static EnumMap featureDisableMap = new EnumMap<>(Feature.class); private FeatureProvider() { @@ -69,13 +71,13 @@ public static Feature of(String featureName) { } } - public static EnumMap getFeatureSupportMap() { - return featureSupportMap; + public static EnumMap getFeatureDisableMap() { + return featureDisableMap; } public static List getAllDisabledFeatures() { - return getFeatureSupportMap().keySet().stream().filter(feature -> - Boolean.TRUE.equals(getFeatureSupportMap().get(feature))).collect( + return getFeatureDisableMap().keySet().stream().filter(feature -> + Boolean.TRUE.equals(getFeatureDisableMap().get(feature))).collect( Collectors.toList()); } @@ -85,13 +87,15 @@ public static void initFeatureSupport( resetInitOfFeatureSupport(); String heatMapProviderCls = ozoneConfiguration.get( OZONE_RECON_HEATMAP_PROVIDER_KEY); - if (StringUtils.isEmpty(heatMapProviderCls)) { - getFeatureSupportMap().put(Feature.HEATMAP, true); + boolean heatMapEnabled = ozoneConfiguration.getBoolean( + OZONE_RECON_HEATMAP_ENABLE_KEY, OZONE_RECON_HEATMAP_ENABLE_DEFAULT); + if (!heatMapEnabled || StringUtils.isEmpty(heatMapProviderCls)) { + getFeatureDisableMap().put(Feature.HEATMAP, true); } } private static void resetInitOfFeatureSupport() { - getFeatureSupportMap().keySet() - .forEach(feature -> getFeatureSupportMap().put(feature, false)); + getFeatureDisableMap().keySet() + .forEach(feature -> getFeatureDisableMap().put(feature, false)); } } diff --git a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestFeaturesEndPoint.java b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestFeaturesEndPoint.java index 3534da7ff601..6790befca7fd 100644 --- a/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestFeaturesEndPoint.java +++ b/hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestFeaturesEndPoint.java @@ -37,6 +37,7 @@ import java.util.List; +import static org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_ENABLE_KEY; import static org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_PROVIDER_KEY; import static org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getTestReconOmMetadataManager; import static org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.initializeNewOmMetadataManager; @@ -89,7 +90,7 @@ public void setUp() throws Exception { } @Test - public void testGetDisabledFeaturesGreaerThanZero() { + public void testGetDisabledFeaturesGreaterThanZero() { ozoneConfiguration.set(OZONE_RECON_HEATMAP_PROVIDER_KEY, ""); FeatureProvider.initFeatureSupport(ozoneConfiguration); Response disabledFeatures = featuresEndPoint.getDisabledFeatures(); @@ -105,6 +106,35 @@ public void testGetDisabledFeaturesGreaerThanZero() { public void testNoDisabledFeatures() { ozoneConfiguration.set(OZONE_RECON_HEATMAP_PROVIDER_KEY, "org.apache.hadoop.ozone.recon.heatmap.TestHeatMapProviderImpl"); + ozoneConfiguration.setBoolean(OZONE_RECON_HEATMAP_ENABLE_KEY, true); + FeatureProvider.initFeatureSupport(ozoneConfiguration); + Response disabledFeatures = featuresEndPoint.getDisabledFeatures(); + List allDisabledFeatures = + (List) disabledFeatures.getEntity(); + Assertions.assertNotNull(allDisabledFeatures); + Assertions.assertTrue(allDisabledFeatures.size() == 0); + } + + @Test + public void testGetHeatMapInDisabledFeaturesListWhenHeatMapFlagIsFalse() { + ozoneConfiguration.set(OZONE_RECON_HEATMAP_PROVIDER_KEY, + "org.apache.hadoop.ozone.recon.heatmap.TestHeatMapProviderImpl"); + ozoneConfiguration.setBoolean(OZONE_RECON_HEATMAP_ENABLE_KEY, false); + FeatureProvider.initFeatureSupport(ozoneConfiguration); + Response disabledFeatures = featuresEndPoint.getDisabledFeatures(); + List allDisabledFeatures = + (List) disabledFeatures.getEntity(); + Assertions.assertNotNull(allDisabledFeatures); + Assertions.assertTrue(allDisabledFeatures.size() > 0); + Assertions.assertEquals(FeatureProvider.Feature.HEATMAP.getFeatureName(), + allDisabledFeatures.get(0).getFeatureName()); + } + + @Test + public void testGetHeatMapNotInDisabledFeaturesListWhenHeatMapFlagIsTrue() { + ozoneConfiguration.set(OZONE_RECON_HEATMAP_PROVIDER_KEY, + "org.apache.hadoop.ozone.recon.heatmap.TestHeatMapProviderImpl"); + ozoneConfiguration.setBoolean(OZONE_RECON_HEATMAP_ENABLE_KEY, true); FeatureProvider.initFeatureSupport(ozoneConfiguration); Response disabledFeatures = featuresEndPoint.getDisabledFeatures(); List allDisabledFeatures =