yarn-container-log.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. import DS from 'ember-data';
  19. import Ember from 'ember';
  20. import Converter from 'yarn-ui/utils/converter';
  21. /**
  22. * REST URL's response when fetching container logs will be
  23. * in plain text format and not JSON.
  24. */
  25. export default DS.RESTAdapter.extend({
  26. headers: {
  27. Accept: 'text/plain'
  28. },
  29. host: Ember.computed("address", function () {
  30. return this.get(`hosts.localBaseAddress`);
  31. }),
  32. namespace: Ember.computed("restNameSpace", function () {
  33. return this.get(`env.app.namespaces.node`);
  34. }),
  35. urlForFindRecord(id, modelName, snapshot) {
  36. var splits = Converter.splitForContainerLogs(id);
  37. var nodeHttpAddr = splits[0];
  38. var containerId = splits[1];
  39. var filename = splits[2];
  40. this.host = this.host + nodeHttpAddr;
  41. var url = this._buildURL();
  42. url = url + "/containerlogs/" + containerId + "/" + filename;
  43. return url;
  44. },
  45. ajax(url, method, hash) {
  46. hash = hash || {};
  47. hash.crossDomain = true;
  48. hash.xhrFields = {withCredentials: true};
  49. hash.targetServer = "NM";
  50. return this._super(url, method, hash);
  51. },
  52. /**
  53. * Override options so that result is not expected to be JSON
  54. */
  55. ajaxOptions: function (url, type, options) {
  56. var hash = options || {};
  57. hash.url = url;
  58. hash.type = type;
  59. // Make sure jQuery does not try to convert response to JSON.
  60. hash.dataType = 'text';
  61. hash.context = this;
  62. var headers = Ember.get(this, 'headers');
  63. if (headers != undefined) {
  64. hash.beforeSend = function (xhr) {
  65. Object.keys(headers).forEach(function (key) {
  66. return xhr.setRequestHeader(key, headers[key]);
  67. });
  68. };
  69. }
  70. return hash;
  71. },
  72. });