step2_controller.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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/wizard/step7_controller');
  20. App.KerberosWizardStep2Controller = App.WizardStep7Controller.extend({
  21. name: "kerberosWizardStep2Controller",
  22. isKerberosWizard: true,
  23. selectedServiceNames: ['KERBEROS'],
  24. allSelectedServiceNames: ['KERBEROS'],
  25. componentName: 'KERBEROS_CLIENT',
  26. installedServiceNames: [],
  27. servicesInstalled: false,
  28. addMiscTabToPage: false,
  29. hostNames: function () {
  30. return this.get('content.hosts');
  31. }.property('content.hosts'),
  32. serviceConfigTags: [],
  33. clearStep: function () {
  34. this._super();
  35. this.get('serviceConfigTags').clear();
  36. this.set('servicesInstalled', false);
  37. },
  38. /**
  39. * On load function
  40. * @method loadStep
  41. */
  42. loadStep: function () {
  43. console.log("TRACE: Loading step7: Configure Services");
  44. this.clearStep();
  45. var kerberosStackService = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  46. if (!kerberosStackService) return;
  47. //STEP 1: Load advanced configs
  48. var advancedConfigs = this.get('content.advancedServiceConfig');
  49. //STEP 2: Load on-site configs by service from local DB
  50. var storedConfigs = this.get('content.serviceConfigProperties');
  51. //STEP 3: Merge pre-defined configs with loaded on-site configs
  52. var configs = App.config.mergePreDefinedWithStored(
  53. storedConfigs,
  54. advancedConfigs,
  55. this.get('selectedServiceNames'));
  56. App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
  57. //STEP 4: Add advanced configs
  58. App.config.addAdvancedConfigs(configs, advancedConfigs);
  59. this.applyServicesConfigs(configs, storedConfigs);
  60. },
  61. submit: function () {
  62. this.set('isSubmitDisabled', true);
  63. var self = this;
  64. this.deleteKerberosService().always(function (data) {
  65. self.createKerberosResources();
  66. });
  67. },
  68. createKerberosResources: function () {
  69. var self = this;
  70. this.createKerberosService().done(function () {
  71. self.createKerberosComponent().done(function () {
  72. self.createKerberosHostComponents().done(function () {
  73. self.createConfigurations().done(function () {
  74. self.createKerberosAdminSession().done(function() {
  75. App.router.send('next');
  76. });
  77. });
  78. });
  79. });
  80. });
  81. },
  82. /**
  83. * Delete Kerberos service if it exists
  84. */
  85. deleteKerberosService: function () {
  86. var serviceName = this.selectedServiceNames[0];
  87. return App.ajax.send({
  88. name: 'common.delete.service',
  89. sender: this,
  90. data: {
  91. serviceName: serviceName
  92. }
  93. });
  94. },
  95. createKerberosService: function () {
  96. return App.ajax.send({
  97. name: 'wizard.step8.create_selected_services',
  98. sender: this,
  99. data: {
  100. data: '{"ServiceInfo": { "service_name": "KERBEROS"}}',
  101. cluster: App.get('clusterName') || App.clusterStatus.get('clusterName')
  102. }
  103. });
  104. },
  105. createKerberosComponent: function () {
  106. return App.ajax.send({
  107. name: 'common.create_component',
  108. sender: this,
  109. data: {
  110. serviceName: this.selectedServiceNames[0],
  111. componentName: this.componentName
  112. }
  113. });
  114. },
  115. createKerberosHostComponents: function() {
  116. var hostNames = this.get('content.hosts');
  117. var queryStr = '';
  118. hostNames.forEach(function (hostName) {
  119. queryStr += 'Hosts/host_name=' + hostName + '|';
  120. });
  121. //slice off last symbol '|'
  122. queryStr = queryStr.slice(0, -1);
  123. var data = {
  124. "RequestInfo": {
  125. "query": queryStr
  126. },
  127. "Body": {
  128. "host_components": [
  129. {
  130. "HostRoles": {
  131. "component_name": this.componentName
  132. }
  133. }
  134. ]
  135. }
  136. };
  137. return App.ajax.send({
  138. name: 'wizard.step8.register_host_to_component',
  139. sender: this,
  140. data: {
  141. cluster: App.router.getClusterName(),
  142. data: JSON.stringify(data)
  143. }
  144. });
  145. },
  146. createConfigurations: function () {
  147. var service = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  148. var serviceConfigTags = [];
  149. var tag = 'version' + (new Date).getTime();
  150. Object.keys(service.get('configTypes')).forEach(function (type) {
  151. if (!serviceConfigTags.someProperty('type', type)) {
  152. var obj = this.createKerberosSiteObj(type, tag);
  153. obj.service_config_version_note = Em.I18n.t('admin.kerberos.wizard.configuration.note');
  154. serviceConfigTags.pushObject(obj);
  155. }
  156. }, this);
  157. var allConfigData = [];
  158. var serviceConfigData = [];
  159. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  160. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  161. if (serviceConfigTag) {
  162. serviceConfigData.pushObject(serviceConfigTag);
  163. }
  164. }, this);
  165. if (serviceConfigData.length) {
  166. allConfigData.pushObject(JSON.stringify({
  167. Clusters: {
  168. desired_config: serviceConfigData
  169. }
  170. }));
  171. }
  172. return App.ajax.send({
  173. name: 'common.across.services.configurations',
  174. sender: this,
  175. data: {
  176. data: '[' + allConfigData.toString() + ']'
  177. }
  178. });
  179. },
  180. createKerberosSiteObj: function (site, tag) {
  181. var properties = {};
  182. var content = this.get('stepConfigs')[0].get('configs');
  183. var configs = content.filterProperty('filename', site + '.xml');
  184. configs.forEach(function (_configProperty) {
  185. // do not pass any globals whose name ends with _host or _hosts
  186. if (_configProperty.isRequiredByAgent !== false) {
  187. properties[_configProperty.name] = _configProperty.value;
  188. }
  189. }, this);
  190. return {"type": site, "tag": tag, "properties": properties};
  191. },
  192. /**
  193. * puts kerberos admin credentials in the live cluster session
  194. * @returns {*} jqXHr
  195. */
  196. createKerberosAdminSession: function () {
  197. var configs = this.get('stepConfigs')[0].get('configs');
  198. var adminPrincipalValue = configs.findProperty('name','admin_principal').value;
  199. var adminPasswordValue = configs.findProperty('name','admin_password').value;
  200. return App.ajax.send({
  201. name: 'common.cluster.update',
  202. sender: this,
  203. data: {
  204. clusterName: App.get('clusterName') || App.clusterStatus.get('clusterName'),
  205. data: [{
  206. session_attributes : {
  207. kerberos_admin : {principal : adminPrincipalValue, password : adminPasswordValue}
  208. }
  209. }]
  210. }
  211. });
  212. }
  213. });