quick_view_link_view.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. isLoaded: false,
  22. loadTags: function () {
  23. App.ajax.send({
  24. name: 'config.tags',
  25. sender: this,
  26. success: 'loadTagsSuccess',
  27. error: 'loadTagsError'
  28. });
  29. },
  30. loadTagsSuccess: function (data) {
  31. this.get('actualTags').clear();
  32. var tags = [];
  33. var self = this;
  34. for (var prop in data.Clusters.desired_configs) {
  35. tags.push(Em.Object.create({
  36. siteName: prop,
  37. tagName: data.Clusters.desired_configs[prop]['tag']
  38. }));
  39. }
  40. this.get('actualTags').pushObjects(tags);
  41. this.setConfigProperties().done(function (data) {
  42. self.get('configProperties').pushObjects(data);
  43. self.getQuickLinksHosts();
  44. });
  45. },
  46. loadTagsError: function() {
  47. this.getQuickLinksHosts();
  48. },
  49. getQuickLinksHosts: function () {
  50. var masterHosts = App.HostComponent.find().filterProperty('isMaster').mapProperty('hostName').uniq();
  51. App.ajax.send({
  52. name: 'hosts.for_quick_links',
  53. sender: this,
  54. data: {
  55. clusterName: App.get('clusterName'),
  56. masterHosts: masterHosts.join(','),
  57. urlParams: ',host_components/metrics/hbase/master/IsActiveMaster'
  58. },
  59. success: 'setQuickLinksSuccessCallback'
  60. });
  61. },
  62. actualTags: [],
  63. configProperties: [],
  64. /**
  65. * list of files that contains properties for enabling/disabling ssl
  66. */
  67. requiredSiteNames: ['hadoop-env','yarn-env','hbase-env','oozie-env','mapred-env','storm-env', 'falcon-env', 'core-site', 'hdfs-site', 'hbase-site', 'oozie-site', 'yarn-site', 'mapred-site', 'storm-site', 'spark-defaults', 'accumulo-site', 'application-properties', 'ranger-admin-site'],
  68. /**
  69. * Get public host name by its host name.
  70. *
  71. * @method getPublicHostName
  72. * @param {Object[]} hosts - list of hosts from response
  73. * @param {String} hostName
  74. * @return {String}
  75. **/
  76. getPublicHostName: function(hosts, hostName) {
  77. return Em.get(hosts.findProperty('Hosts.host_name', hostName), 'Hosts.public_host_name');
  78. },
  79. setConfigProperties: function () {
  80. this.get('configProperties').clear();
  81. var requiredSiteNames = this.get('requiredSiteNames');
  82. var tags = this.get('actualTags').filter(function (tag) {
  83. return requiredSiteNames.contains(tag.siteName);
  84. });
  85. return App.router.get('configurationController').getConfigsByTags(tags);
  86. },
  87. ambariProperties: function () {
  88. return App.router.get('clusterController.ambariProperties');
  89. },
  90. /**
  91. * Updated quick links. Here we put correct hostname to url
  92. */
  93. quickLinks: [],
  94. didInsertElement: function () {
  95. this.setQuickLinks();
  96. },
  97. findComponentHost: function (components, componentName) {
  98. var component = components.find(function (item) {
  99. return item.host_components.someProperty('HostRoles.component_name', componentName);
  100. });
  101. return component && component.Hosts.public_host_name;
  102. },
  103. setQuickLinks: function () {
  104. this.loadTags();
  105. }.observes('App.currentStackVersionNumber', 'App.singleNodeInstall'),
  106. setQuickLinksSuccessCallback: function (response) {
  107. var self = this;
  108. var quickLinks = [];
  109. var hosts = this.setHost(response, this.get('content.serviceName'));
  110. if (!hosts || !this.get('content.quickLinks')) {
  111. quickLinks = [{
  112. label: this.t('quick.links.error.label'),
  113. url: 'javascript:alert("' + this.t('contact.administrator') + '");return false;'
  114. }];
  115. this.set('quickLinks', quickLinks);
  116. this.set('isLoaded', true);
  117. } else if (hosts.length == 1) {
  118. quickLinks = this.get('content.quickLinks').map(function (item) {
  119. var protocol = self.setProtocol(item.get('service_id'), self.get('configProperties'), self.ambariProperties());
  120. if (item.get('template')) {
  121. var port = item.get('http_config') && self.setPort(item, protocol);
  122. if (['FALCON', 'OOZIE', 'ATLAS'].contains(item.get('service_id'))) {
  123. item.set('url', item.get('template').fmt(protocol, hosts[0], port, App.router.get('loginName')));
  124. } else {
  125. item.set('url', item.get('template').fmt(protocol, hosts[0], port));
  126. }
  127. }
  128. return item;
  129. });
  130. this.set('quickLinks', quickLinks);
  131. this.set('isLoaded', true);
  132. } else {
  133. // multiple hbase masters or HDFS HA enabled
  134. var quickLinksArray = [];
  135. hosts.forEach(function(host) {
  136. var quickLinks = [];
  137. self.get('content.quickLinks').forEach(function (item) {
  138. var newItem = {};
  139. var protocol = self.setProtocol(item.get('service_id'), self.get('configProperties'), self.ambariProperties());
  140. if (item.get('template')) {
  141. var port = item.get('http_config') && self.setPort(item, protocol);
  142. if (item.get('service_id')==='OOZIE') {
  143. newItem.url = item.get('template').fmt(protocol, host.publicHostName, port, App.router.get('loginName'));
  144. } else {
  145. newItem.url = item.get('template').fmt(protocol, host.publicHostName, port);
  146. }
  147. newItem.label = item.get('label');
  148. }
  149. quickLinks.push(newItem);
  150. });
  151. if (host.status) {
  152. quickLinks.set('publicHostNameLabel', Em.I18n.t('quick.links.publicHostName').format(host.publicHostName, host.status));
  153. } else {
  154. quickLinks.set('publicHostNameLabel', host.publicHostName);
  155. }
  156. quickLinksArray.push(quickLinks);
  157. }, this);
  158. this.set('quickLinksArray', quickLinksArray);
  159. this.set('isLoaded', true);
  160. }
  161. },
  162. /**
  163. * sets public host names for required masters of current service
  164. * @param {String} serviceName - selected serviceName
  165. * @param {JSON} response
  166. * @returns {Array} containing hostName(s)
  167. * @method setHost
  168. */
  169. setHost: function(response, serviceName) {
  170. if (App.get('singleNodeInstall')) {
  171. return [App.get('singleNodeAlias')];
  172. }
  173. var hosts = [];
  174. switch (serviceName) {
  175. case 'OOZIE':
  176. // active OOZIE components
  177. var components = this.get('content.hostComponents').filterProperty('componentName','OOZIE_SERVER').filterProperty('workStatus', 'STARTED');
  178. if (components && components.length > 1) {
  179. components.forEach(function (component) {
  180. hosts.push({
  181. 'publicHostName': response.items.findProperty('Hosts.host_name', component.get('hostName')).Hosts.public_host_name,
  182. 'status': Em.I18n.t('quick.links.label.active')
  183. });
  184. });
  185. } else if (components && components.length === 1) {
  186. hosts[0] = this.findComponentHost(response.items, 'OOZIE_SERVER');
  187. }
  188. break;
  189. case "HDFS":
  190. if (this.get('content.snameNode')) {
  191. // not HA
  192. hosts[0] = this.findComponentHost(response.items, 'NAMENODE');
  193. } else {
  194. // HA enabled, need both two namenodes hosts
  195. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').forEach(function (component) {
  196. hosts.push({'publicHostName': response.items.findProperty('Hosts.host_name', component.get('hostName')).Hosts.public_host_name});
  197. });
  198. // assign each namenode status label
  199. if (this.get('content.activeNameNode')) {
  200. hosts.findProperty('publicHostName', this.getPublicHostName(response.items, this.get('content.activeNameNode.hostName'))).status = Em.I18n.t('quick.links.label.active');
  201. }
  202. if (this.get('content.standbyNameNode')) {
  203. hosts.findProperty('publicHostName', this.getPublicHostName(response.items, this.get('content.standbyNameNode.hostName'))).status = Em.I18n.t('quick.links.label.standby');
  204. }
  205. if (this.get('content.standbyNameNode2')) {
  206. hosts.findProperty('publicHostName', this.getPublicHostName(response.items, this.get('content.standbyNameNode2.hostName'))).status = Em.I18n.t('quick.links.label.standby');
  207. }
  208. }
  209. break;
  210. case "HBASE":
  211. var masterComponents = response.items.filter(function (item) {
  212. return item.host_components.someProperty('HostRoles.component_name', 'HBASE_MASTER');
  213. });
  214. var activeMaster, standbyMasters, otherMasters;
  215. activeMaster = masterComponents.filter(function (item) {
  216. return item.host_components.someProperty('metrics.hbase.master.IsActiveMaster', 'true');
  217. });
  218. standbyMasters = masterComponents.filter(function (item) {
  219. return item.host_components.someProperty('metrics.hbase.master.IsActiveMaster', 'false');
  220. });
  221. otherMasters = masterComponents.filter(function (item) {
  222. return !(item.host_components.someProperty('metrics.hbase.master.IsActiveMaster', 'true') || item.host_components.someProperty('metrics.hbase.master.IsActiveMaster', 'false'));
  223. });
  224. if (masterComponents.length > 1) {
  225. // need all hbase_masters hosts in quick links
  226. if (activeMaster) {
  227. activeMaster.forEach(function (item) {
  228. hosts.push({'publicHostName': item.Hosts.public_host_name, 'status': Em.I18n.t('quick.links.label.active')});
  229. });
  230. }
  231. if (standbyMasters) {
  232. standbyMasters.forEach(function (item) {
  233. hosts.push({'publicHostName': item.Hosts.public_host_name, 'status': Em.I18n.t('quick.links.label.standby')});
  234. });
  235. }
  236. if (otherMasters) {
  237. otherMasters.forEach(function (item) {
  238. hosts.push({'publicHostName': item.Hosts.public_host_name});
  239. });
  240. }
  241. } else {
  242. hosts[0] = masterComponents[0].Hosts.public_host_name;
  243. }
  244. break;
  245. case "YARN":
  246. if (App.get('isRMHaEnabled')) {
  247. this.get('content.hostComponents').filterProperty('componentName', 'RESOURCEMANAGER').forEach(function (component) {
  248. var newHost = {'publicHostName': response.items.findProperty('Hosts.host_name', component.get('hostName')).Hosts.public_host_name};
  249. var status = '';
  250. switch (component.get('haStatus')) {
  251. case 'ACTIVE':
  252. status = Em.I18n.t('quick.links.label.active');
  253. break;
  254. case 'STANDBY':
  255. status = Em.I18n.t('quick.links.label.standby');
  256. break;
  257. }
  258. if (status) {
  259. newHost.status = status;
  260. }
  261. hosts.push(newHost);
  262. }, this);
  263. } else {
  264. hosts[0] = this.findComponentHost(response.items, 'RESOURCEMANAGER');
  265. }
  266. break;
  267. case "STORM":
  268. hosts[0] = this.findComponentHost(response.items, "STORM_UI_SERVER");
  269. break;
  270. case "ACCUMULO":
  271. hosts[0] = this.findComponentHost(response.items, "ACCUMULO_MONITOR");
  272. break;
  273. case "ATLAS":
  274. hosts[0] = this.findComponentHost(response.items, "ATLAS_SERVER");
  275. break;
  276. default:
  277. var service = App.StackService.find().findProperty('serviceName', serviceName);
  278. if (service && service.get('hasMaster')) {
  279. hosts[0] = this.findComponentHost(response.items, this.get('content.hostComponents') && this.get('content.hostComponents').findProperty('isMaster', true).get('componentName'));
  280. }
  281. break;
  282. }
  283. return hosts;
  284. },
  285. /**
  286. * services that supports security. this array is used to find out protocol.
  287. * becides GANGLIA, YARN, MAPREDUCE2, ACCUMULO. These services use
  288. * their properties to know protocol
  289. */
  290. servicesSupportsHttps: ["HDFS", "HBASE"],
  291. /**
  292. * setProtocol - if cluster is secure for some services (GANGLIA, MAPREDUCE2, YARN and servicesSupportsHttps)
  293. * protocol becomes "https" otherwise "http" (by default)
  294. * @param {String} service_id - service name
  295. * @param {Object} configProperties
  296. * @param {Object} ambariProperties
  297. * @returns {string} "https" or "http" only!
  298. * @method setProtocol
  299. */
  300. setProtocol: function (service_id, configProperties, ambariProperties) {
  301. var hadoopSslEnabled = false;
  302. if (configProperties && configProperties.length > 0) {
  303. var hdfsSite = configProperties.findProperty('type', 'hdfs-site');
  304. hadoopSslEnabled = (hdfsSite && Em.get(hdfsSite, 'properties') && hdfsSite.properties['dfs.http.policy'] === 'HTTPS_ONLY');
  305. }
  306. switch (service_id) {
  307. case "GANGLIA":
  308. return (ambariProperties && ambariProperties['ganglia.https'] == "true") ? "https" : "http";
  309. break;
  310. case "YARN":
  311. var yarnProperties = configProperties && configProperties.findProperty('type', 'yarn-site');
  312. if (yarnProperties && yarnProperties.properties) {
  313. if (yarnProperties.properties['yarn.http.policy'] === 'HTTPS_ONLY') {
  314. return "https";
  315. } else if (yarnProperties.properties['yarn.http.policy'] === 'HTTP_ONLY') {
  316. return "http";
  317. }
  318. }
  319. return hadoopSslEnabled ? "https" : "http";
  320. break;
  321. case "MAPREDUCE2":
  322. var mapred2Properties = configProperties && configProperties.findProperty('type', 'mapred-site');
  323. if (mapred2Properties && mapred2Properties.properties) {
  324. if (mapred2Properties.properties['mapreduce.jobhistory.http.policy'] === 'HTTPS_ONLY') {
  325. return "https";
  326. } else if (mapred2Properties.properties['mapreduce.jobhistory.http.policy'] === 'HTTP_ONLY') {
  327. return "http";
  328. }
  329. }
  330. return hadoopSslEnabled ? "https" : "http";
  331. break;
  332. case "ACCUMULO":
  333. var accumuloProperties = configProperties && configProperties.findProperty('type', 'accumulo-site');
  334. if (accumuloProperties && accumuloProperties.properties) {
  335. if (accumuloProperties.properties['monitor.ssl.keyStore'] && accumuloProperties.properties['monitor.ssl.trustStore']) {
  336. return "https";
  337. } else {
  338. return "http";
  339. }
  340. }
  341. return "http";
  342. break;
  343. case "ATLAS":
  344. var atlasProperties = configProperties && configProperties.findProperty('type', 'application-properties');
  345. if (atlasProperties && atlasProperties.properties) {
  346. if (atlasProperties.properties['metadata.enableTLS'] == "true") {
  347. return "https";
  348. } else {
  349. return "http";
  350. }
  351. }
  352. return "http";
  353. break;
  354. case "RANGER":
  355. var rangerProperties = configProperties && configProperties.findProperty('type', 'ranger-admin-site');
  356. if (rangerProperties && rangerProperties.properties && rangerProperties.properties['ranger.service.https.attrib.ssl.enabled'] == "true") {
  357. return "https";
  358. } else {
  359. return "http";
  360. }
  361. break;
  362. default:
  363. return this.get('servicesSupportsHttps').contains(service_id) && hadoopSslEnabled ? "https" : "http";
  364. }
  365. },
  366. /**
  367. * sets the port of quick link
  368. * @param item
  369. * @param protocol
  370. * @returns {*}
  371. * @method setPort
  372. */
  373. setPort: function (item, protocol) {
  374. var configProperties = this.get('configProperties');
  375. var config = item.get('http_config');
  376. var defaultPort = item.get('default_http_port');
  377. if (protocol === 'https' && item.get('https_config')) {
  378. config = item.get('https_config');
  379. if (item.get('default_https_port')) {
  380. defaultPort = item.get('default_https_port');
  381. }
  382. }
  383. var site = configProperties.findProperty('type', item.get('site'));
  384. var propertyValue = site && site.properties[config];
  385. if (!propertyValue) {
  386. return defaultPort;
  387. }
  388. var re = new RegExp(item.get('regex'));
  389. var portValue = propertyValue.match(re);
  390. return portValue[1];
  391. },
  392. linkTarget: function () {
  393. switch (this.get('content.serviceName').toLowerCase()) {
  394. case "hdfs":
  395. case "yarn":
  396. case "mapreduce2":
  397. case "hbase":
  398. case "oozie":
  399. case "ganglia":
  400. case "storm":
  401. case "spark":
  402. case "falcon":
  403. case "accumulo":
  404. case "atlas":
  405. return "_blank";
  406. break;
  407. default:
  408. return "";
  409. break;
  410. }
  411. }.property('service')
  412. });