123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /**
- * 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 db = require('utils/db');
- /**
- * By Step 6, we have the following information stored in App.db and set on this
- * controller by the router:
- *
- * hosts: App.db.hosts (list of all hosts the user selected in Step 3)
- * selectedServiceNames: App.db.selectedServiceNames (the services that the user selected in Step 4)
- * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
- *
- * Step 6 will set the following information in App.db:
- * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
- *
- */
- App.WizardStep6Controller = Em.Controller.extend({
- hosts: [],
- isAllDataNodes: function () {
- return this.get('hosts').everyProperty('isDataNode', true);
- }.property('hosts.@each.isDataNode'),
- isAllTaskTrackers: function () {
- return this.get('hosts').everyProperty('isTaskTracker', true);
- }.property('hosts.@each.isTaskTracker'),
- isAllRegionServers: function () {
- return this.get('hosts').everyProperty('isRegionServer', true);
- }.property('hosts.@each.isRegionServer'),
- isAllClients: function () {
- return this.get('hosts').everyProperty('isClient', true);
- }.property('hosts.@each.isClient'),
- isNoDataNodes: function () {
- return this.get('hosts').everyProperty('isDataNode', false);
- }.property('hosts.@each.isDataNode'),
- isNoTaskTrackers: function () {
- return this.get('hosts').everyProperty('isTaskTracker', false);
- }.property('hosts.@each.isTaskTracker'),
- isNoRegionServers: function () {
- return this.get('hosts').everyProperty('isRegionServer', false);
- }.property('hosts.@each.isRegionServer'),
- isNoClients: function () {
- return this.get('hosts').everyProperty('isClient', false);
- }.property('hosts.@each.isClient'),
- /**
- * Return whether Hbase service was selected or not.
- * Calculate this information on <code>content.services</code> variable
- * @return Boolean
- */
- isHbSelected: function () {
- return this.get('content.services').findProperty('serviceName', 'HBASE').get('isSelected');
- }.property('content.services'),
- /**
- * Return whether MapReduce service was selected or not.
- * Calculate this information on <code>content.services</code> variable
- * @return Boolean
- */
- isMrSelected: function () {
- return this.get('content.services').findProperty('serviceName', 'MAPREDUCE').get('isSelected');
- }.property('content.services'),
- clearError: function () {
- if (this.get('isNoDataNodes') === false &&
- (this.get('isNoTaskTrackers') === false || this.get('isMrSelected') === false) &&
- (this.get('isNoRegionServers') === false || this.get('isHbSelected') === false) &&
- this.get('isNoClients') === false) {
- this.set('errorMessage', '');
- }
- }.observes('isNoDataNodes', 'isNoTaskTrackers', 'isNoRegionServers', 'isNoClients'),
- /**
- * Check whether current host is currently selected as master
- * @param hostName
- * @return {Boolean}
- */
- hasMasterComponents: function (hostName) {
- return this.get('content.masterComponentHosts').someProperty('hostName', hostName);
- },
- selectAllDataNodes: function () {
- var forFilter = this.get('hosts').filterProperty('isDataNodeInstalled', false);
- forFilter.setEach('isDataNode', true);
- },
- selectAllTaskTrackers: function () {
- var forFilter = this.get('hosts').filterProperty('isTaskTrackerInstalled', false);
- forFilter.setEach('isTaskTracker', true);
- },
- selectAllRegionServers: function () {
- var forFilter = this.get('hosts').filterProperty('isRegionServerInstalled', false);
- forFilter.setEach('isRegionServer', true);
- },
- selectAllClients: function () {
- var forFilter = this.get('hosts').filterProperty('isClientInstalled', false);
- forFilter.setEach('isClient', true);
- },
- deselectAllDataNodes: function () {
- var forFilter = this.get('hosts').filterProperty('isDataNodeInstalled', false);
- forFilter.setEach('isDataNode', false);
- },
- deselectAllTaskTrackers: function () {
- var forFilter = this.get('hosts').filterProperty('isTaskTrackerInstalled', false);
- forFilter.setEach('isTaskTracker', false);
- },
- deselectAllRegionServers: function () {
- var forFilter = this.get('hosts').filterProperty('isRegionServerInstalled', false);
- forFilter.setEach('isRegionServer', false);
- },
- deselectAllClients: function () {
- var forFilter = this.get('hosts').filterProperty('isClientInstalled', false);
- forFilter.setEach('isClient', false);
- },
- clearStep: function () {
- this.set('hosts', []);
- this.clearError();
- },
- loadStep: function () {
- console.log("WizardStep6Controller: Loading step6: Assign Slaves");
- this.clearStep();
- this.renderSlaveHosts();
- if(this.get('content.missSlavesStep')){
- App.router.send('next');
- }
- },
- /**
- * Get active host names
- * @return {Array}
- */
- getHostNames: function () {
- var hostInfo = this.get('content.hostsInfo');
- var hostNames = [];
- for (var index in hostInfo) {
- if (hostInfo[index].bootStatus === 'DONE') //TODO: remove true after integration with bootstrap
- hostNames.push(hostInfo[index].name);
- }
- return hostNames;
- },
- /**
- * Load all data needed for this module. Then it automatically renders in template
- * @return {Ember.Set}
- */
- renderSlaveHosts: function () {
- var hostsObj = Em.Set.create();
- var allHosts = this.getHostNames();
- var maxNoofHostComponents = 9;
- var slaveComponents = this.get('content.slaveComponentHosts');
- allHosts.forEach(function (_hostName) {
- hostsObj.push(Em.Object.create({
- hostName: _hostName,
- isMaster: false,
- isDataNode: false,
- isTaskTracker: false,
- isRegionServer: false,
- isClient: false,
- isDataNodeInstalled: false,
- isTaskTrackerInstalled: false,
- isRegionServerInstalled: false,
- isClientInstalled: false
- }));
- });
- if (!slaveComponents) { // we are at this page for the first time
- if (allHosts.length > 3) { //multiple nodes scenario
- hostsObj.forEach(function (host) {
- host.isMaster = this.hasMasterComponents(host.hostName);
- host.isDataNode = host.isTaskTracker
- = host.isRegionServer = !host.isMaster;
- }, this);
- if (hostsObj.someProperty('isDataNode', true)) {
- hostsObj.findProperty('isDataNode', true).set('isClient', true);
- }
- } else {
- var masterObj = {
- host: null,
- masterComponents: maxNoofHostComponents
- };
- hostsObj.forEach(function (host) {
- host.isMaster = this.hasMasterComponents(host.hostName);
- var countMasterComp = this.getMasterComponentsForHost(host.hostName).length;
- if (countMasterComp <= masterObj.masterComponents) {
- masterObj.masterComponents = countMasterComp;
- masterObj.host = host;
- }
- }, this);
- masterObj.host.set('isClient', true);
- masterObj.host.set('isDataNode', true);
- masterObj.host.set('isTaskTracker', true);
- masterObj.host.set('isRegionServer', true);
- }
- } else {
- var dataNodes = slaveComponents.findProperty('componentName', 'DATANODE');
- dataNodes.hosts.forEach(function (_dataNode) {
- var dataNode = hostsObj.findProperty('hostName', _dataNode.hostName);
- if (dataNode) {
- dataNode.set('isDataNode', true);
- dataNode.set('isDataNodeInstalled', _dataNode.isInstalled);
- }
- });
- if (this.get('isMrSelected')) {
- var taskTrackers = slaveComponents.findProperty('componentName', 'TASKTRACKER');
- taskTrackers.hosts.forEach(function (_taskTracker) {
- var taskTracker = hostsObj.findProperty('hostName', _taskTracker.hostName);
- if (taskTracker) {
- taskTracker.set('isTaskTracker', true);
- taskTracker.set('isTaskTrackerInstalled', _taskTracker.isInstalled);
- }
- });
- }
- if (this.get('isHbSelected')) {
- var regionServers = slaveComponents.findProperty('componentName', 'HBASE_REGIONSERVER');
- regionServers.hosts.forEach(function (_regionServer) {
- var regionServer = hostsObj.findProperty('hostName', _regionServer.hostName);
- if (regionServer) {
- regionServer.set('isRegionServer', true);
- regionServer.set('isRegionServerInstalled', _regionServer.isInstalled);
- }
- });
- }
- var clients = slaveComponents.findProperty('componentName', 'CLIENT');
- clients.hosts.forEach(function (_client) {
- var client = hostsObj.findProperty('hostName', _client.hostName);
- if (client) {
- client.set('isClient', true);
- client.set('isClientInstalled', _client.isInstalled);
- }
- }, this);
- allHosts.forEach(function (_hostname) {
- var host = hostsObj.findProperty('hostName', _hostname);
- if (host) {
- host.set('isMaster', this.hasMasterComponents(_hostname));
- }
- }, this);
- }
- hostsObj.forEach(function (host) {
- this.get('hosts').pushObject(host);
- }, this);
- },
- /**
- * Return list of master components for specified <code>hostname</code>
- * @param hostName
- * @return {*}
- */
- getMasterComponentsForHost: function (hostName) {
- return this.get('content.masterComponentHosts').filterProperty('hostName', hostName).mapProperty('component');
- },
- /**
- * Validate form. Return do we have errors or not
- * @return {Boolean}
- */
- validate: function () {
- var isError = this.get('isNoDataNodes') || this.get('isNoClients')
- || ( this.get('isMrSelected') && this.get('isNoTaskTrackers'))
- || ( this.get('isHbSelected') && this.get('isNoRegionServers'));
- if(this.get('content.isWizard')){
- isError = false;
- }
- if (isError) {
- this.set('errorMessage', Ember.I18n.t('installer.step6.error.mustSelectOne'));
- }
- return !isError;
- }
- });
|