deployAddedNodesProgress.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. return '<pre>' +
  23. globalYui.JSON.stringify( errorInfoJson.logs, null, 4 ) +
  24. '</pre>';
  25. }
  26. function renderDeployAddedNodesProgress(progressInfo) {
  27. hideLoadingImg();
  28. /* At this point, our users are done with the installation wizard
  29. * and have asked for a deploy, so there's no going back - remove
  30. * all traces of #installationWizardProgressBarDivId.
  31. */
  32. var installationWizardProgressBarDiv = globalYui.one('#installationWizardProgressBarDivId');
  33. /* But be safe and perform this removal only if #installationWizardProgressBarDivId
  34. * actually exists on the page - this .js file is now being used in more
  35. * than one place, so this robustness is needed.
  36. */
  37. if (installationWizardProgressBarDiv) {
  38. installationWizardProgressBarDiv.setStyle('display', 'none')
  39. }
  40. var progressStatusMessage = {
  41. success:
  42. '<p>' +
  43. 'Successfully added new nodes to your cluster.<br><a href="index.php" id="addMoreNodesSuccessLink" style="margin-top:10px" class="btn btn-large">Continue</a>' +
  44. '</p>',
  45. failure:
  46. '<p>' +
  47. 'Failed to add new nodes to the cluster.<br>Take a look at the ' +
  48. '<a href="javascript:void(null)" id="showDeployTxnLogsLinkId">deploy logs</a>' +
  49. ' to find out what might have gone wrong.' +
  50. '<a href="index.php" class="btn btn-large" style="margin-top:10px" id="addMoreNodesFailedLink">' +
  51. 'Continue' +
  52. '</a>' +
  53. '</p>'
  54. };
  55. var postCompletionFixup = {
  56. failure: function(txnProgressWidget) {
  57. /* Create the panel that'll display our error info. */
  58. var errorInfoPanel =
  59. createInformationalPanel( '#informationalPanelContainerDivId', 'Deploy Logs' );
  60. /* Prime the panel to start off showing our stock loading image. */
  61. var errorInfoPanelBodyContent =
  62. '<img id="errorInfoPanelLoadingImgId" class="loadingImg" src="../images/loading.gif" />';
  63. /* Make the call to our backend to fetch the report for this txnId. */
  64. globalYui.io('../php/frontend/fetchTxnLogs.php?clusterName=' +
  65. txnProgressWidget.txnProgressContext.clusterName + '&txnId=' + txnProgressWidget.txnProgressContext.txnId, {
  66. timeout: 10000,
  67. on: {
  68. success: function (x,o) {
  69. globalYui.log("RAW JSON DATA: " + o.responseText);
  70. var errorInfoJson = null;
  71. // Process the JSON data returned from the server
  72. try {
  73. errorInfoJson = globalYui.JSON.parse(o.responseText);
  74. }
  75. catch (e) {
  76. alert("JSON Parse failed!");
  77. return;
  78. }
  79. /* TODO XXX Remove some of the noise from this to allow
  80. * for better corelation - for now, just dump a
  81. * pretty-printed version of the returned JSON.
  82. */
  83. errorInfoPanelBodyContent = generateLogsContent(errorInfoJson);
  84. /* Update the contents of errorInfoPanel (which was, till
  85. * now, showing the loading image).
  86. */
  87. errorInfoPanel.set( 'bodyContent', errorInfoPanelBodyContent );
  88. },
  89. failure: function (x,o) {
  90. alert("Async call failed!");
  91. }
  92. }
  93. });
  94. /* Register a click-handler for #showDeployTxnLogsLinkId to render
  95. * the contents inside errorInfoPanel (and make it visible).
  96. */
  97. globalYui.one("#showDeployTxnLogsLinkId").on( "click", function(e) {
  98. errorInfoPanel.set('bodyContent', errorInfoPanelBodyContent);
  99. errorInfoPanel.show();
  100. });
  101. }
  102. };
  103. var progressWidget = new TxnProgressWidget(progressInfo, 'Add Nodes Progress', progressStatusMessage, postCompletionFixup);
  104. progressWidget.show();
  105. }