step2_controller.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. installedServiceNames: [],
  26. servicesInstalled: false,
  27. addMiscTabToPage: false,
  28. hostNames: function() {
  29. return this.get('content.hosts');
  30. }.property('content.hosts'),
  31. serviceConfigTags: [],
  32. clearStep: function () {
  33. this._super();
  34. this.get('serviceConfigTags').clear();
  35. this.set('servicesInstalled', false);
  36. },
  37. /**
  38. * On load function
  39. * @method loadStep
  40. */
  41. loadStep: function () {
  42. console.log("TRACE: Loading step7: Configure Services");
  43. this.clearStep();
  44. var kerberosStackService = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  45. if (!kerberosStackService) return;
  46. //STEP 1: Load advanced configs
  47. var advancedConfigs = this.get('content.advancedServiceConfig');
  48. //STEP 2: Load on-site configs by service from local DB
  49. var storedConfigs = this.get('content.serviceConfigProperties');
  50. //STEP 3: Merge pre-defined configs with loaded on-site configs
  51. var configs = App.config.mergePreDefinedWithStored(
  52. storedConfigs,
  53. advancedConfigs,
  54. this.get('selectedServiceNames'));
  55. App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
  56. //STEP 4: Add advanced configs
  57. App.config.addAdvancedConfigs(configs, advancedConfigs);
  58. this.applyServicesConfigs(configs, storedConfigs);
  59. },
  60. submit: function () {
  61. this.set('isSubmitDisabled', true);
  62. var self = this;
  63. this.deleteKerberosService().always(function (data) {
  64. self.createKerberosResources();
  65. });
  66. },
  67. createKerberosResources: function () {
  68. var self = this;
  69. this.createKerberosService().done(function() {
  70. self.createConfigurations().done(function() {
  71. App.router.send('next');
  72. });
  73. });
  74. },
  75. /**
  76. * Delete Kerberos service if it exists
  77. */
  78. deleteKerberosService: function () {
  79. var serviceName = this.selectedServiceNames[0];
  80. return App.ajax.send({
  81. name: 'common.delete.service',
  82. sender: this,
  83. data: {
  84. serviceName: serviceName
  85. }
  86. });
  87. },
  88. createKerberosService: function () {
  89. return App.ajax.send({
  90. name: 'wizard.step8.create_selected_services',
  91. sender: this,
  92. data: {
  93. data: '{"ServiceInfo": { "service_name": "KERBEROS"}}',
  94. cluster: App.get('clusterName') || App.clusterStatus.get('clusterName')
  95. }
  96. });
  97. },
  98. createConfigurations: function () {
  99. var service = App.StackService.find().findProperty('serviceName', 'KERBEROS');
  100. var serviceConfigTags = [];
  101. var tag = 'version' + (new Date).getTime();
  102. Object.keys(service.get('configTypes')).forEach(function (type) {
  103. if (!serviceConfigTags.someProperty('type', type)) {
  104. var obj = this.createKerberosSiteObj(type, tag);
  105. obj.service_config_version_note = Em.I18n.t('admin.kerberos.wizard.configuration.note');
  106. serviceConfigTags.pushObject(obj);
  107. }
  108. }, this);
  109. var allConfigData = [];
  110. var serviceConfigData = [];
  111. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  112. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  113. if (serviceConfigTag) {
  114. serviceConfigData.pushObject(serviceConfigTag);
  115. }
  116. }, this);
  117. if (serviceConfigData.length) {
  118. allConfigData.pushObject(JSON.stringify({
  119. Clusters: {
  120. desired_config: serviceConfigData
  121. }
  122. }));
  123. }
  124. return App.ajax.send({
  125. name: 'common.across.services.configurations',
  126. sender: this,
  127. data: {
  128. data: '[' + allConfigData.toString() + ']'
  129. }
  130. });
  131. },
  132. createKerberosSiteObj: function (site, tag) {
  133. var properties = {};
  134. var content = this.get('stepConfigs')[0].get('configs');
  135. var configs = content.filterProperty('filename', site + '.xml');
  136. configs.forEach(function (_configProperty) {
  137. // do not pass any globals whose name ends with _host or _hosts
  138. if (_configProperty.isRequiredByAgent !== false) {
  139. properties[_configProperty.name] = _configProperty.value;
  140. }
  141. }, this);
  142. return {"type": site, "tag": tag, "properties": properties};
  143. }
  144. });