uninstallProgress.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 generateLogsContent(errorInfoJson) {
  22. /*
  23. content = '<div id=\"ProgressLogsContainer\">'
  24. for (i=0; i < errorInfoJson['progress'].length; i++) {
  25. var subTxnId = errorInfoJson['progress'][i]['subTxnId'];
  26. var state = errorInfoJson['progress'][i]['state'];
  27. var desc = errorInfoJson['progress'][i]['description'];
  28. var stateClass = 'ProgressLogsSubTxnState' + state;
  29. var subTxnDiv = '<div id=\"'
  30. + 'ProgressLogsSubTxnContainer' + subTxnId + 'Id\"'
  31. + ' class=\"ProgressLogsSubTxnContainer ' + stateClass + ' \" name=\"' + desc + '\">';
  32. for (hostName in errorInfoJson['logs'][subTxnId]['nodeLogs']) {
  33. var nodeReport = errorInfoJson['logs'][subTxnId]['nodeLogs'][hostName];
  34. var hostState = nodeReport['overall'];
  35. var hostStateClass = 'ProgressLogsSubTxnNodeState' + hostState;
  36. var reportContainer = '<div id=\"ProgressLogsSubTxnNodeContainer' + subTxnId + hostName + 'Id\"'
  37. + ' class=\"ProgressLogsSubTxnNodeContainer ' + hostStateClass + '\"' + ' name=\"' + hostName + '\">'
  38. + '<div class=\"ProgressLogsSubTxnNodeContainerLogs\">'
  39. + globalYui.JSON.stringify(nodeReport.message)
  40. + '</div>'
  41. + '</div>' + '<br/>'
  42. subTxnDiv += reportContainer;
  43. }
  44. subTxnDiv += '</div>' + '<br/>';
  45. content += subTxnDiv;
  46. }
  47. content += '</div>';
  48. return content;
  49. */
  50. return '<pre>' +
  51. globalYui.JSON.stringify( errorInfoJson.logs, null, 4 ) +
  52. '</pre>';
  53. }
  54. function renderUninstallProgress (uninstallProgressInfo) {
  55. hideLoadingImg();
  56. var uninstallProgressStatusMessage = {
  57. success:
  58. '<p>' +
  59. 'Uninstalled the cluster successfully.' +
  60. '<a href="javascript:void(null)" style="margin-left:20px" class="btn btn-large" id="clustersListLinkId">' +
  61. 'Continue' +
  62. '</a>' +
  63. '</p>',
  64. failure:
  65. '<p>' +
  66. 'There was a problem with uninstall.<br />Take a look at ' +
  67. '<a href="javascript:void(null)" id="showUninstallTxnLogsLinkId">Uninstall Logs</a>' +
  68. ' to see what might have happened.<br>' +
  69. '<a href="javascript:void(null)" class="btn btn-large" style="margin-top:10px" id="clustersListLinkId">' +
  70. 'Close' +
  71. '</a>' +
  72. '</p>'
  73. };
  74. var uninstallProgressPostCompletionFixup = {
  75. success: function( txnProgressWidget ) {
  76. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  77. document.location.href = generateHMCUrl();
  78. });
  79. },
  80. failure: function( txnProgressWidget ) {
  81. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  82. document.location.href = generateHMCUrl();
  83. });
  84. /* Create the panel that'll display our error info. */
  85. var errorInfoPanel =
  86. createInformationalPanel( '#informationalPanelContainerDivId', 'Uninstall Logs' );
  87. /* Prime the panel to start off showing our stock loading image. */
  88. var errorInfoPanelBodyContent =
  89. '<img id=errorInfoPanelLoadingImgId class=loadingImg src=../images/loading.gif />';
  90. /* Make the call to our backend to fetch the report for this txnId. */
  91. globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' +
  92. txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId, {
  93. timeout: 10000,
  94. on: {
  95. success: function (x,o) {
  96. globalYui.log("RAW JSON DATA: " + o.responseText);
  97. var errorInfoJson = null;
  98. // Process the JSON data returned from the server
  99. try {
  100. errorInfoJson = globalYui.JSON.parse(o.responseText);
  101. }
  102. catch (e) {
  103. alert("JSON Parse failed!");
  104. return;
  105. }
  106. /* TODO XXX Remove some of the noise from this to allow
  107. * for better corelation - for now, just dump a
  108. * pretty-printed version of the returned JSON.
  109. */
  110. errorInfoPanelBodyContent = generateLogsContent(errorInfoJson);
  111. /* Update the contents of errorInfoPanel (which was, till
  112. * now, showing the loading image).
  113. */
  114. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  115. },
  116. failure: function (x,o) {
  117. alert("Async call failed!");
  118. }
  119. }
  120. });
  121. globalYui.one("#showUninstallTxnLogsLinkId").on( "click", function(e) {
  122. errorInfoPanel.set( 'centered', true);
  123. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  124. errorInfoPanel.show();
  125. });
  126. }
  127. };
  128. var uninstallProgressWidget = new TxnProgressWidget
  129. ( uninstallProgressInfo, 'Uninstall Cluster', uninstallProgressStatusMessage, uninstallProgressPostCompletionFixup );
  130. uninstallProgressWidget.show();
  131. }