yarn-container-log.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: 'http://localhost:1337/',
  30. namespace: 'ws/v1/node',
  31. urlForFindRecord(id, modelName, snapshot) {
  32. var splits = Converter.splitForContainerLogs(id);
  33. var nodeHttpAddr = splits[0];
  34. var containerId = splits[1];
  35. var filename = splits[2];
  36. this.host = this.host + nodeHttpAddr;
  37. var url = this._buildURL();
  38. url = url + "/containerlogs/" + containerId + "/" + filename;
  39. return url;
  40. },
  41. ajax(url, method, hash) {
  42. hash = hash || {};
  43. hash.crossDomain = true;
  44. hash.xhrFields = {withCredentials: true};
  45. hash.targetServer = "NM";
  46. return this._super(url, method, hash);
  47. },
  48. /**
  49. * Override options so that result is not expected to be JSON
  50. */
  51. ajaxOptions: function (url, type, options) {
  52. var hash = options || {};
  53. hash.url = url;
  54. hash.type = type;
  55. // Make sure jQuery does not try to convert response to JSON.
  56. hash.dataType = 'text';
  57. hash.context = this;
  58. var headers = Ember.get(this, 'headers');
  59. if (headers != undefined) {
  60. hash.beforeSend = function (xhr) {
  61. Object.keys(headers).forEach(function (key) {
  62. return xhr.setRequestHeader(key, headers[key]);
  63. });
  64. };
  65. }
  66. return hash;
  67. },
  68. });