manage_clusters_controller.js 6.4 KB

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