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 2016/12/12 18:18:42 UTC

qpid-dispatch git commit: DISPATCH-592 Auto login to host:port that served stand-alone console. Move hawtio auto-login to hawtio specific code

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master e7bcfea40 -> 7de6ac3b5


DISPATCH-592 Auto login to host:port that served stand-alone console. Move hawtio auto-login to hawtio specific code


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/7de6ac3b
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/7de6ac3b
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/7de6ac3b

Branch: refs/heads/master
Commit: 7de6ac3b51b5986ad829d709a116e9c8cfe2ed85
Parents: e7bcfea
Author: Ernest Allen <ea...@redhat.com>
Authored: Mon Dec 12 13:18:20 2016 -0500
Committer: Ernest Allen <ea...@redhat.com>
Committed: Mon Dec 12 13:18:20 2016 -0500

----------------------------------------------------------------------
 .../src/main/webapp/plugin/js/dispatchPlugin.js |  33 +++-
 console/stand-alone/plugin/html/qdrConnect.html |   2 +-
 console/stand-alone/plugin/js/dispatchPlugin.js |  68 +++++++-
 console/stand-alone/plugin/js/qdrList.js        |  63 ++++----
 console/stand-alone/plugin/js/qdrService.js     | 160 ++++++++++---------
 console/stand-alone/plugin/js/qdrSettings.js    |  37 ++---
 6 files changed, 233 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7de6ac3b/console/hawtio/src/main/webapp/plugin/js/dispatchPlugin.js
----------------------------------------------------------------------
diff --git a/console/hawtio/src/main/webapp/plugin/js/dispatchPlugin.js b/console/hawtio/src/main/webapp/plugin/js/dispatchPlugin.js
index 124eec0..28ff1be 100644
--- a/console/hawtio/src/main/webapp/plugin/js/dispatchPlugin.js
+++ b/console/hawtio/src/main/webapp/plugin/js/dispatchPlugin.js
@@ -114,7 +114,6 @@ var QDR = (function(QDR) {
     })
     .filter('to_trusted', function($sce){
       return function(text) {
-      debugger;
         return $sce.trustAsHtml(text);
       };
       })
@@ -177,7 +176,7 @@ var QDR = (function(QDR) {
    *     plugin.  This is just a matter of adding to the workspace's
    *     topLevelTabs array.
    */
-  QDR.module.run(function(workspace, viewRegistry, layoutFull, $route, $rootScope, $location, localStorage, QDRService, QDRChartService) {
+  QDR.module.run(function(workspace, viewRegistry, layoutFull, $route, $rootScope, $location, $timeout, localStorage, QDRService, QDRChartService) {
     QDR.log.info("*************creating Dispatch Console************");
     var curPath = $location.path()
     QDR.log.info("curPath is " + curPath)
@@ -219,6 +218,36 @@ var QDR = (function(QDR) {
       QDRChartService.init(); // initialize charting service after we are connected
     });
 
+    var settings = angular.fromJson(localStorage[QDR.SETTINGS_KEY]);
+    if (settings && settings.autostart) {
+      QDRService.addConnectAction(function() {
+        QDRService.addDisconnectAction( function () {
+          $location.path(QDR.pluginRoot + "/connect");
+          $location.replace();
+          $rootScope.$apply();
+        })
+        QDRService.getSchema(function () {
+          QDR.log.debug("got schema after connection")
+          QDRService.addUpdatedAction("initialized", function () {
+            QDRService.delUpdatedAction("initialized")
+            QDR.log.debug("got initial topology")
+            $timeout(function() {
+              if ($location.path().startsWith(QDR.pluginRoot)) {
+                var lastLocation = localStorage[QDR.LAST_LOCATION] || "/overview"
+                $location.search('org', null)
+                $location.path(lastLocation);
+                $location.replace();
+                $rootScope.$apply();
+              }
+            })
+          })
+          QDR.log.debug("requesting a topology")
+          QDRService.setUpdateEntities([])
+          QDRService.topology.get()
+        })
+      });
+      QDRService.connect(settings);
+    }
     $rootScope.$on('$routeChangeSuccess', function() {
       var path = $location.path();
       if (path.startsWith(QDR.pluginRoot)) {

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7de6ac3b/console/stand-alone/plugin/html/qdrConnect.html
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/html/qdrConnect.html b/console/stand-alone/plugin/html/qdrConnect.html
index 1ca10b2..8a73177 100644
--- a/console/stand-alone/plugin/html/qdrConnect.html
+++ b/console/stand-alone/plugin/html/qdrConnect.html
@@ -25,7 +25,7 @@ under the License.
                           Enter the address and a HTML-enabled port of a <strong><a href="http://qpid.apache.org/components/dispatch-router/" target="_blank">Qpid Dispatch Router</a></strong> to connect..
                       </p>
                       <p>
-                          When Autostart is checked, you will be automatically logged in to the router the next time you start the console.
+                          If Autostart is checked, you will be automatically logged in to the router the next time you start the console.
                       </p>
 
                   </div>

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7de6ac3b/console/stand-alone/plugin/js/dispatchPlugin.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/dispatchPlugin.js b/console/stand-alone/plugin/js/dispatchPlugin.js
index 746fb19..7949ceb 100644
--- a/console/stand-alone/plugin/js/dispatchPlugin.js
+++ b/console/stand-alone/plugin/js/dispatchPlugin.js
@@ -78,20 +78,35 @@ var QDR = (function(QDR) {
   QDR.module.config(function($routeProvider) {
     $routeProvider
       .when('/', {
-        templateUrl: QDR.templatePath + 'qdrConnect.html'
+        templateUrl: QDR.templatePath + 'qdrOverview.html'
+        })
+      .when('/QDR/overview', {
+        templateUrl: QDR.templatePath + 'qdrOverview.html'
         })
       .when('/overview', {
           templateUrl: QDR.templatePath + 'qdrOverview.html'
         })
+      .when('/QDR/topology', {
+          templateUrl: QDR.templatePath + 'qdrTopology.html'
+        })
       .when('/topology', {
           templateUrl: QDR.templatePath + 'qdrTopology.html'
         })
+      .when('/QDR/list', {
+          templateUrl: QDR.templatePath + 'qdrList.html'
+        })
       .when('/list', {
           templateUrl: QDR.templatePath + 'qdrList.html'
         })
+      .when('/QDR/schema', {
+          templateUrl: QDR.templatePath + 'qdrSchema.html'
+        })
       .when('/schema', {
           templateUrl: QDR.templatePath + 'qdrSchema.html'
         })
+      .when('/QDR/charts', {
+          templateUrl: QDR.templatePath + 'qdrCharts.html'
+        })
       .when('/charts', {
           templateUrl: QDR.templatePath + 'qdrCharts.html'
         })
@@ -183,10 +198,53 @@ var QDR = (function(QDR) {
       QDRService.delUpdatedAction("initChartService")
       QDRChartService.init(); // initialize charting service after we are connected
     });
-    $timeout(function () {
-      $location.path('/connect')
-      $location.search('org', org)
-    })
+
+    var settings = angular.fromJson(localStorage[QDR.SETTINGS_KEY]) || {autostart: false, address: 'localhost', port: 5673}
+    if (!QDRService.connected) {
+      // attempt to connect to the host:port that served this page
+      var protocol = $location.protocol()
+      var host = $location.host()
+      var port = $location.port()
+      var search = $location.search()
+      if (search.org) {
+        if (search.org === 'connect')
+          $location.search("org", "overview")
+      }
+
+      QDRService.testConnect({address: host, port: port, reconnect: true}, 10000, function (e) {
+        if (e.error) {
+          QDR.log.debug("failed to auto-connect to " + host + ":" + port)
+          // the connect page should rneder
+          $timeout(function () {
+            $location.path('/connect')
+            $location.search('org', org)
+          })
+        } else {
+          QDRService.addConnectAction(function() {
+            QDRService.getSchema(function () {
+              QDR.log.debug("got schema after connection")
+              QDRService.addUpdatedAction("initialized", function () {
+                QDRService.delUpdatedAction("initialized")
+                QDR.log.debug("got initial topology")
+                $timeout(function() {
+                  if (org === '' || org === 'connect') {
+                    org = localStorage[QDR.LAST_LOCATION] || "/overview"
+                  }
+                  QDR.log.debug("after initialization going to " + org)
+                  $location.path(org)
+                  $location.search('org', null)
+                  $location.replace()
+                })
+              })
+              QDR.log.debug("requesting a topology")
+              QDRService.setUpdateEntities([])
+              QDRService.topology.get()
+            })
+          });
+          QDRService.connect(e)
+        }
+      })
+    }
 
     $rootScope.$on('$routeChangeSuccess', function() {
       var path = $location.path();

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7de6ac3b/console/stand-alone/plugin/js/qdrList.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrList.js b/console/stand-alone/plugin/js/qdrList.js
index d5c0873..521a87a 100644
--- a/console/stand-alone/plugin/js/qdrList.js
+++ b/console/stand-alone/plugin/js/qdrList.js
@@ -43,45 +43,50 @@ var QDR = (function(QDR) {
     $scope.selectedRecordName = localStorage['QDRSelectedRecordName'];
     $scope.nodes = []
     $scope.currentNode = undefined;
-    $scope.modes = [{
-          content: '<a><i class="icon-list"></i> Attributes</a>',
-      id: 'attributes',
-      op: 'READ',
-      title: "View router attributes",
-          isValid: function () { return true; }
+    $scope.modes = [
+      {
+        content: '<a><i class="icon-list"></i> Attributes</a>',
+        id: 'attributes',
+        op: 'READ',
+        title: "View router attributes",
+        isValid: function () { return true; }
       },
       {
-          content: '<a><i class="icon-edit"></i> Update</a>',
-          id: 'operations',
-          op: 'UPDATE',
-          title: "Update this attribute",
-          isValid: function () { return $scope.operations.indexOf(this.op) > -1 }
+        content: '<a><i class="icon-edit"></i> Update</a>',
+        id: 'operations',
+        op: 'UPDATE',
+        title: "Update this attribute",
+        isValid: function () {
+          QDR.log.debug("isValid UPDAATE? " + this.op)
+          console.dump($scope.operations)
+          return $scope.operations.indexOf(this.op) > -1
+        }
       },
       {
-          content: '<a><i class="icon-plus"></i> Create</a>',
-          id: 'operations',
-          op: 'CREATE',
-          title: "Create a new attribute",
-          isValid: function () { return $scope.operations.indexOf(this.op) > -1 }
+        content: '<a><i class="icon-plus"></i> Create</a>',
+        id: 'operations',
+        op: 'CREATE',
+        title: "Create a new attribute",
+        isValid: function () { return $scope.operations.indexOf(this.op) > -1 }
       },
       {
-          content: '<a><i class="icon-remove"></i> Delete</a>',
-          id: 'delete',
-          op: 'DELETE',
-          title: "Delete",
-          isValid: function () { return $scope.operations.indexOf(this.op) > -1 }
+        content: '<a><i class="icon-remove"></i> Delete</a>',
+        id: 'delete',
+        op: 'DELETE',
+        title: "Delete",
+        isValid: function () { return $scope.operations.indexOf(this.op) > -1 }
       },
       {
-          content: '<a><i class="icon-eye-open"></i> Fetch</a>',
-          id: 'log',
-          op: 'GET-LOG',
-          title: "Fetch recent log entries",
-          isValid: function () { return ($scope.selectedEntity === 'log') }
+        content: '<a><i class="icon-eye-open"></i> Fetch</a>',
+        id: 'log',
+        op: 'GET-LOG',
+        title: "Fetch recent log entries",
+        isValid: function () { return ($scope.selectedEntity === 'log') }
       }
-      ];
+    ];
     $scope.operations = []
-        $scope.currentMode = $scope.modes[0];
-    $scope.isModeSelected = function (mode) {
+      $scope.currentMode = $scope.modes[0];
+      $scope.isModeSelected = function (mode) {
       return mode === $scope.currentMode;
     }
     $scope.fetchingLog = false;

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7de6ac3b/console/stand-alone/plugin/js/qdrService.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrService.js b/console/stand-alone/plugin/js/qdrService.js
index 6b08b2e..0baa3a9 100644
--- a/console/stand-alone/plugin/js/qdrService.js
+++ b/console/stand-alone/plugin/js/qdrService.js
@@ -34,12 +34,6 @@ var QDR = (function(QDR) {
       updatedActions: {},
       updating: false,        // are we updating the node list in the background
       maxCorrelatorDepth: 10, // max number of outstanding requests to allow
-      /**
-       * @property options
-       * Holds a reference to the connection options when
-       * a connection is started
-       */
-      options: undefined,
 
       /*
        * @property message
@@ -53,7 +47,6 @@ var QDR = (function(QDR) {
 
       schema: undefined,
 
-      toAddress: undefined,
       connected: false,
       gotTopology: false,
       errorText: undefined,
@@ -113,7 +106,7 @@ console.dump(e)
         }
       },
       redirectWhenConnected: function(org) {
-        $location.path("/" + QDR.pluginName + "/connect")
+        $location.path("/connect")
         $location.search('org', org);
       },
 
@@ -810,7 +803,6 @@ console.dump(e)
           self.topology.error(Error("unexpected format for router address: " + toAddr));
           return;
         }
-        //var fullAddr =  self.toAddress + "/" + toAddrParts.join('/');
         var fullAddr = toAddrParts.join('/');
         return fullAddr;
       },
@@ -924,8 +916,39 @@ console.dump(e)
         self.errorText = "Disconnected."
       },
 
+      connectionTimer: null,
+
+      testConnect: function (options, timeout, callback) {
+        clearTimeout(self.connectionTimer)
+        var connection;
+        var reconnect = angular.isDefined(options.reconnect) ? options.reconnect : true
+        QDR.log.debug("testConnect called with reconnect " + reconnect)
+        var baseAddress = options.address + ':' + options.port;
+        try {
+            var ws = self.rhea.websocket_connect(WebSocket);
+            connection = self.rhea.connect({
+            connection_details: ws('ws://' + baseAddress, ["binary"]),
+            reconnect: reconnect,
+            properties: {
+              console_identifier: 'Dispatch console'
+            }
+          });
+        } catch (e) {
+          QDR.log.debug("exception caught on test connect")
+          self.errorText = "Connection failed"
+          callback({error: e})
+        }
+        self.connectionTimer = setTimeout(function () {
+          callback({error: "timedout"})
+        }, timeout)
+        connection.on("connection_open", function (context) {
+          clearTimeout(self.connectionTimer)
+          callback({connection: connection, context: context})
+        })
+      },
+
       connect: function(options) {
-        self.options = options;
+        clearTimeout(self.connectionTimer)
         self.topologyInitialized = false;
         if (!self.connected) {
           var okay = {
@@ -933,10 +956,7 @@ console.dump(e)
             sender: false,
             receiver: false
           }
-          var port = options.port || 5673;
-          var baseAddress = options.address + ':' + port;
-          var ws = self.rhea.websocket_connect(WebSocket);
-          self.toAddress = "amqp://" + baseAddress;
+          var sender, receiver
           self.connectionError = undefined;
 
           var stop = function(context) {
@@ -968,67 +988,63 @@ console.dump(e)
             self.executeDisconnectActions();
           }
 
-          QDR.log.debug("****** calling rhea.connect ********")
-          var connection;
-          try {
-              connection = self.rhea.connect({
-                  // FIXME aconway 2016-11-29: "binary" for wsproxy,
-                  // should also include "amqp" - waiting on libwebsocket fix.
-              connection_details: ws('ws://' + baseAddress, ["binary"]),
-              reconnect: true,
-              properties: {
-                console_identifier: 'Dispatch console'
-              }
-            });
-          } catch (e) {
-            QDR.log.debug("exception caught on connect")
-            self.errorText = "Connection failed"
-            onDisconnect();
-          }
-          if (!self.connectionError) {
-            connection.on('connection_open', function(context) {
-              self.version = context.connection.properties.version
+          // called after connection.open event is fired or connection error has happened
+          var connectionCallback = function (options) {
+            if (!options.error) {
+              connection = options.connection
+              self.version = options.context.connection.properties.version
               QDR.log.debug("connection_opened")
               okay.connection = true;
               okay.receiver = false;
               okay.sender = false;
-            })
-            connection.on('disconnected', function(context) {
-              QDR.log.debug("connection disconnected")
-              self.errorText = "Unable to connect"
-              onDisconnect();
-            })
-            connection.on('connection_close', function(context) {
-              QDR.log.debug("connection closed")
-              self.errorText = "Disconnected"
-              onDisconnect();
-            })
 
-            var sender = connection.open_sender();
-            sender.on('sender_open', function(context) {
-              QDR.log.debug("sender_opened")
-              okay.sender = true
-              maybeStart()
-            })
-            sender.on('sendable', function(context) {
-              //QDR.log.debug("sendable")
-              self.sendable = true;
-              maybeStart();
-            })
+              connection.on('disconnected', function(context) {
+                QDR.log.debug("connection disconnected")
+                self.errorText = "Unable to connect"
+                onDisconnect();
+              })
+              connection.on('connection_close', function(context) {
+                QDR.log.debug("connection closed")
+                self.errorText = "Disconnected"
+                onDisconnect();
+              })
 
-            var receiver = connection.open_receiver({
-              source: {
-                dynamic: true
-              }
-            });
-            receiver.on('receiver_open', function(context) {
-              QDR.log.debug("receiver_opened")
-              okay.receiver = true;
-              maybeStart()
-            })
-            receiver.on("message", function(context) {
-              self.correlator.resolve(context);
-            });
+              sender = connection.open_sender();
+              sender.on('sender_open', function(context) {
+                QDR.log.debug("sender_opened")
+                okay.sender = true
+                maybeStart()
+              })
+              sender.on('sendable', function(context) {
+                //QDR.log.debug("sendable")
+                self.sendable = true;
+                maybeStart();
+              })
+
+              receiver = connection.open_receiver({
+                source: {
+                  dynamic: true
+                }
+              });
+              receiver.on('receiver_open', function(context) {
+                QDR.log.debug("receiver_opened")
+                okay.receiver = true;
+                maybeStart()
+              })
+              receiver.on("message", function(context) {
+                self.correlator.resolve(context);
+              });
+            }
+          }
+
+          QDR.log.debug("****** calling rhea.connect ********")
+          var connection;
+          if (!options.connection) {
+            QDR.log.debug("rhea.connect was not passed an existing connection")
+            self.testConnect(options, 10000, connectionCallback)
+          } else {
+            QDR.log.debug("rhea.connect WAS passed an existing connection")
+            connectionCallback(options)
           }
         }
       }
@@ -1041,11 +1057,11 @@ console.dump(e)
 }(QDR || {}));
 
 (function() {
-  console.dump = function(object) {
+  console.dump = function(o) {
     if (window.JSON && window.JSON.stringify)
-      QDR.log.info(JSON.stringify(object, undefined, 2));
+      QDR.log.info(JSON.stringify(o, undefined, 2));
     else
-      console.log(object);
+      console.log(o);
   };
 })();
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/7de6ac3b/console/stand-alone/plugin/js/qdrSettings.js
----------------------------------------------------------------------
diff --git a/console/stand-alone/plugin/js/qdrSettings.js b/console/stand-alone/plugin/js/qdrSettings.js
index 499b953..f7f8dab 100644
--- a/console/stand-alone/plugin/js/qdrSettings.js
+++ b/console/stand-alone/plugin/js/qdrSettings.js
@@ -71,27 +71,25 @@ var QDR = (function(QDR) {
       }
     }
 
-    var doConnect = function() {
+    var doConnect = function(opts) {
       if (!$scope.formEntity.address)
         $scope.formEntity.address = "localhost"
 
-      console.log("attempting to connect to " + $scope.formEntity.address + ':' + $scope.formEntity.port);
-      QDRService.addDisconnectAction(function() {
-        $timeout(function() {
-          QDR.log.debug("disconnect action called");
-          $scope.connecting = false;
-          $scope.connectionErrorText = QDRService.errorText;
-          $scope.connectionError = true;
-        })
-      });
       QDRService.addConnectAction(function() {
+        QDRService.addDisconnectAction(function() {
+          $timeout(function() {
+            QDR.log.debug("disconnect action called");
+            $scope.connecting = false;
+            $scope.connectionErrorText = QDRService.errorText;
+            $scope.connectionError = true;
+          })
+        });
         QDRService.getSchema(function () {
           QDR.log.debug("got schema after connection")
           QDRService.addUpdatedAction("initialized", function () {
             QDRService.delUpdatedAction("initialized")
             QDR.log.debug("got initial topology")
             $timeout(function() {
-QDR.log.debug("changing location to ")
               $scope.connecting = false;
               if ($location.path().startsWith(QDR.pluginRoot)) {
                   var searchObject = $location.search();
@@ -101,7 +99,6 @@ QDR.log.debug("changing location to ")
                   }
                   $location.search('org', null)
                   $location.path(QDR.pluginRoot + "/" + goto);
-QDR.log.debug(QDR.pluginRoot + "/" + goto)
               }
             })
           })
@@ -110,16 +107,14 @@ QDR.log.debug(QDR.pluginRoot + "/" + goto)
           QDRService.topology.get()
         })
       });
-      QDRService.connect($scope.formEntity);
-    }
-
-    var settings = angular.fromJson(localStorage[QDR.SETTINGS_KEY]);
-    if (settings && settings.autostart && !QDRService.connected) {
-      $scope.connectionError = false;
-      $scope.connecting = true;
-      doConnect()
+      var options = {address: $scope.formEntity.address, port: $scope.formEntity.port}
+      // if we have already successfully connected (the test connections succeeded)
+      if (opts && opts.connection) {
+        options.connection = opts.connection
+        options.context = opts.context
+      }
+      QDRService.connect(options);
     }
-
   }]);
 
 


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