capacity-queue.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. export default DS.JSONAPISerializer.extend({
  20. normalizeSingleResponse(store, primaryModelClass, payload, id,
  21. requestType) {
  22. var children = [];
  23. if (payload.queues) {
  24. payload.queues.queue.forEach(function(queue) {
  25. children.push(queue.queueName);
  26. });
  27. }
  28. var includedData = [];
  29. var relationshipUserData = [];
  30. // update user models
  31. if (payload.users && payload.users.user) {
  32. payload.users.user.forEach(function(u) {
  33. includedData.push({
  34. type: "YarnUser",
  35. id: u.username + "_" + payload.queueName,
  36. attributes: {
  37. name: u.username,
  38. queueName: payload.queueName,
  39. usedMemoryMB: u.resourcesUsed.memory || 0,
  40. usedVCore: u.resourcesUsed.vCores || 0,
  41. }
  42. });
  43. relationshipUserData.push({
  44. type: "YarnUser",
  45. id: u.username + "_" + payload.queueName,
  46. });
  47. });
  48. }
  49. var fixedPayload = {
  50. id: id,
  51. type: primaryModelClass.modelName, // yarn-queue
  52. attributes: {
  53. name: payload.queueName,
  54. parent: payload.myParent,
  55. children: children,
  56. capacity: payload.capacity,
  57. usedCapacity: payload.usedCapacity,
  58. maxCapacity: payload.maxCapacity,
  59. absCapacity: payload.absoluteCapacity,
  60. absMaxCapacity: payload.absoluteMaxCapacity,
  61. absUsedCapacity: payload.absoluteUsedCapacity,
  62. state: payload.state,
  63. userLimit: payload.userLimit,
  64. userLimitFactor: payload.userLimitFactor,
  65. preemptionDisabled: payload.preemptionDisabled,
  66. numPendingApplications: payload.numPendingApplications,
  67. numActiveApplications: payload.numActiveApplications,
  68. resources: payload.resources,
  69. type: "capacity",
  70. },
  71. // Relationships
  72. relationships: {
  73. users: {
  74. data: relationshipUserData
  75. }
  76. }
  77. };
  78. return {
  79. queue: this._super(store, primaryModelClass, fixedPayload, id, requestType),
  80. includedData: includedData
  81. };
  82. },
  83. handleQueue(store, primaryModelClass, payload, id, requestType) {
  84. var data = [];
  85. var includedData = [];
  86. var result = this.normalizeSingleResponse(store, primaryModelClass,
  87. payload, id, requestType);
  88. data.push(result.queue);
  89. includedData = includedData.concat(result.includedData);
  90. if (payload.queues) {
  91. for (var i = 0; i < payload.queues.queue.length; i++) {
  92. var queue = payload.queues.queue[i];
  93. queue.myParent = payload.queueName;
  94. var childResult = this.handleQueue(store, primaryModelClass, queue,
  95. queue.queueName,
  96. requestType);
  97. data = data.concat(childResult.data);
  98. includedData = includedData.concat(childResult.includedData);
  99. }
  100. }
  101. return {
  102. data: data,
  103. includedData: includedData
  104. };
  105. },
  106. normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
  107. var normalizedArrayResponse = {};
  108. var result = this.handleQueue(store, primaryModelClass,
  109. payload.scheduler.schedulerInfo, "root", requestType);
  110. normalizedArrayResponse.data = result.data;
  111. normalizedArrayResponse.included = result.includedData;
  112. return normalizedArrayResponse;
  113. }
  114. });