addNodes.js 8.6 KB

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