You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/11/11 15:17:08 UTC

[04/11] incubator-brooklyn git commit: fix JS GUI server time race (rendering)

fix JS GUI server time race (rendering)

fixes a bug where a server with clock a few seconds ahead of local causes weird message "in a few seconds" and possible flapping with "a few seconds ago"; just backdate it to be a few seconds ago if delta < 10s, else say "server clock in future by a few seconds" (or other time if it's really out of sync)


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/396c600b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/396c600b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/396c600b

Branch: refs/heads/master
Commit: 396c600b15e2fb34882dbe0a1d95447d3bd2a0b2
Parents: 6a5242a
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Mon Nov 10 23:14:01 2014 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Nov 11 13:54:54 2014 +0000

----------------------------------------------------------------------
 .../main/webapp/assets/js/view/ha-summary.js    | 26 ++++++++++++++++----
 1 file changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/396c600b/usage/jsgui/src/main/webapp/assets/js/view/ha-summary.js
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/assets/js/view/ha-summary.js b/usage/jsgui/src/main/webapp/assets/js/view/ha-summary.js
index f700e34..fb96ea1 100644
--- a/usage/jsgui/src/main/webapp/assets/js/view/ha-summary.js
+++ b/usage/jsgui/src/main/webapp/assets/js/view/ha-summary.js
@@ -30,7 +30,7 @@ define([
                 "<% if (isSelf) { %><span class='pull-right badge badge-success'>this</span><% } %>" +
             "</td>" +
             "<td><%= status %></td>" +
-            "<td><span class='timestamp' data-timestamp='<%= timestamp %>'><%= timestampDisplay %><span></td>" +
+            "<td><%= timestampDisplayPrefix %><span class='timestamp' data-timestamp='<%= timestamp %>'><%= timestampDisplay %><span><%= timestampDisplaySuffix %></td>" +
         "</tr>");
     var noServers = "<tr><td colspan='3'><i>Failed to load servers!</i></td></tr>";
 
@@ -59,22 +59,38 @@ define([
             $target.empty();
             // undefined check just in case server returns something odd
             if (nodes == undefined || _.isEmpty(nodes)) {
-                $target.html(noServers)
+                $target.html(noServers);
             } else {
                 _.each(nodes, function (n) {
                     var node = _.clone(n);
+                    node.timestampDisplayPrefix = "";
+                    node.timestampDisplaySuffix = "";
                     if (node['remoteTimestamp']) {
                         node.timestamp = node.remoteTimestamp;
-                        node.timestampDisplay = moment(node.remoteTimestamp).fromNow();
                     } else {
                         node.timestamp = node.localTimestamp;
-                        node.timestampDisplay = moment(node.localTimestamp).fromNow()+" (local)";
+                        node.timestampDisplaySuffix = " (local)";
                     }
+                    if (node.timestamp >= moment().utc() + 10*1000) {
+                        // if server reports time significantly in future, report this, with no timestampe
+                        node.timestampDisplayPrefix = "server clock in future by "+
+                            moment.duration(moment(node.timestamp).diff(moment())).humanize();
+                        node.timestamp = "";
+                        node.timestampDisplay = "";
+                    } else {
+                        // else use timestamp
+                        if (node.timestamp >= moment().utc()) {
+                            // but if just a little bit in future, backdate to show "a few seconds ago"
+                            node.timestamp = moment().utc()-1;
+                        }
+                        node.timestampDisplay = moment(node.timestamp).fromNow();
+                    }
+                    
                     node.isSelf = node.nodeId == self;
                     node.isMaster = self == master;
                     node.isTerminated = node.status == "TERMINATED";
                     $target.append(nodeRowTemplate(node));
-                })
+                });
             }
         },
         updateTimestamps: function() {