addNodes.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. doPostUpload = true;
  137. addNodesFilesForm.submit();
  138. globalYui.log("Files submitted to server.");
  139. e.target.set('disabled', false);
  140. });
  141. var setupNodesJson = "";
  142. var doPostUpload = false; // this flag is to prevent the #fileUploadTargetId iframe onload event from being invoked on browser back action
  143. globalYui.one("#fileUploadTargetId").on('load', function (e) {
  144. if (!doPostUpload) {
  145. return;
  146. }
  147. globalYui.log("File upload finished");
  148. if (freshInstall == false) {
  149. // Do checks only in case of addNodesWizard
  150. var myIFrame = globalYui.one("#fileUploadTargetId");
  151. var myIFrameContent = myIFrame.get('contentWindow.document.body');
  152. var content = myIFrameContent.one('pre:first-child');
  153. var responseText = content.get('text');
  154. var responseJson = globalYui.JSON.parse(responseText);
  155. if (responseJson.result != "0") {
  156. // This means we hit an error
  157. if (responseJson.result == "2") {
  158. alert('Got error : ' + responseJson.error);
  159. hideLoadingImg();
  160. return;
  161. } else if (responseJson.result == "3") {
  162. var confirmed = confirm(responseJson.error + "\n\n" + responseJson.hosts + "\n\nPlease click OK if you want to ignore them and continue.");
  163. if (!confirmed) {
  164. hideLoadingImg();
  165. return;
  166. }
  167. } else {
  168. alert('Got and error ' + responseJson.error);
  169. hideLoadingImg();
  170. return;
  171. }
  172. }
  173. }
  174. doPostUpload = false;
  175. var repoFile = '';
  176. var artifactsUrl = '';
  177. var gplArtifactsUrl = '';
  178. if (globalYui.one("#yumMirrorSupportFormButtonId")) {
  179. if (globalYui.one("#yumMirrorSupportFormButtonId").get('checked')) {
  180. // local yum mirror support
  181. repoFile = globalYui.Lang.trim(globalYui.one("#yumRepoFilePathId").get('value'));
  182. artifactsUrl = globalYui.Lang.trim(globalYui.one("#hmcArtifactsDownloadUrlId").get('value'));
  183. gplArtifactsUrl = globalYui.Lang.trim(globalYui.one("#hmcGplArtifactsDownloadUrlId").get('value'));
  184. }
  185. }
  186. var addNodesRequestData = {
  187. "ClusterDeployUser" : globalYui.Lang.trim(globalYui.one("#clusterDeployUserId").get('value')),
  188. "yumRepoFilePath": repoFile,
  189. "hdpArtifactsDownloadUrl" : artifactsUrl,
  190. "gplArtifactsDownloadUrl": gplArtifactsUrl
  191. }
  192. // Trigger the execution of setting up nodes
  193. var url = "../php/frontend/nodesAction.php?clusterName=" + InstallationWizard.AddNodes.renderData.clusterName + "&action=addNodes";
  194. globalYui.io(url, {
  195. method: 'POST',
  196. data: addNodesRequestData,
  197. timeout : 10000,
  198. on: {
  199. success: function (x,o) {
  200. globalYui.log("RAW JSON DATA: " + o.responseText);
  201. // Process the JSON data returned from the server
  202. try {
  203. setupNodesJson = globalYui.JSON.parse(o.responseText);
  204. } catch (e) {
  205. alert("JSON Parse failed!");
  206. return;
  207. }
  208. globalYui.log("PARSED DATA: " + globalYui.Lang.dump(setupNodesJson));
  209. if (setupNodesJson.result != 0) {
  210. // Error!
  211. alert("Got error!" + setupNodesJson.error);
  212. return;
  213. }
  214. setupNodesJson = setupNodesJson.response;
  215. hideLoadingImg();
  216. globalYui.one("#blackScreenDivId").setStyle("display", "block");
  217. renderProgress( setupNodesJson );
  218. },
  219. failure: function (x,o) {
  220. alert("Async call failed!");
  221. }
  222. }
  223. });
  224. });