step2.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 stringUtils = require('utils/string_utils');
  20. App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
  21. name: 'mainAdminSecurityAddStep2Controller',
  22. stepConfigs: [],
  23. installedServices: [],
  24. selectedService: null,
  25. isSubmitDisabled: function () {
  26. return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0);
  27. }.property('stepConfigs.@each.errorCount'),
  28. clearStep: function () {
  29. this.get('stepConfigs').clear();
  30. },
  31. /**
  32. * Function is called whenever the step is loaded
  33. */
  34. loadStep: function () {
  35. console.log("TRACE: Loading addSecurity step2: Configure Services");
  36. this.clearStep();
  37. this.addMasterHostToGlobals(this.get('content.services'));
  38. this.addSlaveHostToGlobals(this.get('content.services'));
  39. this.renderServiceConfigs(this.get('content.services'));
  40. var storedServices = this.get('content.serviceConfigProperties');
  41. if (storedServices) {
  42. var configs = new Ember.Set();
  43. // for all services`
  44. this.get('stepConfigs').forEach(function (_content) {
  45. //for all components
  46. _content.get('configs').forEach(function (_config) {
  47. var componentVal = storedServices.findProperty('name', _config.get('name'));
  48. //if we have config for specified component
  49. if (componentVal) {
  50. //set it
  51. _config.set('value', componentVal.value);
  52. }
  53. }, this);
  54. }, this);
  55. }
  56. //
  57. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  58. console.log("The services are: " + this.get('installedServices'));
  59. //
  60. },
  61. /**
  62. * Render configs for active services
  63. * @param serviceConfigs
  64. */
  65. renderServiceConfigs: function (serviceConfigs) {
  66. serviceConfigs.forEach(function (_serviceConfig) {
  67. var serviceConfig = App.ServiceConfig.create({
  68. filename: _serviceConfig.filename,
  69. serviceName: _serviceConfig.serviceName,
  70. displayName: _serviceConfig.displayName,
  71. configCategories: _serviceConfig.configCategories,
  72. showConfig: true,
  73. configs: []
  74. });
  75. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  76. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  77. this.get('stepConfigs').pushObject(serviceConfig);
  78. }, this);
  79. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  80. },
  81. /**
  82. * Load child components to service config object
  83. * @param _componentConfig
  84. * @param componentConfig
  85. */
  86. loadComponentConfigs: function (_componentConfig, componentConfig) {
  87. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  88. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  89. componentConfig.configs.pushObject(serviceConfigProperty);
  90. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  91. serviceConfigProperty.validate();
  92. }, this);
  93. },
  94. /**
  95. * fill config with hosts of component
  96. * @param service
  97. * @param configName
  98. * @param componentName
  99. */
  100. setHostsToConfig: function(service, configName, componentName){
  101. if(service){
  102. var hosts = service.configs.findProperty('name', configName);
  103. if(hosts){
  104. hosts.defaultValue = App.Service.find(service.serviceName)
  105. .get('hostComponents')
  106. .filterProperty('componentName', componentName)
  107. .mapProperty('host.hostName');
  108. }
  109. }
  110. },
  111. addSlaveHostToGlobals: function(serviceConfigs){
  112. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  113. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  114. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  115. this.setHostsToConfig(hdfsService, 'datanode_hosts', 'DATANODE');
  116. this.setHostsToConfig(mapReduceService, 'tasktracker_hosts', 'TASKTRACKER');
  117. this.setHostsToConfig(hbaseService, 'regionserver_hosts', 'HBASE_REGIONSERVER');
  118. },
  119. addMasterHostToGlobals: function (serviceConfigs) {
  120. var oozieService = serviceConfigs.findProperty('serviceName', 'OOZIE');
  121. var hiveService = serviceConfigs.findProperty('serviceName', 'HIVE');
  122. var webHcatService = App.Service.find().mapProperty('serviceName').contains('WEBHCAT');
  123. var nagiosService = serviceConfigs.findProperty('serviceName', 'NAGIOS');
  124. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL');
  125. var hbaseService = serviceConfigs.findProperty('serviceName', 'HBASE');
  126. var zooKeeperService = serviceConfigs.findProperty('serviceName', 'ZOOKEEPER');
  127. var hdfsService = serviceConfigs.findProperty('serviceName', 'HDFS');
  128. var mapReduceService = serviceConfigs.findProperty('serviceName', 'MAPREDUCE');
  129. if (oozieService) {
  130. var oozieServerHost = oozieService.configs.findProperty('name', 'oozie_servername');
  131. var oozieServerPrincipal = oozieService.configs.findProperty('name', 'oozie_principal_name');
  132. var oozieSpnegoPrincipal = generalService.configs.findProperty('name', 'oozie_http_principal_name');
  133. if (oozieServerHost && oozieServerPrincipal && oozieSpnegoPrincipal) {
  134. oozieServerHost.defaultValue = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  135. oozieServerPrincipal.defaultValue = 'oozie/' + oozieServerHost.defaultValue;
  136. oozieSpnegoPrincipal.defaultValue = 'HTTP/' + oozieServerHost.defaultValue;
  137. oozieSpnegoPrincipal.isVisible = true;
  138. }
  139. }
  140. if (hiveService) {
  141. var hiveServerHost = hiveService.configs.findProperty('name', 'hive_metastore');
  142. if (hiveServerHost) {
  143. hiveServerHost.defaultValue = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  144. }
  145. }
  146. if(webHcatService) {
  147. var webHcatHost = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER').get('host.hostName');
  148. var webHcatSpnegoPrincipal = generalService.configs.findProperty('name', 'webHCat_http_principal_name');
  149. if(webHcatHost && webHcatSpnegoPrincipal) {
  150. webHcatSpnegoPrincipal.defaultValue = 'HTTP/' + webHcatHost;
  151. webHcatSpnegoPrincipal.isVisible = true;
  152. }
  153. }
  154. if(nagiosService) {
  155. var nagiosServerHost = nagiosService.configs.findProperty('name', 'nagios_server');
  156. var nagiosServerPrincipal = nagiosService.configs.findProperty('name', 'nagios_principal_name');
  157. if (nagiosServerHost && nagiosServerPrincipal) {
  158. nagiosServerHost.defaultValue = App.Service.find('NAGIOS').get('hostComponents').findProperty('componentName', 'NAGIOS_SERVER').get('host.hostName');
  159. nagiosServerPrincipal.defaultValue = 'nagios/' + nagiosServerHost.defaultValue;
  160. }
  161. }
  162. if(hdfsService){
  163. var namenodeHost = hdfsService.configs.findProperty('name', 'namenode_host');
  164. var sNamenodeHost = hdfsService.configs.findProperty('name', 'snamenode_host');
  165. if (namenodeHost && sNamenodeHost) {
  166. namenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'NAMENODE').get('host.hostName');
  167. sNamenodeHost.defaultValue = App.Service.find('HDFS').get('hostComponents').findProperty('componentName', 'SECONDARY_NAMENODE').get('host.hostName');
  168. }
  169. }
  170. if(mapReduceService){
  171. var jobTrackerHost = mapReduceService.configs.findProperty('name', 'jobtracker_host');
  172. if (jobTrackerHost) {
  173. jobTrackerHost.defaultValue = App.Service.find('MAPREDUCE').get('hostComponents').findProperty('componentName', 'JOBTRACKER').get('host.hostName');
  174. }
  175. }
  176. this.setHostsToConfig(hbaseService, 'hbasemaster_host', 'HBASE_MASTER');
  177. this.setHostsToConfig(zooKeeperService, 'zookeeperserver_hosts', 'ZOOKEEPER_SERVER');
  178. },
  179. /**
  180. * submit and move to step3
  181. */
  182. submit: function () {
  183. if (!this.get('isSubmitDisabled')) {
  184. App.router.send('next');
  185. }
  186. }
  187. });