Repository: apache/hadoop
File: hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/webapps/router/federationhealth.js (JavaScript)

Code before:
        } else if (v < 85) {
          r = 'progress-bar-warning';
        } else {
          r = "progress-bar-danger";
        }
        return chunk.write(r);
      },
    };

    function workaround(r) {
      function node_map_to_array(nodes) {
        var res = [];
        for (var n in nodes) {
          var p = nodes[n];
          p.name = n;
          res.push(p);
        }
        return res;
      }

      function augment_live_nodes(nodes) {
        for (var i = 0, e = nodes.length; i < e; ++i) {
          var n = nodes[i];
          n.usedPercentage = Math.round((n.used + n.nonDfsUsedSpace) * 1.0 / n.capacity * 100);
          var infoAddrParts = n.infoAddr.split("]:");
          var port = "9864";
          var dnHost = n.name.split(":")[0];
          if (infoAddrParts.length > 1) {
            // IPv6 url [xxxx:xxxx:...]:port
             port = infoAddrParts[1];
          } else {
            // IPv4 url host:port
            var parts = n.infoAddr.split(":");
            port = parts[1];
          }
          var securePort = "0";
          if (n.infoSecureAddr) {
            var secureAddrParts = n.infoSecureAddr.split("]:");
            if (secureAddrParts.length > 1) {
              securePort = secureAddrParts[1];
            } else {
            securePort = n.infoSecureAddr.split(":")[1];
            }
          }
          n.dnWebAddress = "http://" + dnHost + ":" + port;
          if (securePort != 0) {
            n.dnWebAddress = "https://" + dnHost + ":" + securePort;
          }

          if (n.adminState === "In Service") {
            n.state = "alive";

Review comment (suggestion):
This static value should be not necessary here. It is better to correct it include the following same definition.

Code after:
        } else if (v < 85) {
          r = 'progress-bar-warning';
        } else {
          r = "progress-bar-danger";
        }
        return chunk.write(r);
      },
    };

    function workaround(r) {
      function node_map_to_array(nodes) {
        var res = [];
        for (var n in nodes) {
          var p = nodes[n];
          p.name = n;
          res.push(p);
        }
        return res;
      }

      function augment_live_nodes(nodes) {
        for (var i = 0, e = nodes.length; i < e; ++i) {
          var n = nodes[i];
          n.usedPercentage = Math.round((n.used + n.nonDfsUsedSpace) * 1.0 / n.capacity * 100);

          var infoAddrParts = n.infoAddr.split("]:");
          var dnHost = n.name.split(":")[0];
          var port;
          if (infoAddrParts.length > 1) {
            // IPv6 url [xxxx:xxxx:...]:port
            port = infoAddrParts[1];
          } else {
            // IPv4 url  host:port
            port = n.infoAddr.split(":")[1];
          }

          var securePort = "0";
          if (n.infoSecureAddr) {
            var secureAddrParts = n.infoSecureAddr.split("]:");
            if (secureAddrParts.length > 1) {
              securePort = secureAddrParts[1];
            } else {
            securePort = n.infoSecureAddr.split(":")[1];
            }
          }
          n.dnWebAddress = "http://" + dnHost + ":" + port;
          if (securePort != 0) {
            n.dnWebAddress = "https://" + dnHost + ":" + securePort;
          }

          if (n.adminState === "In Service") {