step7_controller.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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: require('data/mock/slave_component_hosts'),
  41. doInit: true,
  42. loadConfigs: function () {
  43. // load dependent data from the database
  44. var selectedServiceNamesInDB = db.getSelectedServiceNames();
  45. if (selectedServiceNamesInDB !== undefined) {
  46. this.set('selectedServiceNames', selectedServiceNamesInDB);
  47. }
  48. var masterComponentHostsInDB = db.getMasterComponentHosts();
  49. if (masterComponentHostsInDB != undefined) {
  50. this.set('masterComponentHosts', masterComponentHostsInDB);
  51. }
  52. var slaveComponentHostsInDB = db.getSlaveComponentHosts();
  53. if (slaveComponentHostsInDB != undefined) {
  54. this.set('slaveComponentHosts', slaveComponentHostsInDB);
  55. }
  56. // TODO: check App.db to see if configs have been saved already
  57. if (this.doInit) {
  58. var serviceConfigs = require('data/service_configs');
  59. var self = this;
  60. this.set('content', []);
  61. serviceConfigs.forEach(function (_serviceConfig) {
  62. var serviceConfig = App.ServiceConfig.create({
  63. serviceName: _serviceConfig.serviceName,
  64. displayName: _serviceConfig.displayName,
  65. configCategories: _serviceConfig.configCategories,
  66. configs: []
  67. });
  68. if (self.selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  69. _serviceConfig.configs.forEach(function (_serviceConfigProperty) {
  70. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  71. serviceConfigProperty.serviceConfig = serviceConfig;
  72. serviceConfig.configs.pushObject(serviceConfigProperty);
  73. serviceConfigProperty.validate();
  74. });
  75. console.log('pushing ' + serviceConfig.serviceName);
  76. self.content.pushObject(serviceConfig);
  77. } else {
  78. console.log('skipping ' + serviceConfig.serviceName);
  79. }
  80. });
  81. this.set('selectedService', this.objectAt(0));
  82. this.doInit = false;
  83. }
  84. },
  85. submit: function () {
  86. if (!this.get('isSubmitDisabled')) {
  87. // TODO:
  88. // save service configs in App.db (localStorage)
  89. var serviceConfigProperties = [];
  90. this.content.forEach(function(_content){
  91. var config = [];
  92. config = _content.configs;
  93. config.forEach(function(_configProperties){
  94. serviceConfigProperties.push(_configProperties);
  95. console.log('TRACE: pushing: ' + _configProperties.name);
  96. console.log('INFO: value: ' + _configProperties.value);
  97. },this);
  98. },this);
  99. db.setServiceConfigProperties(serviceConfigProperties);
  100. App.router.send('next');
  101. //App.get('router').transitionTo('step8');
  102. }
  103. },
  104. showMasterHosts: function (event) {
  105. var serviceConfig = event.context;
  106. App.ModalPopup.show({
  107. header: serviceConfig.category + ' Hosts',
  108. bodyClass: Ember.View.extend({
  109. serviceConfig: serviceConfig,
  110. templateName: require('templates/installer/master_hosts_popup')
  111. })
  112. });
  113. },
  114. showSlaveHosts: function (event) {
  115. var serviceConfig = event.context;
  116. App.ModalPopup.show({
  117. header: serviceConfig.category + ' Hosts',
  118. bodyClass: Ember.View.extend({
  119. serviceConfig: serviceConfig,
  120. templateName: require('templates/installer/slave_hosts_popup')
  121. })
  122. });
  123. }
  124. });
  125. App.SlaveComponentGroupsController = Ember.ArrayController.extend({
  126. name: 'slaveComponentGroupsController',
  127. contentBinding: 'App.router.installerStep7Controller.slaveComponentHosts',
  128. selectedComponentName: function () {
  129. switch (App.router.get('installerStep7Controller.selectedService.serviceName')) {
  130. case 'HDFS':
  131. return 'DataNode';
  132. case 'MAPREDUCE':
  133. return 'TaskTracker';
  134. case 'HBASE':
  135. return 'RegionServer';
  136. }
  137. }.property('App.router.installerStep7Controller.selectedService'),
  138. showAddSlaveComponentGroup: function (event) {
  139. var componentName = event.context;
  140. App.ModalPopup.show({
  141. header: componentName + ' Groups',
  142. bodyClass: Ember.View.extend({
  143. controllerBinding: 'App.router.slaveComponentGroupsController',
  144. templateName: require('templates/installer/slave_hosts_popup')
  145. }),
  146. onPrimary: function () {
  147. }
  148. });
  149. },
  150. showEditSlaveComponentGroups: function (event) {
  151. this.showAddSlaveComponentGroup(event);
  152. },
  153. hosts: function () {
  154. return this.findProperty('componentName', this.get('selectedComponentName')).hosts;
  155. }.property('@each.hosts', 'selectedComponentName'),
  156. groups: function () {
  157. return this.findProperty('componentName', this.get('selectedComponentName')).hosts.mapProperty('group').uniq();
  158. }.property('@each.hosts', 'selectedComponentName')
  159. });