configureCluster.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 generateEligibleMountPoints () {
  22. /* The list we're about to build up. */
  23. var desiredMountPoints = [];
  24. var selections = globalYui.all("#configureClusterMountPointsDynamicRenderDivId input[type=checkbox]");
  25. selections.each( function(selection) {
  26. if( selection.get('checked') == true ) {
  27. desiredMountPoints.push( selection.get('value') );
  28. }
  29. });
  30. globalYui.log("desired mount points: "+globalYui.Lang.dump(desiredMountPoints));
  31. var customMountPointsString = globalYui.Lang.trim( globalYui.one("#customMountPointsId").get('value') );
  32. if( customMountPointsString.length != 0 ) {
  33. globalYui.log("custom string = " + customMountPointsString);
  34. /* Merge the split version of customMountPointsString into our final list
  35. * of mount points to send back to the server for committing...
  36. */
  37. desiredMountPoints.push.apply( desiredMountPoints, globalYui.Array.filter(customMountPointsString.split(','), function (elem) {
  38. if (globalYui.Lang.trim(elem).length > 0) {
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. } ));
  44. globalYui.log(desiredMountPoints.join(','));
  45. }
  46. /* ...But not before performing a de-dupe, just to be safe. */
  47. return globalYui.Array.dedupe( desiredMountPoints );
  48. }
  49. function generateServiceDirs (servicesInfo) {
  50. var generatedServiceDirs = {};
  51. var eligibleMountPoints = generateEligibleMountPoints();
  52. for (items in servicesInfo) {
  53. for (serviceName in servicesInfo[items]) {
  54. for (component in servicesInfo[items][serviceName]) {
  55. var serviceInfo = servicesInfo[items][serviceName][component];
  56. var serviceDirs = [];
  57. for( currentDirNum = 0; currentDirNum < eligibleMountPoints.length; ++currentDirNum ) {
  58. /* serviceInfo.maxDirectoriesNeeded that we get from the server is a cap
  59. * on how many directories need to be generated for that service - the
  60. * user can always pick fewer than that, so guard against going out of
  61. * bounds.
  62. */
  63. if ((serviceInfo.maxDirectoriesNeeded != -1) &&
  64. (currentDirNum >= serviceInfo.maxDirectoriesNeeded)) {
  65. break;
  66. }
  67. var currentDirName = eligibleMountPoints[currentDirNum];
  68. /* Add a trailing slash if it doesn't exist already. */
  69. if( currentDirName.substr(-1) != '/' ) {
  70. currentDirName += '/';
  71. }
  72. serviceDirs.push( currentDirName + serviceInfo.suffix );
  73. }
  74. var serviceDirValue = serviceDirs.join(',');
  75. generatedServiceDirs[component] = {
  76. "serviceName" : serviceName,
  77. 'value' : serviceDirValue,
  78. 'displayName' : serviceInfo.displayName
  79. };
  80. }
  81. }
  82. }
  83. globalYui.log("Generated Service Dirs: "+globalYui.Lang.dump(generatedServiceDirs));
  84. return generatedServiceDirs;
  85. }
  86. function renderEffectiveClusterConfig (generatedClusterConfig) {
  87. var clusterConfigDisplayMarkup = "";
  88. for (var configKey in generatedClusterConfig) {
  89. if (generatedClusterConfig.hasOwnProperty( configKey )) {
  90. var configElement = generatedClusterConfig[configKey];
  91. var configElementName = configKey;
  92. var configElementIdName = configElementName + 'Id';
  93. var dirsArray = configElement.value.split(',');
  94. /* Inefficient, with all the string concatenations, but clear to read. */
  95. clusterConfigDisplayMarkup +=
  96. '<div class="formElement">' +
  97. '<label for=' + configElementIdName + '>' + configElement.displayName + '</label>' +
  98. '<ul style="list-style-type: none;float:left;" id=' + configElementIdName + '>';
  99. for (var dirs in dirsArray) {
  100. clusterConfigDisplayMarkup +=
  101. '<li>' + dirsArray[dirs] + '</li>';
  102. }
  103. clusterConfigDisplayMarkup += '</ul>' + '<div style="clear:both"></div></div>';
  104. globalYui.log("HTML GENERATED: " + clusterConfigDisplayMarkup);
  105. }
  106. }
  107. /* Link the newly-generated clusterConfigInputMarkup into the DOM (making
  108. * sure it comes before the existing #configureClusterSubmitButtonId), thus
  109. * rendering it.
  110. */
  111. globalYui.one("#configureClusterMountPointsDisplayDivId").setContent( clusterConfigDisplayMarkup );
  112. }
  113. /* Modify the working version of generatedClusterConfig to make it fit for
  114. * sending to our backend.
  115. */
  116. function polishClusterConfig (generatedClusterConfig) {
  117. var polishedClusterConfig = {};
  118. for (var configKey in generatedClusterConfig) {
  119. if (generatedClusterConfig.hasOwnProperty( configKey )) {
  120. serviceName = generatedClusterConfig[configKey]["serviceName"];
  121. if (!polishedClusterConfig.hasOwnProperty(serviceName)) {
  122. polishedClusterConfig[serviceName] = {};
  123. }
  124. polishedClusterConfig[serviceName][configKey] = generatedClusterConfig[configKey].value;
  125. }
  126. }
  127. return polishedClusterConfig;
  128. }
  129. var globalServicesInfo = null;
  130. function eventHandlerFunc (e)
  131. {
  132. renderEffectiveClusterConfig(generateServiceDirs(globalServicesInfo));
  133. }
  134. var registeredConfigureClusterEventHandlers = false;
  135. function renderConfigureCluster (clusterConfig) {
  136. globalServicesInfo = globalYui.Array( clusterConfig.servicesInfo );
  137. /* Clear out the contents of #customMountPointsId each time we render this
  138. * screen, to maintain our guarantee of invalidating all forward pages once
  139. * the user moves back.
  140. */
  141. globalYui.one("#customMountPointsId").set('value', '');
  142. if( !registeredConfigureClusterEventHandlers ) {
  143. globalYui.one('#configureClusterSubmitButtonId').on('click',function (e) {
  144. e.target.set('disabled', true);
  145. var itemsExist = false;
  146. var selections = globalYui.all("#configureClusterMountPointsDynamicRenderDivId input[type=checkbox]");
  147. selections.each( function(selection) {
  148. if( selection.get('checked') == true ) {
  149. itemsExist = true;
  150. }
  151. });
  152. if (globalYui.Lang.trim( globalYui.one("#customMountPointsId").get('value') ) != '') {
  153. itemsExist = true;
  154. }
  155. if (!itemsExist) {
  156. alert("Please select one mount point at the least");
  157. e.target.set('disabled', false);
  158. return;
  159. }
  160. /* For now, our cluster config consists solely of the generated service directories. */
  161. var generatedClusterConfig = generateServiceDirs(globalServicesInfo);
  162. var configureClusterRequestData = {
  163. mountPoints : generateEligibleMountPoints(),
  164. clusterConfig : polishClusterConfig(generatedClusterConfig)
  165. };
  166. globalYui.log(globalYui.Lang.dump(configureClusterRequestData.clusterConfig));
  167. var url = "../php/frontend/configureCluster.php?clusterName="+clusterConfig.clusterName;
  168. var requestData = configureClusterRequestData;
  169. var submitButton = e.target;
  170. var thisScreenId = "#configureClusterCoreDivId";
  171. var nextScreenId = "#configureClusterAdvancedCoreDivId";
  172. var nextScreenRenderFunction = renderOptionsPage;
  173. submitDataAndProgressToNextScreen(url, requestData, submitButton, thisScreenId, nextScreenId, nextScreenRenderFunction);
  174. });
  175. globalYui.one('#previewLinkId').on('click', function(e) {
  176. previewPanel = createInformationalPanel('#informationalPanelContainerDivId', 'Preview Directories to be used by Hadoop');
  177. previewPanel.set('centered', true);
  178. previewPanel.set('bodyContent', globalYui.one('#configureClusterDisplayDivId').getContent());
  179. var okButton = {
  180. value: 'OK',
  181. action: function (e) {
  182. e.preventDefault();
  183. destroyInformationalPanel(previewPanel);
  184. },
  185. section: 'footer'
  186. };
  187. previewPanel.addButton(okButton);
  188. previewPanel.show();
  189. });
  190. /* event on mountPoints to be checked. */
  191. globalYui.one('#configureClusterMountPointsInputDivId').delegate(
  192. {
  193. 'click': eventHandlerFunc,
  194. 'keyup' : eventHandlerFunc
  195. },
  196. "input[type=checkbox],input[type=text]");
  197. registeredConfigureClusterEventHandlers = true;
  198. }
  199. /* Generate the key form elements into clusterConfigInputMarkup. */
  200. var mountPoints = globalYui.Array( clusterConfig.mountPoints.sort(globalYui.ArraySort.compare) );
  201. var clusterConfigInputMarkup = "";
  202. globalYui.Array.each(mountPoints, function(mountPoint) {
  203. /* Inefficient, with all the string concatenations, but clear to read. */
  204. clusterConfigInputMarkup +=
  205. '<label class="checkbox" for="">' + mountPoint +
  206. '<input type=checkbox name=mountPoints id=mountPointsId checked=true value=' + mountPoint + '>' +
  207. '</label><br/>';
  208. });
  209. /* Link the newly-generated clusterConfigInputMarkup into the DOM. */
  210. globalYui.one("#configureClusterMountPointsDynamicRenderDivId").setContent( clusterConfigInputMarkup );
  211. hideLoadingImg();
  212. globalYui.one('#configureClusterCoreDivId').setStyle("display", "block");
  213. renderEffectiveClusterConfig(generateServiceDirs(globalServicesInfo));
  214. }