/** * 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'); App.ReassignMasterController = App.WizardController.extend({ name: 'reassignMasterController', totalSteps: 6, /** * Used for hiding back button in wizard */ hideBackButton: true, /** * All wizards data will be stored in this variable * * cluster - cluster name * installOptions - ssh key, repo info, etc. * services - services list * hosts - list of selected hosts * slaveComponentHosts, - info about slave hosts * masterComponentHosts - info about master hosts * config??? - to be described later */ content: Em.Object.create({ cluster: null, hosts: null, installOptions: null, services: null, slaveComponentHosts: null, masterComponentHosts: null, serviceConfigProperties: null, advancedServiceConfig: null, controllerName: 'reassignMasterController', isWizard: true, reassign: null }), /** * return new object extended from clusterStatusTemplate * @return Object */ getCluster: function(){ return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()}); }, /** * return true if cluster data is loaded and false otherwise */ dataLoading: function(){ var dfd = $.Deferred(); this.connectOutlet('loading'); if (App.router.get('clusterController.isLoaded')){ dfd.resolve(); } else{ var interval = setInterval(function(){ if (App.router.get('clusterController.isLoaded')){ dfd.resolve(); clearInterval(interval); } },50); } return dfd.promise(); }, /** * Load services data from server. */ loadServicesFromServer: function() { var displayOrderConfig = require('data/services'); var apiUrl = App.get('stackVersionURL'); var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl); // apiService.forEach(function(item, index){ apiService[index].isSelected = App.Service.find().someProperty('id', item.serviceName); apiService[index].isDisabled = apiService[index].isSelected; apiService[index].isInstalled = apiService[index].isSelected; }); this.set('content.services', apiService); App.db.setService(apiService); }, /** * Load confirmed hosts. * Will be used at Assign Masters(step5) step */ loadConfirmedHosts: function(){ var hosts = App.db.getHosts(); if(!hosts || !hosts.length){ var hosts = {}; App.Host.find().forEach(function(item){ hosts[item.get('id')] = { name: item.get('id'), cpu: item.get('cpu'), memory: item.get('memory'), disk_info: item.get('diskInfo'), bootStatus: "REGISTERED", isInstalled: true }; }); App.db.setHosts(hosts); } this.set('content.hosts', hosts); console.log('ReassignMasterController.loadConfirmedHosts: loaded hosts', hosts); }, /** * Load master component hosts data for using in required step controllers */ loadMasterComponentHosts: function () { var masterComponentHosts = App.db.getMasterComponentHosts(); if(!masterComponentHosts){ masterComponentHosts = []; App.HostComponent.find().filterProperty('isMaster', true).forEach(function(item){ masterComponentHosts.push({ component: item.get('componentName'), hostName: item.get('host.hostName'), isInstalled: true }) }); } this.set("content.masterComponentHosts", masterComponentHosts); console.log("ReassignMasterController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts); this.set('content.missMasterStep', this.get('content.masterComponentHosts').everyProperty('isInstalled', true)); }, loadComponentToReassign: function () { var masterComponent = App.db.getMasterToReassign(); if (masterComponent) { this.set('content.reassign', masterComponent); } }, saveComponentToReassign: function (masterComponent) { App.db.setMasterToReassign(masterComponent); }, /** * Load data for all steps until current step */ loadAllPriorSteps: function () { var step = this.get('currentStep'); switch (step) { case '6': case '5': case '4': case '3': case '2': this.loadServicesFromServer(); this.loadMasterComponentHosts(); this.loadConfirmedHosts(); case '1': this.loadComponentToReassign(); } }, /** * Remove all loaded data. * Created as copy for App.router.clearAllSteps */ clearAllSteps: function () { this.clearInstallOptions(); // clear temporary information stored during the install this.set('content.cluster', this.getCluster()); }, /** * Clear all temporary data */ finish: function () { this.setCurrentStep('1'); this.clearAllSteps(); this.clearStorageData(); App.router.get('updateController').updateAll(); } });