flume.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 date = require('utils/date');
  19. var sort = require('views/common/sort_view');
  20. App.MainDashboardServiceFlumeView = App.TableView.extend({
  21. templateName: require('templates/main/service/services/flume'),
  22. pagination: false,
  23. isActionsDisabled: true,
  24. isStartAgentDisabled: true,
  25. isStopAgentDisabled: true,
  26. content: function () {
  27. return this.get('service.agents');
  28. }.property('service.agents.length'),
  29. summaryHeader: function () {
  30. var agents = App.FlumeService.find().objectAt(0).get('agents');//this.get('service.agents');
  31. var agentCount = agents.get('length');
  32. var hostCount = agents.mapProperty('host').uniq().get('length');
  33. var prefix = agentCount == 1 ? this.t("dashboard.services.flume.summary.single") :
  34. this.t("dashboard.services.flume.summary.multiple").format(agentCount);
  35. var suffix = hostCount == 1 ? this.t("dashboard.services.flume.summary.hosts.single") :
  36. this.t("dashboard.services.flume.summary.hosts.multiple").format(hostCount);
  37. return prefix + suffix;
  38. }.property('service.agents'),
  39. flumeHandlerComponent: function () {
  40. return App.HostComponent.find().findProperty('componentName', 'FLUME_HANDLER');
  41. }.property(),
  42. agentView: Em.View.extend({
  43. content: null,
  44. tagName: 'tr',
  45. classNameBindings: ['selectedClass'],
  46. selectedClass: function () {
  47. return this.get('controller.selectedFlumeAgent.id') === this.get('content.id') ? 'highlight' : '';
  48. }.property('controller.selectedFlumeAgent'),
  49. click: function () {
  50. this.get('parentView').showAgentInfo(this.get('content'));
  51. }
  52. }),
  53. sortView: sort.wrapperView,
  54. statusSort: sort.fieldView.extend({
  55. column: '1',
  56. name: 'status',
  57. displayName: ''
  58. }),
  59. agentSort: sort.fieldView.extend({
  60. column: '2',
  61. name: 'name',
  62. displayName: Em.I18n.t('dashboard.services.flume.agent')
  63. }),
  64. hostSort: sort.fieldView.extend({
  65. column: '3',
  66. name: 'hostName',
  67. displayName: Em.I18n.t('common.host')
  68. }),
  69. sourceSort: sort.fieldView.extend({
  70. column: '4',
  71. name: 'sourcesCount',
  72. displayName: Em.I18n.t('dashboard.services.flume.sources')
  73. }),
  74. channelSort: sort.fieldView.extend({
  75. column: '5',
  76. name: 'channelsCount',
  77. displayName: Em.I18n.t('dashboard.services.flume.channels')
  78. }),
  79. sinkSort: sort.fieldView.extend({
  80. column: '6',
  81. name: 'sinksCount',
  82. displayName: Em.I18n.t('dashboard.services.flume.sinks')
  83. }),
  84. didInsertElement: function () {
  85. this.set('controller.selectedFlumeAgent', null);
  86. this.filter();
  87. },
  88. /**
  89. * Change classes for dropdown DOM elements after status change of selected agent
  90. */
  91. setActionsDropdownClasses: function () {
  92. var selectedFlumeAgent = this.get('controller.selectedFlumeAgent');
  93. this.set('isActionsDisabled', !selectedFlumeAgent);
  94. if (selectedFlumeAgent) {
  95. this.set('isStartAgentDisabled', selectedFlumeAgent.get('status') !== 'INSTALLED');
  96. this.set('isStopAgentDisabled', selectedFlumeAgent.get('status') !== 'RUNNING');
  97. }
  98. }.observes('controller.selectedFlumeAgent', 'controller.selectedFlumeAgent.status'),
  99. /**
  100. * Action handler from flume tepmlate.
  101. * Highlight selected row and show metrics graphs of selected agent.
  102. *
  103. * @method showAgentInfo
  104. * @param {object} event
  105. */
  106. showAgentInfo: function (agent) {
  107. this.set('controller.selectedFlumeAgent', agent);
  108. this.setAgentMetrics(agent);
  109. },
  110. /**
  111. * Show Flume agent metric.
  112. *
  113. * @method setFlumeAgentMetric
  114. * @param {object} agent - DS.model of agent
  115. */
  116. setAgentMetrics: function(agent) {
  117. var getMetricTitle = function(metricTypeKey, hostName) {
  118. var metricType = Em.I18n.t('services.service.info.metrics.flume.' + metricTypeKey).format(Em.I18n.t('common.metrics'));
  119. return metricType + ' - ' + hostName;
  120. };
  121. var gangliaUrlTpl = App.router.get('clusterController.gangliaUrl') + '/?r=hour&cs=&ce=&m=load_one&s=by+name&c=HDPFlumeServer&h={0}&host_regex=&max_graphs=0&tab=m&vn=&sh=1&z=small&hc=4';
  122. var agentHostMock = agent.get('host.hostName');
  123. var mockMetricData = [
  124. {
  125. header: 'sinkName',
  126. metricView: App.MainServiceInfoFlumeGraphsView.extend(),
  127. metricViewData: {
  128. agent: agent,
  129. metricType: 'SINK'
  130. }
  131. },
  132. {
  133. header: 'sourceName',
  134. metricView: App.MainServiceInfoFlumeGraphsView.extend(),
  135. metricViewData: {
  136. agent: agent,
  137. metricType: 'SOURCE'
  138. }
  139. },
  140. {
  141. header: 'channelName',
  142. metricView: App.MainServiceInfoFlumeGraphsView.extend(),
  143. metricViewData: {
  144. agent: agent,
  145. metricType: 'CHANNEL'
  146. }
  147. }
  148. ];
  149. mockMetricData.forEach(function(mockData, index) {
  150. mockData.header = getMetricTitle(mockData.header, agentHostMock);
  151. mockData.url = gangliaUrlTpl.format(agentHostMock);
  152. mockData.id = 'metric' + index;
  153. mockData.toggleIndex = '#' + mockData.id;
  154. });
  155. this.set('parentView.collapsedSections', mockMetricData);
  156. }
  157. });