clustersList.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. function ClustersList() {
  22. var managerHostName;
  23. function populateHostToMasterRoleMapping(clusterServices, hostMap) {
  24. for (var serviceName in clusterServices) {
  25. if (clusterServices.hasOwnProperty(serviceName)) {
  26. if (clusterServices[serviceName].isEnabled == "1" &&
  27. clusterServices[serviceName].attributes.runnable &&
  28. !clusterServices[serviceName].attributes.noDisplay) {
  29. globalYui.Array.each( clusterServices[serviceName].components, function (serviceComponent) {
  30. if (serviceComponent.isMaster) {
  31. // just add the master to the hostname object
  32. for (var i in serviceComponent.hostNames) {
  33. var hostName = serviceComponent.hostNames[i];
  34. if ( !( hostName in hostMap ) ) {
  35. hostMap[hostName] = new Array();
  36. hostMap[hostName].push({ serviceName: serviceComponent.displayName, isMaster: true });
  37. } else {
  38. hostMap[hostName].push({ serviceName: serviceComponent.displayName, isMaster: true });
  39. }
  40. }
  41. }
  42. });
  43. }
  44. }
  45. }
  46. }
  47. function populateHostToClientRoleMapping(clusterServices, hostMap) {
  48. for (var serviceName in clusterServices) {
  49. if (clusterServices.hasOwnProperty(serviceName)) {
  50. if (clusterServices[serviceName].isEnabled == "1" &&
  51. !clusterServices[serviceName].attributes.noDisplay) {
  52. globalYui.Array.each( clusterServices[serviceName].components, function (serviceComponent) {
  53. if (serviceComponent.isClient) {
  54. // just add the client to the hostname object
  55. for (var i in serviceComponent.hostNames) {
  56. var hostName = serviceComponent.hostNames[i];
  57. if ( !( hostName in hostMap ) ) {
  58. hostMap[hostName] = new Array();
  59. hostMap[hostName].push({ serviceName: serviceComponent.displayName, isMaster: false });
  60. } else {
  61. hostMap[hostName].push({ serviceName: serviceComponent.displayName, isMaster: false });
  62. }
  63. }
  64. }
  65. });
  66. }
  67. }
  68. }
  69. }
  70. function generateHostRoleMappingMarkup( clusterServices ) {
  71. var hostMap = {};
  72. var markup = '';
  73. populateHostToMasterRoleMapping(clusterServices, hostMap);
  74. populateHostToClientRoleMapping(clusterServices, hostMap);
  75. markup += '<div>';
  76. for (var hostName in hostMap) {
  77. markup += '<div class="hostToServices clearfix"><h3>' + hostName + '</h3>' + '<ul>';
  78. if (hostName == managerHostName) {
  79. markup += '<li class="master">HMC Server</li>';
  80. }
  81. for (var service in hostMap[hostName]) {
  82. markup += '<li class="' + ((hostMap[hostName][service].isMaster) ? 'master' : 'client') + '">' + hostMap[hostName][service].serviceName + '</li>';
  83. }
  84. markup += '</ul></div>';
  85. }
  86. markup += '</div>';
  87. return markup;
  88. }
  89. this.render = function() {
  90. globalYui.io("../php/frontend/listClusters.php", {
  91. method: 'GET',
  92. timeout : 10000,
  93. on: {
  94. success: function (x,o) {
  95. globalYui.log("RAW JSON DATA: " + o.responseText);
  96. // Process the JSON data returned from the server
  97. try {
  98. clusterListInfoJson = globalYui.JSON.parse(o.responseText);
  99. }
  100. catch (e) {
  101. alert("JSON Parse failed!");
  102. return;
  103. }
  104. globalYui.log("PARSED DATA: " + globalYui.Lang.dump(clusterListInfoJson));
  105. if (clusterListInfoJson.result != 0) {
  106. // Error!
  107. alert("Got error!" + clusterListInfoJson.error);
  108. return;
  109. }
  110. clusterListInfoJson = clusterListInfoJson.response;
  111. var numClusters = clusterListInfoJson.length;
  112. var clustersListMarkup;
  113. var clusterId;
  114. var multipleClustersSupported = false;
  115. if (numClusters == 0) {
  116. clustersListMarkup = "";
  117. } else {
  118. if (multipleClustersSupported) {
  119. clustersListMarkup = "<table>" +
  120. "<caption>List of clusters</caption>" +
  121. "<thead><tr><th>Name of the cluster</th><th>Cluster status</th><th>Actions</th></tr></thead>";
  122. var i = 0;
  123. for (clusterId in clusterListInfoJson) {
  124. clustersListMarkup += "<tr><td><a href='manageServices.php?clusterId=" + clusterId + "' id='existingClusterLinkDivId'>" + clusterId + "</a></td><td>" + clusterListInfoJson[clusterId] + "</td><td>Uninstall</td></tr>" ;
  125. }
  126. clustersListMarkup += "</table>";
  127. } else {
  128. var clusterName; var clusterInfo;
  129. for (clusterId in clusterListInfoJson) {
  130. clusterName = clusterId;
  131. clusterInfo = globalYui.JSON.parse(clusterListInfoJson[clusterName]);
  132. globalYui.log( "Cluster Info: " + globalYui.Lang.dump(clusterInfo.displayName));
  133. }
  134. }
  135. }
  136. var newClusterLinkHTML = "";
  137. if (multipleClustersSupported || numClusters == 0) {
  138. document.location.href = "/hmc/html/welcome.php";
  139. return;
  140. }
  141. /* Beginning of adding Role Topology information. */
  142. globalYui.io( "../php/frontend/fetchClusterServices.php?clusterName=" + clusterName + "&getConfigs=true&getComponents=true", {
  143. timeout: 10000,
  144. on: {
  145. success: function(x1, o1) {
  146. hideLoadingImg();
  147. globalYui.log("RAW JSON DATA: " + o1.responseText);
  148. var clusterServicesResponseJson;
  149. try {
  150. clusterServicesResponseJson = globalYui.JSON.parse(o1.responseText);
  151. }
  152. catch (e) {
  153. alert("JSON Parse failed");
  154. return;
  155. }
  156. managerHostName = clusterServicesResponseJson.response.managerHostName;
  157. globalYui.log(globalYui.Lang.dump(clusterServicesResponseJson));
  158. /* Check that clusterServicesResponseJson actually indicates success. */
  159. if( clusterServicesResponseJson.result == 0 ) {
  160. var clusterServices = clusterServicesResponseJson.response.services;
  161. var markup =
  162. '<div class="clearfix">' +
  163. '<h2>Cluster: ' + clusterName + '</h2>' +
  164. '<div id="serviceLegend">' +
  165. '<span class="masterLegend">Master</span><span class="clientLegend" style="margin-right:0">Client</span>' +
  166. '</div>' +
  167. '</div>' +
  168. '</div>';
  169. globalYui.one("#clusterHostRoleMappingDynamicRenderDivId").setContent(
  170. markup + generateHostRoleMappingMarkup(clusterServices) );
  171. globalYui.one("#clusterHostRoleMappingDivId").show();
  172. }
  173. else {
  174. alert("Fetching Cluster Services failed");
  175. }
  176. },
  177. failure: function(x1, o1) {
  178. hideLoadingImg();
  179. alert("Async call failed");
  180. }
  181. }
  182. });
  183. /* End of adding Role Topology information. */
  184. globalYui.one("#clustersListDivId").setContent( clustersListMarkup );
  185. globalYui.one("#clustersListDivId").setStyle('display', 'block');
  186. if (globalYui.one('#newClusterLinkDivId') != null) {
  187. globalYui.one('#newClusterLinkDivId').on('click',function (e) {
  188. /* Done with this stage, hide it. */
  189. globalYui.one("#clustersListDivId").setStyle('display','none');
  190. // globalYui.one("#installationWizardDivId").setStyle('display','block');
  191. });
  192. }
  193. },
  194. failure: function (x,o) {
  195. // e.target.set('disabled', false);
  196. alert("Async call failed!");
  197. }
  198. }
  199. });
  200. }; // end render
  201. };
  202. var clustersList = new ClustersList();
  203. clustersList.render();