addSecurity_controller.js 5.6 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.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. var configCategories = require('data/HDP2/secure_configs');
  45. if (this.get('content.isATSInstalled') && App.get('doesATSSupportKerberos')) {
  46. var yarnConfigCategories = configCategories.findProperty('serviceName', 'YARN').configCategories;
  47. yarnConfigCategories.push(App.ServiceConfigCategory.create({ name: 'AppTimelineServer', displayName : 'Application Timeline Service'}));
  48. }
  49. return configCategories;
  50. }.property('App.router.clusterController.isLoaded'),
  51. /**
  52. * Loads all prior steps on refresh
  53. */
  54. loadAllPriorSteps: function () {
  55. var step = this.get('currentStep');
  56. switch (step) {
  57. case '4':
  58. case '3':
  59. case '2':
  60. this.loadServiceConfigs();
  61. case '1':
  62. this.loadServices();
  63. this.loadNnHaStatus();
  64. }
  65. },
  66. /**
  67. * Load installed services, which match secure services, to content
  68. */
  69. loadServices: function () {
  70. var secureServices = this.get('secureServices');
  71. var installedServices = this.get('installedServices');
  72. this.get('content.services').clear();
  73. //General (only non service tab) tab is always displayed
  74. this.get('content.services').push(secureServices.findProperty('serviceName', 'GENERAL'));
  75. installedServices.forEach(function (_service) {
  76. var secureService = secureServices.findProperty('serviceName', _service);
  77. if (secureService) {
  78. this.get('content.services').push(secureService);
  79. }
  80. }, this);
  81. },
  82. /**
  83. * identify whether NameNode in high availability mode
  84. */
  85. loadNnHaStatus: function () {
  86. this.set('content.isNnHa', App.db.getIsNameNodeHa());
  87. },
  88. /**
  89. * save service config properties to localStorage
  90. * @param stepController
  91. */
  92. saveServiceConfigProperties: function (stepController) {
  93. var serviceConfigProperties = [];
  94. stepController.get('stepConfigs').forEach(function (_content) {
  95. _content.get('configs').forEach(function (_configProperties) {
  96. _configProperties.set('value', App.config.trimProperty(_configProperties, true));
  97. var configProperty = {
  98. id: _configProperties.get('id'),
  99. name: _configProperties.get('name'),
  100. value: _configProperties.get('value'),
  101. defaultValue: _configProperties.get('defaultValue'),
  102. serviceName: _configProperties.get('serviceName'),
  103. domain: _configProperties.get('domain'),
  104. filename: _configProperties.get('filename'),
  105. unit: _configProperties.get('unit'),
  106. components: _configProperties.get('components'),
  107. component: _configProperties.get('component'),
  108. overrides: this.getConfigOverrides(_configProperties)
  109. };
  110. serviceConfigProperties.push(configProperty);
  111. }, this);
  112. }, this);
  113. App.db.setSecureConfigProperties(serviceConfigProperties);
  114. this.set('content.serviceConfigProperties', serviceConfigProperties);
  115. },
  116. /**
  117. * get overrides of config
  118. * @param _configProperties
  119. * @return {Array}
  120. */
  121. getConfigOverrides: function (_configProperties) {
  122. var overrides = _configProperties.get('overrides');
  123. var overridesArray = [];
  124. if (Array.isArray(overrides)) {
  125. overrides.forEach(function (override) {
  126. var overrideEntry = {
  127. value: override.get('value'),
  128. hosts: []
  129. };
  130. override.get('selectedHostOptions').forEach(function (host) {
  131. overrideEntry.hosts.push(host);
  132. });
  133. overridesArray.push(overrideEntry);
  134. });
  135. }
  136. return (overridesArray.length > 0) ? overridesArray : null;
  137. },
  138. /**
  139. * Load service config properties from localStorage
  140. */
  141. loadServiceConfigs: function () {
  142. this.set('content.serviceConfigProperties', App.db.getSecureConfigProperties());
  143. },
  144. /**
  145. * Clear all local storage data for Add security wizard namespace
  146. */
  147. finish: function () {
  148. this.resetDbNamespace();
  149. }
  150. });