addNodes.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. InstallationWizard.AddNodes = {
  22. renderData:
  23. {},
  24. render:
  25. function (addNodesRenderData) {
  26. /* Always update the object's renderData first. */
  27. InstallationWizard.AddNodes.renderData = addNodesRenderData;
  28. /* Since this screen is completely statically rendered, nothing else
  29. * needs to be done here.
  30. */
  31. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  32. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  33. globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'block');
  34. } else {
  35. globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'none');
  36. globalYui.one("#yumRepoFilePathId").set('value', '');
  37. }
  38. }
  39. globalYui.one("#addNodesCoreDivId").setStyle('display', 'block');
  40. hideLoadingImg();
  41. }
  42. };
  43. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  44. globalYui.one("#yumMirrorSupportFormButtonId").on('click', function(e) {
  45. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  46. globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'block');
  47. } else {
  48. globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'none');
  49. }
  50. });
  51. }
  52. globalYui.one('#addNodesSubmitButtonId').on('click',function (e) {
  53. var focusId = '';
  54. var message = '';
  55. var errCount = 0;
  56. var userId = globalYui.Lang.trim(globalYui.one("#clusterDeployUserId").get('value'));
  57. if (userId == '') {
  58. errCount++;
  59. focusId = '#clusterDeployUserId';
  60. message += 'SSH Username cannot be empty';
  61. globalYui.one("#clusterDeployUserId").addClass('formInputError');
  62. } else {
  63. globalYui.one("#clusterDeployUserId").removeClass('formInputError');
  64. }
  65. var fileName = globalYui.one("#clusterDeployUserIdentityFileId").get('value');
  66. if (fileName == '') {
  67. errCount++;
  68. if (focusId == '') {
  69. focusId = '#clusterDeployUserIdentityFileId';
  70. }
  71. if (message != '') {
  72. message += '. ';
  73. }
  74. message += 'SSH Private Key File not specified';
  75. globalYui.one("#clusterDeployUserIdentityFileId").addClass('formInputError');
  76. } else {
  77. globalYui.one("#clusterDeployUserIdentityFileId").removeClass('formInputError');
  78. }
  79. fileName = globalYui.one("#clusterHostsFileId").get('value');
  80. if (fileName == '') {
  81. errCount++;
  82. if (focusId == '') {
  83. focusId = '#clusterHostsFileId';
  84. }
  85. if (message != '') {
  86. message += '. ';
  87. }
  88. message += 'Hosts File not specified';
  89. globalYui.one("#clusterHostsFileId").addClass('formInputError');
  90. } else {
  91. globalYui.one("#clusterHostsFileId").removeClass('formInputError');
  92. }
  93. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  94. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  95. // local yum mirror support
  96. var repoFile = globalYui.Lang.trim(globalYui.one("#yumRepoFilePathId").get('value'));
  97. if (repoFile == '') {
  98. errCount++;
  99. if (focusId == '') {
  100. focusId = '#yumRepoFilePathId';
  101. }
  102. if (message != '') {
  103. message += '. ';
  104. }
  105. message += 'Yum Repo file not specified';
  106. globalYui.one("#yumRepoFilePathId").addClass('formInputError');
  107. }
  108. }
  109. }
  110. if (errCount != 0) {
  111. globalYui.one(focusId).focus();
  112. setFormStatus(message, true);
  113. return;
  114. }
  115. clearFormStatus();
  116. showLoadingImg();
  117. globalYui.log("About to upload files.");
  118. e.target.set('disabled', true);
  119. var addNodesFilesForm = globalYui.one("#addNodesFilesFormId");
  120. addNodesFilesForm.set('action', '../php/frontend/addNodes.php?clusterName=' +
  121. InstallationWizard.AddNodes.renderData.clusterName);
  122. /* Set the target of the first form's upload to be a hidden iframe
  123. * on the page so as not to redirect to the PHP page we're POSTing
  124. * to.
  125. *
  126. * See http://www.openjs.com/articles/ajax/ajax_file_upload/ for
  127. * more on this.
  128. */
  129. addNodesFilesForm.set('target', 'fileUploadTarget');
  130. /* And then programmatically submit the first of the 2 forms. */
  131. doPostUpload = true;
  132. addNodesFilesForm.submit();
  133. globalYui.log("Files submitted to server.");
  134. e.target.set('disabled', false);
  135. });
  136. var setupNodesJson = "";
  137. var doPostUpload = false; // this flag is to prevent the #fileUploadTargetId iframe onload event from being invoked on browser back action
  138. globalYui.one("#fileUploadTargetId").on('load', function (e) {
  139. if (!doPostUpload) {
  140. return;
  141. }
  142. globalYui.log("File upload finished");
  143. if (freshInstall == false) {
  144. // Do checks only in case of addNodesWizard
  145. var myIFrame = globalYui.one("#fileUploadTargetId");
  146. var myIFrameContent = myIFrame.get('contentWindow.document.body');
  147. var content = myIFrameContent.one('pre:first-child');
  148. var responseText = content.get('text');
  149. var responseJson = globalYui.JSON.parse(responseText);
  150. if (responseJson.result != 0) {
  151. // This means we hit an error
  152. if (responseJson.result == 3) {
  153. info =
  154. '<p>' +
  155. responseJson.error + '. ' +
  156. '<a href="javascript:void(null)" id=errorHostInfoLinkId>' +
  157. 'Show me the duplicates</a>' +
  158. '</p>';
  159. setFormStatus(info, true);
  160. var infoPanel = createInformationalPanel("#informationalPanelContainerDivId", "Duplicate nodes");
  161. infoPanel.set('centered', true);
  162. var infoPanelContent = '';
  163. for (cluster in responseJson.hosts) {
  164. infoPanelContent += 'Cluster: <b>' + cluster + '</b><ul>';
  165. for (host in responseJson.hosts[cluster]) {
  166. infoPanelContent += '<li>' + responseJson.hosts[cluster][host] + '</li>';
  167. }
  168. infoPanelContent += '</ul><br/>';
  169. }
  170. infoPanel.set('bodyContent', infoPanelContent);
  171. infoPanel.addButton({
  172. value: 'Close',
  173. action: function(e) {
  174. e.preventDefault();
  175. destroyInformationalPanel(infoPanel);
  176. },
  177. className: '',
  178. section: 'footer'
  179. });
  180. globalYui.one('#errorHostInfoLinkId').on("click", function(e) {
  181. infoPanel.show();
  182. });
  183. hideLoadingImg();
  184. return;
  185. } else {
  186. alert('Got and error ' + responseJson.error);
  187. hideLoadingImg();
  188. return;
  189. }
  190. }
  191. }
  192. doPostUpload = false;
  193. var repoFile = '';
  194. var localYumRepo = '';
  195. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  196. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  197. localYumRepo = 'true';
  198. // local yum mirror support
  199. repoFile = globalYui.Lang.trim(globalYui.one("#yumRepoFilePathId").get('value'));
  200. }
  201. }
  202. var addNodesRequestData = {
  203. "ClusterDeployUser" : globalYui.Lang.trim(globalYui.one("#clusterDeployUserId").get('value')),
  204. "useLocalYumRepo" : localYumRepo,
  205. "yumRepoFilePath": repoFile
  206. }
  207. // Trigger the execution of setting up nodes
  208. var url = "../php/frontend/nodesAction.php?clusterName=" + InstallationWizard.AddNodes.renderData.clusterName + "&action=addNodes";
  209. globalYui.io(url, {
  210. method: 'POST',
  211. data: addNodesRequestData,
  212. timeout : 10000,
  213. on: {
  214. success: function (x,o) {
  215. globalYui.log("RAW JSON DATA: " + o.responseText);
  216. // Process the JSON data returned from the server
  217. try {
  218. setupNodesJson = globalYui.JSON.parse(o.responseText);
  219. } catch (e) {
  220. alert("JSON Parse failed!");
  221. return;
  222. }
  223. globalYui.log("PARSED DATA: " + globalYui.Lang.dump(setupNodesJson));
  224. if (setupNodesJson.result != 0) {
  225. // Error!
  226. alert("Got error! " + setupNodesJson.error);
  227. hideLoadingImg();
  228. return;
  229. }
  230. setupNodesJson = setupNodesJson.response;
  231. hideLoadingImg();
  232. globalYui.one("#blackScreenDivId").setStyle("display", "block");
  233. renderProgress( setupNodesJson );
  234. },
  235. failure: function (x,o) {
  236. alert("Async call failed!");
  237. }
  238. }
  239. });
  240. });