summary.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. App.AlertItemView = Em.View.extend({
  19. tagName:"li",
  20. templateName: require('templates/main/service/info/summary_alert'),
  21. classNameBindings: ["status"],
  22. status: function () {
  23. return "status-" + this.get("content.status");
  24. }.property('content'),
  25. didInsertElement: function () {
  26. // Tooltips for alerts need to be enabled.
  27. $("div[rel=tooltip]").tooltip();
  28. $(".tooltip").remove();
  29. }
  30. })
  31. App.MainServiceInfoSummaryView = Em.View.extend({
  32. templateName: require('templates/main/service/info/summary'),
  33. attributes:null,
  34. serviceStatus:{
  35. hdfs:false,
  36. mapreduce:false,
  37. hbase:false,
  38. zookeeper:false,
  39. oozie:false,
  40. hive:false,
  41. ganglia:false,
  42. nagios:false
  43. },
  44. clients: function () {
  45. var result = [];
  46. var service = this.get('controller.content');
  47. if (service.get("id") == "OOZIE" || service.get("id") == "ZOOKEEPER") {
  48. return service.get('hostComponents').filterProperty('isClient');
  49. }
  50. return [];
  51. }.property('controller.content'),
  52. hasManyServers: function () {
  53. if (this.get('servers').length > 1) {
  54. return true;
  55. }
  56. return false;
  57. }.property('servers'),
  58. hasManyClients: function () {
  59. if (this.get('clients').length > 1) {
  60. return true;
  61. }
  62. return false;
  63. }.property('clients'),
  64. servers: function () {
  65. var result = [];
  66. var service = this.get('controller.content');
  67. if (service.get("id") == "ZOOKEEPER") {
  68. var servers = service.get('hostComponents').filterProperty('isMaster');
  69. if (servers.length > 0) {
  70. result = [{
  71. 'host': servers[0].get('displayName'),
  72. 'isComma': false,
  73. 'isAnd': false
  74. }];
  75. }
  76. if (servers.length > 1) {
  77. result[0].isComma = true;
  78. result.push({
  79. 'host': servers[1].get('displayName'),
  80. 'isComma': false,
  81. 'isAnd': false
  82. });
  83. }
  84. if (servers.length > 2) {
  85. result[1].isAnd = true;
  86. result.push({
  87. 'host': Em.I18n.t('services.service.info.summary.serversHostCount').format(servers.length - 2),
  88. 'isComma': false,
  89. 'isAnd': false
  90. });
  91. }
  92. }
  93. return result;
  94. }.property('controller.content'),
  95. monitors: function () {
  96. var result = '';
  97. var service = this.get('controller.content');
  98. if (service.get("id") == "GANGLIA") {
  99. var monitors = service.get('hostComponents').filterProperty('isMaster', false);
  100. if (monitors.length) {
  101. result = monitors.length - 1 ? Em.I18n.t('services.service.info.summary.hostsRunningMonitor').format(monitors.length) : Em.I18n.t('services.service.info.summary.hostRunningMonitor');
  102. }
  103. }
  104. return result;
  105. }.property('controller.content'),
  106. /**
  107. * Property related to GANGLIA service, is unused for other services
  108. * @return {Object}
  109. */
  110. monitorsObj: function(){
  111. var service = this.get('controller.content');
  112. if (service.get("id") == "GANGLIA") {
  113. var monitors = service.get('hostComponents').filterProperty('isMaster', false);
  114. if (monitors.length) {
  115. return monitors[0];
  116. }
  117. }
  118. return {};
  119. }.property('controller.content'),
  120. /**
  121. * Property related to ZOOKEEPER service, is unused for other services
  122. * @return {Object}
  123. */
  124. serversHost: function() {
  125. var service = this.get('controller.content');
  126. if (service.get("id") == "ZOOKEEPER") {
  127. var servers = service.get('hostComponents').filterProperty('isMaster');
  128. if (servers.length > 0) {
  129. return servers[0];
  130. }
  131. }
  132. return {};
  133. }.property('controller.content'),
  134. /**
  135. * Property related to OOZIE and ZOOKEEPER services, is unused for other services
  136. * @return {Object}
  137. */
  138. clientObj: function() {
  139. var service = this.get('controller.content');
  140. if (service.get("id") == "OOZIE" || service.get("id") == "ZOOKEEPER") {
  141. var clients = service.get('hostComponents').filterProperty('isMaster', false);
  142. if (clients.length > 0) {
  143. return clients[0];
  144. }
  145. }
  146. return {};
  147. }.property('controller.content'),
  148. data:{
  149. hive:{
  150. "database":"PostgreSQL",
  151. "databaseName":"hive",
  152. "user":"hive"
  153. }
  154. },
  155. gangliaServer:function(){
  156. var service=this.get('controller.content');
  157. if(service.get("id") == "GANGLIA"){
  158. return service.get("hostComponents").findProperty('isMaster', true).get("host").get("publicHostName");
  159. }else{
  160. return "";
  161. }
  162. }.property('controller.content'),
  163. nagiosServer:function(){
  164. var service=this.get('controller.content');
  165. if(service.get("id") == "NAGIOS"){
  166. return service.get("hostComponents").findProperty('isMaster', true).get("host").get("publicHostName");
  167. }else{
  168. return "";
  169. }
  170. }.property('controller.content'),
  171. oozieServer:function(){
  172. var service=this.get('controller.content');
  173. if(service.get("id") == "OOZIE"){
  174. return service.get("hostComponents").findProperty('isMaster', true).get("host").get("publicHostName");
  175. }else{
  176. return "";
  177. }
  178. }.property('controller.content'),
  179. /**
  180. * Returns hive components information in
  181. * the following format:
  182. * {
  183. * label: "Component Name",
  184. * host: Host,
  185. *
  186. */
  187. hiveComponentsInfo: function(){
  188. var componentInfos = [];
  189. var service=this.get('controller.content');
  190. if(service.get("id") == "HIVE"){
  191. var self = this;
  192. var components = service.get("hostComponents");
  193. if(components){
  194. components.forEach(function(component){
  195. var ci = {
  196. label: component.get('displayName'),
  197. host: component.get('host')
  198. };
  199. if(component.get('id')=='MYSQL_SERVER'){
  200. ci.label = self.t('services.hive.databaseComponent');
  201. }
  202. componentInfos.push(ci);
  203. });
  204. }
  205. }
  206. return componentInfos;
  207. }.property('controller.content'),
  208. service:function () {
  209. var svc = this.get('controller.content');
  210. var svcName = svc.get('serviceName');
  211. if (svcName) {
  212. switch (svcName.toLowerCase()) {
  213. case 'hdfs':
  214. svc = App.HDFSService.find().objectAt(0);
  215. break;
  216. case 'mapreduce':
  217. svc = App.MapReduceService.find().objectAt(0);
  218. break;
  219. case 'hbase':
  220. svc = App.HBaseService.find().objectAt(0);
  221. break;
  222. default:
  223. break;
  224. }
  225. }
  226. return svc;
  227. }.property('controller.content.serviceName').volatile(),
  228. isHide:true,
  229. moreStatsView:Em.View.extend({
  230. tagName:"a",
  231. template:Ember.Handlebars.compile('{{t services.service.summary.moreStats}}'),
  232. attributeBindings:[ 'href' ],
  233. classNames:[ 'more-stats' ],
  234. click:function (event) {
  235. this._parentView._parentView.set('isHide', false);
  236. this.remove();
  237. },
  238. href:'javascript:void(null)'
  239. }),
  240. serviceName:function () {
  241. return this.get('service.serviceName');
  242. }.property('service'),
  243. oldServiceName:'',
  244. /**
  245. * Contains graphs for this particular service
  246. */
  247. serviceMetricGraphs:function () {
  248. var svcName = this.get('service.serviceName');
  249. var graphs = [];
  250. if (svcName) {
  251. switch (svcName.toLowerCase()) {
  252. case 'hdfs':
  253. graphs = [ [App.ChartServiceMetricsHDFS_SpaceUtilization.extend(),
  254. App.ChartServiceMetricsHDFS_FileOperations.extend(),
  255. App.ChartServiceMetricsHDFS_BlockStatus.extend(),
  256. App.ChartServiceMetricsHDFS_IO.extend()],
  257. [App.ChartServiceMetricsHDFS_RPC.extend(),
  258. App.ChartServiceMetricsHDFS_GC.extend(),
  259. App.ChartServiceMetricsHDFS_JVMHeap.extend(),
  260. App.ChartServiceMetricsHDFS_JVMThreads.extend()]];
  261. break;
  262. case 'mapreduce':
  263. graphs = [ [App.ChartServiceMetricsMapReduce_JobsStatus.extend(),
  264. App.ChartServiceMetricsMapReduce_TasksRunningWaiting.extend(),
  265. App.ChartServiceMetricsMapReduce_MapSlots.extend(),
  266. App.ChartServiceMetricsMapReduce_ReduceSlots.extend()],
  267. [App.ChartServiceMetricsMapReduce_GC.extend(),
  268. App.ChartServiceMetricsMapReduce_RPC.extend(),
  269. App.ChartServiceMetricsMapReduce_JVMHeap.extend(),
  270. App.ChartServiceMetricsMapReduce_JVMThreads.extend()]];
  271. break;
  272. case 'hbase':
  273. graphs = [ [App.ChartServiceMetricsHBASE_ClusterRequests.extend(),
  274. App.ChartServiceMetricsHBASE_RegionServerReadWriteRequests.extend(),
  275. App.ChartServiceMetricsHBASE_RegionServerRegions.extend(),
  276. App.ChartServiceMetricsHBASE_RegionServerQueueSize.extend()],
  277. [App.ChartServiceMetricsHBASE_HlogSplitTime.extend(),
  278. App.ChartServiceMetricsHBASE_HlogSplitSize.extend()]];
  279. break;
  280. default:
  281. break;
  282. }
  283. }
  284. return graphs;
  285. }.property(''),
  286. loadServiceSummary:function (serviceName) {
  287. var serviceName = this.get('serviceName');
  288. if (!serviceName) {
  289. return;
  290. }
  291. if (this.get('oldServiceName')) {
  292. // do not delete it!
  293. return;
  294. }
  295. var summaryView = this;
  296. var serviceStatus = summaryView.get('serviceStatus');
  297. $.each(serviceStatus, function (key, value) {
  298. if (key.toUpperCase() == serviceName) {
  299. summaryView.set('serviceStatus.' + key, true);
  300. } else {
  301. summaryView.set('serviceStatus.' + key, false);
  302. }
  303. });
  304. console.log('load ', serviceName, ' info');
  305. this.set('oldServiceName', serviceName);
  306. serviceName = serviceName.toLowerCase();
  307. }.observes('serviceName'),
  308. gangliaUrl:function () {
  309. var gangliaUrl = App.router.get('clusterController.gangliaUrl');
  310. var svcName = this.get('service.serviceName');
  311. if (svcName) {
  312. switch (svcName.toLowerCase()) {
  313. case 'hdfs':
  314. gangliaUrl += "/?r=hour&cs=&ce=&m=&s=by+name&c=HDPNameNode&tab=m&vn=";
  315. break;
  316. case 'mapreduce':
  317. gangliaUrl += "/?r=hour&cs=&ce=&m=&s=by+name&c=HDPJobTracker&tab=m&vn=";
  318. break;
  319. case 'hbase':
  320. gangliaUrl += "?r=hour&cs=&ce=&m=&s=by+name&c=HDPHBaseMaster&tab=m&vn=";
  321. break;
  322. default:
  323. break;
  324. }
  325. }
  326. return gangliaUrl;
  327. }.property('App.router.clusterController.gangliaUrl', 'service.serviceName'),
  328. didInsertElement:function () {
  329. // We have to make the height of the Alerts section
  330. // match the height of the Summary section.
  331. var summaryTable = document.getElementById('summary-info');
  332. var alertsList = document.getElementById('summary-alerts-list');
  333. if (summaryTable && alertsList) {
  334. var rows = $(summaryTable).find('tr');
  335. if (rows != null && rows.length > 0) {
  336. var minimumHeight = 50;
  337. var calculatedHeight = summaryTable.clientHeight;
  338. if (calculatedHeight < minimumHeight) {
  339. $(alertsList).attr('style', "height:" + minimumHeight + "px;");
  340. $(summaryTable).append('<tr><td></td></tr>');
  341. $(summaryTable).attr('style', "height:" + minimumHeight + "px;");
  342. } else {
  343. $(alertsList).attr('style', "height:" + calculatedHeight + "px;");
  344. }
  345. } else if (alertsList.clientHeight > 0) {
  346. $(summaryTable).append('<tr><td></td></tr>');
  347. $(summaryTable).attr('style', "height:" + alertsList.clientHeight + "px;");
  348. }
  349. }
  350. },
  351. clientHosts:App.Host.find(),
  352. clientHostsLength:function () {
  353. var text = this.t('services.service.summary.clientCount');
  354. var self = this;
  355. return text.format(self.get('clientHosts.length'));
  356. }.property('clientHosts'),
  357. clientComponents:function () {
  358. return App.HostComponent.find().filterProperty('isClient', true);
  359. }.property(),
  360. clientComponentsString:function () {
  361. var components = this.get('clientComponents');
  362. var names = [];
  363. components.forEach(function (component) {
  364. if (names.indexOf(component.get('displayName')) == -1) {
  365. names.push(component.get('displayName'));
  366. }
  367. });
  368. return names.length ? names.join(', ') : false;
  369. }.property('clientComponents')
  370. });