disable.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. require('controllers/main/admin/security/security_progress_controller');
  20. App.MainAdminSecurityDisableController = App.MainAdminSecurityProgressController.extend({
  21. name: 'mainAdminSecurityDisableController',
  22. secureServices: [],
  23. /**
  24. * values of site configs when security disabled.
  25. * Properties not defined in data/secure_mapping or data/HDP2/secure_mapping and needs to be changed on disabling
  26. * security should be defined in secureConfigValuesMap Object
  27. */
  28. secureConfigValuesMap: {
  29. 'nimbus.childopts': function(value) {
  30. return value.replace (/-Djava.security.auth.login.config\s*=\s*\S*/g, "");
  31. },
  32. 'ui.childopts': function(value) {
  33. return value.replace (/-Djava.security.auth.login.config\s*=\s*\S*/g, "");
  34. },
  35. 'supervisor.childopts': function(value) {
  36. return value.replace (/-Djava.security.auth.login.config\s*=\s*\S*/g, "");
  37. }
  38. },
  39. isSubmitDisabled: function () {
  40. return !(this.get('commands').someProperty('isError') || this.get('commands').everyProperty('isSuccess'));
  41. }.property('commands.@each.isCompleted'),
  42. /**
  43. * clear step info
  44. */
  45. clearStep: function () {
  46. this.get('commands').clear();
  47. this.get('secureServices').clear();
  48. this.get('serviceConfigTags').clear();
  49. },
  50. /**
  51. * load info required by current step
  52. */
  53. loadStep: function () {
  54. this.clearStep();
  55. var commands = App.db.getSecurityDeployCommands();
  56. if (commands && commands.length > 0) {
  57. commands.forEach(function (_command, index) {
  58. commands[index] = App.Poll.create(_command);
  59. }, this);
  60. if (commands.someProperty('isError', true)) {
  61. this.get('commands').pushObjects(commands);
  62. this.loadSecureServices();
  63. this.addObserverToCommands();
  64. return;
  65. } else if (commands.filterProperty('isStarted', true).someProperty('isCompleted', false)) {
  66. var runningCommand = commands.filterProperty('isStarted', true).findProperty('isCompleted', false);
  67. runningCommand.set('isStarted', false);
  68. this.get('commands').pushObjects(commands);
  69. } else {
  70. this.get('commands').pushObjects(commands);
  71. }
  72. } else {
  73. this.loadCommands();
  74. this.addInfoToCommands();
  75. this.syncStopServicesCommand();
  76. }
  77. this.loadSecureServices();
  78. this.addObserverToCommands();
  79. this.moveToNextCommand();
  80. },
  81. /**
  82. * resume info about commands from local storage
  83. * @return {Boolean}
  84. */
  85. resumeCommands: function () {
  86. var commands = App.db.getSecurityDeployCommands();
  87. if (!commands || commands.length === 0) return false;
  88. commands.forEach(function (_command) {
  89. this.get('commands').pushObject(App.Poll.create(_command));
  90. }, this);
  91. var runningCommand = this.get('commands').filterProperty('isStarted').findProperty('isCompleted', false);
  92. if (runningCommand) {
  93. runningCommand.set('isStarted', false);
  94. }
  95. return true;
  96. },
  97. /**
  98. * synchronize existing background operation "Stop All Services" with command in Security wizard
  99. */
  100. syncStopServicesCommand: function () {
  101. var runningOperations = App.router.get('backgroundOperationsController.services').filterProperty('isRunning');
  102. var stopAllOperation = runningOperations.findProperty('name', 'Stop All Services');
  103. var stopCommand = this.get('commands').findProperty('name', 'STOP_SERVICES');
  104. if (stopCommand && stopAllOperation) {
  105. stopCommand.set('requestId', stopAllOperation.get('id'));
  106. }
  107. },
  108. /**
  109. * load secure configs of installed services
  110. */
  111. loadSecureServices: function () {
  112. var secureServices = require('data/HDP2/secure_configs');
  113. var installedServices = App.Service.find().mapProperty('serviceName');
  114. this.get('secureServices').pushObject(secureServices.findProperty('serviceName', 'GENERAL'));
  115. //General (only non service tab) tab is always displayed
  116. installedServices.forEach(function (_service) {
  117. var secureService = secureServices.findProperty('serviceName', _service);
  118. if (secureService) {
  119. this.get('secureServices').pushObject(secureService);
  120. }
  121. }, this);
  122. },
  123. /**
  124. * manage configurations from serviceConfigTags
  125. * @return {Boolean}
  126. */
  127. manageSecureConfigs: function () {
  128. var serviceConfigTags = this.get('serviceConfigTags');
  129. var secureProperties = this.get('secureProperties');
  130. var secureMapping = this.get('secureMapping');
  131. if (!serviceConfigTags || !secureProperties || !secureMapping) {
  132. var command = this.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS');
  133. command.set('isSuccess', false);
  134. command.set('isError', true);
  135. return false;
  136. } else {
  137. serviceConfigTags.forEach(function (_serviceConfigTags) {
  138. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  139. if (_serviceConfigTags.siteName.contains('-env')) {
  140. this.deleteDisabledConfigs(secureProperties, _serviceConfigTags);
  141. if (_serviceConfigTags.siteName === 'cluster-env') {
  142. _serviceConfigTags.configs.security_enabled = 'false';
  143. }
  144. } else {
  145. this.modifySiteConfigs(secureMapping, _serviceConfigTags);
  146. }
  147. }, this);
  148. return true;
  149. }
  150. },
  151. /**
  152. * delete configs, which aren't required when security disabled
  153. * @param secureProperties
  154. * @param _serviceConfigTags
  155. * @return {Boolean}
  156. */
  157. deleteDisabledConfigs: function (secureProperties, _serviceConfigTags) {
  158. if (!secureProperties || !_serviceConfigTags) return false;
  159. secureProperties.forEach(function (_config) {
  160. if (_config.name in _serviceConfigTags.configs) {
  161. delete _serviceConfigTags.configs[_config.name];
  162. }
  163. }, this);
  164. return true;
  165. },
  166. /**
  167. * delete unnecessary site configs and
  168. * change config values
  169. * @param secureMapping
  170. * @param _serviceConfigTags
  171. * @return {Boolean}
  172. */
  173. modifySiteConfigs: function (secureMapping, _serviceConfigTags) {
  174. var secureConfigValuesMap = this.get('secureConfigValuesMap');
  175. if (!secureMapping || !_serviceConfigTags) return false;
  176. // iterate over secureConfigValuesMap to update service-site configProperties not present in secureMapping metadata
  177. for (var key in secureConfigValuesMap) {
  178. if (key in _serviceConfigTags.configs) {
  179. var value = secureConfigValuesMap[key];
  180. if (typeof value == 'function') {
  181. _serviceConfigTags.configs[key] = value(_serviceConfigTags.configs[key]);
  182. } else if (value) {
  183. _serviceConfigTags.configs[key] = value;
  184. }
  185. }
  186. }
  187. secureMapping.filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  188. var configName = _config.name;
  189. var nonSecureConfigValue = _config.nonSecureValue;
  190. if (configName in _serviceConfigTags.configs) {
  191. if (nonSecureConfigValue) {
  192. _serviceConfigTags.configs[configName] = nonSecureConfigValue;
  193. } else {
  194. delete _serviceConfigTags.configs[configName]
  195. }
  196. }
  197. }, this);
  198. return true;
  199. }
  200. });