sla.utils.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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="label ' + klass + '">' + status + '</span>'
  28. }
  29. function getSLArow(row) {
  30. return [
  31. getSLAStatusLabel(row.slaStatus),
  32. emptyStringIfNull(row.appName),
  33. emptyStringIfNull(row.appType),
  34. '<a href="' + row.appUrl + '#showSla" data-row-selector="true">' + row.id + '</a>',
  35. '<span class="nominalTime">' + emptyStringIfNull(row.nominalTime) + '</span>',
  36. '<span class="expectedStart">' + emptyStringIfNull(row.expectedStart) + '</span>',
  37. '<span class="actualStart">' + emptyStringIfNull(row.actualStart) + '</span>',
  38. '<span class="expectedEnd">' + emptyStringIfNull(row.expectedEnd) + '</span>',
  39. '<span class="actualEnd">' + emptyStringIfNull(row.actualEnd) + '</span>',
  40. emptyStringIfNull(row.expectedDuration),
  41. emptyStringIfNull(row.actualDuration),
  42. emptyStringIfNull(row.jobStatus),
  43. emptyStringIfNull(row.user),
  44. emptyStringIfNull(row.lastModified)
  45. ];
  46. }
  47. function msToTime(millis) {
  48. var s = Math.abs(millis);
  49. var ms = s % 1000;
  50. s = (s - ms) / 1000;
  51. var secs = s % 60;
  52. s = (s - secs) / 60;
  53. var mins = s % 60;
  54. var hrs = (s - mins) / 60;
  55. return (millis < 0 ? "-" : "") + (hrs < 10 ? "0" : "") + hrs + ":" + (mins < 10 ? "0" : "") + mins + ":" + (secs < 10 ? "0" : "") + secs;
  56. }
  57. function updateSLAChart(slaTable, labels, limit) {
  58. $("#slaChart").jHueBlueprint("reset");
  59. var rows = slaTable.fnGetNodes();
  60. for (var i = 0; i < (limit != null && limit < rows.length ? limit : rows.length); i++) {
  61. function getOptions(differenceCellValue, label, color) {
  62. return {
  63. data: [
  64. [moment($(rows[i]).find("span.nominalTime").html()).valueOf(), (moment(differenceCellValue).valueOf() - moment($(rows[i]).find("span.nominalTime").html()).valueOf())]
  65. ],
  66. label: label,
  67. yAxisFormatter: function (val, axis) {
  68. return msToTime(val);
  69. },
  70. type: $.jHueBlueprint.TYPES.POINTCHART,
  71. color: color,
  72. isDateTime: true,
  73. timeFormat: "<span style='color:" + ($(rows[i]).find("td:eq(4)").text().toUpperCase() == "MET" ? $.jHueBlueprint.COLORS.GREEN : $.jHueBlueprint.COLORS.RED) + "'>%Y-%m-%d %H:%M:%S</span>",
  74. fill: false,
  75. height: 300,
  76. tooltipAddon: labels.TOOLTIP_ADDON,
  77. yTooltipFormatter: function (val) {
  78. return msToTime(val);
  79. },
  80. onItemClick: function (pos, item) {
  81. if (item && $(slaTable.fnGetNodes()[item.dataIndex]).find("a").length > 0) {
  82. location.href = $(slaTable.fnGetNodes()[item.dataIndex]).find("a").attr("href");
  83. }
  84. }
  85. }
  86. }
  87. if ($("#slaChart").data('plugin_jHueBlueprint') == null) {
  88. $("#slaChart").jHueBlueprint(getOptions($(rows[i]).find("span.nominalTime").html(), (i == 0 ? labels.NOMINAL_TIME : null), $.jHueBlueprint.COLORS.ORANGE));
  89. }
  90. else {
  91. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.nominalTime").html(), (i == 0 ? labels.NOMINAL_TIME : null), $.jHueBlueprint.COLORS.ORANGE));
  92. }
  93. if ($(rows[i]).find("span.expectedStart").html().trim() != "") {
  94. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.expectedStart").html(), (i == 0 ? labels.EXPECTED_START : null), $.jHueBlueprint.COLORS.BLUE));
  95. }
  96. if ($(rows[i]).find("span.actualStart").html().trim() != "") {
  97. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.actualStart").html(), (i == 0 ? labels.ACTUAL_START : null), $.jHueBlueprint.COLORS.GREEN));
  98. }
  99. if ($(rows[i]).find("span.expectedEnd").html().trim() != "") {
  100. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.expectedEnd").html(), (i == 0 ? labels.EXPECTED_END : null), $.jHueBlueprint.COLORS.FALAFEL));
  101. }
  102. if ($(rows[i]).find("span.actualEnd").html().trim() != "") {
  103. $("#slaChart").jHueBlueprint("add", getOptions($(rows[i]).find("span.actualEnd").html(), (i == 0 ? labels.ACTUAL_END : null), $.jHueBlueprint.COLORS.TURQUOISE));
  104. }
  105. $("#yAxisLabel").removeClass("hide");
  106. }
  107. }