step7_controller.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. /**
  20. * By Step 7, we have the following information stored in App.db and set on this
  21. * controller by the router.
  22. *
  23. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  24. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  25. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  26. *
  27. */
  28. App.InstallerStep7Controller = Em.ArrayController.extend({
  29. name: 'installerStep7Controller',
  30. content: [],
  31. selectedService: null,
  32. slaveHostToGroup: null,
  33. isSubmitDisabled: function() {
  34. return !this.everyProperty('errorCount', 0);
  35. }.property('@each.errorCount'),
  36. // TODO: set attributes from localStorage in router
  37. selectedServiceNames: [ 'HDFS', 'MAPREDUCE', 'GANGLIA', 'NAGIOS', 'HBASE', 'PIG', 'SQOOP', 'OOZIE', 'HIVE', 'ZOOKEEPER'],
  38. masterComponentHosts: require('data/mock/master_component_hosts'),
  39. slaveComponentHosts: require('data/mock/slave_component_hosts'),
  40. doInit: true,
  41. loadConfigs: function() {
  42. // load dependent data from the database
  43. var selectedServiceNamesInDB = App.db.getSelectedServiceNames();
  44. if (selectedServiceNamesInDB !== undefined) {
  45. this.set('selectedServiceNames', selectedServiceNamesInDB);
  46. }
  47. var masterComponentHostsInDB = App.db.getMasterComponentHosts();
  48. if (masterComponentHostsInDB != undefined) {
  49. this.set('masterComponentHosts', masterComponentHostsInDB);
  50. }
  51. var slaveComponentHostsInDB = App.db.getSlaveComponentHosts();
  52. if (slaveComponentHostsInDB != undefined) {
  53. this.set('slaveComponentHosts', slaveComponentHostsInDB);
  54. }
  55. // TODO: check App.db to see if configs have been saved already
  56. if (this.doInit) {
  57. var serviceConfigs = require('data/service_configs');
  58. var self = this;
  59. this.set('content', []);
  60. serviceConfigs.forEach(function(_serviceConfig) {
  61. var serviceConfig = App.ServiceConfig.create({
  62. serviceName: _serviceConfig.serviceName,
  63. displayName: _serviceConfig.displayName,
  64. configCategories: _serviceConfig.configCategories,
  65. configs: []
  66. });
  67. if (self.selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  68. _serviceConfig.configs.forEach(function(_serviceConfigProperty) {
  69. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  70. serviceConfigProperty.serviceConfig = serviceConfig;
  71. serviceConfig.configs.pushObject(serviceConfigProperty);
  72. serviceConfigProperty.validate();
  73. });
  74. console.log('pushing ' + serviceConfig.serviceName);
  75. self.content.pushObject(serviceConfig);
  76. } else {
  77. console.log('skipping ' + serviceConfig.serviceName);
  78. }
  79. });
  80. this.set('selectedService', this.objectAt(0));
  81. this.doInit = false;
  82. }
  83. },
  84. submit: function() {
  85. if (!this.get('isSubmitDisabled')) {
  86. // TODO:
  87. // save service configs in App.db (localStorage)
  88. App.get('router').transitionTo('step8');
  89. }
  90. },
  91. showMasterHosts: function(event) {
  92. var serviceConfig = event.context;
  93. App.ModalPopup.show({
  94. header: serviceConfig.category + ' Hosts',
  95. bodyClass: Ember.View.extend({
  96. serviceConfig: serviceConfig,
  97. templateName: require('templates/installer/master_hosts_popup')
  98. })
  99. });
  100. },
  101. showSlaveHosts: function(event) {
  102. var serviceConfig = event.context;
  103. App.ModalPopup.show({
  104. header: serviceConfig.category + ' Hosts',
  105. bodyClass: Ember.View.extend({
  106. serviceConfig: serviceConfig,
  107. templateName: require('templates/installer/slave_hosts_popup')
  108. })
  109. });
  110. }
  111. });
  112. App.SlaveComponentGroupsController = Ember.ArrayController.extend({
  113. name: 'slaveComponentGroupsController',
  114. contentBinding: 'App.router.installerStep7Controller.slaveComponentHosts',
  115. selectedComponentName: function() {
  116. switch (App.router.get('installerStep7Controller.selectedService.serviceName')) {
  117. case 'HDFS':
  118. return 'DataNode';
  119. case 'MAPREDUCE':
  120. return 'TaskTracker';
  121. case 'HBASE':
  122. return 'RegionServer';
  123. }
  124. }.property('App.router.installerStep7Controller.selectedService'),
  125. showAddSlaveComponentGroup: function (event) {
  126. var componentName = event.context;
  127. App.ModalPopup.show({
  128. header: componentName + ' Groups',
  129. bodyClass: Ember.View.extend({
  130. controllerBinding: 'App.router.slaveComponentGroupsController',
  131. templateName: require('templates/installer/slave_hosts_popup')
  132. }),
  133. onPrimary: function() {
  134. }
  135. });
  136. },
  137. showEditSlaveComponentGroups: function(event) {
  138. this.showAddSlaveComponentGroup(event);
  139. },
  140. hosts: function() {
  141. return this.findProperty('componentName', this.get('selectedComponentName')).hosts;
  142. }.property('@each.hosts', 'selectedComponentName'),
  143. groups: function() {
  144. return this.findProperty('componentName', this.get('selectedComponentName')).hosts.mapProperty('group').uniq();
  145. }.property('@each.hosts', 'selectedComponentName')
  146. });