step2.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. App.MainAdminSecurityAddStep2Controller = Em.Controller.extend({
  20. name: 'mainAdminSecurityAddStep2Controller',
  21. stepConfigs: [],
  22. installedServices: [],
  23. selectedService: null,
  24. isSubmitDisabled: function () {
  25. return !this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0);
  26. }.property('stepConfigs.@each.errorCount'),
  27. clearStep: function () {
  28. this.get('stepConfigs').clear();
  29. },
  30. /**
  31. * Function is called whenever the step is loaded
  32. */
  33. loadStep: function () {
  34. console.log("TRACE: Loading addSecurity step2: Configure Services");
  35. this.clearStep();
  36. this.addMasterHostToGlobals(this.get('content.services'));
  37. this.renderServiceConfigs(this.get('content.services'));
  38. var storedServices = this.get('content.serviceConfigProperties');
  39. if (storedServices) {
  40. var configs = new Ember.Set();
  41. // for all services`
  42. this.get('stepConfigs').forEach(function (_content) {
  43. //for all components
  44. _content.get('configs').forEach(function (_config) {
  45. var componentVal = storedServices.findProperty('name', _config.get('name'));
  46. //if we have config for specified component
  47. if (componentVal) {
  48. //set it
  49. _config.set('value', componentVal.value);
  50. }
  51. }, this);
  52. }, this);
  53. }
  54. //
  55. this.set('installedServices', App.Service.find().mapProperty('serviceName'));
  56. console.log("The services are: " + this.get('installedServices'));
  57. //
  58. },
  59. /**
  60. * Render configs for active services
  61. * @param serviceConfigs
  62. */
  63. renderServiceConfigs: function (serviceConfigs) {
  64. serviceConfigs.forEach(function (_serviceConfig) {
  65. var serviceConfig = App.ServiceConfig.create({
  66. filename: _serviceConfig.filename,
  67. serviceName: _serviceConfig.serviceName,
  68. displayName: _serviceConfig.displayName,
  69. configCategories: _serviceConfig.configCategories,
  70. showConfig: true,
  71. configs: []
  72. });
  73. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  74. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  75. this.get('stepConfigs').pushObject(serviceConfig);
  76. }, this);
  77. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  78. },
  79. /**
  80. * Load child components to service config object
  81. * @param _componentConfig
  82. * @param componentConfig
  83. */
  84. loadComponentConfigs: function (_componentConfig, componentConfig) {
  85. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  86. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  87. componentConfig.configs.pushObject(serviceConfigProperty);
  88. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  89. serviceConfigProperty.validate();
  90. }, this);
  91. },
  92. addMasterHostToGlobals: function (serviceConfigs) {
  93. var oozieService = serviceConfigs.findProperty('serviceName', 'OOZIE');
  94. var hiveService = serviceConfigs.findProperty('serviceName', 'HIVE');
  95. var webHcatService = App.Service.find().mapProperty('serviceName').contains('WEBHCAT');
  96. var nagiosService = serviceConfigs.findProperty('serviceName', 'NAGIOS');
  97. var generalService = serviceConfigs.findProperty('serviceName', 'GENERAL');
  98. if (oozieService) {
  99. var oozieServerHost = oozieService.configs.findProperty('name', 'oozie_servername');
  100. var oozieServerPrincipal = oozieService.configs.findProperty('name', 'oozie_principal_name');
  101. var oozieSpnegoPrincipal = generalService.configs.findProperty('name', 'oozie_http_principal_name');
  102. if (oozieServerHost && oozieServerPrincipal && oozieSpnegoPrincipal) {
  103. oozieServerHost.defaultValue = App.Service.find('OOZIE').get('hostComponents').findProperty('componentName', 'OOZIE_SERVER').get('host.hostName');
  104. oozieServerPrincipal.defaultValue = 'oozie/' + oozieServerHost.defaultValue;
  105. oozieSpnegoPrincipal.defaultValue = 'HTTP/' + oozieServerHost.defaultValue;
  106. oozieSpnegoPrincipal.isVisible = true;
  107. }
  108. }
  109. if (hiveService) {
  110. var hiveServerHost = hiveService.configs.findProperty('name', 'hive_metastore');
  111. if (hiveServerHost) {
  112. hiveServerHost.defaultValue = App.Service.find('HIVE').get('hostComponents').findProperty('componentName', 'HIVE_SERVER').get('host.hostName');
  113. }
  114. }
  115. if(webHcatService) {
  116. var webHcatHost = App.Service.find('WEBHCAT').get('hostComponents').findProperty('componentName', 'WEBHCAT_SERVER').get('host.hostName');
  117. var webHcatSpnegoPrincipal = generalService.configs.findProperty('name', 'webHCat_http_principal_name');
  118. if(webHcatHost && webHcatSpnegoPrincipal) {
  119. webHcatSpnegoPrincipal.defaultValue = 'HTTP/' + webHcatHost;
  120. webHcatSpnegoPrincipal.isVisible = true;
  121. }
  122. }
  123. if(nagiosService) {
  124. var nagiosServerHost = nagiosService.configs.findProperty('name', 'nagios_server');
  125. var nagiosServerPrincipal = nagiosService.configs.findProperty('name', 'nagios_principal_name');
  126. if (nagiosServerHost && nagiosServerPrincipal) {
  127. nagiosServerHost.defaultValue = App.Service.find('NAGIOS').get('hostComponents').findProperty('componentName', 'NAGIOS_SERVER').get('host.hostName');
  128. nagiosServerPrincipal.defaultValue = 'nagios/' + nagiosServerHost.defaultValue;
  129. }
  130. }
  131. },
  132. /**
  133. * submit and move to step3
  134. */
  135. submit: function () {
  136. if (!this.get('isSubmitDisabled')) {
  137. App.router.send('next');
  138. }
  139. }
  140. });