addSecurity_controller.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.AddSecurityController = App.WizardController.extend({
  20. name: 'addSecurityController',
  21. securityEnabled: false,
  22. totalSteps: 4,
  23. content: Em.Object.create({
  24. services: [],
  25. isNnHa: 'false',
  26. serviceConfigProperties: null,
  27. controllerName: 'addSecurityController',
  28. isATSInstalled: function() {
  29. // Because the ATS component can be installed/removed at will, the check has to happen every time that security is added.
  30. var yarnService = App.Service.find().findProperty('serviceName','YARN');
  31. return !!yarnService && yarnService.get('hostComponents').someProperty('componentName', 'APP_TIMELINE_SERVER');
  32. }.property('App.router.clusterController.isLoaded')
  33. }),
  34. /**
  35. * installed services on cluster
  36. */
  37. installedServices: function () {
  38. return App.Service.find().mapProperty('serviceName');
  39. }.property(),
  40. /**
  41. * services with security configurations
  42. */
  43. secureServices: function () {
  44. if (App.get('isHadoop2Stack')) {
  45. var configCategories = require('data/HDP2/secure_configs');
  46. if (this.get('content.isATSInstalled') && App.get('doesATSSupportKerberos')) {
  47. var yarnConfigCategories = configCategories.findProperty('serviceName', 'YARN').configCategories;
  48. yarnConfigCategories.push(App.ServiceConfigCategory.create({ name: 'AppTimelineServer', displayName : 'Application Timeline Service'}));
  49. }
  50. return configCategories;
  51. } else {
  52. return require('data/secure_configs');
  53. }
  54. }.property('App.isHadoop2Stack', 'App.router.clusterController.isLoaded'),
  55. /**
  56. * Loads all prior steps on refresh
  57. */
  58. loadAllPriorSteps: function () {
  59. var step = this.get('currentStep');
  60. switch (step) {
  61. case '4':
  62. case '3':
  63. case '2':
  64. this.loadServiceConfigs();
  65. case '1':
  66. this.loadServices();
  67. this.loadNnHaStatus();
  68. }
  69. },
  70. /**
  71. * Load installed services, which match secure services, to content
  72. */
  73. loadServices: function () {
  74. var secureServices = this.get('secureServices');
  75. var installedServices = this.get('installedServices');
  76. this.get('content.services').clear();
  77. //General (only non service tab) tab is always displayed
  78. this.get('content.services').push(secureServices.findProperty('serviceName', 'GENERAL'));
  79. installedServices.forEach(function (_service) {
  80. var secureService = secureServices.findProperty('serviceName', _service);
  81. if (secureService) {
  82. this.get('content.services').push(secureService);
  83. }
  84. }, this);
  85. },
  86. /**
  87. * identify whether NameNode in high availability mode
  88. */
  89. loadNnHaStatus: function () {
  90. this.set('content.isNnHa', App.db.getIsNameNodeHa());
  91. },
  92. /**
  93. * save service config properties to localStorage
  94. * @param stepController
  95. */
  96. saveServiceConfigProperties: function (stepController) {
  97. var serviceConfigProperties = [];
  98. stepController.get('stepConfigs').forEach(function (_content) {
  99. _content.get('configs').forEach(function (_configProperties) {
  100. _configProperties.set('value', App.config.trimProperty(_configProperties, true));
  101. var configProperty = {
  102. id: _configProperties.get('id'),
  103. name: _configProperties.get('name'),
  104. value: _configProperties.get('value'),
  105. defaultValue: _configProperties.get('defaultValue'),
  106. serviceName: _configProperties.get('serviceName'),
  107. domain: _configProperties.get('domain'),
  108. filename: _configProperties.get('filename'),
  109. unit: _configProperties.get('unit'),
  110. components: _configProperties.get('components'),
  111. component: _configProperties.get('component'),
  112. overrides: this.getConfigOverrides(_configProperties)
  113. };
  114. serviceConfigProperties.push(configProperty);
  115. }, this);
  116. }, this);
  117. App.db.setSecureConfigProperties(serviceConfigProperties);
  118. this.set('content.serviceConfigProperties', serviceConfigProperties);
  119. },
  120. /**
  121. * get overrides of config
  122. * @param _configProperties
  123. * @return {Array}
  124. */
  125. getConfigOverrides: function (_configProperties) {
  126. var overrides = _configProperties.get('overrides');
  127. var overridesArray = [];
  128. if (Array.isArray(overrides)) {
  129. overrides.forEach(function (override) {
  130. var overrideEntry = {
  131. value: override.get('value'),
  132. hosts: []
  133. };
  134. override.get('selectedHostOptions').forEach(function (host) {
  135. overrideEntry.hosts.push(host);
  136. });
  137. overridesArray.push(overrideEntry);
  138. });
  139. }
  140. return (overridesArray.length > 0) ? overridesArray : null;
  141. },
  142. /**
  143. * Load service config properties from localStorage
  144. */
  145. loadServiceConfigs: function () {
  146. this.set('content.serviceConfigProperties', App.db.getSecureConfigProperties());
  147. },
  148. /**
  149. * Clear all local storage data for Add security wizard namespace
  150. */
  151. finish: function () {
  152. this.resetDbNamespace();
  153. }
  154. });