config_history_controller.js 6.1 KB

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