src/webui/master/static/controllers.js
// Update the outermost scope with the new state.
Update the outermost scope with the new state.
Update the outermost scope with the new state .
function update($scope, $defer, data) {
  if ($scope.data == data) {
    return true; 
  }
  $scope.state = $.parseJSON(data);
  if (!$scope.state.leader) {
    $("#no-leader-alert").show();
  } else {
    $("#no-leader-alert").hide();
    if ($scope.state.leader != $scope.state.pid) {
      $scope.redirect = 6000;
      $scope.leader = $scope.state.leader.split("@")[1];
      $("#not-leader-alert").show();
      var countdown = function() {
        if ($scope.redirect == 0) {
          window.location = 'http://' + $scope.leader;
        } else {
          $scope.redirect = $scope.redirect - 1000;
          $defer(countdown, 1000);
        }
      }
      countdown();
      return false; 
    }
  }
  $scope.time_since_update += $scope.delay;
  if (hasSelectedText() && $scope.time_since_update < 20000) {
    return true;
  }
  $scope.data = data;
  $scope.slaves = {};
  $scope.frameworks = {};
  $scope.offers = {};
  $scope.completed_frameworks = {};
  _.each($scope.state.slaves, function(slave) {
    $scope.slaves[slave.id] = slave;
  });
  _.each($scope.state.frameworks, function(framework) {
    $scope.frameworks[framework.id] = framework;
    _.each(framework.offers, function(offer) {
      $scope.offers[offer.id] = offer;
    });
  });
  _.each($scope.state.completed_frameworks, function(framework) {
    $scope.completed_frameworks[framework.id] = framework;
  });
  $scope.cluster = $scope.state.cluster;
  $scope.total_cpus = 0;
  $scope.total_mem = 0;
  $scope.used_cpus = 0;
  $scope.used_mem = 0;
  $scope.offered_cpus = 0;
  $scope.offered_mem = 0;
  $scope.staged_tasks = $scope.state.staged_tasks;
  $scope.started_tasks = $scope.state.started_tasks;
  $scope.finished_tasks = $scope.state.finished_tasks;
  $scope.killed_tasks = $scope.state.killed_tasks;
  $scope.failed_tasks = $scope.state.failed_tasks;
  $scope.lost_tasks = $scope.state.lost_tasks;
  $scope.activated_slaves = $scope.state.activated_slaves;
  $scope.connected_slaves = $scope.state.connected_slaves;
  _.each($scope.slaves, function(slave) {
    $scope.total_cpus += slave.resources.cpus;
    $scope.total_mem += slave.resources.mem;
  });
  _.each($scope.frameworks, function(framework) {
      $scope.used_cpus += framework.resources.cpus;
      $scope.used_mem += framework.resources.mem;
      $scope.active_tasks += framework.tasks.length;
      $scope.completed_tasks += framework.completed_tasks.length;
      framework.cpus_share = 0;
      if ($scope.total_cpus > 0) {
        framework.cpus_share = framework.resources.cpus / $scope.total_cpus;
      }
      framework.mem_share = 0;
      if ($scope.total_mem > 0) {
        framework.mem_share = framework.resources.mem / $scope.total_mem;
      }
      framework.max_share = Math.max(framework.cpus_share, framework.mem_share);
  });
  _.each($scope.offers, function(offer) {
    $scope.offered_cpus += offer.resources.cpus;
    $scope.offered_mem += offer.resources.mem;
    offer.framework_name = $scope.frameworks[offer.framework_id].name;
    offer.hostname = $scope.slaves[offer.slave_id].hostname;
  });
  $scope.used_cpus -= $scope.offered_cpus;
  $scope.used_mem -= $scope.offered_mem;
  $scope.idle_cpus = $scope.total_cpus - ($scope.offered_cpus + $scope.used_cpus);
  $scope.idle_mem = $scope.total_mem - ($scope.offered_mem + $scope.used_mem);
  $scope.time_since_update = 0;
  $.event.trigger('state_updated');
  return true; 
}
function update ( $scope , $defer , data ) { if ( $scope . data == data ) { return true ; } $scope . state = $ . parseJSON ( data ) ; if ( ! $scope . state . leader ) { $ ( "#no-leader-alert" ) . show ( ) ; } else { $ ( "#no-leader-alert" ) . hide ( ) ; if ( $scope . state . leader != $scope . state . pid ) { $scope . redirect = 6000 ; $scope . leader = $scope . state . leader . split ( "@" ) [ 1 ] ; $ ( "#not-leader-alert" ) . show ( ) ; var countdown = function ( ) { if ( $scope . redirect == 0 ) { window . location = 'http://' + $scope . leader ; } else { $scope . redirect = $scope . redirect - 1000 ; $defer ( countdown , 1000 ) ; } } countdown ( ) ; return false ; } } $scope . time_since_update += $scope . delay ; if ( hasSelectedText ( ) && $scope . time_since_update < 20000 ) { return true ; } $scope . data = data ; $scope . slaves = { } ; $scope . frameworks = { } ; $scope . offers = { } ; $scope . completed_frameworks = { } ; _ . each ( $scope . state . slaves , function ( slave ) { $scope . slaves [ slave . id ] = slave ; } ) ; _ . each ( $scope . state . frameworks , function ( framework ) { $scope . frameworks [ framework . id ] = framework ; _ . each ( framework . offers , function ( offer ) { $scope . offers [ offer . id ] = offer ; } ) ; } ) ; _ . each ( $scope . state . completed_frameworks , function ( framework ) { $scope . completed_frameworks [ framework . id ] = framework ; } ) ; $scope . cluster = $scope . state . cluster ; $scope . total_cpus = 0 ; $scope . total_mem = 0 ; $scope . used_cpus = 0 ; $scope . used_mem = 0 ; $scope . offered_cpus = 0 ; $scope . offered_mem = 0 ; $scope . staged_tasks = $scope . state . staged_tasks ; $scope . started_tasks = $scope . state . started_tasks ; $scope . finished_tasks = $scope . state . finished_tasks ; $scope . killed_tasks = $scope . state . killed_tasks ; $scope . failed_tasks = $scope . state . failed_tasks ; $scope . lost_tasks = $scope . state . lost_tasks ; $scope . activated_slaves = $scope . state . activated_slaves ; $scope . connected_slaves = $scope . state . connected_slaves ; _ . each ( $scope . slaves , function ( slave ) { $scope . total_cpus += slave . resources . cpus ; $scope . total_mem += slave . resources . mem ; } ) ; _ . each ( $scope . frameworks , function ( framework ) { $scope . used_cpus += framework . resources . cpus ; $scope . used_mem += framework . resources . mem ; $scope . active_tasks += framework . tasks . length ; $scope . completed_tasks += framework . completed_tasks . length ; framework . cpus_share = 0 ; if ( $scope . total_cpus > 0 ) { framework . cpus_share = framework . resources . cpus / $scope . total_cpus ; } framework . mem_share = 0 ; if ( $scope . total_mem > 0 ) { framework . mem_share = framework . resources . mem / $scope . total_mem ; } framework . max_share = Math . max ( framework . cpus_share , framework . mem_share ) ; } ) ; _ . each ( $scope . offers , function ( offer ) { $scope . offered_cpus += offer . resources . cpus ; $scope . offered_mem += offer . resources . mem ; offer . framework_name = $scope . frameworks [ offer . framework_id ] . name ; offer . hostname = $scope . slaves [ offer . slave_id ] . hostname ; } ) ; $scope . used_cpus -= $scope . offered_cpus ; $scope . used_mem -= $scope . offered_mem ; $scope . idle_cpus = $scope . total_cpus - ( $scope . offered_cpus + $scope . used_cpus ) ; $scope . idle_mem = $scope . total_mem - ( $scope . offered_mem + $scope . used_mem ) ; $scope . time_since_update = 0 ; $ . event . trigger ( 'state_updated' ) ; return true ; }
Update the outermost scope with the new state.
Update the outermost scope with the new state .
// Don't do anything if the data hasn't changed. // Continue polling. // Determine if there is a leader (and redirect if not the leader). // Redirect if we aren't the leader. // TODO(benh): Use '$window'. // Don't continue polling. // Check for selected text, and allow up to 20 seconds to pass before // potentially wiping the user highlighted text. // TODO(bmahler): This is to avoid the annoying loss of highlighting when // the tables update. Once we can have tighter granularity control on the // angular.js dynamic table updates, we should remove this hack. // Update the maps. // Update the stats. // Continue polling.