Github user sohami commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1241#discussion_r185406443
  
    --- Diff: exec/java-exec/src/main/resources/rest/index.ftl ---
    @@ -252,33 +255,129 @@
               timeout = setTimeout(reloadStatus, refreshTime);
           }
     
    -      function fillStatus(data,size) {
    -          var status_map = (data.responseJSON);
    -          for (i = 1; i <= size; i++) {
    -            var address = 
$("#row-"+i).find("#address").contents().get(0).nodeValue;
    -            address = address.trim();
    -            var port = $("#row-"+i).find("#port").html();
    -            var key = address+"-"+port;
    +      function fillStatus(dataResponse,size) {
    +          var status_map = (dataResponse.responseJSON);
    +          //In case localhost has gone down (i.e. we don't know status 
from ZK)
    +          if (typeof status_map == 'undefined') {
    +            //Query other nodes for state details
    +            for (j = 1; j <= size; j++) {
    +              if ($("#row-"+j).find("#current").html() == "Current") {
    +                continue; //Skip LocalHost
    +              }
    +              var address = 
$("#row-"+j).find("#address").contents().get(0).nodeValue.trim();
    +              var restPort = 
$("#row-"+j).find("#httpPort").contents().get(0).nodeValue.trim();
    +              var altStateUrl = location.protocol + "//" + 
address+":"+restPort + "/state";
    +              var goatResponse = $.getJSON(altStateUrl)
    +                    .done(function(stateDataJson) {
    +                        //Update Status & Buttons for alternate stateData
    +                        if (typeof status_map == 'undefined') {
    +                          status_map = (stateDataJson); //Update
    +                          updateStatusAndShutdown(stateDataJson);
    +                        }
    +                      });
    +              //Don't loop any more
    +              if (typeof status_map != 'undefined') {
    +                break;
    +              }
    +            }
    +          } else {
    +            updateStatusAndShutdown(status_map);
    +          }
    +      }
    +
    +      function updateStatusAndShutdown(status_map) {
    +        let bitMap = {};
    +        if (typeof status_map != 'undefined') {
    +            for (var k in status_map) {
    +              bitMap[k] = status_map[k];
    +            }
    +        }
    +        for (i = 1; i <= size; i++) {
    +            let key = "";
    +            if ($("#row-"+i).find("#stateKey").length > 0) { //Check if 
newBit that has no stateKey
    +              key = $("#row-"+i).find("#stateKey").textContent;
    +            } else {
    +              let address = 
$("#row-"+i).find("#address").contents().get(0).nodeValue.trim();
    +              let port = $("#row-"+i).find("#httpPort").html();
    +              key = address+"-"+port;
    +            }
     
    -            if (status_map[key] == null) {
    +            if (typeof status_map == 'undefined') {
    +                $("#row-"+i).find("#status").text(nAText);
    +                
$("#row-"+i).find("#shutdown").prop('disabled',true).css('opacity',0.5);
    +                $("#row-"+i).find("#queriesCount").text("");
    +            } else if (status_map[key] == null) {
                     $("#row-"+i).find("#status").text("OFFLINE");
                     
$("#row-"+i).find("#shutdown").prop('disabled',true).css('opacity',0.5);
                     $("#row-"+i).find("#queriesCount").text("");
    -            }
    -            else {
    +            } else {
                     if (status_map[key] == "ONLINE") {
                         $("#row-"+i).find("#status").text(status_map[key]);
    -                    
$("#row-"+i).find("#shutdown").prop('disabled',false).css('opacity',1.0);
    -                }
    -                else {
    +                    <#if ( model.shouldShowAdminInfo() || 
!model.isAuthEnabled() ) >
    +                    if ( location.protocol != "https" || 
($("#row-"+i).find("#current").html() == "Current") ) {
    +                      
$("#row-"+i).find("#shutdown").prop('disabled',false).css('opacity',1.0).css('cursor','pointer');
    +                    }
    +                    </#if>
    +                } else {
                         if ($("#row-"+i).find("#current").html() == "Current") 
{
                             fillQueryCount(i);
                         }
                         $("#row-"+i).find("#status").text(status_map[key]);
                     }
    +                //Removing accounted key
    +                delete bitMap[key];
                 }
    -          }
    +        }
    +        //If bitMap is not empty, then new bits have been discovered!
    +        listNewDrillbits(bitMap, status_map);
    +      }
    +
    +      //Add new Bits for listing
    +      function listNewDrillbits(newBits, status_map) {
    +        let newBitList = Object.keys(newBits);
    +        let tableRef = 
document.getElementById('bitTable').getElementsByTagName('tbody')[0];
    +        let bitId = size;
    +        for (i = 0; i < newBitList.length; i++) {
    +           var displayNodeName = newBitList[i].substring(0, 
newBitList[i].lastIndexOf("-"));
    +           var newBitHttpPort = 
newBitList[i].substring(newBitList[i].lastIndexOf("-")+1);
    +           var newBitElemId = "neo-"+newBitList[i];
    +           var newBitElem = document.getElementsByName(newBitElemId);
    +           if ( newBitElem.length == 0 ) {
    --- End diff --
    
    What I meant was updateStatueAndShutdown is already performing the check 
for drillbits already part of the table and removing it from bitMap, this means 
bitMap contains list of new drillbits only and hence again checking if this 
drillbit element is present in table or not seems unnecessary. And then you 
don't need to add the name field for these new rows as well.


---

Reply via email to