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 2017/10/23 21:47:44 UTC

[42/45] qpid-dispatch git commit: DISPATCH-834 Add ability to read/write addresses to one or more routers

DISPATCH-834 Add ability to read/write addresses to one or more routers


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

Branch: refs/heads/master
Commit: d0a3dd763e41626f1d298d360eea0da8c391be3a
Parents: 251e142
Author: Ernest Allen <ea...@redhat.com>
Authored: Tue Oct 17 17:40:32 2017 -0400
Committer: Ernest Allen <ea...@redhat.com>
Committed: Tue Oct 17 17:40:32 2017 -0400

----------------------------------------------------------------------
 console/config/config.py             | 10 +++++-
 console/config/css/dispatch.css      |  2 +-
 console/config/html/qdrTopology.html | 15 +++++---
 console/config/js/qdrNewNode.js      | 24 ++++++++++---
 console/config/js/qdrTopology.js     | 59 ++++++++++++++++++++-----------
 console/config/mock/section.py       | 20 +++++++----
 6 files changed, 92 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d0a3dd76/console/config/config.py
----------------------------------------------------------------------
diff --git a/console/config/config.py b/console/config/config.py
index bae1240..1f73e8d 100755
--- a/console/config/config.py
+++ b/console/config/config.py
@@ -35,7 +35,7 @@ import subprocess
 from distutils.spawn import find_executable
 
 get_class = lambda x: globals()[x]
-sectionKeys = {"log": "module", "sslProfile": "name", "connector": "port", "listener": "port"}
+sectionKeys = {"log": "module", "sslProfile": "name", "connector": "port", "listener": "port", "address": "distribution"}
 
 # modified from qpid-dispatch/python/qpid_dispatch_internal/management/config.py
 def _parse(lines):
@@ -355,9 +355,15 @@ class Manager(object):
                 # write other sections
                 for sectionKey in sectionKeys:
                     if sectionKey+'s' in node:
+                        if self.verbose:
+                            print "found", sectionKey+'s'
                         for k in node[sectionKey+'s']:
+                            if self.verbose:
+                                print "processing", k
                             o = node[sectionKey+'s'][k]
                             cname = sectionKey[0].upper() + sectionKey[1:] + "Section"
+                            if self.verbose:
+                                print "class name is", cname
                             c = get_class(cname)
                             if sectionKey == "listener" and o['port'] != 'amqp' and int(o['port']) == http_port:
                                 config_fp.write("\n# Listener for a console\n")
@@ -365,6 +371,8 @@ class Manager(object):
                                     o['httpRoot'] = '/usr/local/share/qpid-dispatch/stand-alone'
                             if node.get('host') == o.get('host'):
                                 o['host'] = '0.0.0.0'
+                            if self.verbose:
+                                print "attributes", o, "is written as", str(c(**o))
                             config_fp.write(str(c(**o)) + "\n")
 
                 if 'listener' in node:

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d0a3dd76/console/config/css/dispatch.css
----------------------------------------------------------------------
diff --git a/console/config/css/dispatch.css b/console/config/css/dispatch.css
index d5b71d3..f21eecc 100644
--- a/console/config/css/dispatch.css
+++ b/console/config/css/dispatch.css
@@ -163,7 +163,7 @@ text.id {
   font-weight: bold;
 }
 
-text.id.log {
+text.id.log, text.id.address {
   text-anchor: middle;
   font-weight: normal;
 }

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d0a3dd76/console/config/html/qdrTopology.html
----------------------------------------------------------------------
diff --git a/console/config/html/qdrTopology.html b/console/config/html/qdrTopology.html
index 0788d4b..8b39fa0 100644
--- a/console/config/html/qdrTopology.html
+++ b/console/config/html/qdrTopology.html
@@ -57,6 +57,10 @@ under the License.
             <li ng-repeat="log in getSectionList(selected_node, 'log')" ng-click="editSection(selected_node, 'log', log)">Edit/Delete {{log}} log section</li>
 
             <li class="context-separator"></li>
+            <li ng-click="editSection(false, 'address', 'new')">Add new address section</li>
+            <li ng-repeat="address in getSectionList(selected_node, 'address')" ng-click="editSection(selected_node, 'address', address)">Edit/Delete {{address}} address section</li>
+
+            <li class="context-separator"></li>
             <li ng-click="editSection(selected_node, 'sslProfile', 'new')">Add new sslProfile section</li>
             <li ng-repeat="ssl in getSectionList(selected_node, 'sslProfile')" ng-click="editSection(selected_node, 'sslProfile', ssl)">Edit/Delete {{ssl}} sslProfile section</li>
 
@@ -85,6 +89,9 @@ under the License.
             <li ng-click="editSection(true, 'log', 'new')">Add log section for selected routers</li>
 
             <li class="context-separator"></li>
+            <li ng-click="editSection(true, 'address', 'new')">Add address section for selected routers</li>
+
+            <li class="context-separator"></li>
             <li ng-click="deleteNode(true)">Delete selected nodes</li>
         </ul>
     </div>
@@ -151,18 +158,18 @@ under the License.
                     <div class="form-input-container" tooltip-append-to-body="true" tooltip-placement="right" uib-tooltip-html="attributeDescription" ng-mouseenter="setDescription(attribute, $event)" tooltip-class="edit-tooltip">
                         <label class="form-label" for="{{attribute.name}}">{{attribute.humanName}}</label>
                         <div ng-if="attribute.input == 'input'">
-                            <input class="edit_input" ng-if="attribute.type == 'number'" type="number" name="{{attribute.name}}" id="{{attribute.name}}" ng-model="attribute.value" ng-required="attribute.required" class="ui-widget-content ui-corner-all"/>
-                            <input class="edit_input" ng-if="attribute.type == 'text'" type="text" name="{{attribute.name}}" id="{{attribute.name}}" ng-model="attribute.value" ng-required="attribute.required" class="ui-widget-content ui-corner-all"/>
+                            <input class="edit_input" ng-if="attribute.type == 'number'" type="number" name="{{attribute.name}}" id="{{attribute.name}}" ng-model="attribute.value" ng-required="isItRequired(attribute)" class="ui-widget-content ui-corner-all"/>
+                            <input class="edit_input" ng-if="attribute.type == 'text'" type="text" name="{{attribute.name}}" id="{{attribute.name}}" ng-model="attribute.value" ng-required="isItRequired(attribute)" class="ui-widget-content ui-corner-all"/>
                         </div>
                         <div ng-if="attribute.input == 'select'">
-                            <select class="edit_input" id="{{attribute.name}}" ng-model="attribute.selected" ng-options="item for item in attribute.rawtype"></select>
+                            <select class="edit_input" id="{{attribute.name}}" ng-model="attribute.selected" ng-required="isItRequired(attribute)" ng-options="item for item in attribute.rawtype"></select>
                         </div>
                         <div ng-if="attribute.input == 'boolean'" class="boolean">
                             <label><input type="radio" ng-model="attribute.value" value="true"> True</label>
                             <label><input type="radio" ng-model="attribute.value" value="false"> False</label>
                         </div>
                         <div ng-if="attribute.input == 'checkbox'" class="boolean">
-                            <label><input id="attribute.name" type="checkbox" ng-model="attribute.value"></label>
+                            <label><input id="attribute.name" type="checkbox" ng-required="isItRequired(attribute)" ng-model="attribute.value"></label>
                         </div>
                     </div>
                 </div>

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d0a3dd76/console/config/js/qdrNewNode.js
----------------------------------------------------------------------
diff --git a/console/config/js/qdrNewNode.js b/console/config/js/qdrNewNode.js
index c66b455..c756d20 100644
--- a/console/config/js/qdrNewNode.js
+++ b/console/config/js/qdrNewNode.js
@@ -37,9 +37,12 @@ var QDR = (function(QDR) {
     myEntities.push(entityType)
     var readOnlyAttrs = { 'router': ['version', 'id', 'identity'],
                           'log': ['name', 'identity'],
+                          'address': ['identity'],
                           'linkRoute': ['identity'],
                           "sslProfile": ['identity'],
                           "connector": ['identity']}
+    // one of the following must be present
+    var requiredAttrs = {'address': ['prefix', 'pattern']}
 
     var typeMap = {
       integer: 'number',
@@ -239,11 +242,12 @@ var QDR = (function(QDR) {
       }
 
       // move entities key into first position
-      var keyIndex = allNames.findIndex(function (name) {
-        return name === entityKey
-      })
-      if (keyIndex > 0) {
-        allNames.move(keyIndex, 0)
+      for (var i=0, keys=entityKey.split('|'); i<keys.length; i++) {
+        var keyIndex = allNames.findIndex(function (name) {
+          return name === keys[i]
+        })
+        if (keyIndex > 0)
+          allNames.move(keyIndex, 0)
       }
       // move any entities with sort: last to end
       for (var i=0; i<ediv.attributes.length; i++) {
@@ -272,6 +276,16 @@ var QDR = (function(QDR) {
     $scope.attributeUnique = '';
     $scope.active = 'router'
     $scope.fieldsetDivs = "/fieldsetDivs.html"
+
+    $scope.isItRequired = function (attribute) {
+      if (requiredAttrs[entityType] && requiredAttrs[entityType].indexOf(attribute.name) > -1) {
+        var s = requiredAttrs[entityType].some( function (attr) {
+          return (getEdivAttr($scope.entities[0], attr).value)
+        })
+        return !s
+      } else
+        return attribute.required
+    }
     $scope.setActive = function(tabName) {
       $scope.active = tabName
     }

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d0a3dd76/console/config/js/qdrTopology.js
----------------------------------------------------------------------
diff --git a/console/config/js/qdrTopology.js b/console/config/js/qdrTopology.js
index 4c48de3..2347c46 100644
--- a/console/config/js/qdrTopology.js
+++ b/console/config/js/qdrTopology.js
@@ -30,7 +30,7 @@ var QDR = (function(QDR) {
     function($scope, $rootScope, QDRService, $location, $timeout, $uibModal) {
 
       var settings = {baseName: "A", http_port: 5673, normal_port: 22000, internal_port: 2000, default_host: "0.0.0.0", artemis_port: 61616, qpid_port: 5672}
-      var sections = ['log', 'connector', 'sslProfile', 'listener']
+      var sections = ['log', 'connector', 'sslProfile', 'listener', 'address']
       // mouse event vars
       var selected_link = null,
         mousedown_link = null,
@@ -953,6 +953,9 @@ var QDR = (function(QDR) {
           if (d.cls === 'log') {
             return 'Log' + (d.entityKey ? (': ' + d.entityKey) : '')
           }
+          if (d.cls === 'address') {
+            return 'Address' + (d.entityKey ? (': ' + d.entityKey) : '')
+          }
           if (d.cdir === 'in')
             return 'Listener on port ' + d.entityKey
           if (d.cdir === 'out')
@@ -984,6 +987,9 @@ var QDR = (function(QDR) {
           .classed('connector', function(d) {
             return d.cls == 'connector'
           })
+          .classed('address', function(d) {
+            return d.cls == 'address'
+          })
           .classed('listener', function(d) {
             return d.cls == 'listener'
           })
@@ -1037,6 +1043,9 @@ var QDR = (function(QDR) {
           .classed('log', function(d) {
             return d.cls === 'log'
           })
+          .classed('address', function(d) {
+            return d.cls === 'address'
+          })
           .classed('console', function(d) {
             return QDRService.isConsole(d)
           })
@@ -1061,6 +1070,8 @@ var QDR = (function(QDR) {
               return '\ue901';
             } else if (d.cls === 'log') {
               return '\uf036';
+            } else if (d.cls === 'address') {
+              return '\uf2bc';
             } else if (d.nodeType === 'route-container') {
               return d.properties.product ? d.properties.product[0].toUpperCase() : 'S'
             } else if (d.nodeType === 'normal' && d.cdir === "in") // listener
@@ -1362,13 +1373,18 @@ var QDR = (function(QDR) {
           node.cdir = "out"
           legendNodes.push(node)
         }
+        if (!svg.selectAll('circle.address').empty()) {
+          var node = aNode("Address", "", "normal", 'address', 4, 0, 0, 0, false, {})
+          node.cdir = "out"
+          legendNodes.push(node)
+        }
         if (!svg.selectAll('circle.sslProfile').empty()) {
-          var node = aNode("sslProfile", "", "normal", 'sslProfile', 4, 0, 0, 0, false, {})
+          var node = aNode("sslProfile", "", "normal", 'sslProfile', 5, 0, 0, 0, false, {})
           node.cdir = "both"
           legendNodes.push(node)
         }
         if (!svg.selectAll('circle.log').empty()) {
-          legendNodes.push(aNode("Logs", "", "normal", 'log', 5, 0, 0, 0, false, {}))
+          legendNodes.push(aNode("Logs", "", "normal", 'log', 6, 0, 0, 0, false, {}))
         }
         if (!svg.selectAll('circle.qpid-cpp').empty()) {
           legendNodes.push(genNodeToAdd({key:'Qpid broker', name:'legend', x:0, y:0, id:'legend'}, 'qpid', ''))
@@ -1377,7 +1393,7 @@ var QDR = (function(QDR) {
           legendNodes.push(genNodeToAdd({key:'Artemis broker', name:'legend', x:0, y:0, id:'legend'}, 'artemis', ''))
         }
         if (!svg.selectAll('circle.route-container').empty()) {
-          legendNodes.push(aNode("Service", "", "route-container", 'service', 8, 0, 0, 0, false,
+          legendNodes.push(aNode("Service", "", "route-container", 'service', 9, 0, 0, 0, false,
           {product: ' External Service'}))
         }
         // add a circle for each unique host in nodes
@@ -1731,7 +1747,7 @@ var QDR = (function(QDR) {
       }
 
       function doEditDialog(node, entity, context, multi) {
-        var entity2key = {router: 'name', log: 'module', sslProfile: 'name', connector: 'port', listener: 'port'}
+        var entity2key = {router: 'name', log: 'module', sslProfile: 'name', connector: 'port', listener: 'port', address: 'pattern|prefix'}
         var d = $uibModal.open({
           dialogClass: "modal dlg-large",
           backdrop: true,
@@ -1770,7 +1786,6 @@ var QDR = (function(QDR) {
             }
           }
         });
-        $timeout(function () {
           d.result.then(function(result) {
             if (result) {
               if (entity === 'router') {
@@ -1785,8 +1800,6 @@ var QDR = (function(QDR) {
                 }
               }
               else {
-                var key = entity2key[entity]
-                var nodeObj = node[entity+'s']
                 if ('del' in result) {
                   // find the 'normal' node that is associated with this entry
                   var n = findChildNode(entity, context, node.name)
@@ -1795,45 +1808,51 @@ var QDR = (function(QDR) {
                 } else {
                   var rVals = valFromMapArray(result.entities, "actualName", entity)
                   if (rVals) {
+                    var nodeObj = node[entity+'s']
+                    var key = entity2key[entity]
                     var o = new FormValues(rVals)
+                    oNodeKey = o.node[key]
+                    // address can have either a prefix or pattern
+                    if (entity === 'address') {
+                      oNodeKey = o.node['prefix'] ? o.node['prefix'] : o.node['pattern']
+                    }
                     if (!angular.isDefined(nodeObj)) {
                       node[entity+'s'] = {}
                       nodeObj = node[entity+'s']
                     }
                     // we were editing an existing section and the key for that section was changed
-                    else if (o.node[key] !== context && (context !== 'new' && context !== 'artemis' && context != 'qpid')) {
+                    else if (oNodeKey !== context && context !== 'new' && context !== 'artemis' && context != 'qpid') {
                       delete nodeObj[context]
                     }
-                    if (entity === 'log') {
+                    if (entity === 'log' || entity === 'address') {
                       if (multi) {
-                        // apply this log module/enable to all selected routers
+                        // apply this entity's key to all selected routers
                         for (var i=0; i<nodes.length; i++) {
                           if (isSelectedNode(nodes[i])) {
-                            var logs = nodes[i]['logs']
-                            if (!logs)
-                              nodes[i]['logs'] = {}
-                            if (!nodes[i].logs[o.node[key]])
-                              addToNode(nodes[i], 'log', o.node[key])
-                            nodes[i].logs[o.node[key]] = o.node
+                            var ents = nodes[i][entity+'s']
+                            if (!ents)
+                              nodes[i][entity+'s'] = {}
+                            if (!nodes[i][entity+'s'][oNodeKey])
+                              addToNode(nodes[i], entity, oNodeKey)
+                            nodes[i][entity+'s'][oNodeKey] = o.node
                           }
                         }
                         return
                       }
                     }
-                    nodeObj[o.node[key]] = o.node
+                    nodeObj[oNodeKey] = o.node
                     if (entity === 'sslProfile')
                       return
                     if (context === 'new' || context === 'artemis' || context === 'qpid') {
                       if (context !== 'new')
                         entity = context
-                      addToNode(node, entity, o.node[key])
+                      addToNode(node, entity, oNodeKey)
                     }
                   }
                 }
               }
             }
           });
-        })
       };
 
       var FormValues = function (entity) {

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/d0a3dd76/console/config/mock/section.py
----------------------------------------------------------------------
diff --git a/console/config/mock/section.py b/console/config/mock/section.py
index 9df97aa..3842302 100644
--- a/console/config/mock/section.py
+++ b/console/config/mock/section.py
@@ -23,7 +23,7 @@ from schema import Schema
 import pdb
 
 class ConfigSection(object):
-    def __init__(self, type, defaults, ignore, opts):
+    def __init__(self, type, defaults, ignore, forced, opts):
         self.type = type
         self.entries = {}
         for key in defaults:
@@ -33,7 +33,9 @@ class ConfigSection(object):
         for key in list(opts.keys()):
             if not key in Schema.attrs(self.type):
                 del opts[key]
-            elif key.endswith('Count') or key in ignore or opts[key] is None or opts[key] == Schema.default(self.type, key):
+            elif key.endswith('Count') or key in ignore or opts[key] is None:
+                del opts[key]
+            elif opts[key] == Schema.default(self.type, key) and key not in forced:
                 del opts[key]
 
         self.setEntries(opts)
@@ -55,7 +57,7 @@ class RouterSection(ConfigSection):
     defaults = {"mode": "interior"}
     ignore = ["type", "routerId", "identity", "name"]
     def __init__(self, id, **kwargs):
-        super(RouterSection, self).__init__("router", RouterSection.defaults, RouterSection.ignore, kwargs)
+        super(RouterSection, self).__init__("router", RouterSection.defaults, RouterSection.ignore, [], kwargs)
         self.setEntry("id", id)
 
     def __repr__(self):
@@ -68,7 +70,7 @@ class ListenerSection(ConfigSection):
                  "saslMechanisms": 'ANONYMOUS'
                  }
     def __init__(self, port, **kwargs):
-        super(ListenerSection, self).__init__("listener", ListenerSection.defaults, [], kwargs)
+        super(ListenerSection, self).__init__("listener", ListenerSection.defaults, [], [], kwargs)
         self.setEntry("port", port)
 
 class ConnectorSection(ConfigSection):
@@ -77,16 +79,20 @@ class ConnectorSection(ConfigSection):
                 "saslMechanisms": 'ANONYMOUS'
                 }
     def __init__(self, port, **kwargs):
-        super(ConnectorSection, self).__init__("connector", ConnectorSection.defaults, [], kwargs)
+        super(ConnectorSection, self).__init__("connector", ConnectorSection.defaults, [], [], kwargs)
         self.setEntry("port", port)
 
 class SslProfileSection(ConfigSection):
     def __init__(self, **kwargs):
-        super(SslProfileSection, self).__init__("sslProfile", {}, [], kwargs)
+        super(SslProfileSection, self).__init__("sslProfile", {}, [], [], kwargs)
 
 class LogSection(ConfigSection):
     def __init__(self, **kwargs):
-        super(LogSection, self).__init__("log", {}, [], kwargs)
+        super(LogSection, self).__init__("log", {}, [], [], kwargs)
+
+class AddressSection(ConfigSection):
+    def __init__(self, **kwargs):
+        super(AddressSection, self).__init__("address", {}, [], ['distribution'], kwargs)
 
 if __name__ == '__main__':
     Schema.init('../')


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