addSecurity_controller.js 5.3 KB

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