manage_clusters_controller.js 6.2 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. 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/<cluster-name>/staging',
  81. working: '/apps/falcon/<cluster-name>/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: 'onError'
  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. onError: function (response) {
  114. if (response && response.responseText) {
  115. var errorMessage = /(?:\<message\>)((.|\n)+)(?:\<\/message\>)/.exec(response.responseText);
  116. if (errorMessage.length > 1) {
  117. App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('mirroring.manageClusters.error') + ': ' + errorMessage[1]);
  118. }
  119. }
  120. },
  121. createNewCluster: function () {
  122. App.ajax.send({
  123. name: 'mirroring.submit_entity',
  124. sender: this,
  125. data: {
  126. type: 'cluster',
  127. entity: this.formatClusterXML(this.get('newCluster')),
  128. falconServer: App.get('falconServerURL')
  129. },
  130. success: 'onCreateClusterSuccess',
  131. error: 'onCreateClusterError'
  132. });
  133. },
  134. onCreateClusterSuccess: function () {
  135. this.get('clusters').pushObject(this.get('newCluster'));
  136. this.get('newClusterPopup').hide();
  137. },
  138. onCreateClusterError: function (response) {
  139. this.set('newClusterPopup.disablePrimary', false);
  140. this.onError(response);
  141. },
  142. /**
  143. * Return XML-formatted string made from cluster object
  144. * @param {Object} cluster - object with cluster data
  145. * @return {String}
  146. */
  147. formatClusterXML: function (cluster) {
  148. return '<?xml version="1.0"?><cluster colo="local" description="" name="' + cluster.get('name') +
  149. '" xmlns="uri:falcon:cluster:0.1"><interfaces><interface type="readonly" endpoint="' + cluster.get('readonly') +
  150. '" version="2.2.0" /><interface type="execute" endpoint="' + cluster.get('execute') +
  151. '" version="2.2.0" /><interface type="workflow" endpoint="' + cluster.get('workflow') +
  152. '" version="4.0.0" />' + '<interface type="messaging" endpoint="tcp://' + App.get('falconServerURL') + ':61616?daemon=true" version="5.1.6" />' +
  153. '<interface type="write" endpoint="' + cluster.get('write') + '" version="2.2.0" />' +
  154. '</interfaces><locations><location name="staging" path="' + cluster.get('staging') +
  155. '" /><location name="temp" path="' + cluster.get('temp') +
  156. '" /><location name="working" path="' + cluster.get('working') +
  157. '" /></locations></cluster>';
  158. }
  159. });