src/main/java/org/apache/hadoop/hdfs/server/namenode/analytics/UserMetrics.java
public HashMap<String, Object> formatForJson() {
    HashMap<String, Object> jsonFormattedUser = new HashMap<>();
    jsonFormattedUser.put(
        "totalQueryCount", totalQueryCountsByIp.values().stream().mapToLong(l -> l).sum());
    jsonFormattedUser.put(
        "totalLoginCount", totalLoginCountsByIp.values().stream().mapToLong(l -> l).sum());
    jsonFormattedUser.put(
        "totalLogoutCount", totalLogoutCountsByIp.values().stream().mapToLong(l -> l).sum());
    jsonFormattedUser.put("userName", userName);

    HashMap<String, Map<String, Long>> ipMap = new HashMap<>();

    for (String ip : totalQueryCountsByIp.keySet()) {
      ipMap.putIfAbsent(ip, new HashMap<>());
      ipMap.get(ip).putIfAbsent("queryCount", totalQueryCountsByIp.getOrDefault(ip, 0L));
    }

    for (String ip : totalLoginCountsByIp.keySet()) {
      ipMap.putIfAbsent(ip, new HashMap<>());
      ipMap.get(ip).putIfAbsent("loginCount", totalLoginCountsByIp.getOrDefault(ip, 0L));
    }

    for (String ip : totalLogoutCountsByIp.keySet()) {
      ipMap.putIfAbsent(ip, new HashMap<>());
      ipMap.get(ip).putIfAbsent("logoutCount", totalLogoutCountsByIp.getOrDefault(ip, 0L));
    }

    ArrayList<Map<String, Map<String, Long>>> ipList = new ArrayList<>();

    ipMap
        .keySet()
        .forEach(
            key -> {
              Map<String, Map<String, Long>> ipMetricMap = new HashMap<>();
              ipMetricMap.put(key, ipMap.get(key));
              ipList.add(ipMetricMap);
            });

    jsonFormattedUser.put("ips", ipList);

    return jsonFormattedUser;
  }
/**
   * Builds a HashMap of this users metrics to be formatted into JSON.
   *
   * @return HashMap
   */
Builds a HashMap of this users metrics to be formatted into JSON.
Builds a HashMap of this users metrics to be formatted into JSON .
public HashMap<String, Object> formatForJson() {
    HashMap<String, Object> jsonFormattedUser = new HashMap<>();
    jsonFormattedUser.put(
        "totalQueryCount", totalQueryCountsByIp.values().stream().mapToLong(l -> l).sum());
    jsonFormattedUser.put(
        "totalLoginCount", totalLoginCountsByIp.values().stream().mapToLong(l -> l).sum());
    jsonFormattedUser.put(
        "totalLogoutCount", totalLogoutCountsByIp.values().stream().mapToLong(l -> l).sum());
    jsonFormattedUser.put("userName", userName);
    HashMap<String, Map<String, Long>> ipMap = new HashMap<>();
    for (String ip : totalQueryCountsByIp.keySet()) {
      ipMap.putIfAbsent(ip, new HashMap<>());
      ipMap.get(ip).putIfAbsent("queryCount", totalQueryCountsByIp.getOrDefault(ip, 0L));
    }
    for (String ip : totalLoginCountsByIp.keySet()) {
      ipMap.putIfAbsent(ip, new HashMap<>());
      ipMap.get(ip).putIfAbsent("loginCount", totalLoginCountsByIp.getOrDefault(ip, 0L));
    }
    for (String ip : totalLogoutCountsByIp.keySet()) {
      ipMap.putIfAbsent(ip, new HashMap<>());
      ipMap.get(ip).putIfAbsent("logoutCount", totalLogoutCountsByIp.getOrDefault(ip, 0L));
    }
    ArrayList<Map<String, Map<String, Long>>> ipList = new ArrayList<>();
    ipMap
        .keySet()
        .forEach(
            key -> {
              Map<String, Map<String, Long>> ipMetricMap = new HashMap<>();
              ipMetricMap.put(key, ipMap.get(key));
              ipList.add(ipMetricMap);
            });
    jsonFormattedUser.put("ips", ipList);
    return jsonFormattedUser;
  }
public HashMap < String , Object > formatForJson ( ) { HashMap < String , Object > jsonFormattedUser = new HashMap < > ( ) ; jsonFormattedUser . put ( "totalQueryCount" , totalQueryCountsByIp . values ( ) . stream ( ) . mapToLong ( l -> l ) . sum ( ) ) ; jsonFormattedUser . put ( "totalLoginCount" , totalLoginCountsByIp . values ( ) . stream ( ) . mapToLong ( l -> l ) . sum ( ) ) ; jsonFormattedUser . put ( "totalLogoutCount" , totalLogoutCountsByIp . values ( ) . stream ( ) . mapToLong ( l -> l ) . sum ( ) ) ; jsonFormattedUser . put ( "userName" , userName ) ; HashMap < String , Map < String , Long > > ipMap = new HashMap < > ( ) ; for ( String ip : totalQueryCountsByIp . keySet ( ) ) { ipMap . putIfAbsent ( ip , new HashMap < > ( ) ) ; ipMap . get ( ip ) . putIfAbsent ( "queryCount" , totalQueryCountsByIp . getOrDefault ( ip , 0L ) ) ; } for ( String ip : totalLoginCountsByIp . keySet ( ) ) { ipMap . putIfAbsent ( ip , new HashMap < > ( ) ) ; ipMap . get ( ip ) . putIfAbsent ( "loginCount" , totalLoginCountsByIp . getOrDefault ( ip , 0L ) ) ; } for ( String ip : totalLogoutCountsByIp . keySet ( ) ) { ipMap . putIfAbsent ( ip , new HashMap < > ( ) ) ; ipMap . get ( ip ) . putIfAbsent ( "logoutCount" , totalLogoutCountsByIp . getOrDefault ( ip , 0L ) ) ; } ArrayList < Map < String , Map < String , Long > > > ipList = new ArrayList < > ( ) ; ipMap . keySet ( ) . forEach ( key -> { Map < String , Map < String , Long > > ipMetricMap = new HashMap < > ( ) ; ipMetricMap . put ( key , ipMap . get ( key ) ) ; ipList . add ( ipMetricMap ) ; } ) ; jsonFormattedUser . put ( "ips" , ipList ) ; return jsonFormattedUser ; }
Builds a HashMap of this users metrics to be formatted into JSON.
Builds a HashMap of this users metrics to be formatted into JSON .