step7_controller.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 = {
  129. name: _configProperties.get('name'),
  130. value: _configProperties.get('value')};
  131. serviceConfigProperties.push(configProperty);
  132. }, this);
  133. }, this);
  134. db.setServiceConfigProperties(serviceConfigProperties);
  135. App.router.send('next');
  136. }
  137. },
  138. showMasterHosts: function (event) {
  139. var serviceConfig = event.context;
  140. App.ModalPopup.show({
  141. header: serviceConfig.category + ' Hosts',
  142. bodyClass: Ember.View.extend({
  143. serviceConfig: serviceConfig,
  144. templateName: require('templates/installer/master_hosts_popup')
  145. })
  146. });
  147. },
  148. showSlaveHosts: function (event) {
  149. var serviceConfig = event.context;
  150. App.ModalPopup.show({
  151. header: serviceConfig.category + ' Hosts',
  152. bodyClass: Ember.View.extend({
  153. serviceConfig: serviceConfig,
  154. templateName: require('templates/installer/slave_hosts_popup')
  155. })
  156. });
  157. }
  158. })
  159. ;
  160. App.SlaveComponentGroupsController = Ember.ArrayController.extend({
  161. name: 'slaveComponentGroupsController',
  162. contentBinding: 'App.router.installerStep7Controller.slaveComponentHosts',
  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 'HBASE_REGIONSERVER';
  171. default:
  172. return null;
  173. }
  174. }.property('App.router.installerStep7Controller.selectedService'),
  175. selectedSlaveComponent: function () {
  176. if (this.get('selectedComponentName') !== null && this.get('selectedComponentName') !== undefined) {
  177. return this.findProperty('componentName', this.get('selectedComponentName'));
  178. }
  179. }.property('selectedComponentName'),
  180. showAddSlaveComponentGroup: function (event) {
  181. var componentName = event.context;
  182. var component = this.get('selectedSlaveComponent');
  183. App.ModalPopup.show({
  184. header: componentName + ' Groups',
  185. bodyClass: Ember.View.extend({
  186. controllerBinding: 'App.router.slaveComponentGroupsController',
  187. templateName: require('templates/installer/slave_component_hosts_popup')
  188. }),
  189. onPrimary: function (event) {
  190. if (component.tempSelectedGroups !== undefined && component.tempSelectedGroups.length) {
  191. component.tempSelectedGroups.forEach(function (item) {
  192. var changed = component.hosts.filterProperty('hostname', item.hostName);
  193. changed.setEach('group', item.groupName);
  194. })
  195. }
  196. delete component.tempSelectedGroups;
  197. this.hide();
  198. },
  199. onSecondary: function (event) {
  200. delete component.tempSelectedGroups;
  201. this.hide();
  202. },
  203. onClose: function (event) {
  204. delete component.tempSelectedGroups;
  205. this.hide();
  206. }
  207. });
  208. },
  209. changeHostGroup: function (host, groupName) {
  210. var component = this.get('selectedSlaveComponent');
  211. if (component.tempSelectedGroups === undefined) {
  212. component.tempSelectedGroups = [];
  213. }
  214. var values = component.tempSelectedGroups.filterProperty('hostName', host.hostname);
  215. if (values.length === 0)
  216. component.tempSelectedGroups.pushObject({hostName: host.hostname, groupName: groupName});
  217. else
  218. values.setEach('groupName', groupName);
  219. },
  220. addSlaveComponentGroup: function (event) {
  221. var component = this.get('selectedSlaveComponent');
  222. var newGroupName = 'New Group';
  223. component.groups.setEach('active', false);
  224. var newGroups = component.groups.filterProperty('name', newGroupName);
  225. if (newGroups.length === 0)
  226. component.newGroupIndex = 0;
  227. else {
  228. if (component.newGroupIndex === undefined)
  229. component.newGroupIndex = 0;
  230. this.checkGroupName();
  231. newGroupName = 'New Group ' + component.newGroupIndex;
  232. }
  233. var newGroup = {name: newGroupName, index: component.newGroupIndex, type: 'new', active: true};
  234. component.groups.pushObject(newGroup);
  235. $('.remove-group-error').hide();
  236. },
  237. checkGroupName: function () {
  238. var component = this.get('selectedSlaveComponent');
  239. component.newGroupIndex++;
  240. var newGroupName = 'New Group ' + component.newGroupIndex;
  241. var groups = component.groups.filterProperty('name', newGroupName);
  242. if (groups.length !== 0) {
  243. this.checkGroupName();
  244. }
  245. },
  246. showEditSlaveComponentGroups: function (event) {
  247. this.showAddSlaveComponentGroup(event);
  248. },
  249. hosts: function () {
  250. if (this.get('selectedComponentName') !== null && this.get('selectedComponentName') !== undefined) {
  251. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  252. if (component !== undefined && component !== null) {
  253. return component.hosts;
  254. }
  255. }
  256. }.property('@each.hosts', 'selectedComponentName'),
  257. groups: function () {
  258. if (this.get('selectedComponentName') !== null) {
  259. var component = this.findProperty('componentName', this.get('selectedComponentName'));
  260. if (component !== undefined && component !== null) {
  261. return component.hosts.mapProperty('group').uniq();
  262. }
  263. }
  264. }.property('@each.hosts', 'selectedComponentName'),
  265. componentGroups: function () {
  266. if (this.get('selectedComponentName') !== null) {
  267. var component = this.get('selectedSlaveComponent');
  268. if (component !== undefined && component !== null) {
  269. if (component.groups === undefined) {
  270. component.groups = [];
  271. var defaultGroup = {name: 'Default', index: 'default', type: 'default', active: true};
  272. component.groups.pushObject(defaultGroup);
  273. }
  274. return component.groups;
  275. }
  276. }
  277. }.property('selectedSlaveComponent'),
  278. getHostsByGroup: function (group) {
  279. var component = this.get('selectedSlaveComponent');
  280. return component.hosts.filterProperty('group', group.name);
  281. },
  282. getGroupsForDropDown: function () {
  283. return this.get('componentGroups').getEach('name');
  284. }.property('selectedComponentName', 'componentGroups.@each.name'),
  285. activeGroup: function () {
  286. if (this.get('componentGroups') !== undefined) {
  287. var active = this.get('componentGroups').findProperty('active', true);
  288. if (active !== undefined)
  289. return active;
  290. }
  291. }.property('selectedComponentName', 'componentGroups.@each.active', 'componentGroups.@each.name'),
  292. showSlaveComponentGroup: function (event) {
  293. var component = this.get('selectedSlaveComponent');
  294. component.groups.setEach('active', false);
  295. var group = component.groups.filterProperty('name', event.context.name);
  296. group.setEach('active', true);
  297. var assignedHosts = component.hosts.filterProperty('group', event.context.name);
  298. if (assignedHosts.length === 0) {
  299. $('.remove-group-error').hide();
  300. }
  301. },
  302. removeSlaveComponentGroup: function (event) {
  303. var group = event.context;
  304. var component = this.get('selectedSlaveComponent');
  305. var assignedHosts = component.hosts.filterProperty('group', group.name);
  306. if (assignedHosts.length !== 0) {
  307. $('.remove-group-error').show();
  308. } else {
  309. $('.remove-group-error').hide();
  310. var key = component.groups.indexOf(group);
  311. component.groups.removeObject(component.groups[key]);
  312. var newGroups = component.groups.filterProperty('type', 'new');
  313. if (newGroups.length == 0)
  314. component.newGroupIndex = 0;
  315. else {
  316. var lastNewGroup = newGroups[newGroups.length - 1];
  317. component.newGroupIndex = lastNewGroup.index;
  318. }
  319. if (group.active) {
  320. var lastGroup;
  321. if (key === component.groups.length)
  322. lastGroup = component.groups.slice(key - 1, key);
  323. else lastGroup = component.groups.slice(key, key + 1);
  324. lastGroup.setEach('active', true);
  325. }
  326. }
  327. },
  328. changeSlaveGroupName: function (group, newGroupName) {
  329. var component = this.get('selectedSlaveComponent');
  330. var isExist = component.groups.filterProperty('name', newGroupName);
  331. if (isExist.length !== 0)
  332. return true;
  333. else {
  334. var assignedHosts = component.hosts.filterProperty('group', group.name);
  335. if (assignedHosts.length !== 0)
  336. assignedHosts.setEach('group', newGroupName);
  337. var groupFilter = component.groups.filterProperty('name', group.name);
  338. groupFilter.setEach('name', newGroupName);
  339. }
  340. return false;
  341. }
  342. });