deployProgress.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 generateClustersListUrl( clusterName ) {
  35. var url = '';
  36. var currentUrl = window.location.href;
  37. globalYui.log('Current URL: ' + currentUrl);
  38. var currentPathPos = currentUrl.indexOf(window.location.pathname);
  39. globalYui.log('Current Path Pos: ' + currentPathPos);
  40. if( -1 != currentPathPos ) {
  41. /*
  42. url = currentUrl.substr(0, currentPathPos) +
  43. '/hmc/html/manageServices.php?clusterName=' + clusterName;
  44. globalYui.log('Services Page URL: ' + url);
  45. */
  46. // ClusterName is no longer needed
  47. url = currentUrl.substr(0, currentPathPos) + '/hmc/html/index.php';
  48. }
  49. return url;
  50. }
  51. function renderDeployProgress (deployProgressInfo) {
  52. hideLoadingImg();
  53. /* At this point, our users are done with the installation wizard
  54. * and have asked for a deploy, so there's no going back - remove
  55. * all traces of #installationWizardProgressBarDivId.
  56. */
  57. var installationWizardProgressBarDiv = globalYui.one('#installationWizardProgressBarDivId');
  58. /* But be safe and perform this removal only if #installationWizardProgressBarDivId
  59. * actually exists on the page - this .js file is now being used in more
  60. * than one place, so this robustness is needed.
  61. */
  62. if (installationWizardProgressBarDiv) {
  63. installationWizardProgressBarDiv.setStyle('display', 'none')
  64. }
  65. var hmcRestartMsg = '';
  66. if (deployProgressInfo.nagiosGangliaCoHosted != null
  67. && deployProgressInfo.nagiosGangliaCoHosted) {
  68. hmcRestartMsg = '<strong>Note:</strong> We detected that you need to restart HMC as'
  69. + ' Nagios/Ganglia are co-hosted on this server. <br/>Please restart'
  70. + ' HMC using \"service hmc restart\" and then head ';
  71. } else {
  72. hmcRestartMsg = 'May we be so bold as to suggest heading ';
  73. }
  74. hmcRestartMsg += 'on over to the ' +
  75. '<a href="javascript:void(null)" id=clustersListLinkId>' +
  76. 'Cluster information' +
  77. '</a>' +
  78. ' page?';
  79. var deployProgressStatusMessage = {
  80. success:
  81. '<p style=\"text-align:center\">' +
  82. 'All done with the deploy! <br/>' + hmcRestartMsg +
  83. '</p>',
  84. failure:
  85. '<p>' +
  86. 'We made a boo-boo! Take a look at the ' +
  87. '<a href="javascript:void(null)" id=showDeployTxnLogsLinkId>Deploy Logs</a>' +
  88. '?' +
  89. '</p>'
  90. };
  91. var deployProgressPostCompletionFixup = {
  92. success: function( txnProgressWidget ) {
  93. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  94. window.open( generateClustersListUrl(txnProgressWidget.txnProgressContext.clusterName) );
  95. });
  96. },
  97. failure: function( txnProgressWidget ) {
  98. /* Create the panel that'll display our error info. */
  99. var errorInfoPanel =
  100. createInformationalPanel( '#informationalPanelContainerDivId', 'Deploy Logs' );
  101. /* Prime the panel to start off showing our stock loading image. */
  102. var errorInfoPanelBodyContent =
  103. '<img id=errorInfoPanelLoadingImgId class=loadingImg src=../images/loading.gif />';
  104. /* Make the call to our backend to fetch the report for this txnId. */
  105. globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' +
  106. txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId, {
  107. timeout: 10000,
  108. on: {
  109. success: function (x,o) {
  110. globalYui.log("RAW JSON DATA: " + o.responseText);
  111. var errorInfoJson = null;
  112. // Process the JSON data returned from the server
  113. try {
  114. errorInfoJson = globalYui.JSON.parse(o.responseText);
  115. }
  116. catch (e) {
  117. alert("JSON Parse failed!");
  118. return;
  119. }
  120. /* TODO XXX Remove some of the noise from this to allow
  121. * for better corelation - for now, just dump a
  122. * pretty-printed version of the returned JSON.
  123. */
  124. errorInfoPanelBodyContent = generateLogsContent(errorInfoJson);
  125. /* Update the contents of errorInfoPanel (which was, till
  126. * now, showing the loading image).
  127. */
  128. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  129. },
  130. failure: function (x,o) {
  131. alert("Async call failed!");
  132. }
  133. }
  134. });
  135. var firstTimeShowingErrorInfoPanel = true;
  136. /* Register a click-handler for #showDeployTxnLogsLinkId to render
  137. * the contents inside errorInfoPanel (and make it visible).
  138. */
  139. globalYui.one("#showDeployTxnLogsLinkId").on( "click", function(e) {
  140. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  141. errorInfoPanel.show();
  142. if( firstTimeShowingErrorInfoPanel ) {
  143. globalYui.one('#txnProgressStatusActionsDivId').setContent(
  144. '<a href="javascript:void(null)" id=restartInstallationWizardLinkId>' +
  145. 'Restart The Installation Wizard' +
  146. '</a>' +
  147. '&nbsp; &nbsp; &nbsp;' +
  148. '<a href="javascript:void(null)" id=clustersListLinkId>' +
  149. 'Go Manage The Cluster\'s Services' +
  150. '</a>' );
  151. globalYui.one("#restartInstallationWizardLinkId").on( "click", function(e) {
  152. window.open( window.location.href );
  153. });
  154. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  155. window.open( generateClustersListUrl(txnProgressWidget.txnProgressContext.clusterName) );
  156. });
  157. firstTimeShowingErrorInfoPanel = false;
  158. }
  159. });
  160. }
  161. };
  162. var deployProgressWidget = new TxnProgressWidget
  163. ( deployProgressInfo, deployProgressStatusMessage, deployProgressPostCompletionFixup );
  164. deployProgressWidget.show();
  165. }