loader.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 getYarnHttpProtocolScheme(rmhost, application) {
  21. var httpUrl = window.location.protocol + '//' +
  22. (ENV.hosts.localBaseAddress? ENV.hosts.localBaseAddress + '/' : '') + rmhost;
  23. httpUrl += '/conf?name=yarn.http.policy';
  24. Ember.Logger.log("yarn.http.policy URL is: " + httpUrl);
  25. var protocolScheme = "";
  26. $.ajax({
  27. type: 'GET',
  28. dataType: 'json',
  29. async: false,
  30. context: this,
  31. url: httpUrl,
  32. success: function(data) {
  33. protocolScheme = data.property.value;
  34. Ember.Logger.log("Protocol scheme from RM: " + protocolScheme);
  35. application.advanceReadiness();
  36. },
  37. error: function() {
  38. application.advanceReadiness();
  39. }
  40. });
  41. return protocolScheme;
  42. }
  43. function getTimeLineURL(rmhost, isHttpsSchemeEnabled) {
  44. var url = window.location.protocol + '//' +
  45. (ENV.hosts.localBaseAddress? ENV.hosts.localBaseAddress + '/' : '') + rmhost;
  46. if(isHttpsSchemeEnabled) {
  47. url += '/conf?name=yarn.timeline-service.reader.webapp.https.address';
  48. } else {
  49. url += '/conf?name=yarn.timeline-service.reader.webapp.address';
  50. }
  51. Ember.Logger.log("Get Timeline V2 Address URL: " + url);
  52. return url;
  53. }
  54. function getTimeLineV1URL(rmhost, isHttpsSchemeEnabled) {
  55. var url = window.location.protocol + '//' +
  56. (ENV.hosts.localBaseAddress? ENV.hosts.localBaseAddress + '/' : '') + rmhost;
  57. if(isHttpsSchemeEnabled) {
  58. url += '/conf?name=yarn.timeline-service.webapp.https.address';
  59. } else {
  60. url += '/conf?name=yarn.timeline-service.webapp.address';
  61. }
  62. Ember.Logger.log("Get Timeline V1 Address URL: " + url);
  63. return url;
  64. }
  65. function getSecurityURL(rmhost) {
  66. var url = window.location.protocol + '//' +
  67. (ENV.hosts.localBaseAddress? ENV.hosts.localBaseAddress + '/' : '') + rmhost;
  68. url += '/conf?name=hadoop.security.authentication';
  69. Ember.Logger.log("Server security mode url is: " + url);
  70. return url;
  71. }
  72. function updateConfigs(application) {
  73. var hostname = window.location.hostname;
  74. var rmhost = hostname + (window.location.port ? ':' + window.location.port: '') + skipTrailingSlash(window.location.pathname);
  75. if(!ENV.hosts.rmWebAddress) {
  76. ENV.hosts.rmWebAddress = rmhost;
  77. ENV.hosts.protocolScheme = window.location.protocol;
  78. } else {
  79. rmhost = ENV.hosts.rmWebAddress;
  80. }
  81. Ember.Logger.log("RM Address: " + rmhost);
  82. var protocolSchemeFromRM = getYarnHttpProtocolScheme(rmhost, application);
  83. Ember.Logger.log("Is protocol scheme https? " + (protocolSchemeFromRM == "HTTPS_ONLY"));
  84. var isHttpsSchemeEnabled = (protocolSchemeFromRM == "HTTPS_ONLY");
  85. if(!ENV.hosts.timelineWebAddress) {
  86. var timelinehost = "";
  87. $.ajax({
  88. type: 'GET',
  89. dataType: 'json',
  90. async: true,
  91. context: this,
  92. url: getTimeLineURL(rmhost, isHttpsSchemeEnabled),
  93. success: function(data) {
  94. timelinehost = data.property.value;
  95. timelinehost = timelinehost.replace(/(^\w+:|^)\/\//, '');
  96. ENV.hosts.timelineWebAddress = timelinehost;
  97. var address = timelinehost.split(":")[0];
  98. var port = timelinehost.split(":")[1];
  99. Ember.Logger.log("Timeline Address from RM: " + timelinehost);
  100. if(address === "0.0.0.0" || address === "localhost") {
  101. var updatedAddress = hostname + ":" + port;
  102. ENV.hosts.timelineWebAddress = updatedAddress;
  103. Ember.Logger.log("Timeline Updated Address: " + updatedAddress);
  104. }
  105. application.advanceReadiness();
  106. },
  107. error: function() {
  108. application.advanceReadiness();
  109. }
  110. });
  111. } else {
  112. Ember.Logger.log("Timeline Address: " + ENV.hosts.timelineWebAddress);
  113. application.advanceReadiness();
  114. }
  115. if(!ENV.hosts.timelineV1WebAddress) {
  116. var timelinehost = "";
  117. $.ajax({
  118. type: 'GET',
  119. dataType: 'json',
  120. async: false,
  121. context: this,
  122. url: getTimeLineV1URL(rmhost, isHttpsSchemeEnabled),
  123. success: function(data) {
  124. timelinehost = data.property.value;
  125. timelinehost = timelinehost.replace(/(^\w+:|^)\/\//, '');
  126. ENV.hosts.timelineV1WebAddress = timelinehost;
  127. var address = timelinehost.split(":")[0];
  128. var port = timelinehost.split(":")[1];
  129. Ember.Logger.log("Timeline V1 Address from RM: " + timelinehost);
  130. if(address === "0.0.0.0" || address === "localhost") {
  131. var updatedAddress = hostname + ":" + port;
  132. ENV.hosts.timelineV1WebAddress = updatedAddress;
  133. Ember.Logger.log("Timeline V1 Updated Address: " + updatedAddress);
  134. }
  135. application.advanceReadiness();
  136. },
  137. error: function() {
  138. application.advanceReadiness();
  139. }
  140. });
  141. } else {
  142. Ember.Logger.log("Timeline V1 Address: " + ENV.hosts.timelineV1WebAddress);
  143. application.advanceReadiness();
  144. }
  145. if(!ENV.hosts.isSecurityEnabled) {
  146. var isSecurityEnabled = "";
  147. $.ajax({
  148. type: 'GET',
  149. dataType: 'json',
  150. async: false,
  151. context: this,
  152. url: getSecurityURL(rmhost),
  153. success: function(data) {
  154. isSecurityEnabled = data.property.value;
  155. ENV.hosts.isSecurityEnabled = isSecurityEnabled;
  156. Ember.Logger.log("Security mode is : " + isSecurityEnabled);
  157. application.advanceReadiness();
  158. },
  159. error: function() {
  160. application.advanceReadiness();
  161. }
  162. });
  163. } else {
  164. Ember.Logger.log("Security mode is: " + ENV.hosts.isSecurityEnabled);
  165. application.advanceReadiness();
  166. }
  167. }
  168. export function initialize( application ) {
  169. application.deferReadiness();
  170. updateConfigs(application);
  171. }
  172. export default {
  173. name: 'loader',
  174. before: 'env',
  175. initialize
  176. };
  177. const skipTrailingSlash = function(path) {
  178. path = path.replace('ui2/', '');
  179. return path.replace(/\/$/, '');
  180. };