addNodes.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. }
  23. };
  24. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  25. globalYui.one("#yumMirrorSupportFormButtonId").on('click', function(e) {
  26. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  27. globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'block');
  28. } else {
  29. globalYui.one('#yumMirrorSupportFormFieldsId').setStyle('display', 'none');
  30. }
  31. });
  32. }
  33. globalYui.one('#addNodesSubmitButtonId').on('click',function (e) {
  34. var focusId = '';
  35. var message = '';
  36. var errCount = 0;
  37. var userId = globalYui.Lang.trim(globalYui.one("#clusterDeployUserId").get('value'));
  38. if (userId == '') {
  39. errCount++;
  40. focusId = '#clusterDeployUserId';
  41. message += 'SSH Username cannot be empty';
  42. globalYui.one("#clusterDeployUserId").addClass('formInputError');
  43. } else {
  44. globalYui.one("#clusterDeployUserId").removeClass('formInputError');
  45. }
  46. var fileName = globalYui.one("#clusterDeployUserIdentityFileId").get('value');
  47. if (fileName == '') {
  48. errCount++;
  49. if (focusId == '') {
  50. focusId = '#clusterDeployUserIdentityFileId';
  51. }
  52. if (message != '') {
  53. message += ',';
  54. }
  55. message += 'SSH Private Key File not specified';
  56. globalYui.one("#clusterDeployUserIdentityFileId").addClass('formInputError');
  57. } else {
  58. globalYui.one("#clusterDeployUserIdentityFileId").removeClass('formInputError');
  59. }
  60. fileName = globalYui.one("#clusterHostsFileId").get('value');
  61. if (fileName == '') {
  62. errCount++;
  63. if (focusId == '') {
  64. focusId = '#clusterHostsFileId';
  65. }
  66. if (message != '') {
  67. message += ',';
  68. }
  69. message += 'Hosts file not specified';
  70. globalYui.one("#clusterHostsFileId").addClass('formInputError');
  71. } else {
  72. globalYui.one("#clusterHostsFileId").removeClass('formInputError');
  73. }
  74. if (errCount != 0) {
  75. globalYui.one(focusId).focus();
  76. setFormStatus(message, true);
  77. return;
  78. }
  79. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  80. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  81. // local yum mirror support
  82. var repoFile = globalYui.Lang.trim(globalYui.one("#yumRepoFilePathId").get('value'));
  83. var artifactsUrl = globalYui.Lang.trim(globalYui.one("#hmcArtifactsDownloadUrlId").get('value'));
  84. var gplArtifactsUrl = globalYui.Lang.trim(globalYui.one("#hmcGplArtifactsDownloadUrlId").get('value'));
  85. if (repoFile = '') {
  86. errCount++;
  87. if (focusId == '') {
  88. focusId = '#yumRepoFilePathId';
  89. }
  90. if (message != '') {
  91. message += ',';
  92. }
  93. message += 'Yum Repo file not specified';
  94. globalYui.one("#yumRepoFilePathId").addClass('formInputError');
  95. }
  96. if (artifactsUrl = '') {
  97. errCount++;
  98. if (focusId == '') {
  99. focusId = '#hmcArtifactsDownloadUrlId';
  100. }
  101. if (message != '') {
  102. message += ',';
  103. }
  104. message += 'HDP Artifacts Download URL not specified';
  105. globalYui.one("#hmcArtifactsDownloadUrlId").addClass('formInputError');
  106. }
  107. if (artifactsUrl = '') {
  108. errCount++;
  109. if (focusId == '') {
  110. focusId = '#hmcGplArtifactsDownloadUrlId';
  111. }
  112. if (message != '') {
  113. message += ',';
  114. }
  115. message += 'GPL Artifacts Download URL not specified';
  116. globalYui.one("#hmcGplArtifactsDownloadUrlId").addClass('formInputError');
  117. }
  118. }
  119. }
  120. clearFormStatus();
  121. showLoadingImg();
  122. globalYui.log("About to upload files.");
  123. e.target.set('disabled', true);
  124. var addNodesFilesForm = globalYui.one("#addNodesFilesFormId");
  125. addNodesFilesForm.set('action', '../php/frontend/addNodes.php?clusterName=' +
  126. InstallationWizard.AddNodes.renderData.clusterName + "&freshInstall=" + InstallationWizard.AddNodes.renderData.freshInstall);
  127. /* Set the target of the first form's upload to be a hidden iframe
  128. * on the page so as not to redirect to the PHP page we're POSTing
  129. * to.
  130. *
  131. * See http://www.openjs.com/articles/ajax/ajax_file_upload/ for
  132. * more on this.
  133. */
  134. addNodesFilesForm.set('target', 'fileUploadTarget');
  135. /* And then programmatically submit the first of the 2 forms. */
  136. addNodesFilesForm.submit();
  137. globalYui.log("Files submitted to server.");
  138. e.target.set('disabled', false);
  139. });
  140. var setupNodesJson = "";
  141. globalYui.one("#fileUploadTargetId").on('load', function (e) {
  142. globalYui.log("File upload finished");
  143. var repoFile = '';
  144. var artifactsUrl = '';
  145. var gplArtifactsUrl = '';
  146. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  147. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  148. // local yum mirror support
  149. repoFile = globalYui.Lang.trim(globalYui.one("#yumRepoFilePathId").get('value'));
  150. artifactsUrl = globalYui.Lang.trim(globalYui.one("#hmcArtifactsDownloadUrlId").get('value'));
  151. gplArtifactsUrl = globalYui.Lang.trim(globalYui.one("#hmcGplArtifactsDownloadUrlId").get('value'));
  152. }
  153. }
  154. var addNodesRequestData = {
  155. "ClusterDeployUser" : globalYui.Lang.trim(globalYui.one("#clusterDeployUserId").get('value')),
  156. "yumRepoFilePath": repoFile,
  157. "hdpArtifactsDownloadUrl" : artifactsUrl,
  158. "gplArtifactsDownloadUrl": gplArtifactsUrl
  159. }
  160. // Trigger the execution of setting up nodes
  161. var url = "../php/frontend/nodesAction.php?clusterName=" + InstallationWizard.AddNodes.renderData.clusterName + "&action=addNodes";
  162. globalYui.io(url, {
  163. method: 'POST',
  164. data: addNodesRequestData,
  165. timeout : 10000,
  166. on: {
  167. success: function (x,o) {
  168. globalYui.log("RAW JSON DATA: " + o.responseText);
  169. // Process the JSON data returned from the server
  170. try {
  171. setupNodesJson = globalYui.JSON.parse(o.responseText);
  172. } catch (e) {
  173. alert("JSON Parse failed!");
  174. return;
  175. }
  176. globalYui.log("PARSED DATA: " + globalYui.Lang.dump(setupNodesJson));
  177. if (setupNodesJson.result != 0) {
  178. // Error!
  179. alert("Got error!" + setupNodesJson.error);
  180. return;
  181. }
  182. setupNodesJson = setupNodesJson.response;
  183. hideLoadingImg();
  184. globalYui.one("#blackScreenDivId").setStyle("display", "block");
  185. renderProgress( setupNodesJson );
  186. },
  187. failure: function (x,o) {
  188. alert("Async call failed!");
  189. }
  190. }
  191. });
  192. });