services_view.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.MainAdminStackServicesView = Em.View.extend({
  20. templateName: require('templates/main/admin/stack_upgrade/services'),
  21. isAddServiceAvailable: function () {
  22. return App.isAccessible('ADMIN');
  23. }.property('App.supports.opsDuringRollingUpgrade', 'App.upgradeState', 'App.isAdmin'),
  24. /**
  25. * @type {Array}
  26. */
  27. services: function() {
  28. var services = App.supports.installGanglia ? App.StackService.find() : App.StackService.find().without(App.StackService.find('GANGLIA'));
  29. return services.map(function(s) {
  30. s.set('isInstalled', App.Service.find().someProperty('serviceName', s.get('serviceName')));
  31. return s;
  32. });
  33. }.property('App.router.clusterController.isLoaded'),
  34. didInsertElement: function () {
  35. if (!App.get('stackVersionsAvailable')) {
  36. this.get('controller').loadStackVersionsToModel(true).done(function () {
  37. App.set('stackVersionsAvailable', App.StackVersion.find().content.length > 0);
  38. });
  39. this.get('controller').loadRepositories();
  40. }
  41. },
  42. /**
  43. * launch Add Service wizard
  44. * @param event
  45. */
  46. goToAddService: function (event) {
  47. if (!App.isAccessible('ADMIN')) {
  48. return;
  49. } else if (event.context == "KERBEROS") {
  50. App.router.get('mainAdminKerberosController').checkAndStartKerberosWizard();
  51. App.router.get('kerberosWizardController').setDBProperty('onClosePath', 'main.admin.stackAndUpgrade.services');
  52. } else {
  53. App.router.get('addServiceController').set('serviceToInstall', event.context);
  54. App.router.get('addServiceController').setDBProperty('onClosePath', 'main.admin.stackAndUpgrade.services');
  55. App.get('router').transitionTo('main.serviceAdd');
  56. }
  57. },
  58. /**
  59. * List of all repo-groups
  60. * @type {Object[][]}
  61. */
  62. allRepositoriesGroups: function () {
  63. var repos = this.get('controller.allRepos');
  64. var reposGroup = [];
  65. var repositories = [];
  66. reposGroup.set('stackVersion', App.get('currentStackVersionNumber'));
  67. if (repos) {
  68. repos.forEach(function (group) {
  69. group.repositories.forEach (function(repo) {
  70. var cur_repo = Em.Object.create({
  71. 'repoId': repo.repoId,
  72. 'id': repo.repoId + '-' + repo.osType,
  73. 'repoName' : repo.repoName,
  74. 'stackName' : repo.stackName,
  75. 'stackVersion' : repo.stackVersion,
  76. 'baseUrl': repo.baseUrl,
  77. 'originalBaseUrl': repo.baseUrl,
  78. 'osType': repo.osType,
  79. 'onEdit': false,
  80. 'empty-error': !repo.baseUrl,
  81. 'undo': false,
  82. 'clearAll': repo.baseUrl
  83. });
  84. var cur_group = reposGroup.findProperty('name', group.name);
  85. if (!cur_group) {
  86. cur_group = Ember.Object.create({
  87. name: group.name,
  88. repositories: []
  89. });
  90. reposGroup.push(cur_group);
  91. }
  92. cur_group.repositories.push(cur_repo);
  93. repositories.push(cur_repo);
  94. });
  95. });
  96. }
  97. this.set('allRepos', repositories);
  98. return reposGroup;
  99. }.property('controller.allRepos'),
  100. /**
  101. * Onclick handler for edit action of each repo, enter edit mode
  102. * @param {object} event
  103. */
  104. onEditClick:function (event) {
  105. var targetRepo = this.get('allRepos').findProperty('id', event.context.get('id'));
  106. if (targetRepo) {
  107. targetRepo.set('onEdit', true);
  108. }
  109. },
  110. /**
  111. * Onclick handler for undo action of each repo group
  112. * @method undoGroupLocalRepository
  113. * @param {object} event
  114. */
  115. undoGroupLocalRepository: function (event) {
  116. this.doActionForGroupLocalRepository(event, 'originalBaseUrl');
  117. },
  118. /**
  119. * Handler for clear icon click
  120. * @method clearGroupLocalRepository
  121. * @param {object} event
  122. */
  123. clearGroupLocalRepository: function (event) {
  124. this.doActionForGroupLocalRepository(event, '');
  125. },
  126. /**
  127. * Common handler for repo groups actions
  128. * @method doActionForGroupLocalRepository
  129. * @param {object} event
  130. * @param {string} newBaseUrlField
  131. */
  132. doActionForGroupLocalRepository: function (event, newBaseUrlField) {
  133. var targetRepo = this.get('allRepos').findProperty('id', event.context.get('id'));
  134. if (targetRepo) {
  135. targetRepo.set('baseUrl', Em.isEmpty(newBaseUrlField) ? '' : Em.get(targetRepo, newBaseUrlField));
  136. }
  137. },
  138. /**
  139. * Handler when editing any repo group BaseUrl
  140. * @method editGroupLocalRepository
  141. */
  142. editGroupLocalRepository: function () {
  143. var repos = this.get('allRepos');
  144. repos.forEach(function (targetRepo) {
  145. targetRepo.set('undo', targetRepo.get('baseUrl') != targetRepo.get('originalBaseUrl'));
  146. targetRepo.set('clearAll', targetRepo.get('baseUrl'));
  147. targetRepo.set('empty-error', !targetRepo.get('baseUrl'));
  148. });
  149. }.observes('allRepos.@each.baseUrl'),
  150. /**
  151. * onSuccess callback for save Repo URL.
  152. */
  153. doSaveRepoUrlsSuccessCallback: function (response, request, data) {
  154. var id = data.repoId + '-' + data.osType;
  155. var targetRepo = this.get('allRepos').findProperty('id', id);
  156. if (!targetRepo) {
  157. return;
  158. } else {
  159. var modalCloseHandler = function() {
  160. this.hide();
  161. targetRepo.set('baseUrl', data.data.Repositories.base_url);
  162. targetRepo.set('originalBaseUrl', data.data.Repositories.base_url);
  163. targetRepo.set('onEdit', false);
  164. };
  165. App.ModalPopup.show({
  166. header: Em.I18n.t('admin.cluster.repositories.popup.header.success'),
  167. secondary: null,
  168. onPrimary: modalCloseHandler,
  169. onClose: modalCloseHandler,
  170. message: Em.I18n.t('admin.cluster.repositories.popup.body.success'),
  171. bodyClass: Em.View.extend({
  172. template: Em.Handlebars.compile('<div class="alert alert-success">{{{message}}}</div>')
  173. })
  174. })
  175. }
  176. },
  177. /**
  178. * onError callback for save Repo URL.
  179. */
  180. doSaveRepoUrlsErrorCallback: function (request, ajaxOptions, error, data) {
  181. var self = this;
  182. var id = data.url.split('/')[10] + '-' + data.url.split('/')[8];
  183. var targetRepo = this.get('allRepos').findProperty('id', id);
  184. if (targetRepo) {
  185. App.ModalPopup.show({
  186. header: Em.I18n.t('admin.cluster.repositories.popup.header.fail'),
  187. primary: Em.I18n.t('common.saveAnyway'),
  188. secondary: Em.I18n.t('common.revert'),
  189. third: Em.I18n.t('common.cancel'),
  190. onPrimary: function () {
  191. // save anyway: Go ahead and save with Repo URL validation turned off and close Dialog when done.
  192. this.hide();
  193. self.doSaveRepoUrls(id, false);
  194. },
  195. onSecondary: function () {
  196. // Revert: Close dialog, revert URL value, go back to non-Edit mode
  197. this.hide();
  198. targetRepo.set('baseUrl', targetRepo.get('originalBaseUrl'));
  199. targetRepo.set('onEdit', false);
  200. },
  201. onThird: function () {
  202. // cancel: Close dialog but stay in Edit mode
  203. this.hide();
  204. },
  205. message: Em.I18n.t('admin.cluster.repositories.popup.body.fail'),
  206. bodyClass: Em.View.extend({
  207. template: Em.Handlebars.compile('<div class="alert alert-warning">{{{message}}}</div>')
  208. })
  209. })
  210. }
  211. },
  212. /**
  213. * Check validation and Save the customized local urls
  214. */
  215. doSaveRepoUrls: function (id, verifyBaseUrl) {
  216. var targetRepo = this.get('allRepos').findProperty('id', id);
  217. App.ajax.send({
  218. name: 'wizard.advanced_repositories.valid_url',
  219. sender: this,
  220. data: {
  221. stackName: targetRepo.stackName,
  222. stackVersion: targetRepo.stackVersion,
  223. repoId: targetRepo.repoId,
  224. osType: targetRepo.osType,
  225. data: {
  226. 'Repositories': {
  227. 'base_url': targetRepo.baseUrl,
  228. "verify_base_url": verifyBaseUrl
  229. }
  230. }
  231. },
  232. success: 'doSaveRepoUrlsSuccessCallback',
  233. error: 'doSaveRepoUrlsErrorCallback'
  234. });
  235. },
  236. /**
  237. * Check validation and Save the customized local urls
  238. */
  239. saveRepoUrls: function (event) {
  240. this.doSaveRepoUrls(event.context.get('id'), true);
  241. },
  242. /**
  243. * on click handler 'Cancel' for current repo in edit mode
  244. */
  245. doCancel: function (event) {
  246. var targetRepo = this.get('allRepos').findProperty('id', event.context.get('id'));
  247. if (targetRepo) {
  248. targetRepo.set('baseUrl', targetRepo.get('originalBaseUrl'));
  249. targetRepo.set('onEdit', false);
  250. }
  251. }
  252. });