You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2015/12/01 19:20:38 UTC

[48/50] ambari git commit: AMBARI-14095. Upgrade: second click shows diff results

AMBARI-14095. Upgrade: second click shows diff results


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: c5d7cf643fe9fccacadd5b47a52792f87bc7bb73
Parents: 58f6266
Author: Alex Antonenko <hi...@gmail.com>
Authored: Tue Dec 1 15:12:06 2015 +0200
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Tue Dec 1 16:02:15 2015 +0200

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |   1 +
 .../app/controllers/main/admin/kerberos.js      |  16 +-
 .../main/admin/stack_and_upgrade_controller.js  |  40 ++-
 .../modal_popups/cluster_check_dialog.hbs       |  24 +-
 .../common/modal_popups/cluster_check_popup.js  | 107 ++------
 .../admin/stack_and_upgrade_controller_test.js  |   2 +-
 .../modal_popups/cluster_check_popup_test.js    | 271 +++++++++++++++++++
 7 files changed, 356 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c5d7cf64/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index f8d59f1..23460b7 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -202,6 +202,7 @@ var files = [
   'test/views/common/widget/graph_widget_view_test',
   'test/views/common/widget/number_widget_view_test',
   'test/views/common/widget/gauge_widget_view_test',
+  'test/views/common/modal_popups/cluster_check_popup_test',
   'test/views/common/modal_popups/hosts_table_list_popup_test',
   'test/views/common/modal_popups/dependent_configs_list_popup_test',
   'test/views/main/admin_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5d7cf64/ambari-web/app/controllers/main/admin/kerberos.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/kerberos.js b/ambari-web/app/controllers/main/admin/kerberos.js
index 57ee8c1..4e5bcd4 100644
--- a/ambari-web/app/controllers/main/admin/kerberos.js
+++ b/ambari-web/app/controllers/main/admin/kerberos.js
@@ -221,10 +221,18 @@ App.MainAdminKerberosController = App.KerberosWizardStep4Controller.extend({
   runSecurityCheckSuccess: function (data, opt, params) {
     //TODO correct check
     if (data.items.someProperty('UpgradeChecks.status', "FAIL")) {
-      var header = Em.I18n.t('popup.clusterCheck.Security.header').format(params.label);
-      var title = Em.I18n.t('popup.clusterCheck.Security.title');
-      var alert = Em.I18n.t('popup.clusterCheck.Security.alert');
-      App.showClusterCheckPopup(data, header, title, alert);
+      var
+        hasFails = data.items.someProperty('UpgradeChecks.status', 'FAIL'),
+        header = Em.I18n.t('popup.clusterCheck.Security.header').format(params.label),
+        title = Em.I18n.t('popup.clusterCheck.Security.title'),
+        alert = Em.I18n.t('popup.clusterCheck.Security.alert');
+
+      App.showClusterCheckPopup(data, {
+        header: header,
+        failTitle: title,
+        failAlert: alert,
+        noCallbackCondition: hasFails
+      });
     } else {
       this.startKerberosWizard();
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5d7cf64/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
index f331540..d553fdb 100644
--- a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
+++ b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
@@ -718,9 +718,11 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
             warningTitle = Em.I18n.t('popup.clusterCheck.Upgrade.warning.title'),
             warningAlert = new Em.Handlebars.SafeString(Em.I18n.t('popup.clusterCheck.Upgrade.warning.alert')),
             configsMergeWarning = data.items.findProperty('UpgradeChecks.id', "CONFIG_MERGE"),
+            popupData = {
+              items: data.items.rejectProperty('UpgradeChecks.id', 'CONFIG_MERGE')
+            },
             configs = [];
           if (configsMergeWarning && Em.get(configsMergeWarning, 'UpgradeChecks.status') === 'WARNING') {
-            data.items = data.items.rejectProperty('UpgradeChecks.id', 'CONFIG_MERGE');
             var configsMergeCheckData = Em.get(configsMergeWarning, 'UpgradeChecks.failed_detail');
             if (configsMergeCheckData) {
               configs = configsMergeCheckData.map(function (item) {
@@ -738,12 +740,21 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
               });
             }
           }
-          App.showPreUpgradeCheckPopup(data, header, failTitle, failAlert, warningTitle, warningAlert, function () {
-            self.runPreUpgradeCheckOnly.call(self, {
-              value: version.get('repositoryVersion'),
-              label: version.get('displayName'),
-              type: event.context.get('type')
-            });
+          App.showClusterCheckPopup(popupData, {
+            header: header,
+            failTitle: failTitle,
+            failAlert: failAlert,
+            warningTitle: warningTitle,
+            warningAlert: warningAlert,
+            primary: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.preCheck.rerun'),
+            secondary: Em.I18n.t('common.cancel'),
+            callback: function () {
+              self.runPreUpgradeCheckOnly.call(self, {
+                value: version.get('repositoryVersion'),
+                label: version.get('displayName'),
+                type: event.context.get('type')
+              });
+            }
           }, configs, version.get('displayName'));
         }
       }),
@@ -958,7 +969,8 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
     var self = this;
     if (data.items.someProperty('UpgradeChecks.status', 'FAIL') || data.items.someProperty('UpgradeChecks.status', 'WARNING')) {
       this.set('requestInProgress', false);
-      var header = Em.I18n.t('popup.clusterCheck.Upgrade.header').format(params.label),
+      var hasFails = data.items.someProperty('UpgradeChecks.status', 'FAIL'),
+        header = Em.I18n.t('popup.clusterCheck.Upgrade.header').format(params.label),
         failTitle = Em.I18n.t('popup.clusterCheck.Upgrade.fail.title'),
         failAlert = new Em.Handlebars.SafeString(Em.I18n.t('popup.clusterCheck.Upgrade.fail.alert')),
         warningTitle = Em.I18n.t('popup.clusterCheck.Upgrade.warning.title'),
@@ -984,8 +996,16 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
           });
         }
       }
-      App.showClusterCheckPopup(data, header, failTitle, failAlert, warningTitle, warningAlert, function () {
-        self.upgrade(params);
+      App.showClusterCheckPopup(data, {
+        header: header,
+        failTitle: failTitle,
+        failAlert: failAlert,
+        warningTitle: warningTitle,
+        warningAlert: warningAlert,
+        noCallbackCondition: hasFails,
+        callback: function () {
+          self.upgrade(params);
+        }
       }, configs, params.label);
     } else {
       this.upgrade(params);

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5d7cf64/ambari-web/app/templates/common/modal_popups/cluster_check_dialog.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/common/modal_popups/cluster_check_dialog.hbs b/ambari-web/app/templates/common/modal_popups/cluster_check_dialog.hbs
index 8767d70..8fd2746 100644
--- a/ambari-web/app/templates/common/modal_popups/cluster_check_dialog.hbs
+++ b/ambari-web/app/templates/common/modal_popups/cluster_check_dialog.hbs
@@ -20,10 +20,14 @@
     <i class="icon-ok"></i>&nbsp;<span>{{t admin.stackVersions.version.upgrade.upgradeOptions.preCheck.allPassed.msg}}</span>
   {{/if}}
   {{#if view.fails.length}}
-    <h4>{{view.failTitle}}</h4>
-    <div class="alert alert-warning">
-      {{view.failAlert}}
-    </div>
+    {{#if view.failTitle}}
+      <h4>{{view.failTitle}}</h4>
+    {{/if}}
+    {{#if view.failAlert}}
+      <div class="alert alert-warning">
+        {{view.failAlert}}
+      </div>
+    {{/if}}
     <div class="limited-height-2">
       {{#each item in view.fails}}
         <i class="icon-remove"></i>&nbsp;<span>{{item.UpgradeChecks.check}}</span>
@@ -32,10 +36,14 @@
     </div>
   {{/if}}
   {{#if view.warnings.length}}
-    <h4>{{view.warningTitle}}</h4>
-    <div class="alert alert-warning">
-      {{view.warningAlert}}
-    </div>
+    {{#if view.warningTitle}}
+      <h4>{{view.warningTitle}}</h4>
+    {{/if}}
+    {{#if view.warningAlert}}
+      <div class="alert alert-warning">
+        {{view.warningAlert}}
+      </div>
+    {{/if}}
     <div class="limited-height-2">
       {{#each item in view.warnings}}
         <i class="icon-warning-sign"></i>&nbsp;<span>{{item.UpgradeChecks.check}}</span>

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5d7cf64/ambari-web/app/views/common/modal_popups/cluster_check_popup.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/modal_popups/cluster_check_popup.js b/ambari-web/app/views/common/modal_popups/cluster_check_popup.js
index 681c807..54f20ba 100644
--- a/ambari-web/app/views/common/modal_popups/cluster_check_popup.js
+++ b/ambari-web/app/views/common/modal_popups/cluster_check_popup.js
@@ -22,30 +22,33 @@ var App = require('app');
  * popup to display requirements that are not met
  * for current action
  * @param data
- * @param header
- * @param failTitle
- * @param failAlert
- * @param warningTitle
- * @param warningAlert
- * @param callback
+ * @param popup
  * @param configs
  * @param upgradeVersion
  * @returns {*|void}
  */
-App.showClusterCheckPopup = function (data, header, failTitle, failAlert, warningTitle, warningAlert, callback, configs, upgradeVersion) {
+App.showClusterCheckPopup = function (data, popup, configs, upgradeVersion) {
   var fails = data.items.filterProperty('UpgradeChecks.status', 'FAIL'),
     warnings = data.items.filterProperty('UpgradeChecks.status', 'WARNING'),
     hasConfigsMergeConflicts = !!(configs && configs.length),
-    popupBody = {
-      failTitle: failTitle,
-      failAlert: failAlert,
-      warningTitle: warningTitle,
-      warningAlert: warningAlert,
-      templateName: require('templates/common/modal_popups/cluster_check_dialog'),
-      fails: fails,
-      warnings: warnings,
-      hasConfigsMergeConflicts: hasConfigsMergeConflicts
-    };
+    primary,
+    secondary,
+    popupBody;
+  popup = popup || {};
+  primary = Em.isNone(popup.primary) ?
+    (fails.length ? Em.I18n.t('common.dismiss') : Em.I18n.t('common.proceedAnyway')) : popup.primary;
+  secondary = Em.isNone(popup.secondary) ? (fails.length ? false : Em.I18n.t('common.cancel')) : popup.secondary;
+  popupBody = {
+    failTitle: popup.failTitle,
+    failAlert: popup.failAlert,
+    warningTitle: popup.warningTitle,
+    warningAlert: popup.warningAlert,
+    templateName: require('templates/common/modal_popups/cluster_check_dialog'),
+    fails: fails,
+    warnings: warnings,
+    hasConfigsMergeConflicts: hasConfigsMergeConflicts,
+    isAllPassed: !fails.length && !warnings.length && !hasConfigsMergeConflicts
+  };
   if (hasConfigsMergeConflicts) {
     popupBody.configsMergeTable = Em.View.extend({
       templateName: require('templates/main/admin/stack_upgrade/upgrade_configs_merge_table'),
@@ -58,75 +61,15 @@ App.showClusterCheckPopup = function (data, header, failTitle, failAlert, warnin
     });
   }
   return App.ModalPopup.show({
-    primary: fails.length ? Em.I18n.t('common.dismiss') : Em.I18n.t('common.proceedAnyway'),
-    secondary: fails.length ? false : Em.I18n.t('common.cancel'),
-    header: header,
-    classNames: ['cluster-check-popup'],
-    bodyClass: Em.View.extend(popupBody),
-    onPrimary: function () {
-      if (!fails.length && callback) {
-        callback();
-      }
-      this._super();
-    },
-    didInsertElement: function () {
-      this._super();
-      this.fitHeight();
-    }
-  });
-};
-
-
-/**
- * popup to display requirements that are not met
- * for current action
- * @param data
- * @param header
- * @param failTitle
- * @param failAlert
- * @param warningTitle
- * @param warningAlert
- * @param callback
- * @param configs
- * @param upgradeVersion
- * @returns {*|void}
- */
-App.showPreUpgradeCheckPopup = function (data, header, failTitle, failAlert, warningTitle, warningAlert, callback, configs, upgradeVersion) {
-  var fails = data.items.filterProperty('UpgradeChecks.status', 'FAIL'),
-    warnings = data.items.filterProperty('UpgradeChecks.status', 'WARNING'),
-    hasConfigsMergeConflicts = !!(configs && configs.length),
-    popupBody = {
-      failTitle: failTitle,
-      failAlert: failAlert,
-      warningTitle: warningTitle,
-      warningAlert: warningAlert,
-      templateName: require('templates/common/modal_popups/cluster_check_dialog'),
-      fails: fails,
-      warnings: warnings,
-      hasConfigsMergeConflicts: hasConfigsMergeConflicts,
-      isAllPassed: !fails.length && !warnings.length && !hasConfigsMergeConflicts.length
-    };
-  if (hasConfigsMergeConflicts) {
-    popupBody.configsMergeTable = Em.View.extend({
-      templateName: require('templates/main/admin/stack_upgrade/upgrade_configs_merge_table'),
-      configs: configs,
-      didInsertElement: function () {
-        App.tooltip($('.recommended-value'), {
-          title: upgradeVersion
-        });
-      }
-    });
-  }
-  return App.ModalPopup.show({
-    primary: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.preCheck.rerun'),
-    secondary: Em.I18n.t('common.cancel'),
-    header: header,
+    primary: primary,
+    secondary: secondary,
+    header: popup.header,
     classNames: ['cluster-check-popup'],
     bodyClass: Em.View.extend(popupBody),
     onPrimary: function () {
       this._super();
-      if (callback) {
-        callback();
+      if (!popup.noCallbackCondition && popup.callback) {
+        popup.callback();
       }
     },
     didInsertElement: function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5d7cf64/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
index 65739cd..b9c7cb7 100644
--- a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
+++ b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
@@ -454,7 +454,7 @@ describe('App.MainAdminStackAndUpgradeController', function() {
         expect(controller.upgrade.callCount).to.equal(item.upgradeCalledCount);
         expect(App.showClusterCheckPopup.callCount).to.equal(item.showClusterCheckPopupCalledCount);
         if (item.check.id == 'CONFIG_MERGE') {
-          expect(App.showClusterCheckPopup.firstCall.args[7]).to.eql(item.configs);
+          expect(App.showClusterCheckPopup.firstCall.args[2]).to.eql(item.configs);
         }
       });
     });

http://git-wip-us.apache.org/repos/asf/ambari/blob/c5d7cf64/ambari-web/test/views/common/modal_popups/cluster_check_popup_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/modal_popups/cluster_check_popup_test.js b/ambari-web/test/views/common/modal_popups/cluster_check_popup_test.js
new file mode 100644
index 0000000..7f02730
--- /dev/null
+++ b/ambari-web/test/views/common/modal_popups/cluster_check_popup_test.js
@@ -0,0 +1,271 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+require('views/common/modal_popups/cluster_check_popup');
+
+describe('App.showClusterCheckPopup', function () {
+
+  var isCallbackExecuted,
+    callback = function () {
+      isCallbackExecuted = true;
+    },
+    cases = [
+      {
+        inputData: {
+          data: {
+            items: [
+              {
+                UpgradeChecks: {
+                  id: 'p0',
+                  status: 'PASS'
+                }
+              },
+              {
+                UpgradeChecks: {
+                  id: 'p1',
+                  status: 'PASS'
+                }
+              }
+            ]
+          }
+        },
+        result: {
+          primary: Em.I18n.t('common.proceedAnyway'),
+          secondary: Em.I18n.t('common.cancel'),
+          header: '&nbsp;'
+        },
+        bodyResult: {
+          failTitle: undefined,
+          failAlert: undefined,
+          warningTitle: undefined,
+          warningAlert: undefined,
+          fails: [],
+          warnings: [],
+          hasConfigsMergeConflicts: false,
+          isAllPassed: true
+        },
+        isCallbackExecuted: false,
+        title: 'no fails, no warnings, no popup customization'
+      },
+      {
+        inputData: {
+          data: {
+            items: [
+              {
+                UpgradeChecks: {
+                  id: 'w0',
+                  status: 'WARNING'
+                }
+              },
+              {
+                UpgradeChecks: {
+                  id: 'w1',
+                  status: 'WARNING'
+                }
+              }
+            ]
+          },
+          popup: {
+            header: 'checks',
+            failTitle: 'fail',
+            failAlert: 'something has failed',
+            warningTitle: 'warning',
+            warningAlert: 'something is not good',
+            callback: callback
+          }
+        },
+        result: {
+          primary: Em.I18n.t('common.proceedAnyway'),
+          secondary: Em.I18n.t('common.cancel'),
+          header: 'checks'
+        },
+        bodyResult: {
+          failTitle: 'fail',
+          failAlert: 'something has failed',
+          warningTitle: 'warning',
+          warningAlert: 'something is not good',
+          fails: [],
+          warnings: [
+            {
+              UpgradeChecks: {
+                id: 'w0',
+                status: 'WARNING'
+              }
+            },
+            {
+              UpgradeChecks: {
+                id: 'w1',
+                status: 'WARNING'
+              }
+            }
+          ],
+          hasConfigsMergeConflicts: false,
+          isAllPassed: false
+        },
+        isCallbackExecuted: true,
+        title: 'no fails, default buttons, callback executed'
+      },
+      {
+        inputData: {
+          data: {
+            items: [
+              {
+                UpgradeChecks: {
+                  id: 'f0',
+                  status: 'FAIL'
+                }
+              },
+              {
+                UpgradeChecks: {
+                  id: 'f1',
+                  status: 'FAIL'
+                }
+              }
+            ]
+          },
+          popup: {
+            callback: callback,
+            noCallbackCondition: true
+          }
+        },
+        result: {
+          primary: Em.I18n.t('common.dismiss'),
+          secondary: false,
+          header: '&nbsp;'
+        },
+        bodyResult: {
+          failTitle: undefined,
+          failAlert: undefined,
+          warningTitle: undefined,
+          warningAlert: undefined,
+          fails: [
+            {
+              UpgradeChecks: {
+                id: 'f0',
+                status: 'FAIL'
+              }
+            },
+            {
+              UpgradeChecks: {
+                id: 'f1',
+                status: 'FAIL'
+              }
+            }
+          ],
+          warnings: [],
+          hasConfigsMergeConflicts: false,
+          isAllPassed: false
+        },
+        isCallbackExecuted: false,
+        title: 'fails detected, default buttons, callback not executed'
+      },
+      {
+        inputData: {
+          data: {
+            items: [
+              {
+                UpgradeChecks: {
+                  id: 'p0',
+                  status: 'PASS'
+                }
+              },
+              {
+                UpgradeChecks: {
+                  id: 'p1',
+                  status: 'PASS'
+                }
+              }
+            ]
+          },
+          popup: {
+            primary: 'ok',
+            secondary: 'cancel'
+          },
+          configs: [
+            {
+              name: 'c0'
+            },
+            {
+              name: 'c1'
+            }
+          ],
+          upgradeVersion: 'HDP-2.3.0.0'
+        },
+        result: {
+          primary: 'ok',
+          secondary: 'cancel',
+          header: '&nbsp;'
+        },
+        bodyResult: {
+          failTitle: undefined,
+          failAlert: undefined,
+          warningTitle: undefined,
+          warningAlert: undefined,
+          fails: [],
+          warnings: [],
+          hasConfigsMergeConflicts: true,
+          isAllPassed: false
+        },
+        configsResult: [
+          {
+            name: 'c0'
+          },
+          {
+            name: 'c1'
+          }
+        ],
+        isCallbackExecuted: false,
+        title: 'configs merge conflicts detected, custom buttons'
+      }
+    ];
+
+  beforeEach(function () {
+    isCallbackExecuted = false;
+    sinon.stub(App, 'tooltip', Em.K);
+  });
+
+  afterEach(function () {
+    App.tooltip.restore();
+  });
+
+  cases.forEach(function (item) {
+    it(item.title, function () {
+      var popup = App.showClusterCheckPopup(item.inputData.data, item.inputData.popup, item.inputData.configs, item.inputData.upgradeVersion),
+        popupBody = popup.bodyClass.create();
+      popup.onPrimary();
+      Em.keys(item.result).forEach(function (key) {
+        expect(popup[key]).to.equal(item.result[key]);
+      });
+      Em.keys(item.bodyResult).forEach(function (key) {
+        expect(popupBody[key]).to.eql(item.bodyResult[key]);
+      });
+      expect(isCallbackExecuted).to.equal(item.isCallbackExecuted);
+      if (item.bodyResult.hasConfigsMergeConflicts) {
+        var configsMergeTable = popupBody.configsMergeTable.create();
+        configsMergeTable.didInsertElement();
+        expect(configsMergeTable.configs).to.eql(item.configsResult);
+        expect(App.tooltip.calledOnce).to.be.true;
+        expect(App.tooltip.firstCall.args[1].title).to.equal(item.inputData.upgradeVersion);
+      } else {
+        expect(App.tooltip.calledOnce).to.be.false;
+      }
+    });
+  });
+
+});