config_history_controller.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. var App = require('app');
  19. App.MainConfigHistoryController = Em.ArrayController.extend(App.TableServerMixin, {
  20. name: 'mainConfigHistoryController',
  21. dataSource: App.ServiceConfigVersion.find(),
  22. content: function () {
  23. return this.get('dataSource').filterProperty('isRequested');
  24. }.property('dataSource.@each.isRequested'),
  25. isPolling: false,
  26. totalCount: 0,
  27. filteredCount: 0,
  28. timeoutRef: null,
  29. resetStartIndex: true,
  30. mockUrl: '/data/configurations/service_versions.json',
  31. realUrl: function () {
  32. return App.apiPrefix + '/clusters/' + App.get('clusterName') + '/configurations/service_config_versions?<parameters>fields=service_config_version,user,group_id,group_name,is_current,createtime,service_name,hosts,service_config_version_note&minimal_response=true';
  33. }.property('App.clusterName'),
  34. /**
  35. * associations between host property and column index
  36. * @type {Array}
  37. */
  38. colPropAssoc: function () {
  39. var associations = [];
  40. associations[1] = 'serviceVersion';
  41. associations[2] = 'configGroup';
  42. associations[3] = 'createTime';
  43. associations[4] = 'author';
  44. associations[5] = 'notes';
  45. return associations;
  46. }.property(),
  47. filterProps: [
  48. {
  49. name: 'serviceVersion',
  50. key: 'service_name',
  51. type: 'EQUAL'
  52. },
  53. {
  54. name: 'configGroup',
  55. key: 'group_name',
  56. type: 'EQUAL'
  57. },
  58. {
  59. name: 'createTime',
  60. key: 'createtime',
  61. type: 'MORE'
  62. },
  63. {
  64. name: 'author',
  65. key: 'user',
  66. type: 'MATCH'
  67. },
  68. {
  69. name: 'notes',
  70. key: 'service_config_version_note',
  71. type: 'MATCH'
  72. }
  73. ],
  74. sortProps: [
  75. {
  76. name: 'serviceVersion',
  77. key: 'service_name'
  78. },
  79. {
  80. name: 'configGroup',
  81. key: 'group_name'
  82. },
  83. {
  84. name: 'createTime',
  85. key: 'createtime'
  86. },
  87. {
  88. name: 'author',
  89. key: 'user'
  90. },
  91. {
  92. name: 'notes',
  93. key: 'service_config_version_note'
  94. }
  95. ],
  96. modifiedFilter: Em.Object.create({
  97. content: [
  98. {
  99. value: 'Any',
  100. label: Em.I18n.t('any')
  101. },
  102. {
  103. value: 'Past 1 hour',
  104. label: 'Past 1 hour'
  105. },
  106. {
  107. value: 'Past 1 Day',
  108. label: 'Past 1 Day'
  109. },
  110. {
  111. value: 'Past 2 Days',
  112. label: 'Past 2 Days'
  113. },
  114. {
  115. value: 'Past 7 Days',
  116. label: 'Past 7 Days'
  117. },
  118. {
  119. value: 'Past 14 Days',
  120. label: 'Past 14 Days'
  121. },
  122. {
  123. value: 'Past 30 Days',
  124. label: 'Past 30 Days'
  125. }
  126. ],
  127. optionValue: 'Any',
  128. filterModified: function () {
  129. var time = "";
  130. var curTime = new Date().getTime();
  131. switch (this.get('optionValue.value')) {
  132. case 'Past 1 hour':
  133. time = curTime - 3600000;
  134. break;
  135. case 'Past 1 Day':
  136. time = curTime - 86400000;
  137. break;
  138. case 'Past 2 Days':
  139. time = curTime - 172800000;
  140. break;
  141. case 'Past 7 Days':
  142. time = curTime - 604800000;
  143. break;
  144. case 'Past 14 Days':
  145. time = curTime - 1209600000;
  146. break;
  147. case 'Past 30 Days':
  148. time = curTime - 2592000000;
  149. break;
  150. case 'Any':
  151. time = "";
  152. break;
  153. }
  154. this.set("actualValues", {
  155. endTime: '',
  156. startTime: time
  157. });
  158. }.observes('optionValue'),
  159. cancel: function () {
  160. this.set('optionValue', this.get('content').findProperty('value', 'Any'));
  161. },
  162. actualValues: Em.Object.create({
  163. startTime: "",
  164. endTime: ""
  165. })
  166. }),
  167. /**
  168. * load all data components required by config history table
  169. * - total counter of service config versions(called in parallel)
  170. * - current versions
  171. * - filtered versions
  172. * @return {*}
  173. */
  174. load: function () {
  175. var dfd = $.Deferred();
  176. this.updateTotalCounter();
  177. this.loadConfigVersionsToModel().done(function () {
  178. dfd.resolve();
  179. });
  180. return dfd.promise();
  181. },
  182. /**
  183. * get filtered service config versions from server and push it to model
  184. * @return {*}
  185. */
  186. loadConfigVersionsToModel: function () {
  187. var dfd = $.Deferred();
  188. var queryParams = this.getQueryParameters();
  189. App.HttpClient.get(this.getUrl(queryParams), App.serviceConfigVersionsMapper, {
  190. complete: function () {
  191. dfd.resolve();
  192. }
  193. });
  194. return dfd.promise();
  195. },
  196. updateTotalCounter: function () {
  197. return App.ajax.send({
  198. name: 'service.serviceConfigVersions.get.total',
  199. sender: this,
  200. data: {},
  201. success: 'updateTotalCounterSuccess'
  202. })
  203. },
  204. updateTotalCounterSuccess: function (data, opt, params) {
  205. this.set('totalCount', data.itemTotal);
  206. },
  207. getUrl: function (queryParams) {
  208. var params = '';
  209. if (App.get('testMode')) {
  210. return this.get('mockUrl');
  211. } else {
  212. if (queryParams) {
  213. params = App.router.get('updateController').computeParameters(queryParams);
  214. }
  215. return this.get('realUrl').replace('<parameters>', params);
  216. }
  217. },
  218. /**
  219. * request latest data from server and update content
  220. */
  221. doPolling: function () {
  222. var self = this;
  223. this.set('timeoutRef', setTimeout(function () {
  224. if (self.get('isPolling')) {
  225. self.load().done(function () {
  226. self.doPolling();
  227. })
  228. }
  229. }, App.componentsUpdateInterval));
  230. },
  231. /**
  232. * get sort properties from local db. A overridden funtion from parent
  233. * @return {Array}
  234. */
  235. getSortProps: function () {
  236. var savedSortConditions = App.db.getSortingStatuses(this.get('name')) || [],
  237. sortProperties = this.get('sortProps'),
  238. sortParams = [];
  239. savedSortConditions.forEach(function (sort) {
  240. var property = sortProperties.findProperty('name', sort.name);
  241. if (property && (sort.status === 'sorting_asc' || sort.status === 'sorting_desc')) {
  242. property.value = sort.status.replace('sorting_', '');
  243. property.type = 'SORT';
  244. if (property.name == 'serviceVersion'){
  245. property.key = "service_name." + sort.status.replace('sorting_', '') + ",service_config_version";
  246. property.value = "desc";
  247. }
  248. if (property.name == 'configGroup'){
  249. property.key = "group_name." + sort.status.replace('sorting_', '') + ",service_config_version";
  250. property.value = "desc";
  251. }
  252. sortParams.push(property);
  253. }
  254. });
  255. return sortParams;
  256. }
  257. });