ソースを参照

AMBARI-20442. Knox proxy - Navigating to Hive view from Hive Summary page is not working (Go to view link) (alexantonenko)

Alex Antonenko 8 年 前
コミット
a526a07cb6

+ 1 - 0
ambari-web/app/assets/test/tests.js

@@ -386,6 +386,7 @@ var files = [
   'test/models/stack_test',
   'test/models/stack_test',
   'test/models/stack_service_test',
   'test/models/stack_service_test',
   'test/models/user_test',
   'test/models/user_test',
+  'test/models/view_instance_test',
   'test/models/widget_test',
   'test/models/widget_test',
   'test/models/widget_property_test',
   'test/models/widget_property_test',
   'test/models/host_stack_version_test',
   'test/models/host_stack_version_test',

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

@@ -855,7 +855,7 @@ App.MainServiceInfoSummaryController = Em.Controller.extend(App.WidgetSectionMix
   },
   },
 
 
   goToView: function(event) {
   goToView: function(event) {
-    App.router.route('main' + event.context.href);
+    App.router.route(event.context.get('internalAmbariUrl'));
   }
   }
 
 
 });
 });

+ 15 - 17
ambari-web/app/controllers/main/views_controller.js

@@ -78,19 +78,20 @@ App.MainViewsController = Em.Controller.extend({
     data.items.forEach(function (view) {
     data.items.forEach(function (view) {
       view.versions.forEach(function (version) {
       view.versions.forEach(function (version) {
         version.instances.forEach(function (instance) {
         version.instances.forEach(function (instance) {
-          var current_instance = Em.Object.create({
-            iconPath: instance.ViewInstanceInfo.icon_path || "/img/ambari-view-default.png",
-            label: instance.ViewInstanceInfo.label || version.ViewVersionInfo.label || instance.ViewInstanceInfo.view_name,
-            visible: instance.ViewInstanceInfo.visible || false,
-            version: instance.ViewInstanceInfo.version,
-            description: instance.ViewInstanceInfo.description || Em.I18n.t('views.main.instance.noDescription'),
-            viewName: instance.ViewInstanceInfo.view_name,
-            shortUrl:instance.ViewInstanceInfo.short_url,
-            instanceName: instance.ViewInstanceInfo.instance_name,
-            href: instance.ViewInstanceInfo.context_path + "/"
+          var info = instance.ViewInstanceInfo;
+          var currentInstance = App.ViewInstance.create({
+            iconPath: info.icon_path || '/img/ambari-view-default.png',
+            label: info.label || version.ViewVersionInfo.label || info.view_name,
+            visible: info.visible || false,
+            version: info.version,
+            description: info.description || Em.I18n.t('views.main.instance.noDescription'),
+            viewName: info.view_name,
+            shortUrl:info.short_url,
+            instanceName: info.instance_name,
+            href: info.context_path + '/'
           });
           });
-          if (current_instance.visible) {
-            instances.push(current_instance);
+          if (currentInstance.visible) {
+            instances.push(currentInstance);
           }
           }
         }, this);
         }, this);
       }, this);
       }, this);
@@ -106,10 +107,7 @@ App.MainViewsController = Em.Controller.extend({
 
 
   setView: function (event) {
   setView: function (event) {
     if (event.context) {
     if (event.context) {
-      if(event.context.shortUrl){
-        App.router.route('main/view/' + event.context.viewName + '/' + event.context.shortUrl);
-      } else {
-      App.router.route('main/views/' + event.context.viewName + '/' + event.context.version + '/' + event.context.instanceName);
-    }}
+      App.router.route(event.context.get('internalAmbariUrl'));
+    }
   }
   }
 });
 });

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

@@ -78,6 +78,7 @@ require('models/configs/theme/config_action');
 require('models/configs/objects/service_config');
 require('models/configs/objects/service_config');
 require('models/configs/objects/service_config_category');
 require('models/configs/objects/service_config_category');
 require('models/configs/objects/service_config_property');
 require('models/configs/objects/service_config_property');
+require('models/view_instance');
 require('models/widget');
 require('models/widget');
 require('models/widget_property');
 require('models/widget_property');
 require('models/widget_layout');
 require('models/widget_layout');

+ 81 - 0
ambari-web/app/models/view_instance.js

@@ -0,0 +1,81 @@
+/**
+ * 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');
+
+App.ViewInstance = Em.Object.extend({
+
+  /**
+   * @type {string}
+   */
+  iconPath: '',
+
+  /**
+   * @type {string}
+   */
+  label: '',
+
+  /**
+   * @type {boolean}
+   */
+  visible: false,
+
+  /**
+   * @type {string}
+   */
+  version: '',
+
+  /**
+   * @type {string}
+   */
+  description: '',
+
+  /**
+   * @type {string}
+   */
+  viewName: '',
+
+  /**
+   * @type {string}
+   */
+  shortUrl: '',
+
+  /**
+   * @type {string}
+   */
+  instanceName: '',
+
+  /**
+   * @type {string}
+   */
+  href: '',
+
+  /**
+   * @type {string}
+   */
+  internalAmbariUrl: function () {
+    var shortUrl = this.get('shortUrl');
+    var viewName = this.get('viewName');
+    var version = this.get('version');
+    var instanceName = this.get('instanceName');
+    if(shortUrl) {
+      return 'main/view/' + viewName + '/' + shortUrl;
+    }
+    return 'main/views/' + viewName + '/' + version + '/' + instanceName;
+  }.property('shortUrl', 'viewName', 'version', 'instanceName')
+});

+ 1 - 1
ambari-web/app/templates/main/service/services/hive.hbs

@@ -40,7 +40,7 @@
     <tr>
     <tr>
         <td class="summary-label">{{link.label}}</td>
         <td class="summary-label">{{link.label}}</td>
         <td class="summary-value" >
         <td class="summary-value" >
-            <a href="#" target="_blank" {{action goToView link target="controller"}}>{{t app.goToView}}</a>
+            <a href="#" target="_blank" {{action goToView link.viewInstance target="controller"}}>{{t app.goToView}}</a>
         </td>
         </td>
     </tr>
     </tr>
 {{/each}}
 {{/each}}

+ 7 - 7
ambari-web/app/views/main/service/services/hive.js

@@ -30,15 +30,15 @@ App.MainDashboardServiceHiveView = App.MainDashboardServiceView.extend({
   viewLinks: function() {
   viewLinks: function() {
     var viewsToShow = this.get('viewsToShow');
     var viewsToShow = this.get('viewsToShow');
     var links = [];
     var links = [];
-    App.router.get('mainViewsController.ambariViews').forEach(function(item) {
-      var view = viewsToShow[item.get('instanceName')];
-      if (view) {
+    App.router.get('mainViewsController.ambariViews').forEach(function(viewInstance) {
+      var viewMeta = viewsToShow[viewInstance.get('instanceName')];
+      if (viewMeta) {
         var link = {
         var link = {
-          href: item.href,
-          label: item.label
+          viewInstance: viewInstance,
+          label: viewInstance.get('label')
         };
         };
-        if (view.overwriteLabel) {
-          link.label = Em.I18n.t(view.overwriteLabel);
+        if (viewMeta.overwriteLabel) {
+          link.label = Em.I18n.t(viewMeta.overwriteLabel);
         }
         }
         links.push(link);
         links.push(link);
       }
       }

+ 27 - 11
ambari-web/test/controllers/main/views_controller_test.js

@@ -103,16 +103,32 @@ describe('MainViewsController', function () {
       ]
       ]
     };
     };
 
 
-    it("should parse view instance data", function () {
+    var viewInstanceFields = {
+      iconPath: 'icon_path1',
+      label: 'label1',
+      visible: true,
+      version: '1.0',
+      description: 'desc1',
+      href: 'path1/'
+    };
+    
+    beforeEach(function () {
       mainViewsController.loadViewInstancesSuccess(data);
       mainViewsController.loadViewInstancesSuccess(data);
-      expect(JSON.parse(JSON.stringify(mainViewsController.get('ambariViews')))).to.be.eql([{
-        "iconPath": "icon_path1",
-        "label": "label1",
-        "visible": true,
-        "version": "1.0",
-        "description": "desc1",
-        "href": "path1/"
-      }]);
+    });
+
+    it('one view instance is parsed', function () {
+      expect(mainViewsController.get('ambariViews.length')).to.be.equal(1);
+    });
+
+
+    Object.keys(viewInstanceFields).forEach(function (fieldName) {
+      it(JSON.stringify(fieldName) + ' is set correctly', function () {
+        expect(mainViewsController.get('ambariViews.firstObject.' + fieldName)).to.be.equal(viewInstanceFields[fieldName]);
+      });
+    });
+
+
+    it('`isDataLoaded` is set `true` when view instances are parsed', function () {
       expect(mainViewsController.get('isDataLoaded')).to.be.true;
       expect(mainViewsController.get('isDataLoaded')).to.be.true;
     });
     });
   });
   });
@@ -142,11 +158,11 @@ describe('MainViewsController', function () {
 
 
     it("context exist", function () {
     it("context exist", function () {
       mainViewsController.setView({
       mainViewsController.setView({
-        context: {
+        context: App.ViewInstance.create({
           viewName: 'view1',
           viewName: 'view1',
           version: '1',
           version: '1',
           instanceName: 'instance1'
           instanceName: 'instance1'
-        }
+        })
       });
       });
       expect(App.router.route.calledWith('main/views/view1/1/instance1')).to.be.true;
       expect(App.router.route.calledWith('main/views/view1/1/instance1')).to.be.true;
     });
     });

+ 59 - 0
ambari-web/test/models/view_instance_test.js

@@ -0,0 +1,59 @@
+/**
+ * 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 model;
+
+describe('App.ViewInstance', function () {
+
+  beforeEach(function () {
+    model = App.ViewInstance.create();
+  });
+
+  describe('#internalAmbariUrl', function () {
+
+    [
+      {
+        props: {
+          shortUrl: '',
+          viewName: 'CAPACITY-SCHEDULER',
+          version: '1.0.0',
+          instanceName: 'AUTO_CS_INSTANCE'
+        },
+        e: 'main/views/CAPACITY-SCHEDULER/1.0.0/AUTO_CS_INSTANCE',
+        m: '`shortUrl` does not exist'
+      },
+      {
+        props: {
+          shortUrl: 'auto_cs_instance',
+          viewName: 'CAPACITY-SCHEDULER',
+          version: '1.0.0',
+          instanceName: 'AUTO_CS_INSTANCE'
+        },
+        e: 'main/view/CAPACITY-SCHEDULER/auto_cs_instance',
+        m: '`shortUrl` exists'
+      }
+    ].forEach(function (test) {
+      it(test.m, function () {
+        model.setProperties(test.props);
+        expect(model.get('internalAmbariUrl')).to.be.equal(test.e);
+      });
+    });
+
+  });
+
+});