manage_clusters_controller.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. this.set('disablePrimary', true);
  70. self.createNewCluster();
  71. },
  72. willInsertElement: function () {
  73. var clusterName = App.get('clusterName');
  74. var newCluster = Ember.Object.create({
  75. name: '',
  76. execute: '',
  77. workflow: '',
  78. write: '',
  79. readonly: '',
  80. staging: '/apps/falcon/' + clusterName + '/staging',
  81. working: '/apps/falcon/' + clusterName + '/working',
  82. temp: '/tmp'
  83. });
  84. self.set('newCluster', newCluster);
  85. },
  86. didInsertElement: function () {
  87. this._super();
  88. this.fitHeight();
  89. }
  90. });
  91. this.set('newClusterPopup', newClusterPopup);
  92. },
  93. removeCluster: function () {
  94. var self = this;
  95. var selectedClusterName = self.get('selectedCluster.name');
  96. App.showConfirmationPopup(function () {
  97. App.ajax.send({
  98. name: 'mirroring.delete_entity',
  99. sender: self,
  100. data: {
  101. name: selectedClusterName,
  102. type: 'cluster',
  103. falconServer: App.get('falconServerURL')
  104. },
  105. success: 'onRemoveClusterSuccess',
  106. error: 'onRemoveClusterError'
  107. });
  108. }, Em.I18n.t('mirroring.manageClusters.remove.confirmation').format(selectedClusterName));
  109. },
  110. onRemoveClusterSuccess: function () {
  111. this.set('clusters', this.get('clusters').without(this.get('selectedCluster')));
  112. },
  113. onRemoveClusterError: function () {
  114. App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('mirroring.manageClusters.error') + ': ' + arguments[2]);
  115. },
  116. createNewCluster: function () {
  117. App.ajax.send({
  118. name: 'mirroring.submit_entity',
  119. sender: this,
  120. data: {
  121. type: 'cluster',
  122. entity: this.formatClusterXML(this.get('newCluster')),
  123. falconServer: App.get('falconServerURL')
  124. },
  125. success: 'onCreateClusterSuccess',
  126. error: 'onCreateClusterError'
  127. });
  128. },
  129. onCreateClusterSuccess: function () {
  130. this.get('clusters').pushObject(this.get('newCluster'));
  131. this.get('newClusterPopup').hide();
  132. },
  133. onCreateClusterError: function () {
  134. this.set('newClusterPopup.disablePrimary', false);
  135. App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('mirroring.manageClusters.error') + ': ' + arguments[2]);
  136. },
  137. /**
  138. * Return XML-formatted string made from cluster object
  139. * @param {Object} cluster - object with cluster data
  140. * @return {String}
  141. */
  142. formatClusterXML: function (cluster) {
  143. return '<?xml version="1.0"?><cluster colo="local" description="" name="' + cluster.get('name') +
  144. '" xmlns="uri:falcon:cluster:0.1"><interfaces><interface type="readonly" endpoint="' + cluster.get('readonly') +
  145. '" version="2.2.0" /><interface type="execute" endpoint="' + cluster.get('execute') +
  146. '" version="2.2.0" /><interface type="workflow" endpoint="' + cluster.get('workflow') +
  147. '" version="4.0.0" />' + '<interface type="messaging" endpoint="tcp://' + App.get('falconServerURL') + ':61616?daemon=true" version="5.1.6" />' +
  148. '<interface type="write" endpoint="' + cluster.get('write') + '" version="2.2.0" />' +
  149. '</interfaces><locations><location name="staging" path="' + cluster.get('staging') +
  150. '" /><location name="temp" path="' + cluster.get('temp') +
  151. '" /><location name="working" path="' + cluster.get('working') +
  152. '" /></locations></cluster>';
  153. }
  154. });