capacity-queue.js 4.6 KB

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