deployProgress.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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\". After that is done, ';
  71. } else {
  72. hmcRestartMsg = 'Please ';
  73. }
  74. hmcRestartMsg +=
  75. '<a href="javascript:void(null)" id="clustersListLinkId">' +
  76. 'click here to start managing your cluster.' +
  77. '</a>';
  78. var deployProgressStatusMessage = {
  79. success:
  80. '<p style=\"text-align:center\">' +
  81. 'Your cluster is ready! <br/>' + hmcRestartMsg +
  82. '</p>',
  83. failure:
  84. '<p>' +
  85. 'Failed to finish setting up the cluster. ' +
  86. '<a href="javascript:void(null)" id="showDeployTxnLogsLinkId">Take a look at the deploy logs</a>' +
  87. ' to find out what might have gone wrong.' +
  88. '</p>'
  89. };
  90. var deployProgressPostCompletionFixup = {
  91. success: function( txnProgressWidget ) {
  92. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  93. document.location.href = generateClustersListUrl(txnProgressWidget.txnProgressContext.clusterName);
  94. });
  95. },
  96. failure: function( txnProgressWidget ) {
  97. globalYui.one('#txnProgressStatusActionsDivId').setContent(
  98. '<a href="javascript:void(null)" id=restartInstallationWizardLinkId>' +
  99. 'Reinstall Cluster' +
  100. '</a>'
  101. );
  102. globalYui.one("#restartInstallationWizardLinkId").on( "click", function(e) {
  103. document.location.href = 'installFailed.php';
  104. });
  105. globalYui.one('#txnProgressStatusActionsDivId').setStyle('display','block');
  106. /* Create the panel that'll display our error info. */
  107. var errorInfoPanel =
  108. createInformationalPanel( '#informationalPanelContainerDivId', 'Deploy Logs' );
  109. /* Prime the panel to start off showing our stock loading image. */
  110. var errorInfoPanelBodyContent =
  111. '<img id=errorInfoPanelLoadingImgId class=loadingImg src=../images/loading.gif />';
  112. /* Make the call to our backend to fetch the report for this txnId. */
  113. globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' +
  114. txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId, {
  115. timeout: 10000,
  116. on: {
  117. success: function (x,o) {
  118. globalYui.log("RAW JSON DATA: " + o.responseText);
  119. var errorInfoJson = null;
  120. // Process the JSON data returned from the server
  121. try {
  122. errorInfoJson = globalYui.JSON.parse(o.responseText);
  123. }
  124. catch (e) {
  125. alert("JSON Parse failed!");
  126. return;
  127. }
  128. /* TODO XXX Remove some of the noise from this to allow
  129. * for better corelation - for now, just dump a
  130. * pretty-printed version of the returned JSON.
  131. */
  132. errorInfoPanelBodyContent = generateLogsContent(errorInfoJson);
  133. /* Update the contents of errorInfoPanel (which was, till
  134. * now, showing the loading image).
  135. */
  136. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  137. },
  138. failure: function (x,o) {
  139. alert("Async call failed!");
  140. }
  141. }
  142. });
  143. /* Register a click-handler for #showDeployTxnLogsLinkId to render
  144. * the contents inside errorInfoPanel (and make it visible).
  145. */
  146. globalYui.one("#showDeployTxnLogsLinkId").on( "click", function(e) {
  147. errorInfoPanel.set('centered', true);
  148. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  149. errorInfoPanel.show();
  150. });
  151. }
  152. };
  153. var deployProgressWidget = new TxnProgressWidget
  154. ( deployProgressInfo, deployProgressStatusMessage, deployProgressPostCompletionFixup );
  155. deployProgressWidget.show();
  156. }