mirroring_controller.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. frequency: parsedData.feed.frequency['#text'].match(/\d/)[0],
  78. frequencyUnit: parsedData.feed.frequency['#text'].match(/\w+(?=\()/)[0],
  79. scheduleEndDate: sourceCluster.validity['@attributes'].end,
  80. scheduleStartDate: sourceCluster.validity['@attributes'].start,
  81. instances: []
  82. })
  83. );
  84. App.ajax.send({
  85. name: 'mirroring.dataset.get_all_instances',
  86. sender: this,
  87. data: {
  88. dataset: parsedData.feed['@attributes'].name
  89. },
  90. success: 'onLoadDatasetInstancesSuccess',
  91. error: 'onLoadDatasetsInstancesError'
  92. });
  93. },
  94. onLoadDatasetDefinitionError: function () {
  95. console.error('Failed to load dataset definition.');
  96. },
  97. onLoadDatasetInstancesSuccess: function (data, sender, opts) {
  98. var datasetJobs = [];
  99. data.instances.forEach(function (instance) {
  100. datasetJobs.push({
  101. dataset: opts.dataset,
  102. id: instance.instance,
  103. status: instance.status,
  104. endTime: new Date(instance.endTime).getTime(),
  105. startTime: new Date(instance.startTime).getTime()
  106. });
  107. }, this);
  108. this.get('datasetsData').findProperty('name', opts.dataset).set('instances', datasetJobs);
  109. this.set('datasetCount', this.get('datasetCount') - 1);
  110. var sortedDatasets = [];
  111. if (this.get('datasetCount') < 1) {
  112. App.dataSetMapper.map(this.get('datasetsData'));
  113. sortedDatasets = App.Dataset.find().toArray().sort(function (a, b) {
  114. if (a.get('name') < b.get('name')) return -1;
  115. if (a.get('name') > b.get('name')) return 1;
  116. return 0;
  117. });
  118. this.set('datasets', sortedDatasets);
  119. this.set('isLoaded', true);
  120. var selectedDataset = this.get('selectedDataset');
  121. if (!selectedDataset) {
  122. this.set('selectedDataset', sortedDatasets[0]);
  123. }
  124. var routerState = App.router.get('currentState.name');
  125. if (routerState === 'index') {
  126. App.router.send('gotoShowJobs');
  127. }
  128. }
  129. },
  130. onLoadDatasetsInstancesError: function () {
  131. console.error('Failed to load dataset instances.');
  132. },
  133. targetClusters: function () {
  134. return App.TargetCluster.find();
  135. }.property(),
  136. manageClusters: function () {
  137. App.ModalPopup.show({
  138. header: Em.I18n.t('mirroring.dataset.manageClusters'),
  139. bodyClass: App.MainMirroringManageClusterstView.extend({
  140. controllerBinding: 'App.router.mainMirroringManageClustersController'
  141. }),
  142. primary: Em.I18n.t('common.save'),
  143. secondary: null,
  144. onPrimary: function () {
  145. this.hide();
  146. App.router.send('gotoShowJobs');
  147. },
  148. onClose: function () {
  149. this.hide();
  150. App.router.send('gotoShowJobs');
  151. },
  152. didInsertElement: function () {
  153. this._super();
  154. this.fitHeight();
  155. }
  156. });
  157. }
  158. });