manage_clusters_controller.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.MainMirroringManageClustersController = Em.ArrayController.extend({
  20. name: 'mainMirroringManageClustersController',
  21. // link to popup object
  22. popup: null,
  23. clusters: [],
  24. newCluster: null,
  25. isLoaded: function () {
  26. return App.router.get('mainMirroringController.isLoaded');
  27. }.property('App.router.mainMirroringController.isLoaded'),
  28. onLoad: function () {
  29. if (this.get('isLoaded')) {
  30. var clusters = [];
  31. App.TargetCluster.find().forEach(function (cluster) {
  32. var newCluster = {
  33. name: cluster.get('name'),
  34. execute: cluster.get('execute'),
  35. workflow: cluster.get('workflow'),
  36. write: cluster.get('write'),
  37. readonly: cluster.get('readonly'),
  38. staging: cluster.get('staging'),
  39. working: cluster.get('working'),
  40. temp: cluster.get('temp')
  41. };
  42. // Source cluster should be shown on top
  43. if (cluster.get('name') === App.get('clusterName')) {
  44. clusters.unshift(Ember.Object.create(newCluster));
  45. } else {
  46. clusters.push(Ember.Object.create(newCluster));
  47. }
  48. }, this);
  49. this.set('clusters', clusters);
  50. }
  51. }.observes('isLoaded'),
  52. selectedCluster: null,
  53. // Disable input fields for already created clusters
  54. isEditDisabled: function () {
  55. return !this.get('clustersToCreate').mapProperty('name').contains(this.get('selectedCluster.name'));
  56. }.property('selectedCluster.name', 'clustersToCreate.@each.name'),
  57. addCluster: function () {
  58. var self = this;
  59. var newClusterPopup = App.ModalPopup.show({
  60. header: Em.I18n.t('mirroring.manageClusters.create.cluster.popup'),
  61. bodyClass: Em.View.extend({
  62. controller: self,
  63. templateName: require('templates/main/mirroring/create_new_cluster')
  64. }),
  65. classNames: ['create-target-cluster-popup'],
  66. primary: Em.I18n.t('common.save'),
  67. secondary: Em.I18n.t('common.cancel'),
  68. onPrimary: function () {
  69. if (this.get('enablePrimary')) {
  70. this.set('enablePrimary', false);
  71. self.createNewCluster();
  72. }
  73. },
  74. willInsertElement: function () {
  75. var clusterName = App.get('clusterName');
  76. var newCluster = Ember.Object.create({
  77. name: '',
  78. execute: '',
  79. workflow: '',
  80. write: '',
  81. readonly: '',
  82. staging: '/apps/falcon/' + clusterName + '/staging',
  83. working: '/apps/falcon/' + clusterName + '/working',
  84. temp: '/tmp'
  85. });
  86. self.set('newCluster', newCluster);
  87. },
  88. didInsertElement: function () {
  89. this._super();
  90. this.fitHeight();
  91. }
  92. });
  93. this.set('newClusterPopup', newClusterPopup);
  94. },
  95. removeCluster: function () {
  96. var self = this;
  97. var selectedClusterName = self.get('selectedCluster.name');
  98. App.showConfirmationPopup(function () {
  99. App.ajax.send({
  100. name: 'mirroring.delete_entity',
  101. sender: self,
  102. data: {
  103. name: selectedClusterName,
  104. type: 'cluster',
  105. falconServer: App.get('falconServerURL')
  106. },
  107. success: 'onRemoveClusterSuccess',
  108. error: 'onRemoveClusterError'
  109. });
  110. }, Em.I18n.t('mirroring.manageClusters.remove.confirmation').format(selectedClusterName));
  111. },
  112. onRemoveClusterSuccess: function () {
  113. this.set('clusters', this.get('clusters').without(this.get('selectedCluster')));
  114. },
  115. onRemoveClusterError: function () {
  116. App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('mirroring.manageClusters.error') + ': ' + arguments[2]);
  117. },
  118. createNewCluster: function () {
  119. App.ajax.send({
  120. name: 'mirroring.submit_entity',
  121. sender: this,
  122. data: {
  123. type: 'cluster',
  124. entity: this.formatClusterXML(this.get('newCluster')),
  125. falconServer: App.get('falconServerURL')
  126. },
  127. success: 'onCreateClusterSuccess',
  128. error: 'onCreateClusterError'
  129. });
  130. },
  131. onCreateClusterSuccess: function () {
  132. this.get('clusters').pushObject(this.get('newCluster'));
  133. this.get('newClusterPopup').hide();
  134. },
  135. onCreateClusterError: function () {
  136. this.set('newClusterPopup.enablePrimary', true);
  137. App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('mirroring.manageClusters.error') + ': ' + arguments[2]);
  138. },
  139. /**
  140. * Return XML-formatted string made from cluster object
  141. * @param {Object} cluster - object with cluster data
  142. * @return {String}
  143. */
  144. formatClusterXML: function (cluster) {
  145. return '<?xml version="1.0"?><cluster colo="local" description="" name="' + cluster.get('name') +
  146. '" xmlns="uri:falcon:cluster:0.1"><interfaces><interface type="readonly" endpoint="' + cluster.get('readonly') +
  147. '" version="2.2.0" /><interface type="execute" endpoint="' + cluster.get('execute') +
  148. '" version="2.2.0" /><interface type="workflow" endpoint="' + cluster.get('workflow') +
  149. '" version="4.0.0" />' + '<interface type="messaging" endpoint="tcp://' + App.get('falconServerURL') + ':61616?daemon=true" version="5.1.6" />' +
  150. '<interface type="write" endpoint="' + cluster.get('write') + '" version="2.2.0" />' +
  151. '</interfaces><locations><location name="staging" path="' + cluster.get('staging') +
  152. '" /><location name="temp" path="' + cluster.get('temp') +
  153. '" /><location name="working" path="' + cluster.get('working') +
  154. '" /></locations></cluster>';
  155. }
  156. });