You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2017/05/25 11:08:55 UTC

ambari git commit: AMBARI-21102. To/From Version Information is Incorrect When Looking at Prior Upgrades (alexantonenko)

Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-12556 770c519a9 -> 7a7f489bc


AMBARI-21102. To/From Version Information is Incorrect When Looking at Prior Upgrades (alexantonenko)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 7a7f489bc51a0351f9e2c0c1fbb79180319f1d80
Parents: 770c519
Author: Alex Antonenko <hi...@gmail.com>
Authored: Thu May 25 14:07:13 2017 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Thu May 25 14:07:13 2017 +0300

----------------------------------------------------------------------
 .../stack_version/stack_upgrade_history.js      |  1 +
 .../admin/stack_upgrade/upgrade_history.hbs     | 14 ++--
 ambari-web/app/utils/array_utils.js             |  6 +-
 .../admin/stack_upgrade/upgrade_history_view.js | 39 ++++-----
 .../stack_upgrade/upgrade_history_view_test.js  | 83 +++++++++++++++++---
 5 files changed, 107 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7a7f489b/ambari-web/app/models/stack_version/stack_upgrade_history.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/stack_version/stack_upgrade_history.js b/ambari-web/app/models/stack_version/stack_upgrade_history.js
index 9b0c8b2..cf38277 100644
--- a/ambari-web/app/models/stack_version/stack_upgrade_history.js
+++ b/ambari-web/app/models/stack_version/stack_upgrade_history.js
@@ -33,6 +33,7 @@ App.StackUpgradeHistory = DS.Model.extend({
   endTime: DS.attr('number'),
   startTime: DS.attr('number'),
   createTime: DS.attr('number'),
+  versions: DS.attr('object'),
   displayStatus: function() {
     return stringUtils.upperUnderscoreToText(this.get('requestStatus'));
   }.property('requestStatus')

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a7f489b/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs b/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
index 44168ca..85fa4c0 100644
--- a/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
+++ b/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
@@ -48,14 +48,16 @@
     </div>
     <table class="table advanced-header-table table-hover" id="upgrade-summary-table">
       <thead>
+      <tr>
         <th>{{t common.direction}}</th>
         <th>{{t common.type}}</th>
-        <th>{{t common.from.version}}</th>
-        <th>{{t common.to.version}}</th>
+        <th>{{t common.service}}</th>
+        <th>{{t common.version}}</th>
         <th>{{t common.start.time}}</th>
         <th>{{t common.duration}}</th>
         <th>{{t common.end.time}}</th>
         <th>{{t common.status}}</th>
+      </tr>
       </thead>
       <tbody>
         {{#if view.pageContent}}
@@ -63,7 +65,7 @@
             <tr>
               <td class='name'>
                 <span class="trim_hostname">
-                  <a href="#" class="black" {{action "showUpgradeHistoryRecord" item target="view"}}>
+                  <a href="#" class="black" {{action "showUpgradeHistoryRecord" item.stackUpgradeHistoryItem target="view"}}>
                     {{unbound item.directionLabel}}
                   </a>
                 </span>
@@ -72,10 +74,10 @@
                 <span>{{item.upgradeTypeLabel}}</span>
               </td>
               <td>
-                <span>{{item.fromVersion}}</span>
+                <span>{{item.serviceName}}</span>
               </td>
               <td>
-                <span>{{item.toVersion}}</span>
+                <span>{{item.version}}</span>
               </td>
               <td>
                 <span>{{item.startTimeLabel}}</span>
@@ -102,4 +104,4 @@
         </tfoot>
     </table>
   </div>
-</div>
\ No newline at end of file
+</div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a7f489b/ambari-web/app/utils/array_utils.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/array_utils.js b/ambari-web/app/utils/array_utils.js
index 76914c4..8bf4e43 100644
--- a/ambari-web/app/utils/array_utils.js
+++ b/ambari-web/app/utils/array_utils.js
@@ -20,6 +20,8 @@ function _parseId(id) {
   return id.replace(/[^\d|\.]/g, '').split('.').map(function (i) {return parseInt(i, 10);});
 }
 
+const flatten = (list) => list.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);
+
 module.exports = {
   /**
    *
@@ -83,6 +85,8 @@ module.exports = {
       return 0
     }
     return lId1 > lId2 ? 1 : -1;
-  }
+  },
+
+  flatten
 
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a7f489b/ambari-web/app/views/main/admin/stack_upgrade/upgrade_history_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/admin/stack_upgrade/upgrade_history_view.js b/ambari-web/app/views/main/admin/stack_upgrade/upgrade_history_view.js
index 718ddc7..0e0ee7f 100644
--- a/ambari-web/app/views/main/admin/stack_upgrade/upgrade_history_view.js
+++ b/ambari-web/app/views/main/admin/stack_upgrade/upgrade_history_view.js
@@ -16,9 +16,9 @@
  * limitations under the License.
  */
 
-
 var App = require('app');
 var date = require('utils/date/date');
+const arrayUtils = require('utils/array_utils');
 
 App.MainAdminStackUpgradeHistoryView = App.TableView.extend(App.TableServerViewMixin, {
 
@@ -98,8 +98,7 @@ App.MainAdminStackUpgradeHistoryView = App.TableView.extend(App.TableServerViewM
   selectedCategory: Em.computed.findBy('categories', 'isSelected', true),
 
   filteredCount: function () {
-    var filteredContent = this.get('filteredContent').toArray();
-    return filteredContent.length;
+    return this.get('filteredContent').map(item => Object.keys(item.get('versions') || {}).length).reduce(Em.sum, 0);
   }.property('filteredContent'),
 
   /**
@@ -115,7 +114,7 @@ App.MainAdminStackUpgradeHistoryView = App.TableView.extend(App.TableServerViewM
   }.property('selectedCategory'),
 
   /**
-   * sort and slice recieved content by pagination parameters
+   * sort and slice received content by pagination parameters
    */
   pageContent: function () {
     var content = this.get('filteredContent').toArray();
@@ -125,21 +124,23 @@ App.MainAdminStackUpgradeHistoryView = App.TableView.extend(App.TableServerViewM
   }.property('filteredContent', 'startIndex', 'endIndex'),
 
   processForDisplay: function (content) {
-    var processedContent = [];
-
-    content.forEach(function (item) {
-      var direction = item.get('direction') === 'UPGRADE' ? Em.I18n.t('common.upgrade') : Em.I18n.t('common.downgrade');
-      var method = this.get('upgradeMethods').findProperty('type', item.get('upgradeType'));
-      item.setProperties({
-        directionLabel: direction,
-        upgradeTypeLabel: method ? method.get('displayName') : method,
-        startTimeLabel: date.startTime(App.dateTimeWithTimeZone(item.get('startTime'))),
-        endTimeLabel: date.endTime(App.dateTimeWithTimeZone(item.get('endTime'))),
-        duration: date.durationSummary(item.get('startTime'), item.get('endTime'))
+    return arrayUtils.flatten(content.map(item => {
+      const versions = item.get('versions');
+      const method = this.get('upgradeMethods').findProperty('type', item.get('upgradeType'));
+      return Object.keys(versions).map(serviceName => {
+        return {
+          version: versions[serviceName].to_repository_version,
+          serviceName: App.format.role(serviceName),
+          directionLabel: item.get('direction') === 'UPGRADE' ? Em.I18n.t('common.upgrade') : Em.I18n.t('common.downgrade'),
+          upgradeTypeLabel: method ? method.get('displayName') : method,
+          startTimeLabel: date.startTime(App.dateTimeWithTimeZone(item.get('startTime'))),
+          endTimeLabel: date.endTime(App.dateTimeWithTimeZone(item.get('endTime'))),
+          duration: date.durationSummary(item.get('startTime'), item.get('endTime')),
+          displayStatus: item.get('displayStatus'),
+          stackUpgradeHistoryItem: item
+        };
       });
-      processedContent.push(item);
-    }, this);
-    return processedContent;
+    }));
   },
 
   paginationLeftClass: function () {
@@ -293,7 +294,7 @@ App.MainAdminStackUpgradeHistoryView = App.TableView.extend(App.TableServerViewM
     var associatedVersion = record.get('associatedVersion');
     var type = this.get('upgradeMethods').findProperty('type', record.get('upgradeType'));
     var displayName = type ? type.get('displayName') : App.format.normalizeName(record.get('upgradeType'));
-    const i18nKeySuffix = direction === 'UPGRADE' ? 'upgrade' : 'downgrade';
+    const i18nKeySuffix = direction.toLowerCase() === 'upgrade' ? 'upgrade' : 'downgrade';
 
     this.get('controller').set('currentUpgradeRecord', record);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/7a7f489b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js
index 0ca7080..de60c74 100644
--- a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js
+++ b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_history_view_test.js
@@ -135,13 +135,13 @@ describe('App.MainAdminStackUpgradeHistoryView', function () {
       event = {
         context: Em.Object.create({
           isSelected: false,
-          value: 'ALL',
+          value: 'ALL'
         })
       };
       view.set('categories', [
         Em.Object.create({
           isSelected: true,
-          value: 'UPGRADE_COMPLETED',
+          value: 'UPGRADE_COMPLETED'
         }),
         event.context
       ]);
@@ -169,6 +169,61 @@ describe('App.MainAdminStackUpgradeHistoryView', function () {
     });
   });
 
+  describe('#filteredCount', function () {
+
+    [
+      {
+        filteredContent: [
+          Em.Object.create({
+            versions: {s1: {}}
+          })
+        ],
+        m: '1 version',
+        e: 1
+      },
+      {
+        filteredContent: [
+          Em.Object.create({
+            versions: {s1: {}, s2: {}}
+          })
+        ],
+        m: '2 versions',
+        e: 2
+      },
+      {
+        filteredContent: [
+          Em.Object.create({
+            versions: {s1: {}, s2: {}}
+          }),
+          Em.Object.create({
+            versions: {s1: {}, s2: {}, s3: {}}
+          })
+        ],
+        m: '5 versions',
+        e: 5
+      }
+    ].forEach(function (test) {
+      describe(test.m, function () {
+        beforeEach(function () {
+          sinon.stub(view, 'get', function (key) {
+            if (key === 'filteredContent') {
+              return test.filteredContent;
+            }
+            return Em.get(this, key);
+          });
+        });
+        afterEach(function () {
+          view.get.restore();
+        });
+        it('should map versions', function () {
+          view.set('filteredContent', test.filteredContent);
+          expect(view.get('filteredCount')).to.be.equal(test.e);
+        });
+      });
+    });
+
+  });
+
   describe('#processForDisplay', function () {
 
     var timestamp = 1484698121448;
@@ -178,13 +233,15 @@ describe('App.MainAdminStackUpgradeHistoryView', function () {
         direction: 'UPGRADE',
         upgradeType: 'ROLLING',
         startTime: timestamp,
-        endTime: timestamp + 3600 * 1000
+        endTime: timestamp + 3600 * 1000,
+        versions: {s1: {}}
       }),
       Em.Object.create({
         direction: 'DOWNGRADE',
         upgradeType: 'HOST_ORDERED',
         startTime: timestamp,
-        endTime: timestamp + 3600 * 1000 * 2
+        endTime: timestamp + 3600 * 1000 * 2,
+        versions: {s1: {}}
       })
     ];
 
@@ -192,16 +249,18 @@ describe('App.MainAdminStackUpgradeHistoryView', function () {
       Em.Object.create({
         directionLabel: Em.I18n.t('common.upgrade'),
         upgradeTypeLabel: Em.I18n.t('common.rolling'),
-        duration: '1.00 hours'
+        duration: '1.00 hours',
+        serviceName: 'S1'
       }),
       Em.Object.create({
         directionLabel: Em.I18n.t('common.downgrade'),
         upgradeTypeLabel: Em.I18n.t('common.hostOrdered'),
-        duration: '2.00 hours'
+        duration: '2.00 hours',
+        serviceName: 'S1'
       })
     ];
 
-    var fields = ['directionLabel', 'upgradeTypeLabel', 'duration'];
+    var fields = ['directionLabel', 'upgradeTypeLabel', 'duration', 'serviceName'];
 
     var processedContent;
 
@@ -216,13 +275,17 @@ describe('App.MainAdminStackUpgradeHistoryView', function () {
       App.dateTimeWithTimeZone.restore();
     });
 
+    it('2 items mapped', function () {
+      expect(processedContent.length).to.be.equal(2);
+    })
+
     expected.forEach(function (item, index) {
 
       describe('test #' + (index + 1), function () {
 
         fields.forEach(function (field) {
           it('#' + field, function () {
-            expect(processedContent[index].get(field)).to.be.equal(item.get(field));
+            expect(processedContent[index][field]).to.be.equal(item.get(field));
           });
         });
 
@@ -232,8 +295,8 @@ describe('App.MainAdminStackUpgradeHistoryView', function () {
 
 
     it('End Time for upgrade in progress is `Not finished`', function () {
-      processedContent = view.processForDisplay([Em.Object.create({endTime: -1})]);
-      expect(processedContent[0].get('endTimeLabel')).to.be.equal('Not finished');
+      processedContent = view.processForDisplay([Em.Object.create({endTime: -1, versions: {s1:{}}})]);
+      expect(processedContent[0].endTimeLabel).to.be.equal('Not finished');
     });
   });