loader.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /* globals ENV: true */
  19. import Ember from 'ember';
  20. function getTimeLineURL(rmhost) {
  21. var url = window.location.protocol + '//' +
  22. (ENV.hosts.localBaseAddress? ENV.hosts.localBaseAddress + '/' : '') + rmhost;
  23. url += '/conf?name=yarn.timeline-service.reader.webapp.address';
  24. Ember.Logger.log("Get Timeline V2 Address URL: " + url);
  25. return url;
  26. }
  27. function getTimeLineV1URL(rmhost) {
  28. var url = window.location.protocol + '//' +
  29. (ENV.hosts.localBaseAddress? ENV.hosts.localBaseAddress + '/' : '') + rmhost;
  30. url += '/conf?name=yarn.timeline-service.webapp.address';
  31. Ember.Logger.log("Get Timeline V1 Address URL: " + url);
  32. return url;
  33. }
  34. function updateConfigs(application) {
  35. var hostname = window.location.hostname;
  36. var rmhost = hostname + (window.location.port ? ':' + window.location.port: '') + skipTrailingSlash(window.location.pathname);
  37. if(!ENV.hosts.rmWebAddress) {
  38. ENV.hosts.rmWebAddress = rmhost;
  39. } else {
  40. rmhost = ENV.hosts.rmWebAddress;
  41. }
  42. Ember.Logger.log("RM Address: " + rmhost);
  43. if(!ENV.hosts.timelineWebAddress) {
  44. var timelinehost = "";
  45. $.ajax({
  46. type: 'GET',
  47. dataType: 'json',
  48. async: true,
  49. context: this,
  50. url: getTimeLineURL(rmhost),
  51. success: function(data) {
  52. timelinehost = data.property.value;
  53. ENV.hosts.timelineWebAddress = timelinehost;
  54. var address = timelinehost.split(":")[0];
  55. var port = timelinehost.split(":")[1];
  56. Ember.Logger.log("Timeline Address from RM: " + timelinehost);
  57. if(address === "0.0.0.0" || address === "localhost") {
  58. var updatedAddress = hostname + ":" + port;
  59. ENV.hosts.timelineWebAddress = updatedAddress;
  60. Ember.Logger.log("Timeline Updated Address: " + updatedAddress);
  61. }
  62. application.advanceReadiness();
  63. },
  64. error: function() {
  65. application.advanceReadiness();
  66. }
  67. });
  68. } else {
  69. Ember.Logger.log("Timeline Address: " + ENV.hosts.timelineWebAddress);
  70. application.advanceReadiness();
  71. }
  72. if(!ENV.hosts.timelineV1WebAddress) {
  73. var timelinehost = "";
  74. $.ajax({
  75. type: 'GET',
  76. dataType: 'json',
  77. async: true,
  78. context: this,
  79. url: getTimeLineV1URL(rmhost),
  80. success: function(data) {
  81. timelinehost = data.property.value;
  82. ENV.hosts.timelineV1WebAddress = timelinehost;
  83. var address = timelinehost.split(":")[0];
  84. var port = timelinehost.split(":")[1];
  85. Ember.Logger.log("Timeline V1 Address from RM: " + timelinehost);
  86. if(address === "0.0.0.0" || address === "localhost") {
  87. var updatedAddress = hostname + ":" + port;
  88. ENV.hosts.timelineV1WebAddress = updatedAddress;
  89. Ember.Logger.log("Timeline V1 Updated Address: " + updatedAddress);
  90. }
  91. application.advanceReadiness();
  92. },
  93. error: function() {
  94. application.advanceReadiness();
  95. }
  96. });
  97. } else {
  98. Ember.Logger.log("Timeline V1 Address: " + ENV.hosts.timelineV1WebAddress);
  99. application.advanceReadiness();
  100. }
  101. }
  102. export function initialize( application ) {
  103. application.deferReadiness();
  104. updateConfigs(application);
  105. }
  106. export default {
  107. name: 'loader',
  108. before: 'env',
  109. initialize
  110. };
  111. const skipTrailingSlash = function(path) {
  112. path = path.replace('ui2/', '');
  113. return path.replace(/\/$/, '');
  114. };