wizard_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.WidgetWizardController = App.WizardController.extend({
  20. name: 'widgetWizardController',
  21. totalSteps: 3,
  22. /**
  23. * Used for hiding back button in wizard
  24. */
  25. hideBackButton: true,
  26. content: Em.Object.create({
  27. controllerName: 'widgetWizardController',
  28. widgetService: null,
  29. widgetType: '',
  30. /**
  31. * Example:
  32. * {
  33. * "display_unit": "%",
  34. * "warning_threshold": 70,
  35. * "error_threshold": 90
  36. * }
  37. */
  38. widgetProperties: {},
  39. /**
  40. * Example:
  41. * [{
  42. * widget_id: "metrics/rpc/closeRegion_num_ops",
  43. * name: "rpc.rpc.closeRegion_num_ops",
  44. * pointInTime: true,
  45. * temporal: true,
  46. * category: "default"
  47. * serviceName: "HBASE"
  48. * componentName: "HBASE_CLIENT"
  49. * type: "GANGLIA"//or JMX
  50. * level: "COMPONENT"//or HOSTCOMPONENT
  51. * }]
  52. * @type {Array}
  53. */
  54. allMetrics: [],
  55. /**
  56. * Example:
  57. * [{
  58. * "name": "regionserver.Server.percentFilesLocal",
  59. * "serviceName": "HBASE",
  60. * "componentName": "HBASE_REGIONSERVER"
  61. * }]
  62. */
  63. widgetMetrics: [],
  64. /**
  65. * Example:
  66. * [{
  67. * "name": "Files Local",
  68. * "value": "${regionserver.Server.percentFilesLocal}"
  69. * }]
  70. */
  71. widgetValues: [],
  72. expressions: [],
  73. dataSets: [],
  74. templateValue: null,
  75. widgetName: null,
  76. widgetDescription: null,
  77. widgetScope: null
  78. }),
  79. loadMap: {
  80. '1': [
  81. {
  82. type: 'sync',
  83. callback: function () {
  84. this.load('widgetService');
  85. this.load('widgetType');
  86. }
  87. }
  88. ],
  89. '2': [
  90. {
  91. type: 'sync',
  92. callback: function () {
  93. this.load('widgetProperties', true);
  94. this.load('widgetValues', true);
  95. this.load('widgetMetrics', true);
  96. this.load('expressions', true);
  97. this.load('dataSets', true);
  98. this.load('templateValue', true);
  99. }
  100. },
  101. {
  102. type: 'async',
  103. callback: function () {
  104. return this.loadAllMetrics();
  105. }
  106. }
  107. ]
  108. },
  109. /**
  110. * set current step
  111. * @param {string} currentStep
  112. * @param {boolean} completed
  113. * @param {boolean} skipStateSave
  114. */
  115. setCurrentStep: function (currentStep, completed, skipStateSave) {
  116. this._super(currentStep, completed);
  117. if (App.get('testMode') || skipStateSave) {
  118. return;
  119. }
  120. this.saveClusterStatus('WIDGET_DEPLOY');
  121. },
  122. setStepsEnable: function () {
  123. for (var i = 1; i <= this.get('totalSteps'); i++) {
  124. var step = this.get('isStepDisabled').findProperty('step', i);
  125. if (i <= this.get('currentStep') && App.get('router.clusterController.isLoaded')) {
  126. step.set('value', false);
  127. } else {
  128. step.set('value', i != this.get('currentStep'));
  129. }
  130. }
  131. }.observes('currentStep', 'App.router.clusterController.isLoaded'),
  132. /**
  133. * save status of the cluster.
  134. * @param {object} clusterStatus
  135. */
  136. saveClusterStatus: function (clusterStatus) {
  137. App.clusterStatus.setClusterStatus({
  138. clusterState: clusterStatus,
  139. wizardControllerName: 'widgetWizardController',
  140. localdb: App.db.data
  141. });
  142. },
  143. /**
  144. * save wizard properties to controller and localStorage
  145. * @param {string} name
  146. * @param value
  147. */
  148. save: function (name, value) {
  149. this.set('content.' + name, value);
  150. if (Array.isArray(value)) {
  151. value = value.map(function (item) {
  152. return this.toObject(item);
  153. }, this);
  154. } else if (typeof value === 'object') {
  155. value = this.toObject(value);
  156. }
  157. this.setDBProperty(name, value);
  158. console.log(this.get('name') + ": saved " + name, value);
  159. },
  160. /**
  161. * load widget metrics
  162. * on resolve deferred return array of widget metrics
  163. * @returns {$.Deferred}
  164. */
  165. loadAllMetrics: function () {
  166. var widgetMetrics = this.getDBProperty('allMetrics');
  167. var self = this;
  168. var dfd = $.Deferred();
  169. if (widgetMetrics.length === 0) {
  170. this.loadAllMetricsFromServer(function () {
  171. dfd.resolve(self.get('content.allMetrics'));
  172. });
  173. } else {
  174. this.set('content.allMetrics', widgetMetrics);
  175. dfd.resolve(widgetMetrics);
  176. }
  177. return dfd.promise();
  178. },
  179. /**
  180. * load metrics from server
  181. * @param {function} callback
  182. * @returns {$.ajax}
  183. */
  184. loadAllMetricsFromServer: function (callback) {
  185. return App.ajax.send({
  186. name: 'widgets.wizard.metrics.get',
  187. sender: this,
  188. data: {
  189. stackVersionURL: App.get('stackVersionURL'),
  190. serviceNames: App.Service.find().mapProperty('serviceName').join(',')
  191. },
  192. callback: callback,
  193. success: 'loadAllMetricsFromServerCallback'
  194. });
  195. },
  196. /**
  197. *
  198. * @param {object} json
  199. */
  200. loadAllMetricsFromServerCallback: function (json) {
  201. var result = [];
  202. var metrics = {};
  203. if (json) {
  204. json.items.forEach(function (service) {
  205. var data = service.artifacts[0].artifact_data[service.StackServices.service_name];
  206. for (var componentName in data) {
  207. for (var level in data[componentName]) {
  208. metrics = data[componentName][level][0]['metrics']['default'];
  209. for (var widgetId in metrics) {
  210. result.push({
  211. widget_id: widgetId,
  212. point_in_time: metrics[widgetId].pointInTime,
  213. temporal: metrics[widgetId].temporal,
  214. name: metrics[widgetId].name,
  215. level: level.toUpperCase(),
  216. type: data[componentName][level][0]["type"].toUpperCase(),
  217. component_name: componentName,
  218. service_name: service.StackServices.service_name
  219. });
  220. }
  221. }
  222. }
  223. }, this);
  224. }
  225. this.save('allMetrics', result);
  226. },
  227. /**
  228. * Remove all loaded data.
  229. * Created as copy for App.router.clearAllSteps
  230. */
  231. clearAllSteps: function () {
  232. this.clearInstallOptions();
  233. // clear temporary information stored during the install
  234. this.set('content.cluster', this.getCluster());
  235. },
  236. clearTasksData: function () {
  237. this.saveTasksStatuses(undefined);
  238. this.saveRequestIds(undefined);
  239. this.saveTasksRequestIds(undefined);
  240. },
  241. /**
  242. * Clear all temporary data
  243. */
  244. finish: function () {
  245. this.setCurrentStep('1', false, true);
  246. this.save('widgetType', '');
  247. this.resetDbNamespace();
  248. App.get('router.updateController').updateAll();
  249. }
  250. });