service_mapper.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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.servicesMapper = App.QuickDataMapper.create({
  19. servicesSortOrder: [
  20. 'HDFS',
  21. 'YARN',
  22. 'MAPREDUCE',
  23. 'MAPREDUCE2',
  24. 'TEZ',
  25. 'HBASE',
  26. 'HIVE',
  27. 'HCATALOG',
  28. 'WEBHCAT',
  29. 'FLUME',
  30. 'OOZIE',
  31. 'GANGLIA',
  32. 'NAGIOS',
  33. 'ZOOKEEPER',
  34. 'PIG',
  35. 'SQOOP',
  36. 'HUE'
  37. ],
  38. sortByOrder: function (sortOrder, array) {
  39. var sorted = [];
  40. for (var i = 0; i < sortOrder.length; i++)
  41. for (var j = 0; j < array.length; j++) {
  42. if (sortOrder[i] == array[j].id) {
  43. sorted.push(array[j]);
  44. }
  45. }
  46. return sorted;
  47. },
  48. model: App.Service,
  49. config: {
  50. id: 'ServiceInfo.service_name',
  51. service_name: 'ServiceInfo.service_name',
  52. work_status: 'ServiceInfo.state',
  53. $rand: Math.random(),
  54. $alerts: [ 1, 2, 3 ],
  55. host_components: 'host_components'
  56. },
  57. hdfsConfig: {
  58. version: 'nameNodeComponent.host_components[0].metrics.dfs.namenode.Version',
  59. name_node_id: 'nameNodeComponent.host_components[0].HostRoles.host_name',
  60. sname_node_id: 'snameNodeComponent.host_components[0].HostRoles.host_name',
  61. active_name_node_id: 'active_name_node_id',
  62. standby_name_node_id: 'standby_name_node_id',
  63. standby_name_node2_id: 'standby_name_node2_id',
  64. data_nodes: 'data_nodes',
  65. journal_nodes: 'journal_nodes',
  66. name_node_start_time: 'nameNodeComponent.host_components[0].metrics.runtime.StartTime',
  67. jvm_memory_heap_used: 'nameNodeComponent.host_components[0].metrics.jvm.memHeapUsedM',
  68. jvm_memory_heap_committed: 'nameNodeComponent.host_components[0].metrics.jvm.memHeapCommittedM',
  69. live_data_nodes: 'live_data_nodes',
  70. dead_data_nodes: 'dead_data_nodes',
  71. decommission_data_nodes: 'decommission_data_nodes',
  72. capacity_used: 'nameNodeComponent.host_components[0].metrics.dfs.FSNamesystem.CapacityUsed',
  73. capacity_total: 'nameNodeComponent.host_components[0].metrics.dfs.FSNamesystem.CapacityTotal',
  74. capacity_remaining: 'nameNodeComponent.host_components[0].metrics.dfs.FSNamesystem.CapacityRemaining',
  75. dfs_total_blocks: 'nameNodeComponent.host_components[0].metrics.dfs.FSNamesystem.BlocksTotal',
  76. dfs_corrupt_blocks: 'nameNodeComponent.host_components[0].metrics.dfs.FSNamesystem.CorruptBlocks',
  77. dfs_missing_blocks: 'nameNodeComponent.host_components[0].metrics.dfs.FSNamesystem.MissingBlocks',
  78. dfs_under_replicated_blocks: 'nameNodeComponent.host_components[0].metrics.dfs.FSNamesystem.UnderReplicatedBlocks',
  79. dfs_total_files: 'nameNodeComponent.host_components[0].metrics.dfs.namenode.TotalFiles',
  80. upgrade_status: 'nameNodeComponent.host_components[0].metrics.dfs.namenode.UpgradeFinalized',
  81. safe_mode_status: 'nameNodeComponent.host_components[0].metrics.dfs.namenode.Safemode',
  82. name_node_cpu: 'nameNodeComponent.host_components[0].metrics.cpu.cpu_wio',
  83. name_node_rpc: 'nameNodeComponent.host_components[0].metrics.rpc.RpcQueueTime_avg_time'
  84. },
  85. yarnConfig: {
  86. version: 'resourceManagerComponent.ServiceComponentInfo.Version',
  87. resource_manager_node_id: 'resourceManagerComponent.host_components[0].HostRoles.host_name',
  88. node_manager_nodes: 'node_manager_nodes',
  89. node_manager_live_nodes: 'node_manager_live_nodes',
  90. yarn_client_nodes: 'yarn_client_nodes',
  91. resource_manager_start_time: 'resourceManagerComponent.ServiceComponentInfo.StartTime',
  92. jvm_memory_heap_used: 'resourceManagerComponent.host_components[0].metrics.jvm.memHeapUsedM',
  93. jvm_memory_heap_committed: 'resourceManagerComponent.host_components[0].metrics.jvm.memHeapCommittedM',
  94. containers_allocated: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AllocatedContainers',
  95. containers_pending: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.PendingContainers',
  96. containers_reserved: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.ReservedContainers',
  97. apps_submitted: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AppsSubmitted',
  98. apps_running: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AppsRunning',
  99. apps_pending: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AppsPending',
  100. apps_completed: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AppsCompleted',
  101. apps_killed: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AppsKilled',
  102. apps_failed: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AppsFailed',
  103. node_managers_count_active: 'resourceManagerComponent.ServiceComponentInfo.rm_metrics.cluster.activeNMcount',
  104. //node_managers_count_lost: 'resourceManagerComponent.ServiceComponentInfo.rm_metrics.cluster.lostNMcount',
  105. node_managers_count_unhealthy: 'resourceManagerComponent.ServiceComponentInfo.rm_metrics.cluster.unhealthyNMcount',
  106. node_managers_count_rebooted: 'resourceManagerComponent.ServiceComponentInfo.rm_metrics.cluster.rebootedNMcount',
  107. node_managers_count_decommissioned: 'resourceManagerComponent.ServiceComponentInfo.rm_metrics.cluster.decommissionedNMcount',
  108. allocated_memory: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AllocatedMB',
  109. available_memory: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.AvailableMB',
  110. reserved_memory: 'resourceManagerComponent.host_components[0].metrics.yarn.Queue.root.ReservedMB',
  111. queue: 'resourceManagerComponent.queue'
  112. },
  113. mapReduce2Config: {
  114. version: 'jobHistoryServerComponent.ServiceComponentInfo.Version',
  115. job_history_server_id: 'jobHistoryServerComponent.host_components[0].HostRoles.host_name',
  116. map_reduce2_clients: 'map_reduce2_clients'
  117. },
  118. mapReduceConfig: {
  119. version: 'jobTrackerComponent.ServiceComponentInfo.Version',
  120. job_tracker_id: 'jobTrackerComponent.host_components[0].HostRoles.host_name',
  121. task_trackers: 'task_trackers',
  122. job_tracker_start_time: 'jobTrackerComponent.ServiceComponentInfo.StartTime',
  123. job_tracker_heap_used: 'jobTrackerComponent.ServiceComponentInfo.HeapMemoryUsed',
  124. job_tracker_heap_max: 'jobTrackerComponent.ServiceComponentInfo.HeapMemoryMax',
  125. alive_trackers: 'alive_trackers',
  126. black_list_trackers: 'black_list_trackers',
  127. gray_list_trackers: 'gray_list_trackers',
  128. map_slots: 'map_slots',
  129. reduce_slots: 'reduce_slots',
  130. jobs_submitted: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.jobs_submitted',
  131. jobs_completed: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.jobs_completed',
  132. jobs_running: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.jobs_running',
  133. map_slots_occupied: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.occupied_map_slots',
  134. map_slots_reserved: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.reserved_map_slots',
  135. reduce_slots_occupied: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.occupied_reduce_slots',
  136. reduce_slots_reserved: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.reserved_reduce_slots',
  137. maps_running: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.running_maps',
  138. maps_waiting: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.waiting_maps',
  139. reduces_running: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.running_reduces',
  140. reduces_waiting: 'jobTrackerComponent.ServiceComponentInfo.jobtracker.waiting_reduces',
  141. trackers_decommissioned: 'jobTrackerComponent.host_components[0].metrics.mapred.jobtracker.trackers_decommissioned',
  142. job_tracker_cpu: 'jobTrackerComponent.host_components[0].metrics.cpu.cpu_wio',
  143. job_tracker_rpc: 'jobTrackerComponent.host_components[0].metrics.rpc.RpcQueueTime_avg_time'
  144. },
  145. hbaseConfig: {
  146. version: 'masterComponent.ServiceComponentInfo.Version',
  147. master_id: 'masterComponent.host_components[0].HostRoles.host_name',
  148. region_servers: 'region_servers',
  149. master_start_time: 'masterComponent.ServiceComponentInfo.MasterStartTime',
  150. master_active_time: 'masterComponent.ServiceComponentInfo.MasterActiveTime',
  151. average_load: 'masterComponent.ServiceComponentInfo.AverageLoad',
  152. regions_in_transition: 'regions_in_transition',
  153. revision: 'masterComponent.ServiceComponentInfo.Revision',
  154. heap_memory_used: 'masterComponent.ServiceComponentInfo.HeapMemoryUsed',
  155. heap_memory_max: 'masterComponent.ServiceComponentInfo.HeapMemoryMax'
  156. },
  157. model3: App.HostComponent,
  158. config3: {
  159. id: 'id',
  160. work_status: 'HostRoles.state',
  161. desired_status: 'HostRoles.desired_state',
  162. component_name: 'HostRoles.component_name',
  163. host_id: 'HostRoles.host_name',
  164. stale_configs: 'HostRoles.stale_configs',
  165. $service_id: 'none' /* will be set outside of parse function */
  166. },
  167. map: function (json) {
  168. if (!this.get('model')) {
  169. return;
  170. }
  171. var start = new Date().getTime();
  172. console.log('in service mapper');
  173. if (json.items) {
  174. var result = [];
  175. json.items.forEach(function (item) {
  176. var finalConfig = jQuery.extend({}, this.config);
  177. var finalJson = [];
  178. item.host_components = [];
  179. item.components.forEach(function (component) {
  180. component.host_components.forEach(function (host_component) {
  181. host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
  182. item.host_components.push(host_component.id);
  183. }, this);
  184. }, this);
  185. item.host_components.sort();
  186. if (item && item.ServiceInfo && item.ServiceInfo.service_name == "HDFS") {
  187. finalJson = this.hdfsMapper(item);
  188. finalJson.rand = Math.random();
  189. result.push(finalJson);
  190. App.store.load(App.HDFSService, finalJson);
  191. }else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "MAPREDUCE") {
  192. finalJson = this.mapreduceMapper(item);
  193. finalJson.rand = Math.random();
  194. result.push(finalJson);
  195. App.store.load(App.MapReduceService, finalJson);
  196. }else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "HBASE") {
  197. finalJson = this.hbaseMapper(item);
  198. finalJson.rand = Math.random();
  199. result.push(finalJson);
  200. App.store.load(App.HBaseService, finalJson);
  201. }else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "FLUME") {
  202. finalJson = this.flumeMapper(item);
  203. finalJson.rand = Math.random();
  204. result.push(finalJson);
  205. if(finalJson.nodeObjs){
  206. finalJson.nodeObjs.forEach(function(no){
  207. App.store.load(App.FlumeNode, no);
  208. });
  209. }
  210. App.store.load(App.FlumeService, finalJson);
  211. }else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "YARN") {
  212. finalJson = this.yarnMapper(item);
  213. finalJson.rand = Math.random();
  214. result.push(finalJson);
  215. App.store.load(App.YARNService, finalJson);
  216. }else if (item && item.ServiceInfo && item.ServiceInfo.service_name == "MAPREDUCE2") {
  217. finalJson = this.mapreduce2Mapper(item);
  218. finalJson.rand = Math.random();
  219. result.push(finalJson);
  220. App.store.load(App.MapReduce2Service, finalJson);
  221. }else {
  222. finalJson = this.parseIt(item, this.config);
  223. finalJson.rand = Math.random();
  224. this.mapQuickLinks(finalJson, item);
  225. result.push(finalJson);
  226. }
  227. }, this);
  228. result = this.sortByOrder(this.get('servicesSortOrder'), result);
  229. App.store.loadMany(this.get('model'), result);
  230. // Host components
  231. result = [];
  232. var hostComponentsMap = {};
  233. json.items.forEach(function(item){
  234. item.components.forEach(function(component){
  235. var service = component.ServiceComponentInfo.service_name;
  236. component.host_components.forEach(function(host_component){
  237. if(host_component.HostRoles.component_name == "HBASE_MASTER"){
  238. this.config3.ha_status = 'metrics.hbase.master.IsActiveMaster';
  239. }
  240. var comp = this.parseIt(host_component, this.config3);
  241. comp.service_id = service;
  242. this.calculateState(comp);
  243. result.push(comp);
  244. hostComponentsMap[comp.id] = comp;
  245. }, this)
  246. }, this)
  247. }, this);
  248. var oldHostComponents = App.HostComponent.find();
  249. var item;
  250. var currentHCWithComponentNames = {};
  251. var currentComponentNameHostNames = {};
  252. var doHostComponentsLoad = false;
  253. oldHostComponents.forEach(function (item) {
  254. if (item) {
  255. if (!hostComponentsMap[item.get('id')]) {
  256. item.deleteRecord();
  257. item.get('stateManager').transitionTo('loading');
  258. } else {
  259. var componentName = item.get('componentName');
  260. if (componentName) {
  261. currentHCWithComponentNames[item.get('id')] = item.get('id');
  262. }
  263. if (!currentComponentNameHostNames[componentName]) {
  264. currentComponentNameHostNames[componentName] = [];
  265. }
  266. currentComponentNameHostNames[componentName].pushObject(item.get('host.hostName'));
  267. }
  268. }
  269. }, this);
  270. for(var i in hostComponentsMap) {
  271. if(!currentHCWithComponentNames[i]) {
  272. doHostComponentsLoad = true;
  273. break;
  274. }
  275. }
  276. result.forEach(function (item) {
  277. if (currentHCWithComponentNames[item.id] != null &&
  278. !currentComponentNameHostNames[item.component_name].contains(item.host_id)) {
  279. item.id = (new Date).getTime();
  280. }
  281. });
  282. if (!App.router.get('clusterController.isLoaded') || doHostComponentsLoad) {
  283. App.store.loadMany(this.get('model3'), result);
  284. }
  285. }
  286. console.log('out service mapper. Took ' + (new Date().getTime() - start) + 'ms');
  287. },
  288. /**
  289. * Map quick links to services:OOZIE,GANGLIA,NAGIOS,HUE
  290. * @param finalJson
  291. * @param item
  292. */
  293. mapQuickLinks: function (finalJson, item){
  294. if(item && item.ServiceInfo && item.ServiceInfo.service_name == "OOZIE"){
  295. finalJson.quick_links = [19];
  296. }else if(item && item.ServiceInfo && item.ServiceInfo.service_name == "GANGLIA"){
  297. finalJson.quick_links = [20];
  298. }else if(item && item.ServiceInfo && item.ServiceInfo.service_name == "NAGIOS"){
  299. finalJson.quick_links = [21];
  300. }else if(item && item.ServiceInfo && item.ServiceInfo.service_name == "HUE"){
  301. finalJson.quick_links = [22];
  302. }
  303. },
  304. hdfsMapper: function (item) {
  305. var finalConfig = jQuery.extend({}, this.config);
  306. // Change the JSON so that it is easy to map
  307. var hdfsConfig = this.hdfsConfig;
  308. item.components.forEach(function (component) {
  309. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "NAMENODE") {
  310. //enabled HA
  311. if ( component.host_components.length == 2) {
  312. var haState1;
  313. var haState2;
  314. if (component.host_components[1].metrics && component.host_components[1].metrics.dfs) {
  315. haState2 = component.host_components[1].metrics.dfs.FSNamesystem.HAState;
  316. }
  317. if (component.host_components[0].metrics && component.host_components[0].metrics.dfs) {
  318. haState1 = component.host_components[0].metrics.dfs.FSNamesystem.HAState;
  319. }
  320. var active_name_node = [];
  321. var standby_name_nodes = [];
  322. switch (haState1) {
  323. case "active":
  324. active_name_node.push(component.host_components[0].HostRoles.host_name);
  325. break;
  326. case "standby":
  327. standby_name_nodes.push(component.host_components[0].HostRoles.host_name);
  328. break;
  329. }
  330. switch (haState2) {
  331. case "active":
  332. active_name_node.push(component.host_components[1].HostRoles.host_name);
  333. break;
  334. case "standby":
  335. standby_name_nodes.push(component.host_components[1].HostRoles.host_name);
  336. break;
  337. }
  338. item.active_name_node_id = null;
  339. item.standby_name_node_id = null;
  340. item.standby_name_node2_id = null;
  341. switch (active_name_node.length) {
  342. case 1:
  343. item.active_name_node_id = active_name_node[0];
  344. break;
  345. }
  346. switch (standby_name_nodes.length) {
  347. case 1:
  348. item.standby_name_node_id = standby_name_nodes[0];
  349. break;
  350. case 2:
  351. item.standby_name_node_id = standby_name_nodes[0];
  352. item.standby_name_node2_id = standby_name_nodes[1];
  353. break;
  354. }
  355. // important: active nameNode always at host_components[0]; if no active, then any nameNode could work.
  356. if (haState2 == "active") { // change places for all model bind with host_component[0]
  357. var tmp = component.host_components[1];
  358. component.host_components[1] = component.host_components[0];
  359. component.host_components[0] = tmp;
  360. }
  361. }
  362. item.nameNodeComponent = component;
  363. finalConfig = jQuery.extend(finalConfig, hdfsConfig);
  364. // Get the live, dead & decommission nodes from string json
  365. if (component.host_components[0].metrics && component.host_components[0].metrics.dfs && component.host_components[0].metrics.dfs.namenode) {
  366. var liveNodesJson = App.parseJSON(component.host_components[0].metrics.dfs.namenode.LiveNodes);
  367. var deadNodesJson = App.parseJSON(component.host_components[0].metrics.dfs.namenode.DeadNodes);
  368. var decommissionNodesJson = App.parseJSON(component.host_components[0].metrics.dfs.namenode.DecomNodes);
  369. }
  370. item.live_data_nodes = [];
  371. item.dead_data_nodes = [];
  372. item.decommission_data_nodes = [];
  373. for (var ln in liveNodesJson) {
  374. item.live_data_nodes.push(ln);
  375. }
  376. for (var dn in deadNodesJson) {
  377. item.dead_data_nodes.push(dn);
  378. }
  379. for (var dcn in decommissionNodesJson) {
  380. item.decommission_data_nodes.push(dcn);
  381. }
  382. }
  383. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "SECONDARY_NAMENODE") {
  384. item.snameNodeComponent = component;
  385. }
  386. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "JOURNALNODE") {
  387. if (!item.journal_nodes) {
  388. item.journal_nodes = [];
  389. }
  390. if (component.host_components) {
  391. component.host_components.forEach(function (hc) {
  392. item.journal_nodes.push(hc.HostRoles.host_name);
  393. });
  394. }
  395. }
  396. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "DATANODE") {
  397. if (!item.data_nodes) {
  398. item.data_nodes = [];
  399. }
  400. if (component.host_components) {
  401. component.host_components.forEach(function (hc) {
  402. item.data_nodes.push(hc.HostRoles.host_name);
  403. });
  404. }
  405. }
  406. });
  407. // Map
  408. var finalJson = this.parseIt(item, finalConfig);
  409. finalJson.quick_links = [1, 2, 3, 4];
  410. return finalJson;
  411. },
  412. yarnMapper: function (item) {
  413. var result = [];
  414. var self = this;
  415. var finalConfig = jQuery.extend({}, this.config);
  416. // Change the JSON so that it is easy to map
  417. var yarnConfig = this.yarnConfig;
  418. item.components.forEach(function (component) {
  419. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "RESOURCEMANAGER") {
  420. item.resourceManagerComponent = component;
  421. // live nodes calculation
  422. var nmList = [];
  423. if (component.ServiceComponentInfo.rm_metrics && component.ServiceComponentInfo.rm_metrics.cluster && component.ServiceComponentInfo.rm_metrics.cluster.nodeManagers) {
  424. nmList = App.parseJSON(component.ServiceComponentInfo.rm_metrics.cluster.nodeManagers);
  425. }
  426. nmList.forEach(function (nm) {
  427. if (nm.State === "RUNNING") {
  428. if (!item.node_manager_live_nodes) {
  429. item.node_manager_live_nodes = [];
  430. }
  431. item.node_manager_live_nodes.push(nm.HostName);
  432. }
  433. });
  434. if (component.host_components[0].metrics && component.host_components[0].metrics.yarn) {
  435. var root = component.host_components[0].metrics.yarn.Queue.root;
  436. var queue = JSON.stringify({
  437. 'root': self.parseObject(root)
  438. });
  439. component.queue = queue;
  440. }
  441. // extend config
  442. finalConfig = jQuery.extend(finalConfig, yarnConfig);
  443. }
  444. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "NODEMANAGER") {
  445. if (!item.node_manager_nodes) {
  446. item.node_manager_nodes = [];
  447. }
  448. if (component.host_components) {
  449. component.host_components.forEach(function (hc) {
  450. item.node_manager_nodes.push(hc.HostRoles.host_name);
  451. });
  452. }
  453. }
  454. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "YARN_CLIENT") {
  455. if (!item.yarn_client_nodes) {
  456. item.yarn_client_nodes = [];
  457. }
  458. if (component.host_components) {
  459. component.host_components.forEach(function (hc) {
  460. item.yarn_client_nodes.push(hc.HostRoles.host_name);
  461. });
  462. }
  463. }
  464. });
  465. // Map
  466. var finalJson = this.parseIt(item, finalConfig);
  467. finalJson.quick_links = [ 23, 24, 25, 26 ];
  468. return finalJson;
  469. },
  470. parseObject: function(obj) {
  471. var res = {};
  472. for (var p in obj) {
  473. if (obj.hasOwnProperty(p)) {
  474. if (obj[p] instanceof Object) {
  475. res[p] = this.parseObject(obj[p]);
  476. }
  477. }
  478. }
  479. return res;
  480. },
  481. mapreduce2Mapper: function (item) {
  482. var result = [];
  483. var finalConfig = jQuery.extend({}, this.config);
  484. // Change the JSON so that it is easy to map
  485. var mapReduce2Config = this.mapReduce2Config;
  486. item.components.forEach(function (component) {
  487. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "HISTORYSERVER") {
  488. item.jobHistoryServerComponent = component;
  489. finalConfig = jQuery.extend(finalConfig, mapReduce2Config);
  490. }
  491. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "MAPREDUCE2_CLIENT") {
  492. if (!item.map_reduce2_clients) {
  493. item.map_reduce2_clients = [];
  494. }
  495. if (component.host_components) {
  496. component.host_components.forEach(function (hc) {
  497. item.map_reduce2_clients.push(hc.HostRoles.host_name);
  498. });
  499. }
  500. }
  501. });
  502. // Map
  503. var finalJson = this.parseIt(item, finalConfig);
  504. finalJson.quick_links = [27, 28, 29, 30];
  505. return finalJson;
  506. },
  507. mapreduceMapper: function (item) {
  508. // Change the JSON so that it is easy to map
  509. var result = [];
  510. var finalConfig = jQuery.extend({}, this.config);
  511. var mapReduceConfig = this.mapReduceConfig;
  512. item.components.forEach(function (component) {
  513. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "JOBTRACKER") {
  514. item.jobTrackerComponent = component;
  515. finalConfig = jQuery.extend(finalConfig, mapReduceConfig);
  516. // Get the live, gray & black nodes from string json
  517. item.map_slots = 0;
  518. item.reduce_slots = 0;
  519. var liveNodesJson = App.parseJSON(component.ServiceComponentInfo.AliveNodes);
  520. var grayNodesJson = App.parseJSON(component.ServiceComponentInfo.GrayListedNodes);
  521. var blackNodesJson = App.parseJSON(component.ServiceComponentInfo.BlackListedNodes);
  522. item.alive_trackers = [];
  523. item.gray_list_trackers = [];
  524. item.black_list_trackers = [];
  525. if (liveNodesJson != null) {
  526. liveNodesJson.forEach(function (nj) {
  527. item.alive_trackers.push(nj.hostname);
  528. if (nj.slots && nj.slots.map_slots)
  529. item.map_slots += nj.slots.map_slots;
  530. if (nj.slots && nj.slots.map_slots_used)
  531. item.map_slots_used += nj.slots.map_slots_used;
  532. if (nj.slots && nj.slots.reduce_slots)
  533. item.reduce_slots += nj.slots.reduce_slots;
  534. if (nj.slots && nj.slots.reduce_slots_used)
  535. item.reduce_slots_used += nj.slots.reduce_slots_used;
  536. });
  537. }
  538. if (grayNodesJson != null) {
  539. grayNodesJson.forEach(function (nj) {
  540. item.gray_list_trackers.push(nj.hostname);
  541. });
  542. }
  543. if (blackNodesJson != null) {
  544. blackNodesJson.forEach(function (nj) {
  545. item.black_list_trackers.push(nj.hostname);
  546. });
  547. }
  548. }
  549. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "TASKTRACKER") {
  550. if (!item.task_trackers) {
  551. item.task_trackers = [];
  552. }
  553. if (component.host_components) {
  554. component.host_components.forEach(function (hc) {
  555. item.task_trackers.push(hc.HostRoles.host_name);
  556. });
  557. }
  558. }
  559. });
  560. // Map
  561. finalJson = this.parseIt(item, finalConfig);
  562. finalJson.quick_links = [5, 6, 7, 8, 9, 10, 11, 12];
  563. return finalJson;
  564. },
  565. hbaseMapper: function (item) {
  566. // Change the JSON so that it is easy to map
  567. var finalConfig = jQuery.extend({}, this.config);
  568. var hbaseConfig = this.hbaseConfig;
  569. item.components.forEach(function (component) {
  570. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "HBASE_MASTER") {
  571. item.masterComponent = component;
  572. finalConfig = jQuery.extend(finalConfig, hbaseConfig);
  573. var regionsArray = App.parseJSON(component.ServiceComponentInfo.RegionsInTransition);
  574. //regions_in_transition can have various type of value: null, array or int
  575. if (Array.isArray(regionsArray)) {
  576. item.regions_in_transition = regionsArray.length;
  577. } else {
  578. item.regions_in_transition = regionsArray == null ? 0 : regionsArray;
  579. }
  580. }
  581. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "HBASE_REGIONSERVER") {
  582. if (!item.region_servers) {
  583. item.region_servers = [];
  584. }
  585. if (component.host_components) {
  586. component.host_components.forEach(function (hc) {
  587. item.region_servers.push(hc.HostRoles.host_name);
  588. });
  589. }
  590. }
  591. });
  592. // Map
  593. finalJson = this.parseIt(item, finalConfig);
  594. finalJson.average_load = parseFloat(finalJson.average_load).toFixed(2);
  595. finalJson.quick_links = [13, 14, 15, 16, 17, 18];
  596. return finalJson;
  597. },
  598. /**
  599. * Flume is different from other services, in that the important
  600. * data is in customizeable channels. Hence we directly transfer
  601. * data into the JSON object.
  602. */
  603. flumeMapper: function (item) {
  604. var finalConfig = jQuery.extend({}, this.config);
  605. var finalJson = this.parseIt(item, finalConfig);
  606. item.components.forEach(function (component) {
  607. if (component.ServiceComponentInfo && component.ServiceComponentInfo.component_name == "FLUME_SERVER") {
  608. if (!finalJson.nodes) {
  609. finalJson.nodes = [];
  610. }
  611. if (!finalJson.nodeObjs) {
  612. finalJson.nodeObjs = [];
  613. }
  614. if (component.host_components) {
  615. component.host_components.forEach(function (hc) {
  616. var fnode = {};
  617. fnode.id = hc.HostRoles.host_name;
  618. fnode.host_id = hc.HostRoles.host_name;
  619. fnode.channels = "";
  620. fnode.sources = "";
  621. fnode.sinks = "";
  622. if (hc.metrics != null && hc.metrics.flume && hc.metrics.flume.flume && hc.metrics.flume.flume) {
  623. if (hc.metrics.flume.flume.CHANNEL) {
  624. for ( var c in hc.metrics.flume.flume.CHANNEL) {
  625. if (fnode.channels.length < 1) {
  626. fnode.channels += c;
  627. } else {
  628. fnode.channels += ("," + c);
  629. }
  630. }
  631. }
  632. if (hc.metrics.flume.flume.SINK) {
  633. for ( var c in hc.metrics.flume.flume.SINK) {
  634. if (fnode.sinks.length < 1) {
  635. fnode.sinks += c;
  636. } else {
  637. fnode.sinks += ("," + c);
  638. }
  639. }
  640. }
  641. if (hc.metrics.flume.flume.SOURCE) {
  642. for ( var c in hc.metrics.flume.flume.SOURCE) {
  643. if (fnode.sources.length < 1) {
  644. fnode.sources += c;
  645. } else {
  646. fnode.sources += ("," + c);
  647. }
  648. }
  649. }
  650. }
  651. finalJson.nodeObjs.push(fnode);
  652. finalJson.nodes.push(hc.HostRoles.host_name);
  653. });
  654. }
  655. }
  656. });
  657. return finalJson;
  658. }
  659. });