You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ea...@apache.org on 2019/01/23 14:01:50 UTC

[qpid-dispatch] branch master updated: DISPATCH-1252 Allow console to redirect to connect page if connection is lost

This is an automated email from the ASF dual-hosted git repository.

eallen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/master by this push:
     new ae6f30d  DISPATCH-1252 Allow console to redirect to connect page if connection is lost
ae6f30d is described below

commit ae6f30dea2e5da7eee632711d061fbb17e5f8ebd
Author: Ernest Allen <ea...@redhat.com>
AuthorDate: Wed Jan 23 09:01:32 2019 -0500

    DISPATCH-1252 Allow console to redirect to connect page if connection is lost
---
 console/stand-alone/plugin/js/amqp/topology.js | 80 +++++++++++++-------------
 console/stand-alone/plugin/js/qdrGlobals.js    |  1 +
 console/stand-alone/plugin/js/qdrService.js    | 57 +++++++++---------
 3 files changed, 71 insertions(+), 67 deletions(-)

diff --git a/console/stand-alone/plugin/js/amqp/topology.js b/console/stand-alone/plugin/js/amqp/topology.js
index 24f504e..baff73e 100644
--- a/console/stand-alone/plugin/js/amqp/topology.js
+++ b/console/stand-alone/plugin/js/amqp/topology.js
@@ -19,15 +19,15 @@
 import { utils } from "./utilities.js";
 
 class Topology {
-  constructor(connectionManager) {
+  constructor(connectionManager, interval) {
     this.connection = connectionManager;
     this.updatedActions = {};
     this.entities = []; // which entities to request each topology update
-    this.entityAttribs = {connection: []};
+    this.entityAttribs = { connection: [] };
     this._nodeInfo = {}; // info about all known nodes and entities
     this.filtering = false; // filter out nodes that don't have connection info
     this.timeout = 5000;
-    this.updateInterval = 5000;
+    this.updateInterval = interval;
     this._getTimer = null;
     this.updating = false;
   }
@@ -82,7 +82,7 @@ class Topology {
           if (
             !this._nodeInfo[rId][entity] ||
             workInfo[rId][entity]["timestamp"] + "" >
-              this._nodeInfo[rId][entity]["timestamp"] + ""
+            this._nodeInfo[rId][entity]["timestamp"] + ""
           ) {
             this._nodeInfo[rId][entity] = utils.copy(workInfo[rId][entity]);
           }
@@ -108,9 +108,9 @@ class Topology {
   }
   get() {
     return new Promise(
-      function(resolve, reject) {
+      function (resolve, reject) {
         this.connection.sendMgmtQuery("GET-MGMT-NODES").then(
-          function(results) {
+          function (results) {
             let routerIds = results.response;
             if (
               Object.prototype.toString.call(routerIds) === "[object Array]"
@@ -121,12 +121,12 @@ class Topology {
                 parts[parts.length - 1] = "$management";
                 routerIds.push(parts.join("/"));
               }
-              let finish = function(workInfo) {
+              let finish = function (workInfo) {
                 this.saveResults(workInfo);
                 this.onDone(this._nodeInfo);
                 resolve(this._nodeInfo);
               };
-              let connectedToEdge = function(response, workInfo) {
+              let connectedToEdge = function (response, workInfo) {
                 let routerId = null;
                 if (response.length === 1) {
                   let parts = response[0].split("/");
@@ -152,14 +152,14 @@ class Topology {
                 return routerId;
               };
               this.doget(routerIds).then(
-                function(workInfo) {
+                function (workInfo) {
                   // test for edge case
                   let routerId = connectedToEdge(routerIds, workInfo);
                   if (routerId) {
                     this.connection
                       .sendMgmtQuery("GET-MGMT-NODES", routerId)
                       .then(
-                        function(results) {
+                        function (results) {
                           let response = results.response;
                           if (
                             Object.prototype.toString.call(response) ===
@@ -172,7 +172,7 @@ class Topology {
                               response = [routerId];
                             }
                             this.doget(response).then(
-                              function(workInfo) {
+                              function (workInfo) {
                                 finish.call(this, workInfo);
                               }.bind(this)
                             );
@@ -186,7 +186,7 @@ class Topology {
               );
             }
           }.bind(this),
-          function(error) {
+          function (error) {
             reject(error);
           }
         );
@@ -195,12 +195,12 @@ class Topology {
   }
   doget(ids) {
     return new Promise(
-      function(resolve) {
+      function (resolve) {
         let workInfo = {};
         for (var i = 0; i < ids.length; ++i) {
           workInfo[ids[i]] = {};
         }
-        var gotResponse = function(nodeName, entity, response) {
+        var gotResponse = function (nodeName, entity, response) {
           workInfo[nodeName][entity] = response;
           workInfo[nodeName][entity]["timestamp"] = new Date();
         };
@@ -218,7 +218,7 @@ class Topology {
           }
         }
         q.await(
-          function() {
+          function () {
             // filter out nodes that have no connection info
             if (this.filtering) {
               for (var id in workInfo) {
@@ -256,7 +256,7 @@ class Topology {
   }
   fetchEntity(node, entity, attrs, callback) {
     var results = {};
-    var gotResponse = function(nodeName, dotentity, response) {
+    var gotResponse = function (nodeName, dotentity, response) {
       results = response;
     };
     var q = d3.queue(this.connection.availableQeueuDepth());
@@ -268,13 +268,13 @@ class Topology {
       q,
       gotResponse
     );
-    q.await(function() {
+    q.await(function () {
       callback(node, entity, results);
     });
   }
   // called from d3.queue.defer so the last argument (callback) is supplied by d3
   q_fetchNodeInfo(nodeId, entity, attrs, q, heartbeat, callback) {
-    this.getNodeInfo(nodeId, entity, attrs, q, function(
+    this.getNodeInfo(nodeId, entity, attrs, q, function (
       nodeName,
       dotentity,
       response
@@ -288,12 +288,12 @@ class Topology {
     var q = d3.queue(this.connection.availableQeueuDepth());
     var results = {};
     if (!resultCallback) {
-      resultCallback = function(nodeName, dotentity, response) {
+      resultCallback = function (nodeName, dotentity, response) {
         if (!results[nodeName]) results[nodeName] = {};
         results[nodeName][dotentity] = response;
       };
     }
-    var gotAResponse = function(nodeName, dotentity, response) {
+    var gotAResponse = function (nodeName, dotentity, response) {
       resultCallback(nodeName, dotentity, response);
     };
     if (Object.prototype.toString.call(entityAttribs) !== "[object Array]") {
@@ -310,7 +310,7 @@ class Topology {
         gotAResponse
       );
     }
-    q.await(function() {
+    q.await(function () {
       doneCallback(results);
     });
   }
@@ -319,12 +319,12 @@ class Topology {
     var q = d3.queue(this.connection.availableQeueuDepth());
     var results = {};
     if (!resultCallback) {
-      resultCallback = function(nodeName, dotentity, response) {
+      resultCallback = function (nodeName, dotentity, response) {
         if (!results[nodeName]) results[nodeName] = {};
         results[nodeName][dotentity] = response;
       };
     }
-    var gotAResponse = function(nodeName, dotentity, response) {
+    var gotAResponse = function (nodeName, dotentity, response) {
       resultCallback(nodeName, dotentity, response);
     };
     if (Object.prototype.toString.call(entityAttribs) !== "[object Array]") {
@@ -344,7 +344,7 @@ class Topology {
         );
       }
     }
-    q.await(function() {
+    q.await(function () {
       doneCallback(results);
     });
   }
@@ -364,7 +364,7 @@ class Topology {
     }
     this.addUpdateEntities(entityAttribs);
     this.doget(nodes).then(
-      function(results) {
+      function (results) {
         this.saveResults(results);
         callback(extra, results);
       }.bind(this)
@@ -389,7 +389,7 @@ class Topology {
     var conns = this._nodeInfo[link.nodeId].connection;
     if (!conns) return {};
     var connIndex = conns.attributeNames.indexOf("identity");
-    var linkCons = conns.results.filter(function(conn) {
+    var linkCons = conns.results.filter(function (conn) {
       return conn[connIndex] === link.connectionId;
     });
     return utils.flatten(conns.attributeNames, linkCons[0]);
@@ -426,28 +426,28 @@ class Topology {
       entity,
       attrs,
       q,
-      function(nodeName, dotentity, response) {
+      function (nodeName, dotentity, response) {
         this.addNodeInfo(nodeName, dotentity, response);
         callback(null);
       }.bind(this)
     );
     return {
-      abort: function() {
+      abort: function () {
         delete this._nodeInfo[nodeId];
       }
     };
   }
   getNodeInfo(nodeName, entity, attrs, q, callback) {
-    var timedOut = function(q) {
+    var timedOut = function (q) {
       q.abort();
     };
     var atimer = setTimeout(timedOut, this.timeout, q);
     this.connection.sendQuery(nodeName, entity, attrs).then(
-      function(response) {
+      function (response) {
         clearTimeout(atimer);
         callback(nodeName, entity, response.response);
       },
-      function() {
+      function () {
         q.abort();
       }
     );
@@ -463,11 +463,11 @@ class Topology {
     var self = this;
     if (typeof aggregate === "undefined") aggregate = true;
     var responses = {};
-    var gotNodesResult = function(nodeName, dotentity, response) {
+    var gotNodesResult = function (nodeName, dotentity, response) {
       responses[nodeName] = response;
     };
     var q = d3.queue(this.connection.availableQeueuDepth());
-    nodeNames.forEach(function(id) {
+    nodeNames.forEach(function (id) {
       q.defer(
         self.q_fetchNodeInfo.bind(self),
         id,
@@ -477,7 +477,7 @@ class Topology {
         gotNodesResult
       );
     });
-    q.await(function() {
+    q.await(function () {
       if (aggregate)
         self.aggregateNodeInfo(
           nodeNames,
@@ -517,7 +517,7 @@ class Topology {
       var result = thisNode.results[i];
       var vals = [];
       // there is a val for each attribute in this entity
-      result.forEach(function(val) {
+      result.forEach(function (val) {
         vals.push({
           sum: val,
           detail: []
@@ -529,15 +529,15 @@ class Topology {
     var ent = self.connection.schema.entityTypes[entity];
     var ids = Object.keys(responses);
     ids.sort();
-    ids.forEach(function(id) {
+    ids.forEach(function (id) {
       var response = responses[id];
       var results = response.results;
-      results.forEach(function(result) {
+      results.forEach(function (result) {
         // find the matching result in the aggregates
-        var found = newResponse.aggregates.some(function(aggregate) {
+        var found = newResponse.aggregates.some(function (aggregate) {
           if (aggregate[nameIndex].sum === result[nameIndex]) {
             // result and aggregate are now the same record, add the graphable values
-            newResponse.attributeNames.forEach(function(key, i) {
+            newResponse.attributeNames.forEach(function (key, i) {
               if (ent.attributes[key] && ent.attributes[key].graph) {
                 if (id != selectedNodeId) aggregate[i].sum += result[i];
               }
@@ -554,7 +554,7 @@ class Topology {
           // this attribute was not found in the aggregates yet
           // because it was not in the selectedNodeId's results
           var vals = [];
-          result.forEach(function(val) {
+          result.forEach(function (val) {
             vals.push({
               sum: val,
               detail: [
diff --git a/console/stand-alone/plugin/js/qdrGlobals.js b/console/stand-alone/plugin/js/qdrGlobals.js
index 6fadf14..42f5ee3 100644
--- a/console/stand-alone/plugin/js/qdrGlobals.js
+++ b/console/stand-alone/plugin/js/qdrGlobals.js
@@ -51,6 +51,7 @@ export class QDRLogger {
 export const QDRTemplatePath = 'html/';
 export const QDR_SETTINGS_KEY = 'QDRSettings';
 export const QDR_LAST_LOCATION = 'QDRLastLocation';
+export const QDR_INTERVAL = 'QDRInterval';
 
 export var QDRRedirectWhenConnected = function ($location, org) {
   $location.path('/connect');
diff --git a/console/stand-alone/plugin/js/qdrService.js b/console/stand-alone/plugin/js/qdrService.js
index 555b966..a51d3c2 100644
--- a/console/stand-alone/plugin/js/qdrService.js
+++ b/console/stand-alone/plugin/js/qdrService.js
@@ -20,65 +20,68 @@ Licensed to the Apache Software Foundation (ASF) under one
 import { Management as dm } from './amqp/management.js';
 import { utils } from './amqp/utilities.js';
 
-import { QDR_LAST_LOCATION, QDRLogger} from './qdrGlobals.js';
+import { QDR_LAST_LOCATION, QDRLogger, QDR_INTERVAL } from './qdrGlobals.js';
 
+// number of milliseconds between topology updates
+const DEFAULT_INTERVAL = 5000;
 export class QDRService {
   constructor($log, $timeout, $location) {
     this.$timeout = $timeout;
     this.$location = $location;
-    this.management = new dm($location.protocol());
+    this.management = new dm($location.protocol(), localStorage[QDR_INTERVAL] || DEFAULT_INTERVAL);
     this.utilities = utils;
     this.QDRLog = new QDRLogger($log, 'QDRService');
   }
-  
+
   // Example service function
-  onReconnect () {
-    this.management.connection.on('disconnected', this.onDisconnect);
+  onReconnect() {
+    this.management.connection.on('disconnected', this.onDisconnect.bind(this));
     let org = localStorage[QDR_LAST_LOCATION] || '/overview';
-    this.$timeout ( function () {
+    this.$timeout(function () {
       this.$location.path(org);
       this.$location.search('org', null);
       this.$location.replace();
     });
   }
-  onDisconnect () {
-    this.management.connection.on('connected', this.onReconnect);
-    this.$timeout( function () {
-      this.$location.path('/connect');
-      let curPath = this.$location.path();
+  onDisconnect() {
+    let self = this;
+    this.$timeout(function () {
+      self.$location.path('/connect');
+      let curPath = self.$location.path();
       let parts = curPath.split('/');
-      let org = parts[parts.length-1];
+      let org = parts[parts.length - 1];
       if (org && org.length > 0 && org !== 'connect') {
-        this.$location.search('org', org);
+        self.$location.search('org', org);
       } else {
-        this.$location.search('org', null);
+        self.$location.search('org', null);
       }
-      this.$location.replace();
+      self.$location.replace();
     });
+    this.management.connection.on('connected', this.onReconnect.bind(this));
   }
-  connect (connectOptions) {
+  connect(connectOptions) {
     let self = this;
-    return new Promise ( function (resolve, reject) {
+    return new Promise(function (resolve, reject) {
       self.management.connection.connect(connectOptions)
-        .then( function (r) {
+        .then(function (r) {
           // if we are ever disconnected, show the connect page and wait for a reconnect
-          self.management.connection.on('disconnected', self.onDisconnect);
+          self.management.connection.on('disconnected', self.onDisconnect.bind(self));
 
           self.management.getSchema()
-            .then( function () {
+            .then(function () {
               self.QDRLog.info('got schema after connection');
               self.management.topology.setUpdateEntities([]);
               self.QDRLog.info('requesting a topology');
               self.management.topology.get() // gets the list of routers
-                .then( function () {
+                .then(function () {
                   self.QDRLog.info('got initial topology');
                   let curPath = self.$location.path();
                   let parts = curPath.split('/');
-                  let org = parts[parts.length-1];
+                  let org = parts[parts.length - 1];
                   if (org === '' || org === 'connect') {
                     org = localStorage[QDR_LAST_LOCATION] || '/overview';
                   }
-                  self.$timeout ( function () {
+                  self.$timeout(function () {
                     self.$location.path(org);
                     self.$location.search('org', null);
                     self.$location.replace();
@@ -91,17 +94,17 @@ export class QDRService {
         });
     });
   }
-  disconnect () {
+  disconnect() {
     this.management.connection.disconnect();
     delete this.management;
-    this.management = new dm(this.$location.protocol());
+    this.management = new dm(this.$location.protocol(), localStorage[QDR_INTERVAL] || DEFAULT_INTERVAL);
   }
 }
 
 QDRService.$inject = ['$log', '$timeout', '$location'];
 
-(function() {
-  console.dump = function(o) {
+(function () {
+  console.dump = function (o) {
     if (window.JSON && window.JSON.stringify)
       console.log(JSON.stringify(o, undefined, 2));
     else


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org