yarn-app-attempt.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 Ember from 'ember';
  19. import DS from 'ember-data';
  20. import Converter from 'yarn-ui/utils/converter';
  21. export default DS.Model.extend({
  22. startTime: DS.attr('string'),
  23. startedTime: DS.attr('string'),
  24. finishedTime: DS.attr('string'),
  25. containerId: DS.attr('string'),
  26. amContainerId: DS.attr('string'),
  27. nodeHttpAddress: DS.attr('string'),
  28. nodeId: DS.attr('string'),
  29. hosts: DS.attr('string'),
  30. logsLink: DS.attr('string'),
  31. state: DS.attr('string'),
  32. appAttemptId: DS.attr('string'),
  33. appId: Ember.computed("id",function () {
  34. var id = this.get("id");
  35. id = id.split("_");
  36. id[0] = "application";
  37. id.pop();
  38. return id.join("_");
  39. }),
  40. attemptStartedTime: function() {
  41. var startTime = this.get("startTime");
  42. // If startTime variable is not present, get from startedTime
  43. if (startTime === undefined ||
  44. startTime === "Invalid date") {
  45. startTime = this.get("startedTime");
  46. }
  47. return startTime;
  48. }.property("startedTime"),
  49. startTs: function() {
  50. return Converter.dateToTimeStamp(this.get('attemptStartedTime'));
  51. }.property("startTime"),
  52. finishedTs: function() {
  53. var ts = Converter.dateToTimeStamp(this.get("finishedTime"));
  54. return ts;
  55. }.property("finishedTime"),
  56. validatedFinishedTs: function() {
  57. if (this.get("finishedTs") < this.get("startTs")) {
  58. return "";
  59. }
  60. return this.get("finishedTime");
  61. }.property("finishedTime"),
  62. shortAppAttemptId: function() {
  63. if (!this.get("containerId")) {
  64. return this.get("id");
  65. }
  66. return "attempt_" +
  67. parseInt(Converter.containerIdToAttemptId(this.get("containerId")).split("_")[3]);
  68. }.property("containerId"),
  69. appMasterContainerId: function() {
  70. var id = this.get("containerId");
  71. // If containerId variable is not present, get from amContainerId
  72. if (id === undefined) {
  73. id = this.get("amContainerId");
  74. }
  75. return id;
  76. }.property("amContainerId"),
  77. IsAmNodeUrl: function() {
  78. var url = this.get("nodeHttpAddress");
  79. // If nodeHttpAddress variable is not present, hardcode it.
  80. if (url === undefined) {
  81. url = "Not Available";
  82. }
  83. return url !== "Not Available";
  84. }.property("nodeHttpAddress"),
  85. amNodeId : function() {
  86. var id = this.get("nodeId");
  87. // If nodeId variable is not present, get from host
  88. if (id === undefined) {
  89. id = this.get("hosts");
  90. }
  91. return id;
  92. }.property("nodeId"),
  93. IsLinkAvailable: function() {
  94. var url = this.get("logsLink");
  95. // If logsLink variable is not present, hardcode its.
  96. if (url === undefined) {
  97. url = "Not Available";
  98. }
  99. return url !== "Not Available";
  100. }.property("logsLink"),
  101. elapsedTime: function() {
  102. var elapsedMs = this.get("finishedTs") - this.get("startTs");
  103. if (elapsedMs <= 0) {
  104. elapsedMs = Date.now() - this.get("startTs");
  105. }
  106. return Converter.msToElapsedTime(elapsedMs);
  107. }.property(),
  108. tooltipLabel: function() {
  109. return "<p>Id:" + this.get("id") +
  110. "</p><p>ElapsedTime:" +
  111. String(this.get("elapsedTime")) + "</p>";
  112. }.property(),
  113. link: function() {
  114. return "/yarn-app-attempt/" + this.get("id");
  115. }.property(),
  116. linkname: function() {
  117. return "yarn-app-attempt";
  118. }.property(),
  119. attemptState: function() {
  120. return this.get("state");
  121. }.property(),
  122. });