manageServicesProgress.js 6.1 KB

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