This is an automated email from the ASF dual-hosted git repository. akovalenko pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new bab87d1 AMBARI-23707. NN Federation Wizard: move out of wizard create widgets operaions (akovalenko) bab87d1 is described below commit bab87d1e010bdc1e196ef23c4dd006c4c79fb767 Author: Aleksandr Kovalenko <akovale...@apache.org> AuthorDate: Thu Apr 26 18:17:02 2018 +0300 AMBARI-23707. NN Federation Wizard: move out of wizard create widgets operaions (akovalenko) --- .../main/admin/federation/step4_controller.js | 116 +------------ ambari-web/app/messages.js | 7 +- .../app/mixins/common/widgets/widget_section.js | 190 ++++++++++++++++----- ambari-web/app/utils/ajax/ajax.js | 5 + 4 files changed, 159 insertions(+), 159 deletions(-) diff --git a/ambari-web/app/controllers/main/admin/federation/step4_controller.js b/ambari-web/app/controllers/main/admin/federation/step4_controller.js index f5022ed..b1606f3 100644 --- a/ambari-web/app/controllers/main/admin/federation/step4_controller.js +++ b/ambari-web/app/controllers/main/admin/federation/step4_controller.js @@ -22,7 +22,7 @@ App.NameNodeFederationWizardStep4Controller = App.HighAvailabilityProgressPageCo name: "nameNodeFederationWizardStep4Controller", - commands: ['stopRequiredServices', 'reconfigureServices', 'installNameNode', 'installZKFC', 'startJournalNodes', 'startNameNodes', 'formatNameNode', 'formatZKFC', 'startZKFC', 'startNameNode', 'bootstrapNameNode', 'createWidgets', 'startZKFC2', 'startNameNode2', 'restartAllServices'], + commands: ['stopRequiredServices', 'reconfigureServices', 'installNameNode', 'installZKFC', 'startJournalNodes', 'startNameNodes', 'formatNameNode', 'formatZKFC', 'startZKFC', 'startNameNode', 'bootstrapNameNode', 'startZKFC2', 'startNameNode2', 'restartAllServices'], tasksMessagesPrefix: 'admin.nameNodeFederation.wizard.step', @@ -130,74 +130,6 @@ App.NameNodeFederationWizardStep4Controller = App.HighAvailabilityProgressPageCo }); }, - createWidgets: function () { - var self = this; - this.getNameNodeWidgets().done(function (data) { - var newWidgetsIds = []; - var oldWidgetIds = []; - var nameservice1 = App.HDFSService.find().objectAt(0).get('masterComponentGroups')[0].name; - var nameservice2 = self.get('content.nameServiceId'); - var widgetsCount = data.items.length; - data.items.forEach(function (widget) { - if (!widget.WidgetInfo.tag) { - var oldId = widget.WidgetInfo.id; - oldWidgetIds.push(oldId); - delete widget.href; - delete widget.WidgetInfo.id; - delete widget.WidgetInfo.cluster_name; - delete widget.WidgetInfo.author; - widget.WidgetInfo.tag = nameservice1; - widget.WidgetInfo.metrics = JSON.parse(widget.WidgetInfo.metrics); - widget.WidgetInfo.values = JSON.parse(widget.WidgetInfo.values); - self.createWidget(widget).done(function (w) { - newWidgetsIds.push(w.resources[0].WidgetInfo.id); - widget.WidgetInfo.tag = nameservice2; - self.createWidget(widget).done(function (w) { - newWidgetsIds.push(w.resources[0].WidgetInfo.id); - self.deleteWidget(oldId).done(function () { - if (!--widgetsCount) { - self.getDefaultHDFStWidgetLayout().done(function (layout) { - layout = layout.items[0].WidgetLayoutInfo; - layout.widgets = layout.widgets.filter(function (w) { - return !oldWidgetIds.contains(w.WidgetInfo.id); - }).map(function (w) { - return w.WidgetInfo.id; - }).concat(newWidgetsIds); - self.updateDefaultHDFStWidgetLayout(layout).done(function () { - self.onTaskCompleted(); - }); - }); - } - }); - }); - }); - } else { - widgetsCount--; - } - }); - }); - }, - - createWidget: function (data) { - return App.ajax.send({ - name: 'widgets.wizard.add', - sender: this, - data: { - data: data - } - }); - }, - - deleteWidget: function (id) { - return App.ajax.send({ - name: 'widget.action.delete', - sender: self, - data: { - id: id - } - }); - }, - startZKFC2: function () { this.updateComponent('ZKFC', this.get('newNameNodeHosts')[1], "HDFS", "Start"); }, @@ -213,51 +145,5 @@ App.NameNodeFederationWizardStep4Controller = App.HighAvailabilityProgressPageCo success: 'startPolling', error: 'onTaskError' }); - }, - - getNameNodeWidgets: function () { - return App.ajax.send({ - name: 'widgets.get', - sender: this, - data: { - urlParams: 'WidgetInfo/widget_type.in(GRAPH,NUMBER,GAUGE)&WidgetInfo/scope=CLUSTER&WidgetInfo/metrics.matches(.*\"component_name\":\"NAMENODE\".*)&fields=*' - } - }); - }, - - getDefaultHDFStWidgetLayout: function () { - return App.ajax.send({ - name: 'widget.layout.get', - sender: this, - data: { - urlParams: 'WidgetLayoutInfo/layout_name=default_hdfs_dashboard' - } - }); - }, - - updateDefaultHDFStWidgetLayout: function (widgetLayoutData) { - var layout = widgetLayoutData; - var data = { - "WidgetLayoutInfo": { - "display_name": layout.display_name, - "layout_name": layout.layout_name, - "id": layout.id, - "scope": "USER", - "section_name": layout.section_name, - "widgets": layout.widgets.map(function (id) { - return { - "id":id - } - }) - } - }; - return App.ajax.send({ - name: 'widget.layout.edit', - sender: this, - data: { - layoutId: layout.id, - data: data - }, - }); } }); diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js index 327612d..0e68bdb 100644 --- a/ambari-web/app/messages.js +++ b/ambari-web/app/messages.js @@ -1703,10 +1703,9 @@ Em.I18n.translations = { 'admin.nameNodeFederation.wizard.step4.task8.title': 'Start ZKFC', 'admin.nameNodeFederation.wizard.step4.task9.title': 'Start NameNode', 'admin.nameNodeFederation.wizard.step4.task10.title': 'Bootstrap NameNode', - 'admin.nameNodeFederation.wizard.step4.task11.title': 'Create widgets', - 'admin.nameNodeFederation.wizard.step4.task12.title': 'Start ZKFC', - 'admin.nameNodeFederation.wizard.step4.task13.title': 'Start NameNode', - 'admin.nameNodeFederation.wizard.step4.task14.title': 'Restart Required Services', + 'admin.nameNodeFederation.wizard.step4.task11.title': 'Start ZKFC', + 'admin.nameNodeFederation.wizard.step4.task12.title': 'Start NameNode', + 'admin.nameNodeFederation.wizard.step4.task13.title': 'Restart Required Services', 'admin.security.title':'Kerberos security has not been enabled', 'admin.security.enabled': 'Kerberos security is enabled', diff --git a/ambari-web/app/mixins/common/widgets/widget_section.js b/ambari-web/app/mixins/common/widgets/widget_section.js index 0ac7ba0..4eabf62 100644 --- a/ambari-web/app/mixins/common/widgets/widget_section.js +++ b/ambari-web/app/mixins/common/widgets/widget_section.js @@ -145,9 +145,70 @@ App.WidgetSectionMixin = Ember.Mixin.create({ */ getActiveWidgetLayoutSuccessCallback: function (data) { var self = this; + if (this.get('isHDFSFederatedSummary')) { + this.getNameNodeWidgets().done(function (widgets) { + widgets = widgets.items; + var widgetsNamespaces = widgets.mapProperty('WidgetInfo.tag').uniq().without(null); + var namespaces = App.HDFSService.find().objectAt(0).get('masterComponentGroups').mapProperty('name'); + var defaultNNWidgets = widgets.filterProperty('WidgetInfo.tag', null); + var widgetsToCreateCount; + if (namespaces.length > widgetsNamespaces.length) { + widgetsToCreateCount = (namespaces.length - widgetsNamespaces.length) * defaultNNWidgets.length; + namespaces.forEach(function (namespace) { + if (!widgetsNamespaces.contains(namespace)) { + defaultNNWidgets.forEach(function (widget) { + if (widget.href) { + delete widget.href; + delete widget.WidgetInfo.id; + delete widget.WidgetInfo.cluster_name; + delete widget.WidgetInfo.author; + widget.WidgetInfo.metrics = JSON.parse(widget.WidgetInfo.metrics); + widget.WidgetInfo.values = JSON.parse(widget.WidgetInfo.values); + } + widget.WidgetInfo.tag = namespace; + self.postWidget(widget).done(function () { + if (!--widgetsToCreateCount) { + self.createLayouts(data); + } + }); + }); + } + }); + } else { + self.createLayouts(data); + } + }) + } else { + this.createLayouts(data); + } + }, + + getNameNodeWidgets: function () { + return App.ajax.send({ + name: 'widgets.get', + sender: this, + data: { + urlParams: 'WidgetInfo/widget_type.in(GRAPH,NUMBER,GAUGE)&WidgetInfo/scope=CLUSTER&WidgetInfo/metrics.matches(.*\"component_name\":\"NAMENODE\".*)&fields=*' + } + }); + }, + + postWidget: function (data) { + return App.ajax.send({ + name: 'widgets.wizard.add', + sender: this, + data: { + data: data + } + }); + }, + + createLayouts: function (data) { + var self = this; + var namespaces = App.HDFSService.find().objectAt(0).get('masterComponentGroups'); if (data.items[0]) { - if (this.get('isHDFSFederatedSummary') && data.items.length === 1) { - this.createFederationWidgetLayouts(data.items[0]); + if (this.get('isHDFSFederatedSummary') && namespaces.length + 2 !== data.items.length) { + this.createFederationWidgetLayouts(data); } else { self.getWidgetLayoutSuccessCallback(data); } @@ -323,50 +384,99 @@ App.WidgetSectionMixin = Ember.Mixin.create({ this.set('activeNSWidgetLayouts', []); }, - createFederationWidgetLayouts: function (currentLWidgetLayout) { + createFederationWidgetLayouts: function (data) { var self = this; - currentLWidgetLayout = currentLWidgetLayout.WidgetLayoutInfo; - var newLayoutsIds = [currentLWidgetLayout.id]; - var userLayoutName = this.get('userLayoutName'); - var nameServices = App.HDFSService.find().objectAt(0).get('masterComponentGroups'); - var nameServiceToWidgetMap = {all: []}; - var nonNameServiceSpecific = []; - this.getDefaultWidgetLayoutByName(this.get('defaultLayoutName')).done(function (defaultWidgetLayoutData) { - var newLayout = defaultWidgetLayoutData.items[0].WidgetLayoutInfo; - - newLayout.widgets.forEach(function (widget) { - var tag = widget.WidgetInfo.tag; - if (widget.WidgetInfo.scope === 'CLUSTER' && tag) { - if (!nameServiceToWidgetMap[tag]) { - nameServiceToWidgetMap[tag] = []; + var currentLayouts = data.items; + self.getDefaultWidgetLayoutByName(self.get('defaultLayoutName')).done(function (defaultWidgetLayoutData) { + self.getNameNodeWidgets().done(function (widgets) { + var newNameServices = []; + var newWidgets = []; + var currentLayoutsNames = []; + var newLayout = defaultWidgetLayoutData.items[0].WidgetLayoutInfo; + var newLayoutsIds = []; + var nameServiceToWidgetMap = {all: []}; + var namespaces = App.HDFSService.find().objectAt(0).get('masterComponentGroups').mapProperty('name'); + var nonNameServiceSpecific = newLayout.widgets.slice(); + var userLayoutName = self.get('userLayoutName'); + widgets.items.forEach(function (widget) { + var tag = widget.WidgetInfo.tag; + nonNameServiceSpecific = nonNameServiceSpecific.without(nonNameServiceSpecific.findProperty('WidgetInfo.id', widget.WidgetInfo.id)); + if (tag) { + if (!nameServiceToWidgetMap[tag]) { + nameServiceToWidgetMap[tag] = []; + } + nameServiceToWidgetMap[tag].push(widget); + nameServiceToWidgetMap.all.push(widget); } - nameServiceToWidgetMap[tag].push(widget); - nameServiceToWidgetMap.all.push(widget); + }); + if (currentLayouts.length === 1) { + self.removeWidgetLayout(currentLayouts[0].WidgetLayoutInfo.id).done(function () { + newLayout.layout_name = userLayoutName; + newLayout.widgets = nonNameServiceSpecific; + self.createUserWidgetLayout(newLayout).done(function (data) { + newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id); + Em.keys(nameServiceToWidgetMap).forEach(function (nameService) { + newLayout.layout_name = userLayoutName + '_nameservice_' + nameService; + newLayout.display_name = nameService === 'all' ? 'All' : nameService; + newLayout.widgets = nameServiceToWidgetMap[nameService]; + self.createUserWidgetLayout(newLayout).done(function (data) { + newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id); + if (newLayoutsIds.length >= Em.keys(nameServiceToWidgetMap).length + 1) { + self.saveActiveWidgetLayouts({ + "WidgetLayouts": newLayoutsIds.map(function (layout) { + return {id: layout}; + }) + }).done(function () { + self.getActiveWidgetLayout(); + }); + } + }); + }) + }); + }); } else { - nonNameServiceSpecific.push(widget); + currentLayoutsNames = currentLayouts.map(function (l) { + return l.WidgetLayoutInfo.layout_name.split('_nameservice_')[1]; + }).without(undefined).without('all'); + namespaces.forEach(function (n) { + if (!currentLayoutsNames.contains(n)) { + newNameServices.push(n); + } + }); + newNameServices.forEach(function (nameService) { + newLayout.layout_name = userLayoutName + '_nameservice_' + nameService; + newLayout.display_name = nameService; + newLayout.widgets = nameServiceToWidgetMap[nameService]; + newWidgets = newWidgets.concat(nameServiceToWidgetMap[nameService]); + self.createUserWidgetLayout(newLayout).done(function (data) { + newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id); + if (newLayoutsIds.length >= newNameServices.length) { + self.saveActiveWidgetLayouts({ + "WidgetLayouts": newLayoutsIds.concat(currentLayouts.mapProperty('WidgetLayoutInfo.id')).map(function (layout) { + return {id: layout}; + }) + }).done(function () { + var allNSLayout = currentLayouts.findProperty('WidgetLayoutInfo.display_name', 'All').WidgetLayoutInfo; + allNSLayout.widgets = allNSLayout.widgets.concat(newWidgets); + self.updateUserWidgetLayout(allNSLayout).done(function() { + self.getActiveWidgetLayout(); + }); + }); + } + }); + }) } }); + }); + }, - Em.keys(nameServiceToWidgetMap).forEach(function (nameService) { - newLayout.layout_name = userLayoutName + '_nameservice_' + nameService; - newLayout.display_name = nameService === 'all' ? 'All' : nameService; - newLayout.widgets = nameServiceToWidgetMap[nameService]; - self.createUserWidgetLayout(newLayout).done(function (data) { - newLayoutsIds.push(data.resources[0].WidgetLayoutInfo.id); - if (newLayoutsIds.length >= nameServices.length) { - self.saveActiveWidgetLayouts({ - "WidgetLayouts": newLayoutsIds.map(function (layout) { - return {id: layout}; - }) - }).done(function () { - currentLWidgetLayout.widgets = nonNameServiceSpecific; - self.updateUserWidgetLayout(currentLWidgetLayout).done(function () { - self.getActiveWidgetLayout(); - }); - }); - } - }); - }) + removeWidgetLayout: function (id) { + return App.ajax.send({ + name: 'widget.layout.delete', + sender: this, + data: { + layoutId: id + }, }); } }); \ No newline at end of file diff --git a/ambari-web/app/utils/ajax/ajax.js b/ambari-web/app/utils/ajax/ajax.js index 898c3ba..de62d5e 100644 --- a/ambari-web/app/utils/ajax/ajax.js +++ b/ambari-web/app/utils/ajax/ajax.js @@ -2987,6 +2987,11 @@ var urls = { mock: '/data/widget_layouts/{serviceName}/default_dashboard.json' }, + 'widget.layout.delete': { + real: '/clusters/{clusterName}/widget_layouts/{layoutId}', + type: 'DELETE' + }, + 'widget.layout.get': { real: '/clusters/{clusterName}/widget_layouts?{urlParams}', mock: '/data/widget_layouts/{serviceName}/default_dashboard.json' -- To stop receiving notification emails like this one, please contact akovale...@apache.org.