addSecurity_controller.js 4.9 KB

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