sumitagrawl commented on code in PR #4540:
URL: https://github.com/apache/ozone/pull/4540#discussion_r1196081402


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/AuditLogFacetsResources.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api.types;
+
+import java.util.Arrays;
+
+/**
+ * This class is used to encapsulate entity's audit log event metadata objects.
+ */
+public class AuditLogFacetsResources {

Review Comment:
   class name needs change, may not be related to audit log



##########
hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/package.json:
##########
@@ -3,6 +3,7 @@
   "version": "0.1.0",
   "private": true,
   "dependencies": {
+    "@ant-design/icons": "^5.0.1",
     "@babel/core": "^7.0.0",

Review Comment:
   remove the webapps related file changes as not in scope of this PR



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/heatmap/IHeatMapProvider.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.heatmap;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.ozone.recon.api.types.EntityMetaData;
+import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
+
+/**
+ * This interface is to provide heatmap data.
+ */
+public interface IHeatMapProvider {
+  EntityMetaData[] retrieveData(
+      String normalizePath,
+      String entityType,
+      String startDate) throws Exception;
+  void init(OzoneConfiguration ozoneConfiguration,

Review Comment:
   init can throw exception, can add throws exception



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/heatmap/IHeatMapProvider.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.heatmap;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.ozone.recon.api.types.EntityMetaData;
+import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
+
+/**
+ * This interface is to provide heatmap data.
+ */
+public interface IHeatMapProvider {
+  EntityMetaData[] retrieveData(

Review Comment:
   Plz add java doc for these interface and better to use Collection<> as 
output instead of primitive array type.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/AccessHeatMapEndpoint.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api;
+
+import org.apache.hadoop.ozone.recon.api.types.EntityReadAccessHeatMapResponse;
+import org.apache.hadoop.ozone.recon.heatmap.HeatMapServiceImpl;
+
+import javax.inject.Inject;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import static 
org.apache.hadoop.ozone.recon.ReconConstants.RECON_ACCESS_METADATA_START_DATE;
+import static org.apache.hadoop.ozone.recon.ReconConstants.RECON_ENTITY_PATH;
+import static org.apache.hadoop.ozone.recon.ReconConstants.RECON_ENTITY_TYPE;
+
+
+/**
+ * Endpoint for querying access metadata from HeatMapProvider interface
+ * to generate heatmap in Recon.
+ */
+@Path("/heatmap")
+@Produces(MediaType.APPLICATION_JSON)
+@AdminOnly
+@InternalOnly(feature = "Heatmap", description = "Heatmap feature has " +
+    "dependency on heatmap provider service component implementation.")
+public class AccessHeatMapEndpoint {
+
+  private HeatMapServiceImpl heatMapService;
+
+  @Inject
+  public AccessHeatMapEndpoint(HeatMapServiceImpl heatMapService) {
+    this.heatMapService = heatMapService;
+  }
+
+  /**
+   * Return the top 100 prefixes or paths
+   * in tree nested structure with root as
+   * "/" and based on top 100 paths, response
+   * will be structured as tree starting
+   * with volume, buckets under that volume,
+   * then directories, subdirectories and paths
+   * under that bucket.
+   * E.g. -------->>
+   * vol1                           vol2
+   * - bucket1                      - bucket2
+   * - dir1/dir2/key1               - dir4/dir1/key1
+   * - dir1/dir2/key2               - dir4/dir5/key2
+   * - dir1/dir3/key1               - dir5/dir3/key1
+   *
+   * @return {@link Response}
+   */
+  @GET
+  @Path("/readaccess")
+  public Response getReadAccessMetaData(
+      @QueryParam(RECON_ENTITY_PATH) String path,
+      @DefaultValue("key") @QueryParam(RECON_ENTITY_TYPE) String entityType,
+      @DefaultValue("24H") @QueryParam(RECON_ACCESS_METADATA_START_DATE)
+      String startDate) {
+    EntityReadAccessHeatMapResponse entityReadAccessHeatMapResponse = null;
+    try {
+      entityReadAccessHeatMapResponse =

Review Comment:
   what if entityReadAccessHeatMapResponse is null?



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/AuditLogFacetsResources.java:
##########
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api.types;
+
+import java.util.Arrays;
+
+/**
+ * This class is used to encapsulate entity's audit log event metadata objects.
+ */
+public class AuditLogFacetsResources {
+  private EntityMetaData[] buckets;

Review Comment:
   field name buckets does not seems correct, its metaDataList



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/heatmap/HeatMapUtil.java:
##########
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.heatmap;
+
+import com.google.inject.Inject;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.ozone.recon.api.handlers.EntityHandler;
+import org.apache.hadoop.ozone.recon.api.types.DUResponse;
+import org.apache.hadoop.ozone.recon.api.types.EntityMetaData;
+import org.apache.hadoop.ozone.recon.api.types.EntityReadAccessHeatMapResponse;
+import org.apache.hadoop.ozone.recon.api.types.ResponseStatus;
+import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * This class is general utility class for keeping heatmap utility functions.
+ */
+public class HeatMapUtil {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(HeatMapUtil.class);
+  private OzoneConfiguration ozoneConfiguration;
+  private final ReconNamespaceSummaryManager reconNamespaceSummaryManager;
+  private final ReconOMMetadataManager omMetadataManager;
+  private final OzoneStorageContainerManager reconSCM;
+
+  @Inject
+  public HeatMapUtil(ReconNamespaceSummaryManager
+                      namespaceSummaryManager,
+                     ReconOMMetadataManager omMetadataManager,
+                     OzoneStorageContainerManager reconSCM,
+                     OzoneConfiguration ozoneConfiguration) {
+    this.reconNamespaceSummaryManager = namespaceSummaryManager;
+    this.omMetadataManager = omMetadataManager;
+    this.reconSCM = reconSCM;
+    this.ozoneConfiguration = ozoneConfiguration;
+  }
+
+  private void addBucketData(
+      EntityReadAccessHeatMapResponse rootEntity,
+      EntityReadAccessHeatMapResponse volumeEntity, String[] split,
+      int readAccessCount, long keySize) {
+    List<EntityReadAccessHeatMapResponse> children =
+        volumeEntity.getChildren();
+    EntityReadAccessHeatMapResponse bucketEntity = null;
+    List<EntityReadAccessHeatMapResponse> bucketList =
+        children.stream().filter(entity -> entity.getLabel().
+            equalsIgnoreCase(split[1])).collect(Collectors.toList());
+    if (bucketList.size() > 0) {
+      bucketEntity = bucketList.get(0);
+    }
+    if (children.contains(bucketEntity)) {
+      addPrefixPathInfoToBucket(rootEntity, split, bucketEntity,
+          readAccessCount, keySize);
+    } else {
+      addBucketAndPrefixPath(split, rootEntity, volumeEntity, readAccessCount,
+          keySize);
+    }
+  }
+
+  private void addVolumeData(
+      EntityReadAccessHeatMapResponse rootEntity,
+      String[] split, int readAccessCount, long keySize) {
+    List<EntityReadAccessHeatMapResponse> children =
+        rootEntity.getChildren();
+    EntityReadAccessHeatMapResponse volumeInfo =
+        new EntityReadAccessHeatMapResponse();
+    volumeInfo.setLabel(split[0]);
+    children.add(volumeInfo);
+    addBucketAndPrefixPath(split, rootEntity, volumeInfo, readAccessCount,
+        keySize);
+  }
+
+  private void updateVolumeSize(
+      EntityReadAccessHeatMapResponse volumeInfo) {
+    List<EntityReadAccessHeatMapResponse> children =
+        volumeInfo.getChildren();
+    children.stream().forEach(bucket -> {
+      volumeInfo.setSize(volumeInfo.getSize() + bucket.getSize());
+      updateBucketLevelMinMaxAccessCount(bucket);
+      updateBucketAccessRatio(bucket);
+    });
+  }
+
+  private void updateBucketAccessRatio(EntityReadAccessHeatMapResponse bucket) 
{
+    long delta = bucket.getMaxAccessCount() - bucket.getMinAccessCount();
+    List<EntityReadAccessHeatMapResponse> children =
+        bucket.getChildren();
+    children.stream().forEach(path -> {
+      path.setColor(1.000);
+      if (delta > 0) {
+        double truncatedValue = truncate(
+            ((double) path.getAccessCount() /
+                (double) bucket.getMaxAccessCount()), 3);
+        path.setColor(truncatedValue);
+      }
+    });
+  }
+
+  private static double truncate(double value, int decimalPlaces) {
+    if (decimalPlaces < 0) {
+      throw new IllegalArgumentException();
+    }
+    value = value * Math.pow(10, decimalPlaces);
+    value = Math.floor(value);
+    value = value / Math.pow(10, decimalPlaces);
+    return value;
+  }
+
+  private void updateRootEntitySize(
+      EntityReadAccessHeatMapResponse rootEntity) {
+    List<EntityReadAccessHeatMapResponse> children =
+        rootEntity.getChildren();
+    children.stream().forEach(volume -> {
+      updateVolumeSize(volume);
+      rootEntity.setSize(rootEntity.getSize() + volume.getSize());
+    });
+  }
+
+  private void addBucketAndPrefixPath(
+      String[] split, EntityReadAccessHeatMapResponse rootEntity,
+      EntityReadAccessHeatMapResponse volumeEntity,
+      long readAccessCount, long keySize) {
+    List<EntityReadAccessHeatMapResponse> bucketEntities =
+        volumeEntity.getChildren();
+    EntityReadAccessHeatMapResponse bucket =
+        new EntityReadAccessHeatMapResponse();
+    bucket.setLabel(split[1]);
+    bucketEntities.add(bucket);
+    bucket.setMinAccessCount(readAccessCount);
+    addPrefixPathInfoToBucket(rootEntity, split, bucket, readAccessCount,
+        keySize);
+  }
+
+  private void addPrefixPathInfoToBucket(
+      EntityReadAccessHeatMapResponse rootEntity, String[] split,
+      EntityReadAccessHeatMapResponse bucket,
+      long readAccessCount, long keySize) {
+    List<EntityReadAccessHeatMapResponse> prefixes = bucket.getChildren();
+    updateBucketSize(bucket, keySize);
+    String path = Arrays.stream(split)
+        .skip(2).collect(Collectors.joining("/"));
+    EntityReadAccessHeatMapResponse prefixPathInfo =
+        new EntityReadAccessHeatMapResponse();
+    prefixPathInfo.setLabel(path);
+    prefixPathInfo.setAccessCount(readAccessCount);
+    prefixPathInfo.setSize(keySize);
+    prefixes.add(prefixPathInfo);
+    // This is done for specific ask by UI treemap to render and provide
+    // varying color shades based on varying ranges of access count.
+    updateRootLevelMinMaxAccessCount(readAccessCount, rootEntity);
+  }
+
+  private void updateBucketLevelMinMaxAccessCount(
+      EntityReadAccessHeatMapResponse bucket) {
+    List<EntityReadAccessHeatMapResponse> children =
+        bucket.getChildren();
+    if (children.size() > 0) {
+      bucket.setMinAccessCount(Long.MAX_VALUE);
+    }
+    children.stream().forEach(path -> {
+      long readAccessCount = path.getAccessCount();
+      bucket.setMinAccessCount(
+          path.getAccessCount() < bucket.getMinAccessCount() ? readAccessCount 
:
+              bucket.getMinAccessCount());
+      bucket.setMaxAccessCount(
+          readAccessCount > bucket.getMaxAccessCount() ? readAccessCount :
+              bucket.getMaxAccessCount());
+    });
+  }
+
+  private void updateRootLevelMinMaxAccessCount(
+      long readAccessCount,
+      EntityReadAccessHeatMapResponse rootEntity) {
+    rootEntity.setMinAccessCount(
+        readAccessCount < rootEntity.getMinAccessCount() ? readAccessCount :
+            rootEntity.getMinAccessCount());
+    rootEntity.setMaxAccessCount(
+        readAccessCount > rootEntity.getMaxAccessCount() ? readAccessCount :
+            rootEntity.getMaxAccessCount());
+  }
+
+  private void updateBucketSize(EntityReadAccessHeatMapResponse bucket,
+                                       long keySize) {
+    bucket.setSize(bucket.getSize() + keySize);
+  }
+
+  public EntityReadAccessHeatMapResponse generateHeatMap(
+      EntityMetaData[] entities) {
+    EntityReadAccessHeatMapResponse rootEntity =
+        new EntityReadAccessHeatMapResponse();
+    rootEntity.setMinAccessCount(entities[0].getReadAccessCount());
+    rootEntity.setLabel("root");
+    List<EntityReadAccessHeatMapResponse> children =
+        rootEntity.getChildren();
+    Arrays.stream(entities).forEach(entityMetaData -> {
+      String path = entityMetaData.getVal();
+      String[] split = path.split("/");
+      if (split.length == 0) {
+        return;
+      }
+      long keySize = 0;
+      try {
+        keySize = getEntitySize(path);
+      } catch (IOException e) {
+        LOG.error("IOException while getting key size for key : " +
+            "{} - {}", path, e);
+      }
+      EntityReadAccessHeatMapResponse volumeEntity = null;
+      List<EntityReadAccessHeatMapResponse> volumeList =
+          children.stream().filter(entity -> entity.getLabel().
+              equalsIgnoreCase(split[0])).collect(Collectors.toList());
+      if (volumeList.size() > 0) {
+        volumeEntity = volumeList.get(0);
+      }
+      if (null != volumeEntity) {
+        if (validateLength(split, 2)) {
+          return;
+        }
+        addBucketData(rootEntity, volumeEntity, split,
+            entityMetaData.getReadAccessCount(), keySize);
+      } else {
+        if (validateLength(split, 1)) {
+          return;
+        }
+        addVolumeData(rootEntity, split,
+            entityMetaData.getReadAccessCount(), keySize);
+      }
+    });
+    updateRootEntitySize(rootEntity);
+    return rootEntity;
+  }
+
+  private static boolean validateLength(String[] split, int minLength) {
+    return (split.length < minLength);
+  }
+
+  private long getEntitySize(String path) throws IOException {
+    long entitySize = 0;
+    LOG.info("Getting entity size for {}: ", path);
+    EntityHandler entityHandler =
+        EntityHandler.getEntityHandler(reconNamespaceSummaryManager,
+            omMetadataManager, reconSCM, path);
+    if (null != entityHandler) {
+      DUResponse duResponse = entityHandler.getDuResponse(false, false);
+      if (null != duResponse && duResponse.getStatus() == ResponseStatus.OK) {
+        return duResponse.getSize();
+      }
+    }
+    // returning some default value due to some issue
+    return 256L;
+  }
+
+  public EntityReadAccessHeatMapResponse retrieveData(
+      IHeatMapProvider heatMapProvider, String normalizePath,
+      String entityType,
+      String startDate) throws Exception {
+    if (null != heatMapProvider) {
+      EntityMetaData[] entities = heatMapProvider.retrieveData(normalizePath,
+          entityType, startDate);
+      if (null != entities && !(ArrayUtils.isEmpty(entities))) {
+        return generateHeatMap(entities);

Review Comment:
   What kind of transformation we do in generateHeatMap, please add comment



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/filters/HeatMapFilter.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api.filters;
+
+import org.apache.hadoop.ozone.recon.heatmap.IHeatMapProvider;
+import org.apache.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.time.Instant;
+
+import static 
org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_PROVIDER_KEY;
+import static org.apache.hadoop.ozone.recon.ReconUtils.loadHeatMapProvider;
+
+/**
+ * This is a filter for internal heatmap feature.
+ */
+public class HeatMapFilter implements Filter {
+  private static Logger log = LoggerFactory.getLogger(HeatMapFilter.class);
+
+  private String heatMapProviderImplCls;
+
+  public HeatMapFilter() {
+  }
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+    heatMapProviderImplCls = filterConfig.
+        getInitParameter(OZONE_RECON_HEATMAP_PROVIDER_KEY);
+  }
+
+  @Override
+  public void doFilter(ServletRequest servletRequest,
+                       ServletResponse servletResponse, FilterChain 
filterChain)
+      throws IOException, ServletException {
+    String reason;
+    int errCode = HttpStatus.SC_FAILED_DEPENDENCY;
+    HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
+    try {
+      IHeatMapProvider iHeatMapProvider =
+          loadHeatMapProvider(heatMapProviderImplCls);

Review Comment:
   need use ReconUtils.loadHeatMapProvider instead of importing static method.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -342,4 +342,26 @@ private static int nextClosestPowerIndexOfTwo(long 
dataSize) {
     }
     return index;
   }
+
+  /**
+   * This method loads heatMapProvider implementation class.
+   *
+   * @param className - load the class and instantiate object.
+   * @return the implementation class object of IHeatMapProvider
+   * @throws Exception
+   */
+  public static IHeatMapProvider loadHeatMapProvider(String className)

Review Comment:
   This methods needs to be part of HeatMapUtil



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/filters/HeatMapFilter.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership.  The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api.filters;
+
+import org.apache.hadoop.ozone.recon.heatmap.IHeatMapProvider;
+import org.apache.http.HttpStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.time.Instant;
+
+import static 
org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_PROVIDER_KEY;
+import static org.apache.hadoop.ozone.recon.ReconUtils.loadHeatMapProvider;
+
+/**
+ * This is a filter for internal heatmap feature.
+ */
+public class HeatMapFilter implements Filter {
+  private static Logger log = LoggerFactory.getLogger(HeatMapFilter.class);
+
+  private String heatMapProviderImplCls;
+
+  public HeatMapFilter() {
+  }
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+    heatMapProviderImplCls = filterConfig.
+        getInitParameter(OZONE_RECON_HEATMAP_PROVIDER_KEY);
+  }
+
+  @Override
+  public void doFilter(ServletRequest servletRequest,

Review Comment:
   We are loading and quering data to check if data exist, this may not be 
required here, or this filter may not be required.
   OR only check if its already loaded or not by heatmap service.



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/heatmap/HeatMapServiceImpl.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.heatmap;
+
+import com.google.inject.Inject;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
+import org.apache.hadoop.ozone.recon.ReconUtils;
+import org.apache.hadoop.ozone.recon.api.types.EntityReadAccessHeatMapResponse;
+import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
+import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.hadoop.hdds.recon.ReconConfigKeys.OZONE_RECON_HEATMAP_PROVIDER_KEY;
+import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
+
+/**
+ * This class is an implementation of abstract class for retrieving
+ * data through HeatMapService.
+ */
+public class HeatMapServiceImpl extends HeatMapService {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(HeatMapServiceImpl.class);
+  private final OzoneConfiguration ozoneConfiguration;
+  private final ReconNamespaceSummaryManager reconNamespaceSummaryManager;
+  private final ReconOMMetadataManager omMetadataManager;
+  private final OzoneStorageContainerManager reconSCM;
+  private IHeatMapProvider heatMapProvider;
+
+  @Inject
+  public HeatMapServiceImpl(OzoneConfiguration ozoneConfiguration,
+                            ReconNamespaceSummaryManager
+                                     namespaceSummaryManager,
+                            ReconOMMetadataManager omMetadataManager,
+                            OzoneStorageContainerManager reconSCM)
+      throws Exception {
+    this.ozoneConfiguration = ozoneConfiguration;
+    this.reconNamespaceSummaryManager = namespaceSummaryManager;
+    this.omMetadataManager = omMetadataManager;
+    this.reconSCM = reconSCM;
+    initializeProvider();
+  }
+
+  private void initializeProvider() throws Exception {
+    String heatMapProviderCls = ozoneConfiguration.get(
+        OZONE_RECON_HEATMAP_PROVIDER_KEY);
+    LOG.info("HeatMapProvider: {}", heatMapProviderCls);
+    if (StringUtils.isEmpty(heatMapProviderCls)) {
+      heatMapProvider = new HeatMapProviderImpl();
+    } else {
+      IHeatMapProvider iHeatMapProvider =
+          ReconUtils.loadHeatMapProvider(heatMapProviderCls);
+      if (null != iHeatMapProvider) {

Review Comment:
   under exception case, what should be behavior?



##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/types/EntityMetaData.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.hadoop.ozone.recon.api.types;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * This class is used as a placeholder for entity's audit log related metadata.
+ */
+public class EntityMetaData {
+  private String val;
+  private int count;

Review Comment:
   Do this need count in interface? I think it should not have it as there is 
no usecase,



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to