step7_controller.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. loadStep: function () {
  49. console.log("TRACE: Loading step7: Configure Services");
  50. this.clearStep();
  51. this.loadConfigs();
  52. this.renderServiceConfigs(this.serviceConfigs);
  53. var storedServices = db.getServiceConfigProperties();
  54. if (storedServices === undefined) {
  55. return;
  56. } else {
  57. var configs = new Ember.Set();
  58. var configProperties = new Ember.Set();
  59. this.forEach(function (_content) {
  60. _content.get('configs').forEach(function (_config) {
  61. configs.add(_config);
  62. }, this);
  63. }, this);
  64. var configProperties = new Ember.Set();
  65. configs.forEach(function (_config) {
  66. var temp = {name: _config.get('name'),
  67. value: _config.get('value')};
  68. configProperties.add(temp);
  69. if (storedServices.someProperty('name', _config.get('name'))) {
  70. var componentVal = storedServices.findProperty('name', _config.get('name'));
  71. _config.set('value', componentVal.value)
  72. }
  73. }, this);
  74. }
  75. },
  76. loadConfigs: function () {
  77. // load dependent data from the database
  78. var selectedServiceNamesInDB = db.getSelectedServiceNames();
  79. if (selectedServiceNamesInDB !== undefined) {
  80. this.set('selectedServiceNames', selectedServiceNamesInDB);
  81. }
  82. var masterComponentHostsInDB = db.getMasterComponentHosts();
  83. if (masterComponentHostsInDB != undefined) {
  84. this.set('masterComponentHosts', masterComponentHostsInDB);
  85. }
  86. var slaveComponentHostsInDB = db.getSlaveComponentHosts();
  87. if (slaveComponentHostsInDB != undefined) {
  88. this.set('slaveComponentHosts', slaveComponentHostsInDB);
  89. }
  90. },
  91. renderServiceConfigs: function (serviceConfigs) {
  92. var self = this;
  93. serviceConfigs.forEach(function (_serviceConfig) {
  94. var serviceConfig = App.ServiceConfig.create({
  95. serviceName: _serviceConfig.serviceName,
  96. displayName: _serviceConfig.displayName,
  97. configCategories: _serviceConfig.configCategories,
  98. configs: []
  99. });
  100. if (self.selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  101. self.renderComponentConfigs(_serviceConfig, serviceConfig);
  102. } else {
  103. console.log('skipping ' + serviceConfig.serviceName);
  104. }
  105. }, this);
  106. },
  107. renderComponentConfigs: function (_componentConfig, componentConfig) {
  108. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  109. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  110. serviceConfigProperty.serviceConfig = componentConfig;
  111. serviceConfigProperty.initialValue();
  112. componentConfig.configs.pushObject(serviceConfigProperty);
  113. serviceConfigProperty.validate();
  114. }, this);
  115. console.log('pushing ' + componentConfig.serviceName);
  116. this.content.pushObject(componentConfig);
  117. this.set('selectedService', this.objectAt(0));
  118. },
  119. submit: function () {
  120. if (!this.get('isSubmitDisabled')) {
  121. // TODO:
  122. // save service configs in App.db (localStorage)
  123. var serviceConfigProperties = [];
  124. this.content.forEach(function (_content) {
  125. var config = [];
  126. config = _content.get('configs');
  127. config.forEach(function (_configProperties) {
  128. var configProperty = {name: _configProperties.get('name'),
  129. value: _configProperties.get('value')};
  130. serviceConfigProperties.push(configProperty);
  131. }, this);
  132. }, this);
  133. db.setServiceConfigProperties(serviceConfigProperties);
  134. App.router.send('next');
  135. }
  136. },
  137. showMasterHosts: function (event) {
  138. var serviceConfig = event.context;
  139. App.ModalPopup.show({
  140. header: serviceConfig.category + ' Hosts',
  141. bodyClass: Ember.View.extend({
  142. serviceConfig: serviceConfig,
  143. templateName: require('templates/installer/master_hosts_popup')
  144. })
  145. });
  146. },
  147. showSlaveHosts: function (event) {
  148. var serviceConfig = event.context;
  149. App.ModalPopup.show({
  150. header: serviceConfig.category + ' Hosts',
  151. bodyClass: Ember.View.extend({
  152. serviceConfig: serviceConfig,
  153. templateName: require('templates/installer/slave_hosts_popup')
  154. })
  155. });
  156. }
  157. })
  158. ;
  159. App.SlaveComponentGroupsController = Ember.ArrayController.extend({
  160. name: 'slaveComponentGroupsController',
  161. contentBinding: 'App.router.installerStep7Controller.slaveComponentHosts',
  162. slaveComponentGroups: [],
  163. selectedComponentName: function () {
  164. switch (App.router.get('installerStep7Controller.selectedService.serviceName')) {
  165. case 'HDFS':
  166. return 'DataNode';
  167. case 'MAPREDUCE':
  168. return 'TaskTracker';
  169. case 'HBASE':
  170. return 'RegionServer';
  171. default:
  172. return null;
  173. }
  174. }.property('App.router.installerStep7Controller.selectedService'),
  175. showAddSlaveComponentGroup: function (event) {
  176. var componentName = event.context;
  177. App.ModalPopup.show({
  178. header: componentName + ' Groups',
  179. bodyClass: Ember.View.extend({
  180. controllerBinding: 'App.router.slaveComponentGroupsController',
  181. templateName: require('templates/installer/slave_hosts_popup')
  182. }),
  183. onPrimary: function () {
  184. }
  185. });
  186. },
  187. addSlaveComponentGroup: function (event) {
  188. var componentName = event.context;
  189. var component = this.findProperty('componentName', componentName);
  190. var slaveGroups = this.get('slaveComponentGroups');
  191. var newGroupName;
  192. console.log(slaveGroups);
  193. slaveGroups.forEach(function(group) {
  194. });
  195. var newGroup = {
  196. groupName: "New Group"
  197. };
  198. slaveGroups.pushObject(newGroup);
  199. console.log(slaveGroups);
  200. },
  201. showEditSlaveComponentGroups: function (event) {
  202. this.showAddSlaveComponentGroup(event);
  203. },
  204. hosts: function () {
  205. if (this.get('selectedComponentName') !== null && this.get('selectedComponentName') !== undefined) {
  206. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  207. if (component !== undefined && component !== null) {
  208. return component.hosts;
  209. }
  210. }
  211. }.property('@each.hosts', 'selectedComponentName'),
  212. groups: function () {
  213. if (this.get('selectedComponentName') !== null) {
  214. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  215. if (component !== undefined && component !== null) {
  216. return component.hosts.mapProperty('group').uniq();
  217. }
  218. }
  219. }.property('@each.hosts', 'selectedComponentName'),
  220. getHostsGroups: function () {
  221. var slaveGroups = this.get('slaveComponentGroups');
  222. if (slaveGroups.length == 0){
  223. var defaultGroup = {
  224. groupName: "Default",
  225. label: "default"
  226. };
  227. slaveGroups.pushObject(defaultGroup);
  228. }
  229. return slaveGroups;
  230. }.property('slaveComponentGroups')
  231. });