addSecurity_controller.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. installedServices: function() {
  30. return App.Service.find().mapProperty('serviceName');
  31. }.property(),
  32. /**
  33. * Loads all prior steps on refresh
  34. */
  35. loadAllPriorSteps: function () {
  36. var step = this.get('currentStep');
  37. switch (step) {
  38. case '4':
  39. case '3':
  40. case '2':
  41. this.loadServiceConfigs();
  42. case '1':
  43. this.loadServices();
  44. this.loadNnHastatus();
  45. }
  46. },
  47. clearServices: function () {
  48. if (this.get('content.services')) {
  49. this.get('content.services').clear();
  50. }
  51. },
  52. /**
  53. * Loads all installed services
  54. */
  55. loadServices: function () {
  56. this.clearServices();
  57. var secureServices;
  58. if(App.get('isHadoop2Stack')) {
  59. secureServices = $.extend(true, [], require('data/HDP2/secure_configs'));
  60. } else {
  61. secureServices = $.extend(true, [], require('data/secure_configs'));
  62. }
  63. var installedServices = this.get('installedServices');
  64. //General (only non service tab) tab is always displayed
  65. this.get('content.services').push(secureServices.findProperty('serviceName', 'GENERAL'));
  66. installedServices.forEach(function (_service) {
  67. var secureService = secureServices.findProperty('serviceName', _service);
  68. if (secureService) {
  69. this.get('content.services').push(secureService);
  70. }
  71. }, this);
  72. },
  73. loadNnHastatus: function() {
  74. var isNnHa = App.db.getIsNameNodeHa();
  75. this.set('content.isNnHa', isNnHa);
  76. },
  77. saveServiceConfigProperties: function (stepController) {
  78. var serviceConfigProperties = [];
  79. stepController.get('stepConfigs').forEach(function (_content) {
  80. _content.get('configs').forEach(function (_configProperties) {
  81. var displayType = _configProperties.get('displayType');
  82. if (displayType === 'directories' || displayType === 'directory') {
  83. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  84. _configProperties.set('value', value);
  85. }
  86. var overrides = _configProperties.get('overrides');
  87. var overridesArray = [];
  88. if(overrides!=null){
  89. overrides.forEach(function(override){
  90. var overrideEntry = {
  91. value: override.get('value'),
  92. hosts: []
  93. };
  94. override.get('selectedHostOptions').forEach(function(host){
  95. overrideEntry.hosts.push(host);
  96. });
  97. overridesArray.push(overrideEntry);
  98. });
  99. }
  100. overridesArray = (overridesArray.length) ? overridesArray : null;
  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: overridesArray
  113. };
  114. serviceConfigProperties.push(configProperty);
  115. }, this);
  116. }, this);
  117. App.db.setSecureConfigProperties(serviceConfigProperties);
  118. this.set('content.serviceConfigProperties', serviceConfigProperties);
  119. },
  120. /**
  121. * Loads all service config properties
  122. */
  123. loadServiceConfigs: function () {
  124. var serviceConfigProperties = App.db.getSecureConfigProperties();
  125. this.set('content.serviceConfigProperties', serviceConfigProperties);
  126. }
  127. });