deployProgress.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 renderDeployProgress (deployProgressInfo) {
  55. hideLoadingImg();
  56. /* At this point, our users are done with the installation wizard
  57. * and have asked for a deploy, so there's no going back - remove
  58. * all traces of #installationWizardProgressBarDivId.
  59. */
  60. var installationWizardProgressBarDiv = globalYui.one('#installationWizardProgressBarDivId');
  61. /* But be safe and perform this removal only if #installationWizardProgressBarDivId
  62. * actually exists on the page - this .js file is now being used in more
  63. * than one place, so this robustness is needed.
  64. */
  65. if (installationWizardProgressBarDiv) {
  66. installationWizardProgressBarDiv.setStyle('display', 'none')
  67. }
  68. var hmcRestartMsg = '';
  69. if (deployProgressInfo.nagiosGangliaCoHosted != null
  70. && deployProgressInfo.nagiosGangliaCoHosted) {
  71. hmcRestartMsg = '<span style="color:red"><strong>Note:</strong> You need to restart HMC as'
  72. + ' Nagios/Ganglia are co-hosted on this server.<br>Please restart'
  73. + ' HMC using \"service ambari restart\".</span><br>After that is done, ';
  74. } else {
  75. hmcRestartMsg = 'Please ';
  76. }
  77. hmcRestartMsg +=
  78. '<a href="javascript:void(null)" id="clustersListLinkId">' +
  79. 'click here to start managing your cluster.' +
  80. '</a>';
  81. var deployProgressStatusMessage = {
  82. success:
  83. '<p>' +
  84. 'Your cluster is ready! <br/>' + hmcRestartMsg +
  85. '</p>',
  86. failure:
  87. '<p>' +
  88. 'Failed to finish setting up the cluster.<br>Take a look at the ' +
  89. '<a href="javascript:void(null)" id="showDeployTxnLogsLinkId">deploy logs</a>' +
  90. ' to find out what might have gone wrong.' +
  91. '<a href="javascript:void(null)" class="btn btn-large" style="margin-top:10px" id="restartInstallationWizardLinkId">' +
  92. 'Reinstall Cluster' +
  93. '</a>' +
  94. '</p>'
  95. };
  96. var deployProgressPostCompletionFixup = {
  97. success: function( txnProgressWidget ) {
  98. globalYui.one("#clustersListLinkId").on( "click", function(e) {
  99. document.location.href = generateHMCUrl();
  100. });
  101. },
  102. failure: function( txnProgressWidget ) {
  103. globalYui.one("#restartInstallationWizardLinkId").on( "click", function(e) {
  104. document.location.href = 'installFailed.php';
  105. });
  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, 'Deployment Progress', deployProgressStatusMessage, deployProgressPostCompletionFixup );
  155. deployProgressWidget.show();
  156. }