manageServicesProgress.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. function renderManageServicesProgress( manageServicesProgressInfo ) {
  2. var manageServicesProgressStatusMessage = {
  3. success:
  4. '<p>' +
  5. 'Successfully completed the operation. ' +
  6. '<a href="javascript:void(null)" id=closeManageServicesProgressWidgetLinkId>' +
  7. 'Continue' +
  8. '</a>' +
  9. '</p>',
  10. failure:
  11. '<p>' +
  12. 'Failed to complete the operation. Please ' +
  13. '<a href="javascript:void(null)" id=showManageServicesTxnLogsLinkId>take a look at Operation Logs</a>' +
  14. ' to see what might have gone wrong.' +
  15. '</p>'
  16. };
  17. var manageServicesProgressPostCompletionFixup = {
  18. success: function( txnProgressWidget ) {
  19. /* Register a click-handler for the just-rendered
  20. * #closeManageServicesProgressWidgetLinkId.
  21. *
  22. * Don't worry about this being a double-registration - although
  23. * it looks that way, it's not, because (an identical, but that's
  24. * irrelevant, really) manageServicesProgressStatusMessage.success
  25. * is re-rendered afresh each time through, and thus this
  26. * click-handler must also be re-registered each time 'round.
  27. */
  28. globalYui.one("#closeManageServicesProgressWidgetLinkId").on( "click", function(e) {
  29. var manageServicesUriPath = '/hmc/html/manageServices.php';
  30. var manageServicesUriPathRegEx = new RegExp(manageServicesUriPath);
  31. /* If we're already on manageServicesUriPath, just close the txnProgressWidget. */
  32. if( window.location.pathname.match(manageServicesUriPathRegEx) ) {
  33. txnProgressWidget.hide();
  34. }
  35. /* If not, redirect to manageServicesUriPath. */
  36. else {
  37. document.location.href = generateHMCUrl
  38. ( manageServicesUriPath + '?clusterName=' + txnProgressWidget.txnProgressContext.clusterName );
  39. }
  40. });
  41. /* Resume polling for information about the cluster's services. */
  42. if( typeof fetchClusterServicesPoller != 'undefined' ) {
  43. fetchClusterServicesPoller.start();
  44. }
  45. },
  46. failure: function( txnProgressWidget ) {
  47. /* <-------------------- REZXXX BEGIN -----------------------> */
  48. /* Create the panel that'll display our error info. */
  49. var errorInfoPanel =
  50. createInformationalPanel( '#informationalPanelContainerDivId', 'Operation Logs' );
  51. /* Prime the panel to start off showing our stock loading image. */
  52. var errorInfoPanelBodyContent =
  53. '<img id=errorInfoPanelLoadingImgId class=loadingImg src=../images/loading.gif />';
  54. /* Make the call to our backend to fetch the report for this txnId. */
  55. globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' +
  56. txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId, {
  57. timeout: 10000,
  58. on: {
  59. success: function (x,o) {
  60. globalYui.log("RAW JSON DATA: " + o.responseText);
  61. var errorInfoJson = null;
  62. // Process the JSON data returned from the server
  63. try {
  64. errorInfoJson = globalYui.JSON.parse(o.responseText);
  65. }
  66. catch (e) {
  67. alert("JSON Parse failed!");
  68. return;
  69. }
  70. /* TODO XXX Remove some of the noise from this to allow
  71. * for better corelation - for now, just dump a
  72. * pretty-printed version of the returned JSON.
  73. */
  74. errorInfoPanelBodyContent =
  75. '<pre>' +
  76. globalYui.JSON.stringify( errorInfoJson.logs, null, 4 ) +
  77. '</pre>';
  78. /* Update the contents of errorInfoPanel (which was, till
  79. * now, showing the loading image).
  80. */
  81. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  82. },
  83. failure: function (x,o) {
  84. alert("Async call failed!");
  85. }
  86. }
  87. });
  88. var firstTimeShowingErrorInfoPanel = true;
  89. /* Register a click-handler for #showManageServicesTxnLogsLinkId
  90. * to render the contents inside errorInfoPanel (and make it visible).
  91. */
  92. globalYui.one("#showManageServicesTxnLogsLinkId").on( "click", function(e) {
  93. errorInfoPanel.set( 'centered', true );
  94. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  95. errorInfoPanel.show();
  96. if( firstTimeShowingErrorInfoPanel ) {
  97. globalYui.one('#txnProgressStatusActionsDivId').setContent(
  98. '<a href="javascript:void(null)" id=closeManageServicesProgressWidgetLinkId>' +
  99. 'Close' +
  100. '</a>' );
  101. globalYui.one("#closeManageServicesProgressWidgetLinkId").on( "click", function(e) {
  102. txnProgressWidget.hide();
  103. });
  104. firstTimeShowingErrorInfoPanel = false;
  105. }
  106. });
  107. /* <--------------------- REZXXX END ------------------------> */
  108. if( typeof fetchClusterServicesPoller != 'undefined' ) {
  109. /* Resume polling for information about the cluster's services. */
  110. fetchClusterServicesPoller.start();
  111. }
  112. }
  113. };
  114. var manageServicesProgressWidget = new TxnProgressWidget
  115. ( manageServicesProgressInfo, 'Manage Services', manageServicesProgressStatusMessage, manageServicesProgressPostCompletionFixup );
  116. manageServicesProgressWidget.show();
  117. }