step7_controller.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 db = require('utils/db');
  20. /**
  21. * By Step 7, we have the following information stored in App.db and set on this
  22. * controller by the router.
  23. *
  24. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  25. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  26. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  27. *
  28. */
  29. App.InstallerStep7Controller = Em.ArrayController.extend({
  30. name: 'installerStep7Controller',
  31. content: [],
  32. selectedService: null,
  33. slaveHostToGroup: null,
  34. isSubmitDisabled: function () {
  35. return !this.everyProperty('errorCount', 0);
  36. }.property('@each.errorCount'),
  37. // TODO: set attributes from localStorage in router
  38. selectedServiceNames: [ 'HDFS', 'MAPREDUCE', 'GANGLIA', 'NAGIOS', 'HBASE', 'PIG', 'SQOOP', 'OOZIE', 'HIVE', 'ZOOKEEPER'],
  39. masterComponentHosts: require('data/mock/master_component_hosts'),
  40. slaveComponentHosts: [],
  41. serviceConfigs: require('data/service_configs'),
  42. clearStep: function () {
  43. this.clear();
  44. this.selectedServiceNames.clear();
  45. this.masterComponentHosts.clear();
  46. this.slaveComponentHosts.clear();
  47. },
  48. navigateStep: function () {
  49. if (App.router.get('isFwdNavigation') === true && !App.router.get('backBtnForHigherStep')) {
  50. this.loadStep();
  51. } else {
  52. this.loadStepFromDb();
  53. }
  54. App.router.set('backBtnForHigherStep', false);
  55. },
  56. loadStep: function () {
  57. console.log("TRACE: Loading step7: Configure Services");
  58. this.clearStep();
  59. this.loadConfigs();
  60. this.renderServiceConfigs(this.serviceConfigs);
  61. },
  62. loadStepFromDb: function () {
  63. console.log("TRACE: Loading step7 from localstorage data: Configure Services");
  64. this.loadStep();
  65. var storedServices = db.getServiceConfigProperties();
  66. var configs = new Ember.Set();
  67. var configProperties = new Ember.Set();
  68. this.forEach(function (_content) {
  69. _content.get('configs').forEach(function (_config) {
  70. configs.add(_config);
  71. }, this);
  72. }, this);
  73. var configProperties = new Ember.Set();
  74. configs.forEach(function (_config) {
  75. var temp = {name: _config.get('name'),
  76. value: _config.get('value')};
  77. configProperties.add(temp);
  78. if (storedServices.someProperty('name', _config.get('name'))) {
  79. var componentVal = storedServices.findProperty('name', _config.get('name'));
  80. _config.set('value', componentVal.value)
  81. }
  82. }, this);
  83. },
  84. loadConfigs: function () {
  85. // load dependent data from the database
  86. var selectedServiceNamesInDB = db.getSelectedServiceNames();
  87. if (selectedServiceNamesInDB !== undefined) {
  88. this.set('selectedServiceNames', selectedServiceNamesInDB);
  89. }
  90. var masterComponentHostsInDB = db.getMasterComponentHosts();
  91. if (masterComponentHostsInDB != undefined) {
  92. this.set('masterComponentHosts', masterComponentHostsInDB);
  93. }
  94. var slaveComponentHostsInDB = db.getSlaveComponentHosts();
  95. if (slaveComponentHostsInDB != undefined) {
  96. this.set('slaveComponentHosts', slaveComponentHostsInDB);
  97. }
  98. },
  99. renderServiceConfigs: function (serviceConfigs) {
  100. var self = this;
  101. serviceConfigs.forEach(function (_serviceConfig) {
  102. var serviceConfig = App.ServiceConfig.create({
  103. serviceName: _serviceConfig.serviceName,
  104. displayName: _serviceConfig.displayName,
  105. configCategories: _serviceConfig.configCategories,
  106. configs: []
  107. });
  108. if (self.selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  109. self.renderComponentConfigs(_serviceConfig, serviceConfig);
  110. } else {
  111. console.log('skipping ' + serviceConfig.serviceName);
  112. }
  113. }, this);
  114. },
  115. renderComponentConfigs: function (_componentConfig, componentConfig) {
  116. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  117. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  118. serviceConfigProperty.serviceConfig = componentConfig;
  119. serviceConfigProperty.initialValue();
  120. componentConfig.configs.pushObject(serviceConfigProperty);
  121. serviceConfigProperty.validate();
  122. }, this);
  123. console.log('pushing ' + componentConfig.serviceName);
  124. this.content.pushObject(componentConfig);
  125. this.set('selectedService', this.objectAt(0));
  126. },
  127. submit: function () {
  128. if (!this.get('isSubmitDisabled')) {
  129. // TODO:
  130. // save service configs in App.db (localStorage)
  131. var serviceConfigProperties = [];
  132. this.content.forEach(function (_content) {
  133. var config = [];
  134. config = _content.get('configs');
  135. config.forEach(function (_configProperties) {
  136. var configProperty = {name: _configProperties.get('name'),
  137. value: _configProperties.get('value')};
  138. serviceConfigProperties.push(configProperty);
  139. }, this);
  140. }, this);
  141. db.setServiceConfigProperties(serviceConfigProperties);
  142. App.router.send('next');
  143. }
  144. },
  145. showMasterHosts: function (event) {
  146. var serviceConfig = event.context;
  147. App.ModalPopup.show({
  148. header: serviceConfig.category + ' Hosts',
  149. bodyClass: Ember.View.extend({
  150. serviceConfig: serviceConfig,
  151. templateName: require('templates/installer/master_hosts_popup')
  152. })
  153. });
  154. },
  155. showSlaveHosts: function (event) {
  156. var serviceConfig = event.context;
  157. App.ModalPopup.show({
  158. header: serviceConfig.category + ' Hosts',
  159. bodyClass: Ember.View.extend({
  160. serviceConfig: serviceConfig,
  161. templateName: require('templates/installer/slave_hosts_popup')
  162. })
  163. });
  164. }
  165. })
  166. ;
  167. App.SlaveComponentGroupsController = Ember.ArrayController.extend({
  168. name: 'slaveComponentGroupsController',
  169. contentBinding: 'App.router.installerStep7Controller.slaveComponentHosts',
  170. selectedComponentName: function () {
  171. switch (App.router.get('installerStep7Controller.selectedService.serviceName')) {
  172. case 'HDFS':
  173. return 'DataNode';
  174. case 'MAPREDUCE':
  175. return 'TaskTracker';
  176. case 'HBASE':
  177. return 'RegionServer';
  178. default:
  179. return null;
  180. }
  181. }.property('App.router.installerStep7Controller.selectedService'),
  182. showAddSlaveComponentGroup: function (event) {
  183. var componentName = event.context;
  184. App.ModalPopup.show({
  185. header: componentName + ' Groups',
  186. bodyClass: Ember.View.extend({
  187. controllerBinding: 'App.router.slaveComponentGroupsController',
  188. templateName: require('templates/installer/slave_hosts_popup')
  189. }),
  190. onPrimary: function () {
  191. }
  192. });
  193. },
  194. showEditSlaveComponentGroups: function (event) {
  195. this.showAddSlaveComponentGroup(event);
  196. },
  197. hosts: function () {
  198. if (this.get('selectedComponentName') !== null && this.get('selectedComponentName') !== undefined) {
  199. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  200. if (component !== undefined && component !== null) {
  201. return component.hosts;
  202. }
  203. }
  204. }.property('@each.hosts', 'selectedComponentName'),
  205. groups: function () {
  206. if (this.get('selectedComponentName') !== null) {
  207. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  208. if (component !== undefined && component !== null) {
  209. return component.hosts.mapProperty('group').uniq();
  210. }
  211. }
  212. }.property('@each.hosts', 'selectedComponentName')
  213. });