quick_view_link_view.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. App.QuickViewLinks = Em.View.extend({
  21. loadTags: function() {
  22. App.ajax.send({
  23. name: 'config.tags.sync',
  24. sender: this,
  25. success: 'loadTagsSuccess',
  26. error: 'loadTagsError'
  27. });
  28. },
  29. loadTagsSuccess: function(data) {
  30. var tags = [];
  31. for( var prop in data.Clusters.desired_configs){
  32. tags.push(Em.Object.create({
  33. siteName: prop,
  34. tagName: data.Clusters.desired_configs[prop]['tag']
  35. }));
  36. }
  37. this.set('actualTags', tags);
  38. this.getSecurityProperties();
  39. },
  40. actualTags: [],
  41. securityProperties: [],
  42. /**
  43. * list of files that contains properties for enabling/disabling ssl
  44. */
  45. requiredSiteNames: ['core-site'],
  46. getSecurityProperties: function () {
  47. this.set('securityProperties', []);
  48. var requiredSiteNames = this.get('requiredSiteNames');
  49. var tags = this.get('actualTags').filter(function(tag){
  50. return requiredSiteNames.contains(tag.siteName);
  51. });
  52. var data = App.router.get('configurationController').getConfigsByTags(tags);
  53. var properties = this.get('securityProperties');
  54. var coreSiteProperties = data.findProperty('type', 'core-site');
  55. if(coreSiteProperties) {
  56. properties.pushObject(coreSiteProperties);
  57. this.set('securityProperties', properties);
  58. }
  59. },
  60. ambariProperties: function() {
  61. return App.router.get('clusterController.ambariProperties');
  62. },
  63. /**
  64. * Updated quick links. Here we put correct hostname to url
  65. */
  66. quickLinks: [],
  67. didInsertElement: function() {
  68. this.setQuickLinks();
  69. },
  70. setQuickLinks: function () {
  71. this.loadTags();
  72. var serviceName = this.get('content.serviceName');
  73. var components = this.get('content.hostComponents');
  74. var host;
  75. var self = this;
  76. var version = App.get('currentStackVersionNumber');
  77. var quickLinks = [];
  78. switch (serviceName) {
  79. case "HDFS":
  80. if ( this.get('content.snameNode')) { // not HA
  81. host = App.singleNodeInstall ? App.singleNodeAlias : components.findProperty('componentName', 'NAMENODE').get('host.publicHostName');
  82. } else {
  83. // HA
  84. if (this.get('content.activeNameNode')) {
  85. host = this.get('content.activeNameNode.publicHostName');
  86. }else {
  87. host = 'noActiveNN';
  88. }
  89. }
  90. break;
  91. case "MAPREDUCE":
  92. case "OOZIE":
  93. case "GANGLIA":
  94. case "NAGIOS":
  95. case "HUE":
  96. host = App.singleNodeInstall ? App.singleNodeAlias : components.findProperty('isMaster', true).get("host").get("publicHostName");
  97. break;
  98. case "HBASE":
  99. var component;
  100. if (App.supports.multipleHBaseMasters) {
  101. component = components.filterProperty('componentName', 'HBASE_MASTER').findProperty('haStatus', 'true');
  102. } else {
  103. component = components.findProperty('componentName', 'HBASE_MASTER');
  104. }
  105. if (component) {
  106. if (App.singleNodeInstall) {
  107. host = App.singleNodeAlias;
  108. } else {
  109. host = component.get('host.publicHostName');
  110. }
  111. }
  112. break;
  113. case "YARN":
  114. host = App.singleNodeInstall ? App.singleNodeAlias : components.findProperty('componentName', 'RESOURCEMANAGER').get('host.publicHostName');
  115. break;
  116. case "MAPREDUCE2":
  117. host = App.singleNodeInstall ? App.singleNodeAlias : components.findProperty('componentName', 'HISTORYSERVER').get('host.publicHostName');
  118. break;
  119. }
  120. if (!host) {
  121. quickLinks = [
  122. {
  123. label: this.t('quick.links.error.label'),
  124. url: 'javascript:alert("' + this.t('contact.administrator') + '");return false;'
  125. }
  126. ];
  127. } else {
  128. quickLinks = this.get('content.quickLinks').map(function (item) {
  129. if (host == 'noActiveNN') {
  130. item.set('disabled', true);
  131. } else {
  132. item.set('disabled', false);
  133. var protocol = self.setProtocol(item.get('service_id'));
  134. if (item.get('template')) {
  135. if(item.get('service_id') === 'YARN'){
  136. var port = self.setPort(item.get('service_id'),protocol, version);
  137. item.set('url', item.get('template').fmt(protocol,host,port));
  138. } else {
  139. item.set('url', item.get('template').fmt(protocol,host));
  140. }
  141. }
  142. }
  143. return item;
  144. });
  145. }
  146. this.set('quickLinks',quickLinks);
  147. }.observes('App.currentStackVersionNumber', 'App.router.mainAdminSecurityController.securityEnabled'),
  148. setProtocol: function(service_id){
  149. var properties = this.ambariProperties();
  150. var securityProperties = this.get('securityProperties');
  151. var hadoopSslEnabled = false;
  152. if(securityProperties) {
  153. securityProperties.forEach(function(property){
  154. property['hadoop.ssl.enabled'] && property['hadoop.ssl.enabled'] === 'true' ? hadoopSslEnabled = true : null;
  155. });
  156. }
  157. switch(service_id){
  158. case "GANGLIA":
  159. return (properties && properties.hasOwnProperty('ganglia.https') && properties['ganglia.https']) ? "https" : "http";
  160. break;
  161. case "NAGIOS":
  162. return (properties && properties.hasOwnProperty('nagios.https') && properties['nagios.https']) ? "https" : "http";
  163. break;
  164. case "HDFS":
  165. case "YARN":
  166. case "MAPREDUCE":
  167. case "MAPREDUCE2":
  168. case "HBASE":
  169. return hadoopSslEnabled ? "https" : "http";
  170. break;
  171. default:
  172. return "http";
  173. }
  174. },
  175. setPort: function(service_id, protocol, version) {
  176. var port = '';
  177. if (service_id === 'YARN') {
  178. port = (protocol === 'https' && stringUtils.compareVersions(version,'2.0.5') === 1) ? '8090' : '8088'
  179. }
  180. return port;
  181. },
  182. linkTarget: function () {
  183. switch (this.get('content.serviceName').toLowerCase()) {
  184. case "hdfs":
  185. case "yarn":
  186. case "mapreduce2":
  187. case "mapreduce":
  188. case "hbase":
  189. case "oozie":
  190. case "ganglia":
  191. case "nagios":
  192. case "hue":
  193. return "_blank";
  194. break;
  195. default:
  196. return "";
  197. break;
  198. }
  199. }.property('service')
  200. });