yarn-container.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 Converter from 'yarn-ui/utils/converter';
  20. export default DS.JSONAPISerializer.extend({
  21. internalNormalizeSingleResponse(store, primaryModelClass, payload, id,
  22. requestType) {
  23. var fixedPayload = {
  24. id: payload.containerId,
  25. type: primaryModelClass.modelName, // yarn-app
  26. attributes: {
  27. allocatedMB: payload.allocatedMB,
  28. allocatedVCores: payload.allocatedVCores,
  29. assignedNodeId: payload.assignedNodeId,
  30. priority: payload.priority,
  31. startedTime: Converter.timeStampToDate(payload.startedTime),
  32. finishedTime: Converter.timeStampToDate(payload.finishedTime),
  33. elapsedTime: payload.elapsedTime,
  34. logUrl: payload.logUrl,
  35. containerExitStatus: payload.containerExitStatus,
  36. containerState: payload.containerState,
  37. nodeHttpAddress: payload.nodeHttpAddress
  38. }
  39. };
  40. return fixedPayload;
  41. },
  42. normalizeSingleResponse(store, primaryModelClass, payload, id,
  43. requestType) {
  44. var p = this.internalNormalizeSingleResponse(store,
  45. primaryModelClass, payload, id, requestType);
  46. return { data: p };
  47. },
  48. normalizeArrayResponse(store, primaryModelClass, payload, id,
  49. requestType) {
  50. // return expected is { data: [ {}, {} ] }
  51. var normalizedArrayResponse = {};
  52. if (payload && payload.container) {
  53. if (Array.isArray(payload.container)) {
  54. // payload has apps : { app: [ {},{},{} ] }
  55. // need some error handling for ex apps or app may not be defined.
  56. normalizedArrayResponse.data = payload.container.map(singleContainer => {
  57. return this.internalNormalizeSingleResponse(store, primaryModelClass,
  58. singleContainer, singleContainer.id, requestType);
  59. }, this);
  60. } else {
  61. normalizedArrayResponse.data = [this.internalNormalizeSingleResponse(
  62. store, primaryModelClass, payload.container, payload.container.id,
  63. requestType)];
  64. }
  65. return normalizedArrayResponse;
  66. } else {
  67. normalizedArrayResponse.data = [];
  68. }
  69. return normalizedArrayResponse;
  70. }
  71. });