diff options
| author | Alex Rudyy <orudyy@apache.org> | 2014-05-29 09:32:24 +0000 |
|---|---|---|
| committer | Alex Rudyy <orudyy@apache.org> | 2014-05-29 09:32:24 +0000 |
| commit | e16f6cc14b3495fc96f132b25b56413ec19a5ce5 (patch) | |
| tree | b52bfa2ab39aa068be6712451e30559ad9207789 /qpid/java/broker-plugins | |
| parent | 89b34f256872a4e6ee64748235a18b133e185bcc (diff) | |
| download | qpid-python-e16f6cc14b3495fc96f132b25b56413ec19a5ce5.tar.gz | |
QPID-5413: [Java Broker-Web Management] Allow stopping and starting of virtual host nodes and virtual hosts from the broker tab
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1598232 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker-plugins')
4 files changed, 260 insertions, 46 deletions
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js index 97b1e32798..b89ea3932c 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/UpdatableStore.js @@ -18,10 +18,12 @@ * under the License. * */ -define(["dojo/store/Memory", - "dojox/grid/DataGrid", - "dojo/data/ObjectStore", - "dojo/store/Observable"], function (Memory, DataGrid, ObjectStore, Observable) { +define(["dojo/json", + "qpid/common/util", + "dojo/store/Memory", + "dojox/grid/DataGrid", + "dojo/data/ObjectStore", + "dojo/store/Observable"], function (json, util, Memory, DataGrid, ObjectStore, Observable) { function UpdatableStore( data, divName, structure, func, props, Grid, notObservable ) { @@ -86,19 +88,10 @@ define(["dojo/store/Memory", if(data) { for(var i=0; i < data.length; i++) { if(theItem = store.get(data[i].id)) { - var modified; - for(var propName in data[i]) { - if(data[i].hasOwnProperty(propName)) { - if(theItem[ propName ] != data[i][ propName ]) { - theItem[ propName ] = data[i][ propName ]; - modified = true; - changed = true; - } - } - } + var modified = !util.equals(theItem, data[i]); if(modified) { store.put(data[i], {overwrite: true}); - if (store instanceof Observable) + if (store.notify) { store.notify(theItem, data[i].id); } diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js index e7f3b00463..46d0cfa35d 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/common/util.js @@ -21,7 +21,7 @@ define(["dojo/_base/xhr", "dojo/_base/event", - "dojo/_base/json", + "dojo/json", "dojo/_base/lang", "dojo/dom-construct", "dojo/dom-geometry", @@ -266,7 +266,7 @@ define(["dojo/_base/xhr", } xhr.put({url: url , sync: true, handleAs: "json", headers: { "Content-Type": "application/json"}, - putData: json.toJson(values), + putData: json.stringify(values), load: function(x) {that.success = true; }, error: function(error) {that.success = false; that.failureReason = error;}}); if(this.success === true) @@ -371,5 +371,125 @@ define(["dojo/_base/xhr", } } + util.sendRequest = function (url, method, attributes, sync) + { + var success = false; + var failureReason = ""; + var syncRequired = sync == undefined ? true : sync; + if (method == "POST" || method == "PUT") + { + xhr.put({ + url: url, + sync: syncRequired, + handleAs: "json", + headers: { "Content-Type": "application/json"}, + putData: json.stringify(attributes), + load: function(x) {success = true; }, + error: function(error) {success = false; failureReason = error;} + }); + } + else if (method == "DELETE") + { + xhr.del({url: url, sync: syncRequired, handleAs: "json"}).then( + function(data) { success = true; }, + function(error) {success = false; failureReason = error;} + ); + } + + if (syncRequired && !success) + { + alert("Error:" + failureReason); + } + return success; + } + + util.equals = function(object1, object2) + { + if (object1 && object2) + { + if (typeof object1 != typeof object2) + { + return false; + } + else + { + if (object1 instanceof Array || typeof object1 == "array") + { + if (object1.length != object2.length) + { + return false; + } + + for (var i = 0, l=object1.length; i < l; i++) + { + var item = object1[i]; + if (item && (item instanceof Array || typeof item == "array" || item instanceof Object)) + { + if (!this.equals(item, object2[i])) + { + return false; + } + } + else if (item != object2[i]) + { + return false; + } + } + + return true; + } + else if (object1 instanceof Object) + { + for (propName in object1) + { + if (object1.hasOwnProperty(propName) != object2.hasOwnProperty(propName)) + { + return false; + } + else if (typeof object1[propName] != typeof object2[propName]) + { + return false; + } + } + + for(propName in object2) + { + var object1Prop = object1[propName]; + var object2Prop = object2[propName]; + + if (object2.hasOwnProperty(propName) != object1.hasOwnProperty(propName)) + { + return false; + } + else if (typeof object1Prop != typeof object2Prop) + { + return false; + } + + if(!object2.hasOwnProperty(propName)) + { + // skip functions + continue; + } + + if (object1Prop && (object1Prop instanceof Array || typeof object1Prop == "array" || object1Prop instanceof Object)) + { + if (!this.equals(object1Prop, object2Prop)) + { + return false; + } + } + else if(object1Prop != object2Prop) + { + return false; + } + } + return true; + } + } + } + return object1 === object2; + } + return util; }); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Broker.js b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Broker.js index 03f7383f51..46afe7d8cb 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Broker.js +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/js/qpid/management/Broker.js @@ -21,6 +21,7 @@ define(["dojo/_base/xhr", "dojo/parser", "dojo/query", + "dojo/json", "dojo/_base/connect", "qpid/common/properties", "qpid/common/updater", @@ -48,7 +49,7 @@ define(["dojo/_base/xhr", "dijit/Menu", "dijit/MenuItem", "dojo/domReady!"], - function (xhr, parser, query, connect, properties, updater, util, UpdatableStore, EnhancedGrid, registry, entities, addAuthenticationProvider, addVirtualHostNode, addPort, addKeystore, addGroupProvider, addAccessControlProvider) { + function (xhr, parser, query, json, connect, properties, updater, util, UpdatableStore, EnhancedGrid, registry, entities, addAuthenticationProvider, addVirtualHostNode, addPort, addKeystore, addGroupProvider, addAccessControlProvider) { function Broker(name, parent, controller) { this.name = name; @@ -330,7 +331,7 @@ define(["dojo/_base/xhr", selectionMode: "single", plugins: { pagination: { - pageSizes: ["10", "25", "50", "100"], + pageSizes: [10, 25, 50, 100], description: true, sizeSwitch: true, pageStepper: true, @@ -382,24 +383,31 @@ define(["dojo/_base/xhr", function(evt){ var idx = evt.rowIndex, theItem = this.getItem(idx); - that.showVirtualHost(theItem, brokerObj); + if (theItem.virtualhosts) + { + that.showVirtualHost(theItem, brokerObj); + } }); - }, gridProperties, EnhancedGrid); + }, gridProperties, EnhancedGrid, true); - var virtualHostNodeMenuButton = registry.byNode(query(".virtualHostNodeMenuButton", node)[0]); - var virtualHostMenuButton = registry.byNode(query(".virtualHostMenuButton", node)[0]); + that.virtualHostNodeMenuButton = registry.byNode(query(".virtualHostNodeMenuButton", node)[0]); + that.virtualHostMenuButton = registry.byNode(query(".virtualHostMenuButton", node)[0]); - var toggleVirtualHostNodeNodeMenus = function(rowIndex){ - var data = that.vhostsGrid.grid.selection.getSelected(); - virtualHostNodeMenuButton.set("disabled",data.length!=1); - virtualHostMenuButton.set("disabled",data.length!=1 ); - }; + var hostMenuItems = that.virtualHostMenuButton.dropDown.getChildren(); + var viewVirtualHostItem = hostMenuItems[0]; + var startVirtualHostItem = hostMenuItems[1]; + var stopVirtualHostItem = hostMenuItems[2]; - connect.connect(that.vhostsGrid.grid.selection, 'onSelected', toggleVirtualHostNodeNodeMenus); - connect.connect(that.vhostsGrid.grid.selection, 'onDeselected', toggleVirtualHostNodeNodeMenus); + var nodeMenuItems = that.virtualHostNodeMenuButton.dropDown.getChildren(); + var viewNodeItem = nodeMenuItems[0]; + var deleteNodeItem = nodeMenuItems[1]; + var startNodeItem = nodeMenuItems[2]; + var stopNodeItem = nodeMenuItems[3]; + + var toggler = function(index){ that.toggleVirtualHostNodeNodeMenus(index);} + connect.connect(that.vhostsGrid.grid.selection, 'onSelected', toggler); + connect.connect(that.vhostsGrid.grid.selection, 'onDeselected', toggler); - var hostMenuItems = virtualHostMenuButton.dropDown.getChildren(); - var viewVirtualHostItem = hostMenuItems[0]; viewVirtualHostItem.on("click", function(){ var data = that.vhostsGrid.grid.selection.getSelected(); if (data.length == 1) @@ -408,9 +416,7 @@ define(["dojo/_base/xhr", } }); - var nodeMenuItems = virtualHostNodeMenuButton.dropDown.getChildren(); - var viewNodeButton = nodeMenuItems[0]; - viewNodeButton.on("click", + viewNodeItem.on("click", function(evt){ var data = that.vhostsGrid.grid.selection.getSelected(); if (data.length == 1) @@ -420,8 +426,8 @@ define(["dojo/_base/xhr", } } ); - var deleteNodeButton = nodeMenuItems[1]; - deleteNodeButton.on("click", + + deleteNodeItem.on("click", function(evt){ util.deleteGridSelections( that, @@ -431,6 +437,63 @@ define(["dojo/_base/xhr", } ); + startNodeItem.on("click", + function(event) + { + var data = that.vhostsGrid.grid.selection.getSelected(); + if (data.length == 1) + { + var item = data[0]; + util.sendRequest("api/latest/virtualhostnode/" + encodeURIComponent(item.name), + "PUT", {desiredState: "ACTIVE"}); + } + }); + + stopNodeItem.on("click", + function(event) + { + var data = that.vhostsGrid.grid.selection.getSelected(); + if (data.length == 1) + { + var item = data[0]; + if (confirm("Stopping the node will also shutdown the virtual host. " + + "Are you sure you want to stop virtual host node '" + + entities.encode(String(item.name)) +"'?")) + { + util.sendRequest("api/latest/virtualhostnode/" + encodeURIComponent(item.name), + "PUT", {desiredState: "STOPPED"}); + } + } + }); + + startVirtualHostItem.on("click", function(event) + { + var data = that.vhostsGrid.grid.selection.getSelected(); + if (data.length == 1 && data[0].virtualhosts) + { + var item = data[0]; + var host = item.virtualhosts[0]; + util.sendRequest("api/latest/virtualhost/" + encodeURIComponent(item.name) + "/" + encodeURIComponent(host.name), + "PUT", {desiredState: "ACTIVE"}); + } + }); + + stopVirtualHostItem.on("click", function(event) + { + var data = that.vhostsGrid.grid.selection.getSelected(); + if (data.length == 1 && data[0].virtualhosts) + { + var item = data[0]; + var host = item.virtualhosts[0]; + if (confirm("Are you sure you want to stop virtual host '" + + entities.encode(String(host.name)) +"'?")) + { + util.sendRequest("api/latest/virtualhost/" + encodeURIComponent(item.name) + "/" + encodeURIComponent(host.name), + "PUT", {desiredState: "STOPPED"}); + } + } + }); + gridProperties.selectionMode="extended"; that.portsGrid = @@ -633,7 +696,11 @@ define(["dojo/_base/xhr", that.updateHeader(); - that.vhostsGrid.update(that.brokerData.virtualhostnodes); + if (that.vhostsGrid.update(that.brokerData.virtualhostnodes)) + { + that.vhostsGrid.grid._refresh(); + that.toggleVirtualHostNodeNodeMenus(); + } that.portsGrid.update(that.brokerData.ports); @@ -670,5 +737,43 @@ define(["dojo/_base/xhr", dojo.byId("brokerAttribute.modelVersion").innerHTML = entities.encode(String(brokerData.modelVersion)); } + BrokerUpdater.prototype.toggleVirtualHostNodeNodeMenus = function(rowIndex) + { + var data = this.vhostsGrid.grid.selection.getSelected(); + var selected = data.length==1; + this.virtualHostNodeMenuButton.set("disabled", !selected); + this.virtualHostMenuButton.set("disabled", !selected || !data[0].virtualhosts); + if (selected) + { + var nodeMenuItems = this.virtualHostNodeMenuButton.dropDown.getChildren(); + var hostMenuItems = this.virtualHostMenuButton.dropDown.getChildren(); + + var startNodeItem = nodeMenuItems[2]; + var stopNodeItem = nodeMenuItems[3]; + + var viewVirtualHostItem = hostMenuItems[0]; + var startVirtualHostItem = hostMenuItems[1]; + var stopVirtualHostItem = hostMenuItems[2]; + + var node = data[0]; + startNodeItem.set("disabled", node.state != "STOPPED"); + stopNodeItem.set("disabled", node.state != "ACTIVE"); + + if (node.virtualhosts) + { + viewVirtualHostItem.set("disabled", false); + + var host = node.virtualhosts[0]; + startVirtualHostItem.set("disabled", host.state != "STOPPED"); + stopVirtualHostItem.set("disabled", host.state != "ACTIVE"); + } + else + { + viewVirtualHostItem.set("disabled", true); + startVirtualHostItem.set("disabled", true); + stopVirtualHostItem.set("disabled", true); + } + } + }; return Broker; }); diff --git a/qpid/java/broker-plugins/management-http/src/main/java/resources/showBroker.html b/qpid/java/broker-plugins/management-http/src/main/java/resources/showBroker.html index d036fd9e22..7572856e35 100644 --- a/qpid/java/broker-plugins/management-http/src/main/java/resources/showBroker.html +++ b/qpid/java/broker-plugins/management-http/src/main/java/resources/showBroker.html @@ -79,20 +79,16 @@ <div data-dojo-type="dijit.Menu"> <div data-dojo-type="dijit.MenuItem">View</div> <div data-dojo-type="dijit.MenuItem">Delete</div> - <div data-dojo-type="dijit.MenuItem" - data-dojo-props="disabled: true,onClick: function(){alert('TODO');}">Start</div> - <div data-dojo-type="dijit.MenuItem" - data-dojo-props="disabled:true, onClick: function(){alert('TODO');}">Stop</div> + <div data-dojo-type="dijit.MenuItem" data-dojo-props="disabled:true">Start</div> + <div data-dojo-type="dijit.MenuItem" data-dojo-props="disabled:true">Stop</div> </div> </div> <div data-dojo-type="dijit.form.DropDownButton" class="virtualHostMenuButton" data-dojo-props="iconClass: 'dijitIconPackage',disabled:true"> <span>Virtual Host</span> <div data-dojo-type="dijit.Menu" class="virtualHostMenu"> <div data-dojo-type="dijit.MenuItem" class="viewVirtualHost" >View</div> - <div data-dojo-type="dijit.MenuItem" - data-dojo-props="disabled: true,onClick: function(){alert('TODO');}">Start</div> - <div data-dojo-type="dijit.MenuItem" - data-dojo-props="disabled:true, onClick: function(){alert('TODO');}">Quiesce</div> + <div data-dojo-type="dijit.MenuItem" data-dojo-props="disabled:true">Start</div> + <div data-dojo-type="dijit.MenuItem" data-dojo-props="disabled:true">Stop</div> </div> </div> </div> |
