step7_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. selectedComponentName: function () {
  163. switch (App.router.get('installerStep7Controller.selectedService.serviceName')) {
  164. case 'HDFS':
  165. return 'DATANODE';
  166. case 'MAPREDUCE':
  167. return 'TASKTRACKER';
  168. case 'HBASE':
  169. return 'HBASE_REGIONSERVER';
  170. default:
  171. return null;
  172. }
  173. }.property('App.router.installerStep7Controller.selectedService'),
  174. selectedSlaveComponent: function () {
  175. if (this.get('selectedComponentName') !== null && this.get('selectedComponentName') !== undefined) {
  176. return this.findProperty('componentName', this.get('selectedComponentName'));
  177. }
  178. }.property('selectedComponentName'),
  179. showAddSlaveComponentGroup: function (event) {
  180. var componentName = event.context;
  181. var component = this.get('selectedSlaveComponent');
  182. App.ModalPopup.show({
  183. header: componentName + ' Groups',
  184. bodyClass: Ember.View.extend({
  185. controllerBinding: 'App.router.slaveComponentGroupsController',
  186. templateName: require('templates/installer/slave_component_hosts_popup')
  187. }),
  188. onPrimary: function (event) {
  189. if (component.tempSelectedGroups !== undefined && component.tempSelectedGroups.length){
  190. component.tempSelectedGroups.forEach(function(item){
  191. var changed = component.hosts.filterProperty('hostname', item.hostName);
  192. changed.setEach('group', item.groupName);
  193. })
  194. }
  195. delete component.tempSelectedGroups;
  196. this.hide();
  197. },
  198. onSecondary: function (event) {
  199. delete component.tempSelectedGroups;
  200. this.hide();
  201. },
  202. onClose: function (event) {
  203. delete component.tempSelectedGroups;
  204. this.hide();
  205. }
  206. });
  207. },
  208. changeHostGroup: function(host, groupName){
  209. var component = this.get('selectedSlaveComponent');
  210. if (component.tempSelectedGroups === undefined){
  211. component.tempSelectedGroups = [];
  212. }
  213. var values = component.tempSelectedGroups.filterProperty('hostName', host.hostname);
  214. if (values.length === 0)
  215. component.tempSelectedGroups.pushObject({hostName: host.hostname, groupName:groupName});
  216. else
  217. values.setEach('groupName', groupName);
  218. },
  219. addSlaveComponentGroup: function (event) {
  220. var component = this.get('selectedSlaveComponent');
  221. var newGroupName;
  222. component.groups.setEach('active', false);
  223. var newGroups = component.groups.filterProperty('type', 'new');
  224. if (newGroups.length === 0) {
  225. component.newGroupIndex = 0;
  226. newGroupName = 'New Group';
  227. } else {
  228. component.newGroupIndex++;
  229. newGroupName = 'New Group ' + component.newGroupIndex;
  230. }
  231. var newGroup = {name: newGroupName, index: component.newGroupIndex, type: 'new', active: true};
  232. component.groups.pushObject(newGroup);
  233. $('.remove-group-error').hide();
  234. },
  235. showEditSlaveComponentGroups: function (event) {
  236. this.showAddSlaveComponentGroup(event);
  237. },
  238. hosts: function () {
  239. if (this.get('selectedComponentName') !== null && this.get('selectedComponentName') !== undefined) {
  240. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  241. if (component !== undefined && component !== null) {
  242. return component.hosts;
  243. }
  244. }
  245. }.property('@each.hosts', 'selectedComponentName'),
  246. groups: function () {
  247. if (this.get('selectedComponentName') !== null) {
  248. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  249. if (component !== undefined && component !== null) {
  250. return component.hosts.mapProperty('group').uniq();
  251. }
  252. }
  253. }.property('@each.hosts', 'selectedComponentName'),
  254. componentGroups: function () {
  255. if (this.get('selectedComponentName') !== null) {
  256. var component = this.get('selectedSlaveComponent');
  257. if (component !== undefined && component !== null) {
  258. if (component.groups === undefined){
  259. component.groups = [];
  260. var defaultGroup = {name: 'Default', index: 'default', type: 'default', active: true};
  261. component.groups.pushObject(defaultGroup);
  262. }
  263. return component.groups;
  264. }
  265. }
  266. }.property('selectedComponentName'),
  267. getHostsByGroup: function(group){
  268. var component = this.get('selectedSlaveComponent');
  269. return component.hosts.filterProperty('group', group.name);
  270. },
  271. getGroupsForDropDown: function(){
  272. return this.get('componentGroups').getEach('name');
  273. }.property('selectedComponentName', 'componentGroups.@each'),
  274. activeGroup: function(){
  275. var active = this.get('componentGroups').findProperty('active', true);
  276. if (active !== undefined)
  277. return active;
  278. }.property('selectedComponentName', 'componentGroups.@each.active'),
  279. showSlaveComponentGroup: function(event){
  280. var component = this.get('selectedSlaveComponent');
  281. component.groups.setEach('active', false);
  282. var group = component.groups.filterProperty('name', event.context.name);
  283. group.setEach('active', true);
  284. var assignedHosts = component.hosts.filterProperty('group', event.context.name);
  285. if (assignedHosts.length === 0){
  286. $('.remove-group-error').hide();
  287. }
  288. },
  289. removeSlaveComponentGroup: function(event){
  290. var group = event.context;
  291. var component = this.get('selectedSlaveComponent');
  292. var assignedHosts = component.hosts.filterProperty('group', group.name);
  293. if (assignedHosts.length !== 0){
  294. $('.remove-group-error').show();
  295. } else {
  296. $('.remove-group-error').hide();
  297. var key = component.groups.indexOf(group);
  298. component.groups.removeObject(component.groups[key]);
  299. var newGroups = component.groups.filterProperty('type', 'new');
  300. if (newGroups.length == 0)
  301. component.newGroupIndex = 0;
  302. else {
  303. var lastNewGroup = newGroups[newGroups.length - 1];
  304. component.newGroupIndex = lastNewGroup.index;
  305. }
  306. if (group.active){
  307. var lastGroup;
  308. if (key === component.groups.length)
  309. lastGroup = component.groups.slice(key-1, key);
  310. else lastGroup = component.groups.slice(key, key+1);
  311. lastGroup.setEach('active', true);
  312. }
  313. }
  314. }
  315. });