clustersList.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. function populateHostToMasterRoleMapping(clusterServices, hostMap) {
  2. for (var serviceName in clusterServices) {
  3. if (clusterServices.hasOwnProperty(serviceName)) {
  4. if (clusterServices[serviceName].isEnabled == "1" &&
  5. clusterServices[serviceName].attributes.runnable &&
  6. !clusterServices[serviceName].attributes.noDisplay) {
  7. globalYui.Array.each( clusterServices[serviceName].components, function (serviceComponent) {
  8. if (serviceComponent.isMaster) {
  9. // just add the client to the hostname object
  10. if ( !( serviceComponent.hostName in hostMap ) ) {
  11. hostMap[serviceComponent.hostName] = new Array();
  12. hostMap[serviceComponent.hostName].push({ serviceName: serviceComponent.displayName, isMaster: true });
  13. } else {
  14. hostMap[serviceComponent.hostName].push({ serviceName: serviceComponent.displayName, isMaster: true});
  15. }
  16. }
  17. });
  18. }
  19. }
  20. }
  21. }
  22. function populateHostToClientRoleMapping(clusterServices, hostMap) {
  23. for (var serviceName in clusterServices) {
  24. if (clusterServices.hasOwnProperty(serviceName)) {
  25. if (clusterServices[serviceName].isEnabled == "1" &&
  26. !clusterServices[serviceName].attributes.noDisplay) {
  27. globalYui.Array.each( clusterServices[serviceName].components, function (serviceComponent) {
  28. if (serviceComponent.isClient) {
  29. // just add the client to the hostname object
  30. if ( !( serviceComponent.hostName in hostMap ) ) {
  31. hostMap[serviceComponent.hostName] = new Array();
  32. hostMap[serviceComponent.hostName].push({ serviceName: serviceComponent.displayName, isMaster: false });
  33. } else {
  34. hostMap[serviceComponent.hostName].push({ serviceName: serviceComponent.displayName, isMaster: false });
  35. }
  36. }
  37. });
  38. }
  39. }
  40. }
  41. }
  42. function generateHostRoleMappingMarkup( clusterServices ) {
  43. var hostMap = {};
  44. var markup = '';
  45. populateHostToMasterRoleMapping(clusterServices, hostMap);
  46. populateHostToClientRoleMapping(clusterServices, hostMap);
  47. markup = '<div>';
  48. for (var hostName in hostMap) {
  49. markup += '<div class="hostToServices"><h3>' + hostName + '</h3>' + '<ul>';
  50. for (var service in hostMap[hostName]) {
  51. markup += '<li class="' + ((hostMap[hostName][service].isMaster) ? 'master' : 'client') + '">' + hostMap[hostName][service].serviceName + '</li>';
  52. }
  53. markup += '</ul><div style="clear:both"></div></div>';
  54. }
  55. markup += '</div>';
  56. return markup;
  57. }
  58. function renderClusterList() {
  59. globalYui.io("../php/frontend/listClusters.php", {
  60. method: 'GET',
  61. timeout : 10000,
  62. on: {
  63. success: function (x,o) {
  64. globalYui.log("RAW JSON DATA: " + o.responseText);
  65. // Process the JSON data returned from the server
  66. try {
  67. clusterListInfoJson = globalYui.JSON.parse(o.responseText);
  68. }
  69. catch (e) {
  70. alert("JSON Parse failed!");
  71. return;
  72. }
  73. globalYui.log("PARSED DATA: " + globalYui.Lang.dump(clusterListInfoJson));
  74. if (clusterListInfoJson.result != 0) {
  75. // Error!
  76. alert("Got error!" + clusterListInfoJson.error);
  77. return;
  78. }
  79. clusterListInfoJson = clusterListInfoJson.response;
  80. var numClusters = clusterListInfoJson.length;
  81. var clustersListMarkup;
  82. var clusterId;
  83. var multipleClustersSupported = false;
  84. if (numClusters == 0) {
  85. clustersListMarkup = "";
  86. } else {
  87. if (multipleClustersSupported) {
  88. clustersListMarkup = "<table>" +
  89. "<caption>List of clusters</caption>" +
  90. "<thead><tr><th>Name of the cluster</th><th>Cluster status</th><th>Actions</th></tr></thead>";
  91. var i = 0;
  92. for (clusterId in clusterListInfoJson) {
  93. clustersListMarkup += "<tr><td><a href='manageServices.php?clusterId=" + clusterId + "' id='existingClusterLinkDivId'>" + clusterId + "</a></td><td>" + clusterListInfoJson[clusterId] + "</td><td>Uninstall</td></tr>" ;
  94. }
  95. clustersListMarkup += "</table>";
  96. } else {
  97. var clusterName; var clusterInfo;
  98. for (clusterId in clusterListInfoJson) {
  99. clusterName = clusterId;
  100. clusterInfo = globalYui.JSON.parse(clusterListInfoJson[clusterName]);
  101. globalYui.log( "Cluster Info: " + globalYui.Lang.dump(clusterInfo.displayName));
  102. }
  103. clustersListMarkup = '<h3>Cluster information</h3>';
  104. clustersListMarkup += '<div class="clusterDiv">' +
  105. '<div class="formElement">' +
  106. '<label>Cluster Name</label>' +
  107. '<input type=text readonly=readonly value="' + clusterName + '">' +
  108. '</div>' +
  109. '<div class="formElement">' +
  110. '<label>State</label>' +
  111. '<input type=text readonly=readonly value="' + clusterInfo['displayName'] + '">' +
  112. '</div>' +
  113. '<div class="formElement">' +
  114. '<a class="btn" href="/hdp/dashboard/ui/home.html">Monitoring Dashboard</a>' +
  115. '<a class="btn" style="margin-left:10px" href="manageServices.php?clusterName=' + clusterName + '" id="existingClusterLinkDivId">Manage Services</a>' +
  116. '<a class="btn" style="margin-left:10px" href="addNodesWizard.php?clusterName=' + clusterName + '">Add Nodes</a>' +
  117. '<a class="btn" style="margin-left:10px" href="uninstallWizard.php?clusterName=' + clusterName + '">Uninstall</a>' +
  118. '</div>' +
  119. '</div>';
  120. }
  121. }
  122. var newClusterLinkHTML = "";
  123. if (multipleClustersSupported || numClusters == 0) {
  124. document.location.href = "/hmc/html/welcome.php";
  125. return;
  126. }
  127. /* Beginning of adding Role Topology information. */
  128. globalYui.io( "../php/frontend/fetchClusterServices.php?clusterName=" + clusterName + "&getConfigs=true&getComponents=true", {
  129. timeout: 10000,
  130. on: {
  131. success: function(x1, o1) {
  132. hideLoadingImg();
  133. globalYui.log("RAW JSON DATA: " + o1.responseText);
  134. var clusterServicesResponseJson;
  135. try {
  136. clusterServicesResponseJson = globalYui.JSON.parse(o1.responseText);
  137. }
  138. catch (e) {
  139. alert("JSON Parse failed");
  140. return;
  141. }
  142. globalYui.log(globalYui.Lang.dump(clusterServicesResponseJson));
  143. /* Check that clusterServicesResponseJson actually indicates success. */
  144. if( clusterServicesResponseJson.result == 0 ) {
  145. var clusterServices = clusterServicesResponseJson.response.services;
  146. /* Link the newly-generated markup into the DOM. */
  147. globalYui.one("#clusterHostRoleMappingDynamicRenderDivId").setContent(
  148. generateHostRoleMappingMarkup(clusterServices) );
  149. globalYui.one("#clusterHostRoleMappingDivId").show();
  150. }
  151. else {
  152. alert("Fetching Cluster Services failed");
  153. }
  154. },
  155. failure: function(x1, o1) {
  156. hideLoadingImg();
  157. alert("Async call failed");
  158. }
  159. }
  160. });
  161. /* End of adding Role Topology information. */
  162. globalYui.one("#clustersListDivId").setContent( clustersListMarkup );
  163. globalYui.one("#clustersListDivId").setStyle('display', 'block');
  164. if (globalYui.one('#newClusterLinkDivId') != null) {
  165. globalYui.one('#newClusterLinkDivId').on('click',function (e) {
  166. /* Done with this stage, hide it. */
  167. globalYui.one("#clustersListDivId").setStyle('display','none');
  168. // globalYui.one("#installationWizardDivId").setStyle('display','block');
  169. });
  170. }
  171. if(numClusters !=0) {
  172. globalYui.one('#existingClusterLinkDivId').on('click',function (e) {
  173. e.target.set('disabled', true);
  174. /* Done with this stage, hide it. */
  175. globalYui.one("#clustersListDivId").setStyle('display','none');
  176. /* Render the next stage. */
  177. getServicesStatus(globalYui, clusterId);
  178. /* Show off our rendering. */
  179. globalYui.one("#displayServiceStatusCoreDivId").setStyle('display','block');
  180. });
  181. }
  182. },
  183. failure: function (x,o) {
  184. // e.target.set('disabled', false);
  185. alert("Async call failed!");
  186. }
  187. }
  188. });
  189. }
  190. /* Main() */
  191. renderClusterList();