deployProgress.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. function generateLogsContent(errorInfoJson) {
  2. /*
  3. content = '<div id=\"ProgressLogsContainer\">'
  4. for (i=0; i < errorInfoJson['progress'].length; i++) {
  5. var subTxnId = errorInfoJson['progress'][i]['subTxnId'];
  6. var state = errorInfoJson['progress'][i]['state'];
  7. var desc = errorInfoJson['progress'][i]['description'];
  8. var stateClass = 'ProgressLogsSubTxnState' + state;
  9. var subTxnDiv = '<div id=\"'
  10. + 'ProgressLogsSubTxnContainer' + subTxnId + 'Id\"'
  11. + ' class=\"ProgressLogsSubTxnContainer ' + stateClass + ' \" name=\"' + desc + '\">';
  12. for (hostName in errorInfoJson['logs'][subTxnId]['nodeLogs']) {
  13. var nodeReport = errorInfoJson['logs'][subTxnId]['nodeLogs'][hostName];
  14. var hostState = nodeReport['overall'];
  15. var hostStateClass = 'ProgressLogsSubTxnNodeState' + hostState;
  16. var reportContainer = '<div id=\"ProgressLogsSubTxnNodeContainer' + subTxnId + hostName + 'Id\"'
  17. + ' class=\"ProgressLogsSubTxnNodeContainer ' + hostStateClass + '\"' + ' name=\"' + hostName + '\">'
  18. + '<div class=\"ProgressLogsSubTxnNodeContainerLogs\">'
  19. + globalYui.JSON.stringify(nodeReport.message)
  20. + '</div>'
  21. + '</div>' + '<br/>'
  22. subTxnDiv += reportContainer;
  23. }
  24. subTxnDiv += '</div>' + '<br/>';
  25. content += subTxnDiv;
  26. }
  27. content += '</div>';
  28. return content;
  29. */
  30. return '<pre>' +
  31. globalYui.JSON.stringify( errorInfoJson.logs, null, 4 ) +
  32. '</pre>';
  33. }
  34. function renderDeployProgress (deployProgressInfo) {
  35. hideLoadingImg();
  36. /* At this point, our users are done with the installation wizard
  37. * and have asked for a deploy, so there's no going back - remove
  38. * all traces of #installationWizardProgressBarDivId.
  39. */
  40. var installationWizardProgressBarDiv = globalYui.one('#installationWizardProgressBarDivId');
  41. /* But be safe and perform this removal only if #installationWizardProgressBarDivId
  42. * actually exists on the page - this .js file is now being used in more
  43. * than one place, so this robustness is needed.
  44. */
  45. if (installationWizardProgressBarDiv) {
  46. installationWizardProgressBarDiv.setStyle('display', 'none')
  47. }
  48. var hmcRestartMsg = '';
  49. if (deployProgressInfo.nagiosGangliaCoHosted != null
  50. && deployProgressInfo.nagiosGangliaCoHosted) {
  51. hmcRestartMsg = '<span style="color:red"><strong>Note:</strong> You need to restart HMC as'
  52. + ' Nagios/Ganglia are co-hosted on this server.<br>Please restart'
  53. + ' HMC using \"service hmc restart\".</span><br>After that is done, ';
  54. } else {
  55. hmcRestartMsg = 'Please ';
  56. }
  57. hmcRestartMsg +=
  58. '<a href="javascript:void(null)" id="clustersListLinkId">' +
  59. 'click here to start managing your cluster.' +
  60. '</a>';
  61. var deployProgressStatusMessage = {
  62. success:
  63. '<p>' +
  64. 'Your cluster is ready! <br/>' + hmcRestartMsg +
  65. '</p>',
  66. failure:
  67. '<p>' +
  68. 'Failed to finish setting up the cluster.<br>Take a look at the ' +
  69. '<a href="javascript:void(null)" id="showDeployTxnLogsLinkId">deploy logs</a>' +
  70. ' to find out what might have gone wrong.' +
  71. '<a href="javascript:void(null)" class="btn btn-large" style="margin-top:10px" id="restartInstallationWizardLinkId">' +
  72. 'Reinstall Cluster' +
  73. '</a>' +
  74. '</p>'
  75. };
  76. var deployProgressPostCompletionFixup = {
  77. success: function( txnProgressWidget ) {
  78. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  79. document.location.href = generateHMCUrl();
  80. });
  81. },
  82. failure: function( txnProgressWidget ) {
  83. globalYui.one("#restartInstallationWizardLinkId").on( "click", function(e) {
  84. document.location.href = 'installFailed.php';
  85. });
  86. /* Create the panel that'll display our error info. */
  87. var errorInfoPanel =
  88. createInformationalPanel( '#informationalPanelContainerDivId', 'Deploy Logs' );
  89. /* Prime the panel to start off showing our stock loading image. */
  90. var errorInfoPanelBodyContent =
  91. '<img id="errorInfoPanelLoadingImgId" class="loadingImg" src="../images/loading.gif" />';
  92. /* Make the call to our backend to fetch the report for this txnId. */
  93. globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' +
  94. txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId, {
  95. timeout: 10000,
  96. on: {
  97. success: function (x,o) {
  98. globalYui.log("RAW JSON DATA: " + o.responseText);
  99. var errorInfoJson = null;
  100. // Process the JSON data returned from the server
  101. try {
  102. errorInfoJson = globalYui.JSON.parse(o.responseText);
  103. }
  104. catch (e) {
  105. alert("JSON Parse failed!");
  106. return;
  107. }
  108. /* TODO XXX Remove some of the noise from this to allow
  109. * for better corelation - for now, just dump a
  110. * pretty-printed version of the returned JSON.
  111. */
  112. errorInfoPanelBodyContent = generateLogsContent(errorInfoJson);
  113. /* Update the contents of errorInfoPanel (which was, till
  114. * now, showing the loading image).
  115. */
  116. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  117. },
  118. failure: function (x,o) {
  119. alert("Async call failed!");
  120. }
  121. }
  122. });
  123. /* Register a click-handler for #showDeployTxnLogsLinkId to render
  124. * the contents inside errorInfoPanel (and make it visible).
  125. */
  126. globalYui.one("#showDeployTxnLogsLinkId").on( "click", function(e) {
  127. errorInfoPanel.set( 'centered', true );
  128. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  129. errorInfoPanel.show();
  130. });
  131. }
  132. };
  133. var deployProgressWidget = new TxnProgressWidget
  134. ( deployProgressInfo, 'Cluster Deploy', deployProgressStatusMessage, deployProgressPostCompletionFixup );
  135. deployProgressWidget.show();
  136. }