mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r1364825 - in /incubator/mesos/trunk/src: master/http.cpp master/master.cpp master/master.hpp webui/master/static/controllers.js webui/master/static/index.html
Date Mon, 23 Jul 2012 22:33:36 GMT
Author: benh
Date: Mon Jul 23 22:33:35 2012
New Revision: 1364825

URL: http://svn.apache.org/viewvc?rev=1364825&view=rev
Log:
Added current master "leader" to '/state.json' as well as redirection
in the webui (https://reviews.apache.org/r/6083).

Modified:
    incubator/mesos/trunk/src/master/http.cpp
    incubator/mesos/trunk/src/master/master.cpp
    incubator/mesos/trunk/src/master/master.hpp
    incubator/mesos/trunk/src/webui/master/static/controllers.js
    incubator/mesos/trunk/src/webui/master/static/index.html

Modified: incubator/mesos/trunk/src/master/http.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/http.cpp?rev=1364825&r1=1364824&r2=1364825&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/http.cpp (original)
+++ incubator/mesos/trunk/src/master/http.cpp Mon Jul 23 22:33:35 2012
@@ -269,6 +269,11 @@ Future<Response> state(
   object.values["id"] = master.info.id();
   object.values["pid"] = string(master.self());
 
+  // TODO(benh): Use an Option for the leader PID.
+  if (master.leader != UPID()) {
+    object.values["leader"] = string(master.leader);
+  }
+
   if (master.flags.log_dir.isSome()) {
     object.values["log_dir"] = master.flags.log_dir.get();
   }

Modified: incubator/mesos/trunk/src/master/master.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.cpp?rev=1364825&r1=1364824&r2=1364825&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.cpp (original)
+++ incubator/mesos/trunk/src/master/master.cpp Mon Jul 23 22:33:35 2012
@@ -528,16 +528,16 @@ void Master::newMasterDetected(const UPI
   // master, (2) newly elected master, (3) no longer elected master,
   // or (4) still elected master.
 
-  UPID master = pid;
+  leader = pid;
 
-  if (master != self() && !elected) {
+  if (leader != self() && !elected) {
     LOG(INFO) << "Waiting to be master!";
-  } else if (master == self() && !elected) {
+  } else if (leader == self() && !elected) {
     LOG(INFO) << "Elected as master!";
     elected = true;
-  } else if (master != self() && elected) {
+  } else if (leader != self() && elected) {
     LOG(FATAL) << "No longer elected master ... committing suicide!";
-  } else if (master == self() && elected) {
+  } else if (leader == self() && elected) {
     LOG(INFO) << "Still acting as master!";
   }
 }

Modified: incubator/mesos/trunk/src/master/master.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/master/master.hpp?rev=1364825&r1=1364824&r2=1364825&view=diff
==============================================================================
--- incubator/mesos/trunk/src/master/master.hpp (original)
+++ incubator/mesos/trunk/src/master/master.hpp Mon Jul 23 22:33:35 2012
@@ -198,6 +198,8 @@ private:
 
   const flags::Flags<logging::Flags, master::Flags> flags;
 
+  UPID leader; // Current leading master.
+
   bool elected;
 
   Allocator* allocator;

Modified: incubator/mesos/trunk/src/webui/master/static/controllers.js
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/master/static/controllers.js?rev=1364825&r1=1364824&r2=1364825&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/master/static/controllers.js (original)
+++ incubator/mesos/trunk/src/webui/master/static/controllers.js Mon Jul 23 22:33:35 2012
@@ -2,15 +2,41 @@
 
 
 // Update the outermost scope with the new state.
-function update($scope, data) {
+function update($scope, $defer, data) {
   // Don't do anything if the data hasn't changed.
   if ($scope.data == data) {
-    return;
+    return true; // Continue polling.
   }
 
   $scope.data = data;
   $scope.state = $.parseJSON(data);
 
+  // Determine if there is a leader (and redirect if not the leader).
+  if (!$scope.state.leader) {
+    $("#no-leader-alert").show();
+  } else {
+    $("#no-leader-alert").hide();
+
+    // Redirect if we aren't the leader.
+    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) {
+          // TODO(benh): Use '$window'.
+          window.location = 'http://' + $scope.leader;
+        } else {
+          $scope.redirect = $scope.redirect - 1000;
+          $defer(countdown, 1000);
+        }
+      }
+      countdown();
+      return false; // Don't continue polling.
+    }
+  }
+
   $scope.total_cpus = 0;
   $scope.total_mem = 0;
   $scope.used_cpus = 0;
@@ -75,6 +101,8 @@ function update($scope, data) {
   });
 
   $.event.trigger('state_updated');
+
+  return true; // Continue polling.
 }
 
 // Main controller that can be used to handle "global" events. E.g.,:
@@ -100,9 +128,10 @@ function MainCntl($scope, $http, $route,
     $http.get('master/state.json',
               {transformResponse: function(data) { return data; }})
       .success(function(data) {
-        update($scope, data);
-        $scope.delay = 2000;
-        $defer(poll, $scope.delay);
+        if (update($scope, $defer, data)) {
+          $scope.delay = 2000;
+          $defer(poll, $scope.delay);
+        }
       })
       .error(function(data) {
         if ($scope.delay >= 128000) {
@@ -111,7 +140,7 @@ function MainCntl($scope, $http, $route,
           $scope.delay = $scope.delay * 2;
         }
         $scope.retry = $scope.delay;
-        function countdown() {
+        var countdown = function() {
           if ($scope.retry == 0) {
             $('#error-modal').modal('hide');
           } else {

Modified: incubator/mesos/trunk/src/webui/master/static/index.html
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/webui/master/static/index.html?rev=1364825&r1=1364824&r2=1364825&view=diff
==============================================================================
--- incubator/mesos/trunk/src/webui/master/static/index.html (original)
+++ incubator/mesos/trunk/src/webui/master/static/index.html Mon Jul 23 22:33:35 2012
@@ -53,6 +53,16 @@
     <div ng-controller="MainCntl">
 
       <div class="container">
+        <div class="alert hide" id="no-leader-alert">
+          <button class="close" data-dismiss="alert">×</button>
+          <strong>No master is currently leading ...</strong>
+        </div>
+        <div class="alert alert-error hide" id="not-leader-alert">
+          <button class="close" data-dismiss="alert">×</button>
+          <strong>This master is <u>not the leader</u>, redirecting in
{{redirect / 1000}} seconds ...</strong>
+          <a href="http://{{leader}}">go now</a>
+        </div>
+
         <div ng-view></div>
       </div>
 



Mime
View raw message