sla.utils.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. 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,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. function getSLAStatusLabel(status) {
  17. var klass = "";
  18. if (['MET'].indexOf(status.toUpperCase()) > -1) {
  19. klass = "label-success";
  20. }
  21. else if (['NOT_STARTED', 'IN_PROCESS'].indexOf(status.toUpperCase()) > -1) {
  22. klass = "label-warning";
  23. }
  24. else {
  25. klass = "label-important";
  26. }
  27. return '<span class="slaStatus label ' + klass + '">' + status + '</span>'
  28. }
  29. function getXAxisColor(status) {
  30. if (['MET'].indexOf(status.toUpperCase()) > -1) {
  31. return $.jHueBlueprint.COLORS.GREEN;
  32. }
  33. else if (['NOT_STARTED', 'IN_PROCESS'].indexOf(status.toUpperCase()) > -1) {
  34. return $.jHueBlueprint.COLORS.ORANGE;
  35. }
  36. else {
  37. return $.jHueBlueprint.COLORS.RED;
  38. }
  39. }
  40. function getSLArow(row) {
  41. return [
  42. getSLAStatusLabel(row.slaStatus),
  43. emptyStringIfNull(row.appName),
  44. emptyStringIfNull(row.appType),
  45. '<a href="' + row.appUrl + '#showSla" data-row-selector="true">' + row.id + '</a>',
  46. '<span class="nominalTime">' + emptyStringIfNull(row.nominalTime) + '</span>',
  47. '<span class="expectedStart">' + emptyStringIfNull(row.expectedStart) + '</span>',
  48. '<span class="actualStart">' + emptyStringIfNull(row.actualStart) + '</span>',
  49. '<span class="expectedEnd">' + emptyStringIfNull(row.expectedEnd) + '</span>',
  50. '<span class="actualEnd">' + emptyStringIfNull(row.actualEnd) + '</span>',
  51. emptyStringIfNull(row.expectedDuration),
  52. emptyStringIfNull(row.actualDuration),
  53. emptyStringIfNull(row.jobStatus),
  54. emptyStringIfNull(row.user),
  55. emptyStringIfNull(row.lastModified)
  56. ];
  57. }
  58. function msToTime(millis) {
  59. var s = Math.abs(millis);
  60. var ms = s % 1000;
  61. s = (s - ms) / 1000;
  62. var secs = s % 60;
  63. s = (s - secs) / 60;
  64. var mins = s % 60;
  65. var hrs = (s - mins) / 60;
  66. return (millis < 0 ? "-" : "") + (hrs < 10 ? "0" : "") + hrs + ":" + (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "") + secs;
  67. }
  68. function updateSLAChart(slaTable, labels, limit) {
  69. $("#slaChart").jHueBlueprint("reset");
  70. var rows = slaTable.fnGetNodes();
  71. for (var i = 0; i < (limit != null && limit < rows.length ? limit : rows.length); i++) {
  72. function getOptions(differenceCellValue, label, color) {
  73. return {
  74. data: [
  75. [moment($(rows[i]).find("span.nominalTime").html()).valueOf(), (moment(differenceCellValue).valueOf() - moment($(rows[i]).find("span.nominalTime").html()).valueOf())]
  76. ],
  77. label: label,
  78. yAxisFormatter: function (val, axis) {
  79. return msToTime(val);
  80. },
  81. type: $.jHueBlueprint.TYPES.POINTCHART,
  82. color: color,
  83. isDateTime: true,
  84. timeFormat: "<span data-link='"+ $(rows[i]).find("a").attr("href") +"' style='color:" + getXAxisColor($(rows[i]).find(".slaStatus").text()) + "'>%Y-%m-%d %H:%M:%S</span>",
  85. fill: false,
  86. height: 300,
  87. tooltipAddon: labels.TOOLTIP_ADDON,
  88. yTooltipFormatter: function (val) {
  89. return msToTime(val);
  90. },
  91. onItemClick: function (pos, item) {
  92. if (!item) { // detect if it's a label click
  93. $(".flot-x-axis .tickLabel").each(function(cnt, label){
  94. if (pos.pageX >= $(label).offset().left && pos.pageX <= $(label).offset().left + $(label).width() && pos.pageY >= $(label).offset().top && pos.pageY <= $(label).offset().top + $(label).height()){
  95. location.href = $(label).find("span").data("link");
  96. }
  97. });
  98. }
  99. if (item && $(slaTable.fnGetNodes()[item.dataIndex]).find("a").length > 0) {
  100. location.href = $(slaTable.fnGetNodes()[item.dataIndex]).find("a").attr("href");
  101. }
  102. }
  103. }
  104. }
  105. if ($("#slaChart").data('plugin_jHueBlueprint') == null) {
  106. $("#slaChart").jHueBlueprint(getOptions($(rows[i]).find("span.nominalTime").html(), (i == 0 ? labels.NOMINAL_TIME : null), $.jHueBlueprint.COLORS.ORANGE));
  107. }
  108. else {
  109. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.nominalTime").html(), (i == 0 ? labels.NOMINAL_TIME : null), $.jHueBlueprint.COLORS.ORANGE));
  110. }
  111. if ($(rows[i]).find("span.expectedStart").html().trim() != "") {
  112. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.expectedStart").html(), (i == 0 ? labels.EXPECTED_START : null), $.jHueBlueprint.COLORS.BLUE));
  113. }
  114. if ($(rows[i]).find("span.actualStart").html().trim() != "") {
  115. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.actualStart").html(), (i == 0 ? labels.ACTUAL_START : null), $.jHueBlueprint.COLORS.GREEN));
  116. }
  117. if ($(rows[i]).find("span.expectedEnd").html().trim() != "") {
  118. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.expectedEnd").html(), (i == 0 ? labels.EXPECTED_END : null), $.jHueBlueprint.COLORS.FALAFEL));
  119. }
  120. if ($(rows[i]).find("span.actualEnd").html().trim() != "") {
  121. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.actualEnd").html(), (i == 0 ? labels.ACTUAL_END : null), $.jHueBlueprint.COLORS.TURQUOISE));
  122. }
  123. $("#yAxisLabel").removeClass("hide");
  124. }
  125. }