update_controller.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. App.UpdateController = Em.Controller.extend({
  20. name:'updateController',
  21. isUpdated:false,
  22. getUrl:function (testUrl, url) {
  23. return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
  24. },
  25. updateServiceMetric:function(){
  26. var servicesUrl1 = this.getUrl('/data/dashboard/services.json', '/services?ServiceInfo/service_name!=MISCELLANEOUS&ServiceInfo/service_name!=DASHBOARD&fields=*,components/host_components/*');
  27. var servicesUrl2 = this.getUrl('/data/dashboard/serviceComponents.json', '/services?ServiceInfo/service_name!=MISCELLANEOUS&ServiceInfo/service_name!=DASHBOARD&fields=components/ServiceComponentInfo');
  28. self = this;
  29. this.set("isUpdated", false);
  30. var metricsJson = null;
  31. var serviceComponentJson = null;
  32. var metricsMapper = {
  33. map:function (data) {
  34. metricsJson = data;
  35. }
  36. };
  37. var serviceComponentMapper = {
  38. map:function (data) {
  39. serviceComponentJson = data;
  40. if (metricsJson != null && serviceComponentJson != null) {
  41. var hdfsSvc1 = null;
  42. var hdfsSvc2 = null;
  43. var mrSvc1 = null;
  44. var mrSvc2 = null;
  45. var hbaseSvc1 = null;
  46. var hbaseSvc2 = null;
  47. metricsJson.items.forEach(function (svc) {
  48. if (svc.ServiceInfo.service_name == "HDFS") {
  49. hdfsSvc1 = svc;
  50. }
  51. if (svc.ServiceInfo.service_name == "MAPREDUCE") {
  52. mrSvc1 = svc;
  53. }
  54. if (svc.ServiceInfo.service_name == "HBASE") {
  55. hbaseSvc1 = svc;
  56. }
  57. });
  58. serviceComponentJson.items.forEach(function (svc) {
  59. if (svc.ServiceInfo.service_name == "HDFS") {
  60. hdfsSvc2 = svc;
  61. }
  62. if (svc.ServiceInfo.service_name == "MAPREDUCE") {
  63. mrSvc2 = svc;
  64. }
  65. if (svc.ServiceInfo.service_name == "HBASE") {
  66. hbaseSvc2 = svc;
  67. }
  68. });
  69. var nnC1 = null;
  70. var nnC2 = null;
  71. var jtC1 = null;
  72. var jtC2 = null;
  73. var hbm1 = null;
  74. var hbm2 = null;
  75. if (hdfsSvc1) {
  76. hdfsSvc1.components.forEach(function (c) {
  77. if (c.ServiceComponentInfo.component_name == "NAMENODE") {
  78. nnC1 = c;
  79. }
  80. });
  81. }
  82. if (hdfsSvc2) {
  83. hdfsSvc2.components.forEach(function (c) {
  84. if (c.ServiceComponentInfo.component_name == "NAMENODE") {
  85. nnC2 = c;
  86. }
  87. });
  88. }
  89. if (mrSvc1) {
  90. mrSvc1.components.forEach(function (c) {
  91. if (c.ServiceComponentInfo.component_name == "JOBTRACKER") {
  92. jtC1 = c;
  93. }
  94. });
  95. }
  96. if (mrSvc2) {
  97. mrSvc2.components.forEach(function (c) {
  98. if (c.ServiceComponentInfo.component_name == "JOBTRACKER") {
  99. jtC2 = c;
  100. }
  101. });
  102. }
  103. if (hbaseSvc1) {
  104. hbaseSvc1.components.forEach(function (c) {
  105. if (c.ServiceComponentInfo.component_name == "HBASE_MASTER") {
  106. hbm1 = c;
  107. }
  108. });
  109. }
  110. if (hbaseSvc2) {
  111. hbaseSvc2.components.forEach(function (c) {
  112. if (c.ServiceComponentInfo.component_name == "HBASE_MASTER") {
  113. hbm2 = c;
  114. }
  115. });
  116. }
  117. if (nnC1 && nnC2) {
  118. nnC1.ServiceComponentInfo = nnC2.ServiceComponentInfo;
  119. }
  120. if (jtC1 && jtC2) {
  121. jtC1.ServiceComponentInfo = jtC2.ServiceComponentInfo;
  122. }
  123. if (hbm1 && hbm2) {
  124. hbm1.ServiceComponentInfo = hbm2.ServiceComponentInfo;
  125. }
  126. App.updateMapper.map(metricsJson);
  127. }
  128. }
  129. }
  130. App.HttpClient.get(servicesUrl1, metricsMapper, {
  131. complete:function (jqXHR, textStatus) {
  132. App.HttpClient.get(servicesUrl2, serviceComponentMapper, {
  133. complete:function (jqXHR, textStatus) {
  134. self.set("isUpdated", true);
  135. }
  136. });
  137. }
  138. });
  139. }
  140. });