123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var App = require('app');
- var misc = require('utils/misc');
- App.MainMirroringController = Em.ArrayController.extend({
- name: 'mainMirroringController',
- datasetsData: [],
- datasetCount: 0,
- datasets: [],
- isLoaded: false,
- loadDatasets: function () {
- this.set('isLoaded', false);
- this.get('datasetsData').clear();
- this.set('datasetCount', 0);
- this.set('datasets', []);
- App.ajax.send({
- name: 'mirroring.get_all_datasets',
- sender: this,
- success: 'onLoadDatasetsListSuccess',
- error: 'onLoadDatasetsListError'
- });
- },
- onLoadDatasetsListSuccess: function (data) {
- if (data && data.entity) {
- this.set('datasetCount', data.entity.length);
- data.entity.mapProperty('name').forEach(function (dataset) {
- App.ajax.send({
- name: 'mirroring.get_dataset_definition',
- sender: this,
- data: {
- dataset: dataset
- },
- success: 'onLoadDatasetDefinitionSuccess',
- error: 'onLoadDatasetDefinitionError'
- });
- }, this);
- } else {
- this.onLoadDatasetsListError();
- }
- },
- onLoadDatasetsListError: function () {
- console.error('Failed to load datasets list.');
- },
- onLoadDatasetDefinitionSuccess: function (data) {
- var parsedData = misc.xmlToObject(data);
- var clusters = parsedData.feed.clusters;
- var targetCluster, sourceCluster;
- if (clusters.cluster[0].locations) {
- targetCluster = clusters.cluster[0];
- sourceCluster = clusters.cluster[1];
- } else {
- targetCluster = clusters.cluster[1];
- sourceCluster = clusters.cluster[0];
- }
- this.get('datasetsData').push(
- Ember.Object.create({
- name: parsedData.feed['@attributes'].name,
- sourceClusterName: sourceCluster['@attributes'].name,
- targetClusterName: targetCluster['@attributes'].name,
- sourceDir: parsedData.feed.locations.location['@attributes'].path,
- targetDir: targetCluster.locations.location['@attributes'].path,
- frequency: parsedData.feed.frequency['#text'].match(/\d/)[0],
- frequencyUnit: parsedData.feed.frequency['#text'].match(/\w+(?=\()/)[0],
- scheduleEndDate: sourceCluster.validity['@attributes'].end,
- scheduleStartDate: sourceCluster.validity['@attributes'].start,
- instances: []
- })
- );
- App.ajax.send({
- name: 'mirroring.dataset.get_all_instances',
- sender: this,
- data: {
- dataset: parsedData.feed['@attributes'].name
- },
- success: 'onLoadDatasetInstancesSuccess',
- error: 'onLoadDatasetsInstancesError'
- });
- },
- onLoadDatasetDefinitionError: function () {
- console.error('Failed to load dataset definition.');
- },
- onLoadDatasetInstancesSuccess: function (data, sender, opts) {
- var datasetJobs = [];
- data.instances.forEach(function (instance) {
- datasetJobs.push({
- dataset: opts.dataset,
- id: instance.instance,
- status: instance.status,
- endTime: new Date(instance.endTime).getTime(),
- startTime: new Date(instance.startTime).getTime()
- });
- }, this);
- this.get('datasetsData').findProperty('name', opts.dataset).set('instances', datasetJobs);
- this.set('datasetCount', this.get('datasetCount') - 1);
- var sortedDatasets = [];
- if (this.get('datasetCount') < 1) {
- App.dataSetMapper.map(this.get('datasetsData'));
- sortedDatasets = App.Dataset.find().toArray().sort(function (a, b) {
- if (a.get('name') < b.get('name')) return -1;
- if (a.get('name') > b.get('name')) return 1;
- return 0;
- });
- this.set('datasets', sortedDatasets);
- this.set('isLoaded', true);
- var selectedDataset = this.get('selectedDataset');
- if (!selectedDataset) {
- this.set('selectedDataset', sortedDatasets[0]);
- }
- var routerState = App.router.get('currentState.name');
- if (routerState === 'index') {
- App.router.send('gotoShowJobs');
- }
- }
- },
- onLoadDatasetsInstancesError: function () {
- console.error('Failed to load dataset instances.');
- },
- targetClusters: function () {
- return App.TargetCluster.find();
- }.property(),
- manageClusters: function () {
- App.ModalPopup.show({
- header: Em.I18n.t('mirroring.dataset.manageClusters'),
- bodyClass: App.MainMirroringManageClusterstView.extend({
- controllerBinding: 'App.router.mainMirroringManageClustersController'
- }),
- primary: Em.I18n.t('common.save'),
- secondary: null,
- onPrimary: function () {
- this.hide();
- App.router.send('gotoShowJobs');
- },
- onClose: function () {
- this.hide();
- App.router.send('gotoShowJobs');
- },
- didInsertElement: function () {
- this._super();
- this.fitHeight();
- }
- });
- }
- });
|