uninstallProgress.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 renderUninstallProgress (uninstallProgressInfo) {
  52. hideLoadingImg();
  53. var hmcRestartMsg = '';
  54. if (uninstallProgressInfo.nagiosGangliaCoHosted != null
  55. && uninstallProgressInfo.nagiosGangliaCoHosted) {
  56. hmcRestartMsg = '<strong>Note:</strong> We detected that you need to restart HMC as'
  57. + ' Nagios/Ganglia are co-hosted on this server. <br/>Please restart'
  58. + ' HMC using \"service hmc restart\" and then head ';
  59. } else {
  60. hmcRestartMsg = 'May we be so bold as to suggest heading ';
  61. }
  62. hmcRestartMsg += 'on over to the ' +
  63. '<a href="javascript:void(null)" id=clustersListLinkId>' +
  64. 'Cluster information' +
  65. '</a>' +
  66. ' page?';
  67. var uninstallProgressStatusMessage = {
  68. success:
  69. '<p style=\"text-align:center\">' +
  70. 'All done with the uninstall! <br/>' + hmcRestartMsg +
  71. '</p>',
  72. failure:
  73. '<p>' +
  74. 'We made a boo-boo! Take a look at the ' +
  75. '<a href="javascript:void(null)" id=showUninstallTxnLogsLinkId>Uninstall Logs</a>' +
  76. '?' +
  77. '</p>'
  78. };
  79. var uninstallProgressPostCompletionFixup = {
  80. success: function( txnProgressWidget ) {
  81. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  82. window.open( generateClustersListUrl(txnProgressWidget.txnProgressContext.clusterName) );
  83. });
  84. },
  85. failure: function( txnProgressWidget ) {
  86. /* Create the panel that'll display our error info. */
  87. var errorInfoPanel =
  88. createInformationalPanel( '#informationalPanelContainerDivId', 'Uninstall 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. var firstTimeShowingErrorInfoPanel = true;
  124. /* Register a click-handler for #showUninstallTxnLogsLinkId to render
  125. * the contents inside errorInfoPanel (and make it visible).
  126. */
  127. globalYui.one("#showUninstallTxnLogsLinkId").on( "click", function(e) {
  128. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  129. errorInfoPanel.show();
  130. if( firstTimeShowingErrorInfoPanel ) {
  131. globalYui.one('#txnProgressStatusActionsDivId').setContent(
  132. '<a href="javascript:void(null)" id=clustersListLinkId>' +
  133. 'Restart the installation wizard' +
  134. '</a>' );
  135. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  136. window.open( generateClustersListUrl(txnProgressWidget.txnProgressContext.clusterName) );
  137. });
  138. firstTimeShowingErrorInfoPanel = false;
  139. }
  140. });
  141. }
  142. };
  143. var uninstallProgressWidget = new TxnProgressWidget
  144. ( uninstallProgressInfo, uninstallProgressStatusMessage, uninstallProgressPostCompletionFixup );
  145. uninstallProgressWidget.show();
  146. }