Pārlūkot izejas kodu

AMBARI-9665 Handle Missing Storm Metric Graphs. (atkach)

Andrii Tkach 10 gadi atpakaļ
vecāks
revīzija
1bf9a6fbef

+ 1 - 0
ambari-web/app/config.js

@@ -51,6 +51,7 @@ App.healthIconClassRed = 'icon-warning-sign'; // bootstrap icon class for master
 App.healthIconClassOrange = 'icon-minus-sign'; // bootstrap icon class for slave down/decommissioned host/host-component
 App.healthIconClassYellow = 'icon-question-sign'; // bootstrap icon class for heartbeat lost service/host/host-component
 App.isManagedMySQLForHiveEnabled = false;
+App.isStormMetricsSupported = true;
 App.healthStatusRed = '#ff0000';
 App.healthStatusGreen = '#5AB400';
 App.healthStatusOrange = '#FF8E00';

+ 41 - 0
ambari-web/app/controllers/global/cluster_controller.js

@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var stringUtils = require('utils/string_utils');
 
 App.ClusterController = Em.Controller.extend({
   name: 'clusterController',
@@ -434,5 +435,45 @@ App.ClusterController = Em.Controller.extend({
         $.ajax(ajaxOpt);
       }
     });
+  },
+
+  //TODO Replace this check with any other which is applicable to non-HDP stack
+  /**
+   * Check if HDP stack version is more or equal than 2.2.2 to determine if pluggable metrics for Storm are supported
+   * @method checkDetailedRepoVersion
+   * @returns {promise|*|promise|promise|HTMLElement|promise}
+   */
+  checkDetailedRepoVersion: function () {
+    var dfd;
+    var currentStackName = App.get('currentStackName');
+    var currentStackVersionNumber = App.get('currentStackVersionNumber');
+    if (currentStackName == 'HDP' && currentStackVersionNumber == '2.2') {
+      dfd = App.ajax.send({
+        name: 'cluster.load_detailed_repo_version',
+        sender: this,
+        success: 'checkDetailedRepoVersionSuccessCallback',
+        error: 'checkDetailedRepoVersionErrorCallback'
+      });
+    } else {
+      dfd = $.Deferred();
+      App.set('isStormMetricsSupported', currentStackName != 'HDP' || stringUtils.compareVersions(currentStackVersionNumber, '2.2') == 1);
+      dfd.resolve();
+    }
+    return dfd.promise();
+  },
+
+  checkDetailedRepoVersionSuccessCallback: function (data) {
+    var items = data.items;
+    var version;
+    if (items && items.length) {
+      var repoVersions = items[0].repository_versions;
+      if (repoVersions && repoVersions.length) {
+        version = Em.get(repoVersions[0], 'RepositoryVersions.repository_version');
+      }
+    }
+    App.set('isStormMetricsSupported', stringUtils.compareVersions(version, '2.2.2') > -1 || !version);
+  },
+  checkDetailedRepoVersionErrorCallback: function () {
+    App.set('isStormMetricsSupported', true);
   }
 });

+ 5 - 1
ambari-web/app/controllers/main/admin/kerberos.js

@@ -182,18 +182,22 @@ App.MainAdminKerberosController = App.KerberosWizardStep4Controller.extend({
    * @returns {$.Deferred}
    */
   getSecurityStatus: function () {
+    var dfd;
     if (App.get('testMode')) {
+      dfd = $.Deferred();
       this.set('securityEnabled', !App.get('testEnableSecurity'));
       this.set('dataIsLoaded', true);
+      dfd.resolve();
     } else {
       //get Security Status From Server
-      return App.ajax.send({
+      dfd = App.ajax.send({
         name: 'admin.security_status',
         sender: this,
         success: 'getSecurityStatusSuccessCallback',
         error: 'errorCallback'
       });
     }
+    return dfd.promise();
   },
 
   getSecurityStatusSuccessCallback: function(data) {

+ 9 - 1
ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js

@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var stringUtils = require('utils/string_utils');
 
 App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage, {
   name: 'mainAdminStackAndUpgradeController',
@@ -673,5 +674,12 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
     }).done(function () {
       item.set('status', status);
     });
-  }
+  },
+
+  currentVersionObserver: function () {
+    var versionNumber = this.get('currentVersion.repository_version');
+    var currentVersionObject = App.RepositoryVersion.find().findProperty('status', 'CURRENT');
+    var versionName = currentVersionObject && currentVersionObject.get('stackVersionType');
+    App.set('isStormMetricsSupported', versionName != 'HDP' || stringUtils.compareVersions(versionNumber, '2.2.2') > -1 || !versionNumber);
+  }.observes('currentVersion.repository_version')
 });

+ 3 - 1
ambari-web/app/routes/main.js

@@ -36,7 +36,9 @@ module.exports = Em.Route.extend({
             } else {
               if (router.get('clusterInstallCompleted')) {
                 App.router.get('clusterController').loadClientServerClockDistance().done(function () {
-                  router.get('mainController').initialize();
+                  App.router.get('clusterController').checkDetailedRepoVersion().done(function () {
+                    router.get('mainController').initialize();
+                  });
                 });
               }
               else {

+ 4 - 0
ambari-web/app/utils/ajax/ajax.js

@@ -1104,6 +1104,10 @@ var urls = {
       };
     }
   },
+  'cluster.load_detailed_repo_version': {
+    'real': '/clusters/{clusterName}/stack_versions?ClusterStackVersions/state=CURRENT&fields=repository_versions/RepositoryVersions/repository_version&minimal_response=true',
+    'mock': '/data/stack_versions/stack_version_all.json'
+  },
   'cluster.save_provisioning_state': {
     'real': '/clusters/{clusterName}',
     'type': 'PUT',

+ 2 - 1
ambari-web/app/views/main/service/info/summary.js

@@ -460,7 +460,8 @@ App.MainServiceInfoSummaryView = Em.View.extend(App.UserPref, {
 
   didInsertElement: function () {
     var svcName = this.get('service.serviceName');
-    if (svcName) {
+    var isMetricsSupported = svcName != 'STORM' || App.get('isStormMetricsSupported');
+    if (svcName && isMetricsSupported) {
       this.constructGraphObjects(App.service_graph_config[svcName.toLowerCase()]);
     }
     // adjust the summary table height

+ 161 - 0
ambari-web/test/controllers/global/cluster_controller_test.js

@@ -24,6 +24,7 @@ require('utils/http_client');
 require('models/service');
 require('models/host');
 require('utils/ajax/ajax');
+require('utils/string_utils');
 
 var modelSetup = require('test/init_model_test');
 
@@ -343,5 +344,165 @@ describe('App.clusterController', function () {
     });
   });
 
+  describe('#checkDetailedRepoVersion()', function () {
+
+    var cases = [
+      {
+        currentStackName: 'HDP',
+        currentStackVersionNumber: '2.1',
+        isStormMetricsSupported: false,
+        title: 'HDP < 2.2'
+      },
+      {
+        currentStackName: 'HDP',
+        currentStackVersionNumber: '2.3',
+        isStormMetricsSupported: true,
+        title: 'HDP > 2.2'
+      },
+      {
+        currentStackName: 'BIGTOP',
+        currentStackVersionNumber: '0.8',
+        isStormMetricsSupported: true,
+        title: 'not HDP'
+      }
+    ];
+
+    beforeEach(function () {
+      sinon.stub(App.ajax, 'send').returns({
+        promise: Em.K
+      });
+    });
+
+    afterEach(function () {
+      App.ajax.send.restore();
+      App.get.restore();
+    });
+
+    it('should check detailed repo version for HDP 2.2', function () {
+      sinon.stub(App, 'get').withArgs('currentStackName').returns('HDP').withArgs('currentStackVersionNumber').returns('2.2');
+      controller.checkDetailedRepoVersion();
+      expect(App.ajax.send.calledOnce).to.be.true;
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        sinon.stub(App, 'get', function (key) {
+          return item[key] || Em.get(App, key);
+        });
+        controller.checkDetailedRepoVersion();
+        expect(App.ajax.send.called).to.be.false;
+        expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
+      });
+    });
+
+  });
+
+  describe('#checkDetailedRepoVersionSuccessCallback()', function () {
+
+    var cases = [
+      {
+        items: [
+          {
+            repository_versions: [
+              {
+                RepositoryVersions: {
+                  repository_version: '2.1'
+                }
+              }
+            ]
+          }
+        ],
+        isStormMetricsSupported: false,
+        title: 'HDP < 2.2.2'
+      },
+      {
+        items: [
+          {
+            repository_versions: [
+              {
+                RepositoryVersions: {
+                  repository_version: '2.2.2'
+                }
+              }
+            ]
+          }
+        ],
+        isStormMetricsSupported: true,
+        title: 'HDP 2.2.2'
+      },
+      {
+        items: [
+          {
+            repository_versions: [
+              {
+                RepositoryVersions: {
+                  repository_version: '2.2.3'
+                }
+              }
+            ]
+          }
+        ],
+        isStormMetricsSupported: true,
+        title: 'HDP > 2.2.2'
+      },
+      {
+        items: null,
+        isStormMetricsSupported: true,
+        title: 'empty response'
+      },
+      {
+        items: [],
+        isStormMetricsSupported: true,
+        title: 'no items'
+      },
+      {
+        items: [{}],
+        isStormMetricsSupported: true,
+        title: 'empty item'
+      },
+      {
+        items: [{
+          repository_versions: []
+        }],
+        isStormMetricsSupported: true,
+        title: 'no versions'
+      },
+      {
+        items: [{
+          repository_versions: [{}]
+        }],
+        isStormMetricsSupported: true,
+        title: 'no version info'
+      },
+      {
+        items: [{
+          repository_versions: [
+            {
+              RepositoryVersions: {}
+            }
+          ]
+        }],
+        isStormMetricsSupported: true,
+        title: 'empty version info'
+      }
+    ];
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        controller.checkDetailedRepoVersionSuccessCallback({
+          items: item.items
+        });
+        expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
+      });
+    });
+
+  });
+
+  describe('#checkDetailedRepoVersionErrorCallback()', function () {
+    it('should set isStormMetricsSupported to default value', function () {
+      controller.checkDetailedRepoVersionErrorCallback();
+      expect(App.get('isStormMetricsSupported')).to.be.true;
+    });
+  });
 
 });

+ 51 - 0
ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js

@@ -19,6 +19,7 @@
 
 var App = require('app');
 require('controllers/main/admin/stack_and_upgrade_controller');
+require('utils/string_utils');
 
 describe('App.MainAdminStackAndUpgradeController', function() {
 
@@ -835,4 +836,54 @@ describe('App.MainAdminStackAndUpgradeController', function() {
       expect(App.HttpClient.get.calledOnce).to.be.true;
     });
   });
+
+  describe('#currentVersionObserver()', function () {
+
+    var cases = [
+      {
+        stackVersionType: 'HDP',
+        repoVersion: '2.2.1.1.0-1',
+        isStormMetricsSupported: false,
+        title: 'HDP < 2.2.2'
+      },
+      {
+        stackVersionType: 'HDP',
+        repoVersion: '2.2.2.1.0-1',
+        isStormMetricsSupported: true,
+        title: 'HDP 2.2.2'
+      },
+      {
+        stackVersionType: 'HDP',
+        repoVersion: '2.2.3.1.0-1',
+        isStormMetricsSupported: true,
+        title: 'HDP > 2.2.2'
+      },
+      {
+        stackVersionType: 'BIGTOP',
+        repoVersion: '0.8.1.1.0-1',
+        isStormMetricsSupported: true,
+        title: 'not HDP'
+      }
+    ];
+
+    afterEach(function () {
+      App.RepositoryVersion.find.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        sinon.stub(App.RepositoryVersion, 'find').returns([
+          Em.Object.create({
+            status: 'CURRENT',
+            stackVersionType: item.stackVersionType
+          })
+        ]);
+        controller.set('currentVersion', {
+          repository_version: item.repoVersion
+        });
+        expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
+      });
+    });
+
+  });
 });

+ 44 - 1
ambari-web/test/views/main/service/info/summary_test.js

@@ -31,7 +31,8 @@ describe('App.MainServiceInfoSummaryView', function() {
         hostComponents: []
       })
     }),
-    alertsController: Em.Object.create()
+    alertsController: Em.Object.create(),
+    service: Em.Object.create()
   });
 
   describe('#servers', function () {
@@ -137,4 +138,46 @@ describe('App.MainServiceInfoSummaryView', function() {
       });
     })
   });
+
+  describe('#didInsertElement', function () {
+
+    var cases = [
+      {
+        serviceName: 'STORM',
+        isStormMetricsSupported: false,
+        isConstructGraphObjectsCalled: false,
+        title: 'Storm, metrics not supported'
+      },
+      {
+        serviceName: 'STORM',
+        isStormMetricsSupported: true,
+        isConstructGraphObjectsCalled: true,
+        title: 'Storm, metrics supported'
+      },
+      {
+        serviceName: 'HDFS',
+        isConstructGraphObjectsCalled: true,
+        title: 'not Storm'
+      }
+    ];
+
+    beforeEach(function () {
+      sinon.stub(view, 'constructGraphObjects', Em.K);
+    });
+
+    afterEach(function () {
+      view.constructGraphObjects.restore();
+      App.get.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        view.set('service.serviceName', item.serviceName);
+        sinon.stub(App, 'get').withArgs('isStormMetricsSupported').returns(item.isStormMetricsSupported);
+        view.didInsertElement();
+        expect(view.constructGraphObjects.calledOnce).to.equal(item.isConstructGraphObjectsCalled);
+      });
+    });
+
+  });
 });