yarn-node-container.js 2.6 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. export default DS.JSONAPISerializer.extend({
  21. internalNormalizeSingleResponse(store, primaryModelClass, payload) {
  22. if (payload.container) {
  23. payload = payload.container;
  24. }
  25. var fixedPayload = {
  26. id: payload.id,
  27. type: primaryModelClass.modelName,
  28. attributes: {
  29. containerId: payload.id,
  30. state: payload.state,
  31. user: payload.user,
  32. diagnostics: payload.diagnostics,
  33. exitCode: payload.exitCode,
  34. totalMemoryNeeded: payload.totalMemoryNeededMB,
  35. totalVCoresNeeded: payload.totalVCoresNeeded,
  36. containerLogFiles: payload.containerLogFiles
  37. }
  38. };
  39. return fixedPayload;
  40. },
  41. normalizeSingleResponse(store, primaryModelClass, payload, id,
  42. requestType) {
  43. // payload is of the form {"container":{}}
  44. var p = this.internalNormalizeSingleResponse(store,
  45. primaryModelClass, payload);
  46. return { data: p };
  47. },
  48. normalizeArrayResponse(store, primaryModelClass, payload, id,
  49. requestType) {
  50. // expected return response is of the form { data: [ {}, {} ] }
  51. var normalizedArrayResponse = {};
  52. if (payload.containers) {
  53. // payload is of the form { "containers" : { "container": [ {},{},{} ] } }
  54. normalizedArrayResponse.data =
  55. payload.containers.container.map(singleContainer => {
  56. return this.internalNormalizeSingleResponse(store, primaryModelClass,
  57. singleContainer);
  58. }, this);
  59. } else {
  60. // No container reported inside containers.
  61. // Response of the form { "containers": null }
  62. normalizedArrayResponse.data = Ember.makeArray({
  63. id: "dummy",
  64. type: primaryModelClass.modelName,
  65. attributes: {}});
  66. }
  67. return normalizedArrayResponse;
  68. }
  69. });