cluster.js 8.0 KB

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