mirroring_controller.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 misc = require('utils/misc');
  20. App.MainMirroringController = Em.ArrayController.extend({
  21. name: 'mainMirroringController',
  22. datasetsData: [],
  23. datasetCount: 0,
  24. datasets: [],
  25. isLoaded: false,
  26. loadDatasets: function () {
  27. this.set('isLoaded', false);
  28. this.get('datasetsData').clear();
  29. this.set('datasetCount', 0);
  30. this.set('datasets', []);
  31. App.ajax.send({
  32. name: 'mirroring.get_all_datasets',
  33. sender: this,
  34. success: 'onLoadDatasetsListSuccess',
  35. error: 'onLoadDatasetsListError'
  36. });
  37. },
  38. onLoadDatasetsListSuccess: function (data) {
  39. if (data && data.entity) {
  40. this.set('datasetCount', data.entity.length);
  41. data.entity.mapProperty('name').forEach(function (dataset) {
  42. App.ajax.send({
  43. name: 'mirroring.get_dataset_definition',
  44. sender: this,
  45. data: {
  46. dataset: dataset
  47. },
  48. success: 'onLoadDatasetDefinitionSuccess',
  49. error: 'onLoadDatasetDefinitionError'
  50. });
  51. }, this);
  52. } else {
  53. this.onLoadDatasetsListError();
  54. }
  55. },
  56. onLoadDatasetsListError: function () {
  57. console.error('Failed to load datasets list.');
  58. },
  59. onLoadDatasetDefinitionSuccess: function (data) {
  60. var parsedData = misc.xmlToObject(data);
  61. var clusters = parsedData.feed.clusters;
  62. var targetCluster, sourceCluster;
  63. if (clusters.cluster[0].locations) {
  64. targetCluster = clusters.cluster[0];
  65. sourceCluster = clusters.cluster[1];
  66. } else {
  67. targetCluster = clusters.cluster[1];
  68. sourceCluster = clusters.cluster[0];
  69. }
  70. this.get('datasetsData').push(
  71. Ember.Object.create({
  72. name: parsedData.feed['@attributes'].name,
  73. sourceClusterName: sourceCluster['@attributes'].name,
  74. targetClusterName: targetCluster['@attributes'].name,
  75. sourceDir: parsedData.feed.locations.location['@attributes'].path,
  76. targetDir: targetCluster.locations.location['@attributes'].path,
  77. instances: []
  78. })
  79. );
  80. App.ajax.send({
  81. name: 'mirroring.dataset.get_all_instances',
  82. sender: this,
  83. data: {
  84. dataset: parsedData.feed['@attributes'].name
  85. },
  86. success: 'onLoadDatasetInstancesSuccess',
  87. error: 'onLoadDatasetsInstancesError'
  88. });
  89. },
  90. onLoadDatasetDefinitionError: function () {
  91. console.error('Failed to load dataset definition.');
  92. },
  93. onLoadDatasetInstancesSuccess: function (data, sender, opts) {
  94. var datasetJobs = [];
  95. data.instances.forEach(function (instance) {
  96. datasetJobs.push({
  97. dataset: opts.dataset,
  98. id: instance.instance,
  99. status: instance.status,
  100. endTime: new Date(instance.endTime).getTime(),
  101. startTime: new Date(instance.startTime).getTime()
  102. });
  103. }, this);
  104. this.get('datasetsData').findProperty('name', opts.dataset).set('instances', datasetJobs);
  105. this.set('datasetCount', this.get('datasetCount') - 1);
  106. var sortedDatasets = [];
  107. if (this.get('datasetCount') < 1) {
  108. App.dataSetMapper.map(this.get('datasetsData'));
  109. sortedDatasets = App.Dataset.find().toArray().sort(function (a, b) {
  110. if (a.get('name') < b.get('name')) return -1;
  111. if (a.get('name') > b.get('name')) return 1;
  112. return 0;
  113. });
  114. this.set('datasets', sortedDatasets);
  115. this.set('isLoaded', true);
  116. }
  117. var selectedDataset = this.get('selectedDataset');
  118. App.router.transitionTo('showDatasetJobs', selectedDataset || sortedDatasets[0]);
  119. },
  120. onLoadDatasetsInstancesError: function () {
  121. console.error('Failed to load dataset instances.');
  122. },
  123. targetClusters: function () {
  124. return App.TargetCluster.find();
  125. }.property(),
  126. manageClusters: function () {
  127. App.ModalPopup.show({
  128. header: Em.I18n.t('mirroring.dataset.manageClusters'),
  129. bodyClass: App.MainMirroringManageClusterstView.extend({
  130. controllerBinding: 'App.router.mainMirroringManageClustersController'
  131. }),
  132. primary: Em.I18n.t('common.save'),
  133. secondary: null,
  134. onPrimary: function () {
  135. this.hide();
  136. App.router.transitionTo('main.mirroring.index');
  137. },
  138. onClose: function () {
  139. this.hide();
  140. App.router.transitionTo('main.mirroring.index');
  141. },
  142. didInsertElement: function () {
  143. this._super();
  144. this.fitHeight();
  145. }
  146. });
  147. }
  148. });