yarn.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. appTimelineServerNode: function() {
  23. return this.get('hostComponents').filterProperty('componentName', 'APP_TIMELINE_SERVER').mapProperty('host').objectAt(0);
  24. }.property(),
  25. nodeManagerNodes: function () {
  26. return this.get('hostComponents').filterProperty('componentName', 'NODEMANAGER');
  27. }.property('hostComponents.@each'),
  28. nodeManagersCountActive: DS.attr('number'),
  29. nodeManagersCountUnhealthy: DS.attr('number'),
  30. nodeManagersCountRebooted: DS.attr('number'),
  31. nodeManagersCountDecommissioned: DS.attr('number'),
  32. containersAllocated: DS.attr('number'),
  33. containersPending: DS.attr('number'),
  34. containersReserved: DS.attr('number'),
  35. appsSubmitted: DS.attr('number'),
  36. appsRunning: DS.attr('number'),
  37. appsPending: DS.attr('number'),
  38. appsCompleted: DS.attr('number'),
  39. appsKilled: DS.attr('number'),
  40. appsFailed: DS.attr('number'),
  41. ahsWebPort: function() {
  42. var yarnConf = App.db.getConfigs().findProperty('type', 'yarn-site')
  43. if(yarnConf){
  44. return yarnConf.properties['yarn.timeline-service.webapp.address'].match(/:(\d+)/)[1];;
  45. }
  46. return "8188";
  47. }.property(),
  48. yarnClientNodes: function(){
  49. return this.get('hostComponents').filterProperty('componentName', 'YARN_CLIENT').mapProperty('host');
  50. }.property('hostComponents.length'),
  51. resourceManagerStartTime: DS.attr('number'),
  52. jvmMemoryHeapUsed: DS.attr('number'),
  53. jvmMemoryHeapMax: DS.attr('number'),
  54. allocatedMemory: DS.attr('number'),
  55. reservedMemory: DS.attr('number'),
  56. availableMemory: DS.attr('number'),
  57. queue: DS.attr('string'),
  58. queueFormatted: function() {
  59. var queue = JSON.parse(this.get('queue'));
  60. return objectUtils.recursiveTree(queue);
  61. }.property('queue'),
  62. queuesCount: function() {
  63. var queue = JSON.parse(this.get('queue'));
  64. return objectUtils.recursiveKeysCount(queue);
  65. }.property('queue'),
  66. allQueueNames: [],
  67. childQueueNames: [],
  68. /**
  69. * Provides a flat array of queue names.
  70. * Example: root, root/default
  71. */
  72. maxMemory: function() {
  73. return this.get('allocatedMemory') + this.get('availableMemory');
  74. }.property('allocatedMemory','availableMemory'),
  75. queueNames: function () {
  76. var queueString = this.get('queue');
  77. var allQueueNames = [];
  78. var childQueueNames = [];
  79. if (queueString != null) {
  80. var queues = JSON.parse(queueString);
  81. var addQueues = function (queuesObj, path){
  82. var names = [];
  83. for ( var subQueue in queuesObj) {
  84. if (queuesObj[subQueue] instanceof Object) {
  85. var qFN = path=='' ? subQueue : path+'/'+subQueue;
  86. names.push(qFN);
  87. var subNames = addQueues(queuesObj[subQueue], qFN);
  88. names = names.concat(subNames);
  89. if (!subNames || subNames.length < 1) {
  90. childQueueNames.push(qFN);
  91. }
  92. }
  93. }
  94. return names;
  95. };
  96. allQueueNames = addQueues(queues, '');
  97. }
  98. this.set('allQueueNames', allQueueNames);
  99. this.set('childQueueNames', childQueueNames);
  100. }.observes('queue'),
  101. /**
  102. * ResourceManager's lost count is not accurate once RM is rebooted. Since
  103. * Ambari knows the total number of nodes and the counts of nodes in other
  104. * states, we calculate the lost count.
  105. */
  106. nodeManagersCountLost: function () {
  107. var allNMs = this.get('nodeManagerNodes');
  108. var totalCount = allNMs != null ? allNMs.get('length') : 0;
  109. var activeCount = this.get('nodeManagersCountActive');
  110. var rebootedCount = this.get('nodeManagersCountRebooted');
  111. var unhealthyCount = this.get('nodeManagersCountUnhealthy');
  112. var decomCount = this.get('nodeManagersCountDecommissioned');
  113. var nonLostHostsCount = activeCount + rebootedCount + decomCount + unhealthyCount;
  114. return totalCount >= nonLostHostsCount ? totalCount - nonLostHostsCount : 0;
  115. }.property('nodeManagerNodes', 'nodeManagersCountActive', 'nodeManagersCountRebooted', 'nodeManagersCountUnhealthy', 'nodeManagersCountDecommissioned')
  116. });
  117. App.YARNService.FIXTURES = [];