step4.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.MainAdminSecurityAddStep4Controller = App.MainAdminSecurityProgressController.extend(App.AddSecurityConfigs, {
  20. name: 'mainAdminSecurityAddStep4Controller',
  21. isBackBtnDisabled: function () {
  22. return !this.get('commands').someProperty('isError');
  23. }.property('commands.@each.isCompleted'),
  24. isSecurityApplied: function () {
  25. return this.get('commands').someProperty('name', 'START_SERVICES') && this.get('commands').findProperty('name', 'START_SERVICES').get('isSuccess');
  26. }.property('commands.@each.isCompleted'),
  27. /**
  28. * control disabled property of completion button
  29. */
  30. enableSubmit: function () {
  31. var addSecurityController = App.router.get('addSecurityController');
  32. if (this.get('commands').someProperty('isError') || this.get('commands').everyProperty('isSuccess')) {
  33. this.set('isSubmitDisabled', false);
  34. if (this.get('commands').someProperty('isError')) {
  35. addSecurityController.setStepsEnable();
  36. }
  37. } else {
  38. this.set('isSubmitDisabled', true);
  39. addSecurityController.setLowerStepsDisable(4);
  40. }
  41. }.observes('commands.@each.isCompleted'),
  42. /**
  43. * clear step info
  44. */
  45. clearStep: function () {
  46. this.set('commands', []);
  47. this.set('isSubmitDisabled', true);
  48. this.get('serviceConfigTags').clear();
  49. },
  50. loadCommands: function () {
  51. this._super();
  52. // Determine if ATS Component needs to be removed
  53. var isATSInstalled = this.get('content.isATSInstalled');
  54. var doesATSSupportKerberos = App.get("doesATSSupportKerberos");
  55. if (isATSInstalled && !doesATSSupportKerberos) {
  56. this.get('commands').splice(2, 0, App.Poll.create({name: 'DELETE_ATS', label: Em.I18n.translations['admin.addSecurity.apply.delete.ats'], isPolling: false}));
  57. }
  58. },
  59. /**
  60. * load step info
  61. */
  62. loadStep: function () {
  63. this.clearStep();
  64. this.prepareSecureConfigs();
  65. if (!this.resumeSavedCommands()) {
  66. this.loadCommands();
  67. this.addInfoToCommands();
  68. this.syncStopServicesOperation();
  69. this.addObserverToCommands();
  70. this.moveToNextCommand();
  71. }
  72. },
  73. /**
  74. * synchronize "STOP_SERVICES" operation from BO with command of step
  75. * @return {Boolean}
  76. */
  77. syncStopServicesOperation: function () {
  78. var runningOperations = App.router.get('backgroundOperationsController.services').filterProperty('isRunning');
  79. var stopAllOperation = runningOperations.findProperty('name', 'Stop All Services');
  80. var stopCommand = this.get('commands').findProperty('name', 'STOP_SERVICES');
  81. if (stopCommand && stopAllOperation) {
  82. stopCommand.set('requestId', stopAllOperation.get('id'));
  83. return true;
  84. }
  85. return false;
  86. },
  87. /**
  88. * resume previously saved commands
  89. * @return {Boolean}
  90. */
  91. resumeSavedCommands: function () {
  92. var commands = App.db.getSecurityDeployCommands();
  93. if (Em.isNone(commands) || commands.length === 0) return false;
  94. commands.forEach(function (_command, index) {
  95. commands[index] = App.Poll.create(_command);
  96. }, this);
  97. if (commands.someProperty('isError')) {
  98. this.get('commands').pushObjects(commands);
  99. this.addObserverToCommands();
  100. return true;
  101. } else if (commands.filterProperty('isStarted').someProperty('isCompleted', false)) {
  102. var runningCommand = commands.filterProperty('isStarted').findProperty('isCompleted', false);
  103. runningCommand.set('isStarted', false);
  104. this.get('commands').pushObjects(commands);
  105. } else {
  106. this.get('commands').pushObjects(commands);
  107. }
  108. this.addObserverToCommands();
  109. this.moveToNextCommand();
  110. return true;
  111. },
  112. manageSecureConfigs: function () {
  113. var serviceConfigTags = this.get('serviceConfigTags');
  114. var secureConfigs = this.get('secureConfigs');
  115. var siteProperties = this.get('configs');
  116. if (serviceConfigTags) {
  117. secureConfigs.forEach(function (config) {
  118. this.setPrincipalValue(config.serviceName, config.name);
  119. }, this);
  120. serviceConfigTags.forEach(function (_serviceConfigTags) {
  121. _serviceConfigTags.newTagName = 'version' + (new Date).getTime();
  122. siteProperties.filterProperty('filename', _serviceConfigTags.siteName + '.xml').forEach(function (_config) {
  123. if (!/_hosts?$/.test(_config.name)) {
  124. _serviceConfigTags.configs[_config.name] = _config.value;
  125. }
  126. }, this);
  127. }, this);
  128. return true;
  129. } else {
  130. var command = this.get('commands').findProperty('name', 'APPLY_CONFIGURATIONS');
  131. command.set('isSuccess', false);
  132. command.set('isError', true);
  133. this.onJsError();
  134. return false;
  135. }
  136. },
  137. /**
  138. * send DELETE command to server to delete component
  139. * @param componentName
  140. * @param hostName
  141. */
  142. deleteComponents: function(componentName, hostName) {
  143. App.ajax.send({
  144. name: 'common.delete.host_component',
  145. sender: this,
  146. data: {
  147. componentName: componentName,
  148. hostName: hostName
  149. },
  150. success: 'onDeleteComplete',
  151. error: 'onDeleteError'
  152. });
  153. },
  154. /**
  155. * callback on successful deletion of component
  156. */
  157. onDeleteComplete: function () {
  158. var deleteAtsCommand = this.get('commands').findProperty('name', 'DELETE_ATS');
  159. console.warn('APP_TIMELINE_SERVER doesn\'t support security mode in this HDP stack. It has been removed from YARN service ');
  160. deleteAtsCommand.set('isError', false);
  161. deleteAtsCommand.set('isSuccess', true);
  162. },
  163. /**
  164. * callback on failed deletion of component
  165. */
  166. onDeleteError: function () {
  167. var deleteAtsCommand = this.get('commands').findProperty('name', 'DELETE_ATS');
  168. console.warn('Error: Can\'t delete APP_TIMELINE_SERVER');
  169. deleteAtsCommand.set('isError', true);
  170. deleteAtsCommand.set('isSuccess', false);
  171. },
  172. /**
  173. * show popup when js error occurred
  174. */
  175. onJsError: function () {
  176. App.ModalPopup.show({
  177. header: Em.I18n.t('common.error'),
  178. secondary: false,
  179. bodyClass: Ember.View.extend({
  180. template: Ember.Handlebars.compile('<p>{{t admin.security.apply.configuration.error}}</p>')
  181. })
  182. });
  183. }
  184. });