step5_controller.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 stringUtils = require('utils/string_utils');
  19. var fileUtils = require('utils/file_utils');
  20. App.KerberosWizardStep5Controller = App.KerberosProgressPageController.extend({
  21. name: 'kerberosWizardStep5Controller',
  22. /**
  23. * @type {Array}
  24. */
  25. csvData: [],
  26. /**
  27. * @type {Array}
  28. */
  29. kdcProperties: [
  30. {
  31. key: Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'),
  32. properties: ['kdc_type', 'kdc_hosts', 'realm', 'executable_search_paths']
  33. },
  34. {
  35. key: Em.I18n.t('admin.kerberos.wizard.step1.option.ad'),
  36. properties: ['kdc_type', 'kdc_hosts', 'realm', 'ldap_url', 'container_dn', 'executable_search_paths']
  37. },
  38. {
  39. key: Em.I18n.t('admin.kerberos.wizard.step1.option.ipa'),
  40. properties: ['kdc_type', 'kdc_hosts', 'realm', 'executable_search_paths']
  41. },
  42. {
  43. key: Em.I18n.t('admin.kerberos.wizard.step1.option.manual'),
  44. properties: ['kdc_type', 'realm', 'executable_search_paths']
  45. }
  46. ],
  47. submit: function() {
  48. App.router.send('next');
  49. },
  50. /**
  51. * get CSV data from the server
  52. */
  53. getCSVData: function (skipDownload) {
  54. return App.ajax.send({
  55. name: 'admin.kerberos.cluster.csv',
  56. sender: this,
  57. data: {
  58. 'skipDownload': skipDownload
  59. },
  60. success: 'getCSVDataSuccessCallback',
  61. error: 'getCSVDataSuccessCallback'
  62. });
  63. },
  64. /**
  65. * get CSV data from server success callback
  66. * @param data {string}
  67. * @param opt {object}
  68. * @param params {object}
  69. */
  70. getCSVDataSuccessCallback: function (data, opt, params) {
  71. this.set('csvData', this.prepareCSVData(data.split('\n')));
  72. if (!Em.get(params, 'skipDownload')) {
  73. fileUtils.downloadTextFile(stringUtils.arrayToCSV(this.get('csvData')), 'csv', 'kerberos.csv');
  74. }
  75. },
  76. prepareCSVData: function (array) {
  77. for (var i = 0; i < array.length; i += 1) {
  78. array[i] = array[i].split(',');
  79. }
  80. return array;
  81. },
  82. /**
  83. * Send request to post kerberos descriptor
  84. * @param kerberosDescriptor
  85. * @returns {$.ajax|*}
  86. */
  87. postKerberosDescriptor: function (kerberosDescriptor) {
  88. return App.ajax.send({
  89. name: 'admin.kerberos.cluster.artifact.create',
  90. sender: this,
  91. data: {
  92. artifactName: 'kerberos_descriptor',
  93. data: {
  94. artifact_data: kerberosDescriptor
  95. }
  96. }
  97. });
  98. },
  99. /**
  100. * Send request to update kerberos descriptor
  101. * @param kerberosDescriptor
  102. * @returns {$.ajax|*}
  103. */
  104. putKerberosDescriptor: function (kerberosDescriptor) {
  105. return App.ajax.send({
  106. name: 'admin.kerberos.cluster.artifact.update',
  107. sender: this,
  108. data: {
  109. artifactName: 'kerberos_descriptor',
  110. data: {
  111. artifact_data: kerberosDescriptor
  112. }
  113. },
  114. success: 'unkerberizeCluster',
  115. error: 'unkerberizeCluster'
  116. });
  117. },
  118. /**
  119. * Send request to unkerberisze cluster
  120. * @returns {$.ajax}
  121. */
  122. unkerberizeCluster: function () {
  123. return App.ajax.send({
  124. name: 'admin.unkerberize.cluster',
  125. sender: this,
  126. success: 'goToNextStep',
  127. error: 'goToNextStep'
  128. });
  129. },
  130. goToNextStep: function() {
  131. this.clearStage();
  132. App.router.transitionTo('step5');
  133. },
  134. isSubmitDisabled: Em.computed.notExistsIn('status', ['COMPLETED', 'FAILED']),
  135. confirmProperties: function () {
  136. var wizardController = App.router.get('kerberosWizardController');
  137. var kdc_type = wizardController.get('content.kerberosOption'),
  138. kdcTypeProperties = this.get('kdcProperties').filter(function (item) {
  139. return item.key === kdc_type;
  140. }),
  141. properties = kdcTypeProperties.length ? kdcTypeProperties[0].properties : [];
  142. return wizardController.get('content.serviceConfigProperties').filter(function (item) {
  143. return properties.contains(item.name);
  144. }).map(function (item) {
  145. item['label'] = Em.I18n.t('admin.kerberos.wizard.step5.' + item['name'] + '.label');
  146. return item;
  147. });
  148. }.property('App.router.kerberosWizardController.content.@each.serviceConfigProperties')
  149. });