yarn.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. var objectUtils = require('utils/object_utils');
  19. App.YARNService = App.Service.extend({
  20. version: DS.attr('string'),
  21. resourceManagerNode: DS.belongsTo('App.Host'),
  22. nodeManagerNodes: function () {
  23. return this.get('hostComponents').filterProperty('componentName', 'NODEMANAGER');
  24. }.property('hostComponents.@each'),
  25. nodeManagerLiveNodes: DS.hasMany('App.Host'),
  26. nodeManagersCountActive: DS.attr('number'),
  27. nodeManagersCountUnhealthy: DS.attr('number'),
  28. nodeManagersCountRebooted: DS.attr('number'),
  29. nodeManagersCountDecommissioned: DS.attr('number'),
  30. containersAllocated: DS.attr('number'),
  31. containersPending: DS.attr('number'),
  32. containersReserved: DS.attr('number'),
  33. appsSubmitted: DS.attr('number'),
  34. appsRunning: DS.attr('number'),
  35. appsPending: DS.attr('number'),
  36. appsCompleted: DS.attr('number'),
  37. appsKilled: DS.attr('number'),
  38. appsFailed: DS.attr('number'),
  39. yarnClientNodes: function(){
  40. return this.get('hostComponents').filterProperty('componentName', 'YARN_CLIENT').mapProperty('host');
  41. }.property('hostComponents.length'),
  42. resourceManagerStartTime: DS.attr('number'),
  43. jvmMemoryHeapUsed: DS.attr('number'),
  44. jvmMemoryHeapMax: DS.attr('number'),
  45. allocatedMemory: DS.attr('number'),
  46. reservedMemory: DS.attr('number'),
  47. availableMemory: DS.attr('number'),
  48. queue: DS.attr('string'),
  49. queueFormatted: function() {
  50. var queue = JSON.parse(this.get('queue'));
  51. return objectUtils.recursiveTree(queue);
  52. }.property('queue'),
  53. queuesCount: function() {
  54. var queue = JSON.parse(this.get('queue'));
  55. return objectUtils.recursiveKeysCount(queue);
  56. }.property('queue'),
  57. allQueueNames: [],
  58. childQueueNames: [],
  59. /**
  60. * Provides a flat array of queue names.
  61. * Example: root, root/default
  62. */
  63. maxMemory: function() {
  64. return this.get('allocatedMemory') + this.get('availableMemory');
  65. }.property('allocatedMemory','availableMemory'),
  66. queueNames: function () {
  67. var queueString = this.get('queue');
  68. var allQueueNames = [];
  69. var childQueueNames = [];
  70. if (queueString != null) {
  71. var queues = JSON.parse(queueString);
  72. var addQueues = function (queuesObj, path){
  73. var names = [];
  74. for ( var subQueue in queuesObj) {
  75. if (queuesObj[subQueue] instanceof Object) {
  76. var qFN = path=='' ? subQueue : path+'/'+subQueue;
  77. names.push(qFN);
  78. var subNames = addQueues(queuesObj[subQueue], qFN);
  79. names = names.concat(subNames);
  80. if (!subNames || subNames.length < 1) {
  81. childQueueNames.push(qFN);
  82. }
  83. }
  84. }
  85. return names;
  86. }
  87. allQueueNames = addQueues(queues, '');
  88. }
  89. this.set('allQueueNames', allQueueNames);
  90. this.set('childQueueNames', childQueueNames);
  91. }.observes('queue'),
  92. /**
  93. * ResourceManager's lost count is not accurate once RM is rebooted. Since
  94. * Ambari knows the total number of nodes and the counts of nodes in other
  95. * states, we calculate the lost count.
  96. */
  97. nodeManagersCountLost: function () {
  98. var allNMs = this.get('nodeManagerNodes');
  99. var totalCount = allNMs != null ? allNMs.get('length') : 0;
  100. var activeCount = this.get('nodeManagersCountActive');
  101. var rebootedCount = this.get('nodeManagersCountRebooted');
  102. var unhealthyCount = this.get('nodeManagersCountUnhealthy');
  103. var decomCount = this.get('nodeManagersCountDecommissioned');
  104. var nonLostHostsCount = activeCount + rebootedCount + decomCount + unhealthyCount;
  105. return totalCount >= nonLostHostsCount ? totalCount - nonLostHostsCount : 0;
  106. }.property('nodeManagerNodes', 'nodeManagersCountActive', 'nodeManagersCountRebooted', 'nodeManagersCountUnhealthy', 'nodeManagersCountDecommissioned')
  107. });
  108. App.YARNService.FIXTURES = [];