config_history_controller.js 6.3 KB

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