per-app-memusage-by-nodes-stacked-barchart.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 StackedBarchart from 'yarn-ui/components/stacked-barchart';
  19. import Converter from 'yarn-ui/utils/converter';
  20. export default StackedBarchart.extend({
  21. getDataForRender: function(containers, nodes) {
  22. var arr = [];
  23. var nodeToResources = {};
  24. nodes.forEach(function(n) {
  25. nodeToResources[n.id] =
  26. {
  27. used: Number(n.get("usedMemoryMB")),
  28. avail: Number(n.get("availMemoryMB"))
  29. };
  30. });
  31. containers.forEach(function(c) {
  32. res = nodeToResources[c.get("assignedNodeId")];
  33. if (res) {
  34. if (!res.usedByTheApp) {
  35. res.usedByTheApp = 0;
  36. }
  37. res.usedByTheApp += Number(c.get("allocatedMB"));
  38. }
  39. });
  40. for (var nodeId in nodeToResources) {
  41. var res = nodeToResources[nodeId];
  42. var subArr = [];
  43. var value = res.usedByTheApp ? res.usedByTheApp : 0;
  44. subArr.push({
  45. value: value,
  46. bindText: "This app uses " + Converter.memoryToSimpliedUnit(value) + ". On node=" + nodeId,
  47. });
  48. value = res.used - value;
  49. value = Math.max(value, 0);
  50. subArr.push({
  51. value: value,
  52. bindText: "Other applications uses " + Converter.memoryToSimpliedUnit(value) + ". On node=" + nodeId,
  53. });
  54. subArr.push({
  55. value: res.avail,
  56. bindText: "Free resource " + Converter.memoryToSimpliedUnit(res.avail) + " . On node=" + nodeId
  57. });
  58. arr.push(subArr);
  59. }
  60. console.log(arr);
  61. return arr;
  62. },
  63. didInsertElement: function() {
  64. this.initChart(true);
  65. this.colors = ["Orange", "Grey", "LimeGreen"];
  66. var containers = this.get("rmContainers");
  67. var nodes = this.get("nodes");
  68. var data = this.getDataForRender(containers, nodes);
  69. this.show(
  70. data, this.get("title"), ["Used by this app", "Used by other apps",
  71. "Available"]);
  72. },
  73. });