yarn-rm-node.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 Ember from 'ember';
  19. import DS from 'ember-data';
  20. import Converter from 'yarn-ui/utils/converter';
  21. export default DS.JSONAPISerializer.extend({
  22. internalNormalizeSingleResponse(store, primaryModelClass, payload, id) {
  23. if (payload.node) {
  24. payload = payload.node;
  25. }
  26. var fixedPayload = {
  27. id: id,
  28. type: primaryModelClass.modelName,
  29. attributes: {
  30. rack: payload.rack,
  31. state: payload.state,
  32. nodeHostName: payload.nodeHostName,
  33. nodeHTTPAddress: payload.nodeHTTPAddress,
  34. lastHealthUpdate: Converter.timeStampToDate(payload.lastHealthUpdate),
  35. healthReport: payload.healthReport,
  36. numContainers: payload.numContainers,
  37. usedMemoryMB: payload.usedMemoryMB,
  38. availMemoryMB: payload.availMemoryMB,
  39. usedVirtualCores: payload.usedVirtualCores,
  40. availableVirtualCores: payload.availableVirtualCores,
  41. version: payload.version,
  42. nodeLabels: payload.nodeLabels
  43. }
  44. };
  45. return fixedPayload;
  46. },
  47. normalizeSingleResponse(store, primaryModelClass, payload, id,
  48. requestType) {
  49. // payload is of the form {"nodeInfo":{}}
  50. var p = this.internalNormalizeSingleResponse(store,
  51. primaryModelClass, payload, id);
  52. return { data: p };
  53. },
  54. normalizeArrayResponse(store, primaryModelClass, payload, id,
  55. requestType) {
  56. // expected response is of the form { data: [ {}, {} ] }
  57. var normalizedArrayResponse = {};
  58. if (payload.nodes) {
  59. // payload is of the form { "nodes": { "node": [ {},{},{} ] } }
  60. normalizedArrayResponse.data = payload.nodes.node.map(singleNode => {
  61. return this.internalNormalizeSingleResponse(store, primaryModelClass,
  62. singleNode, singleNode.id);
  63. }, this);
  64. } else {
  65. normalizedArrayResponse.data = Ember.makeArray({
  66. id: "dummy",
  67. type: primaryModelClass.modelName,
  68. attributes: {}});
  69. }
  70. return normalizedArrayResponse;
  71. }
  72. });