quick_view_link_view.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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.setConfigProperties();
  39. },
  40. actualTags: [],
  41. configProperties: [],
  42. /**
  43. * list of files that contains properties for enabling/disabling ssl
  44. */
  45. requiredSiteNames: ['global','core-site', 'hdfs-site', 'hbase-site', 'oozie-site', 'yarn-site', 'mapred-site'],
  46. setConfigProperties: function () {
  47. this.set('configProperties', []);
  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. this.set('configProperties', data);
  54. },
  55. ambariProperties: function () {
  56. return App.router.get('clusterController.ambariProperties');
  57. },
  58. /**
  59. * Updated quick links. Here we put correct hostname to url
  60. */
  61. quickLinks: [],
  62. didInsertElement: function () {
  63. this.setQuickLinks();
  64. },
  65. findComponentHost: function (componentName) {
  66. var components = this.get('content.hostComponents');
  67. return App.singleNodeInstall ? App.singleNodeAlias : components.findProperty('componentName', componentName).get('host.publicHostName')
  68. },
  69. setQuickLinks: function () {
  70. this.loadTags();
  71. var serviceName = this.get('content.serviceName');
  72. var components = this.get('content.hostComponents');
  73. var host;
  74. var self = this;
  75. var version = App.get('currentStackVersionNumber');
  76. var quickLinks = [];
  77. switch (serviceName) {
  78. case "HDFS":
  79. if (this.get('content.snameNode')) { // not HA
  80. host = this.findComponentHost('NAMENODE');
  81. } else {
  82. // HA
  83. if (this.get('content.activeNameNode')) {
  84. host = this.get('content.activeNameNode.publicHostName');
  85. } else {
  86. host = 'noActiveNN';
  87. }
  88. }
  89. break;
  90. case "MAPREDUCE":
  91. case "OOZIE":
  92. case "GANGLIA":
  93. case "NAGIOS":
  94. case "HUE":
  95. host = App.singleNodeInstall ? App.singleNodeAlias : components.findProperty('isMaster', true).get("host").get("publicHostName");
  96. break;
  97. case "HBASE":
  98. var component;
  99. if (App.supports.multipleHBaseMasters) {
  100. component = components.filterProperty('componentName', 'HBASE_MASTER').findProperty('haStatus', 'true');
  101. } else {
  102. component = components.findProperty('componentName', 'HBASE_MASTER');
  103. }
  104. if (component) {
  105. if (App.singleNodeInstall) {
  106. host = App.singleNodeAlias;
  107. } else {
  108. host = component.get('host.publicHostName');
  109. }
  110. } else {
  111. host = 'noActiveHbaseMaster';
  112. }
  113. break;
  114. case "YARN":
  115. host = this.findComponentHost('RESOURCEMANAGER');
  116. break;
  117. case "MAPREDUCE2":
  118. host = this.findComponentHost('HISTORYSERVER');
  119. break;
  120. case "FALCON":
  121. host = this.findComponentHost('FALCON_SERVER');
  122. break;
  123. case "STORM":
  124. host = this.findComponentHost('NIMBUS');
  125. break;
  126. }
  127. if (!host) {
  128. quickLinks = [
  129. {
  130. label: this.t('quick.links.error.label'),
  131. url: 'javascript:alert("' + this.t('contact.administrator') + '");return false;'
  132. }
  133. ];
  134. } else {
  135. quickLinks = this.get('content.quickLinks').map(function (item) {
  136. if (host == 'noActiveNN' || host == 'noActiveHbaseMaster') {
  137. item.set('disabled', true);
  138. } else {
  139. item.set('disabled', false);
  140. var protocol = self.setProtocol(item.get('service_id'));
  141. if (item.get('template')) {
  142. var port = item.get('http_config') && self.setPort(item, protocol, version);
  143. item.set('url', item.get('template').fmt(protocol, host, port));
  144. }
  145. }
  146. return item;
  147. });
  148. }
  149. this.set('quickLinks', quickLinks);
  150. }.observes('App.currentStackVersionNumber', 'App.singleNodeInstall'),
  151. setProtocol: function (service_id) {
  152. var properties = this.ambariProperties();
  153. var configProperties = this.get('configProperties');
  154. var hadoopSslEnabled = false;
  155. if (configProperties) {
  156. var site = configProperties.findProperty('type', 'core-site');
  157. site.properties['hadoop.ssl.enabled'] && site.properties['hadoop.ssl.enabled'] === 'true' ? hadoopSslEnabled = true : null;
  158. }
  159. switch (service_id) {
  160. case "GANGLIA":
  161. return (properties && properties.hasOwnProperty('ganglia.https') && properties['ganglia.https']) ? "https" : "http";
  162. break;
  163. case "NAGIOS":
  164. return (properties && properties.hasOwnProperty('nagios.https') && properties['nagios.https']) ? "https" : "http";
  165. break;
  166. case "HDFS":
  167. case "HBASE":
  168. case "MAPREDUCE":
  169. return hadoopSslEnabled ? "https" : "http";
  170. break;
  171. case "YARN":
  172. var yarnProperties = configProperties.findProperty('type', 'yarn-site');
  173. if (yarnProperties && yarnProperties.properties) {
  174. if (yarnProperties.properties['yarn.http.policy'] === 'HTTPS_ONLY') {
  175. return "https";
  176. } else if (yarnProperties.properties['yarn.http.policy'] === 'HTTP_ONLY') {
  177. return "http";
  178. }
  179. }
  180. return hadoopSslEnabled ? "https" : "http";
  181. break;
  182. case "MAPREDUCE2":
  183. var mapred2Properties = configProperties.findProperty('type', 'mapred-site');
  184. if (mapred2Properties && mapred2Properties.properties) {
  185. if (mapred2Properties.properties['mapreduce.jobhistory.http.policy'] === 'HTTPS_ONLY') {
  186. return "https";
  187. } else if (mapred2Properties.properties['mapreduce.jobhistory.http.policy'] === 'HTTP_ONLY') {
  188. return "http";
  189. }
  190. }
  191. return hadoopSslEnabled ? "https" : "http";
  192. break;
  193. default:
  194. return "http";
  195. }
  196. },
  197. setPort: function (item, protocol, version) {
  198. var service_id = item.get('service_id');
  199. var configProperties = this.get('configProperties');
  200. var config = item.get('http_config');
  201. var defaultPort = item.get('default_http_port');
  202. if (protocol === 'https' && item.get('https_config')) {
  203. config = item.get('https_config');
  204. if (item.get('default_https_port')) {
  205. defaultPort = item.get('default_https_port');
  206. }
  207. }
  208. var site = configProperties.findProperty('type', item.get('site'));
  209. var propertyValue = site && site.properties[config];
  210. if (!propertyValue) {
  211. return defaultPort;
  212. }
  213. var re = new RegExp(item.get('regex'));
  214. var portValue = propertyValue.match(re);
  215. return portValue[1];
  216. },
  217. linkTarget: function () {
  218. switch (this.get('content.serviceName').toLowerCase()) {
  219. case "hdfs":
  220. case "yarn":
  221. case "mapreduce2":
  222. case "mapreduce":
  223. case "hbase":
  224. case "oozie":
  225. case "ganglia":
  226. case "nagios":
  227. case "hue":
  228. case "storm":
  229. case "falcon":
  230. return "_blank";
  231. break;
  232. default:
  233. return "";
  234. break;
  235. }
  236. }.property('service')
  237. });