123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /**
- * 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.
- */
- App = require('app');
- require('controllers/main/service/reassign/step2_controller');
- require('models/host_component');
- describe('App.ReassignMasterWizardStep2Controller', function () {
- var controller = App.ReassignMasterWizardStep2Controller.create({
- content: Em.Object.create({
- reassign: Em.Object.create({}),
- services: []
- }),
- renderComponents: Em.K,
- multipleComponents: []
- });
- controller.set('_super', Em.K);
- describe('#loadStep', function () {
- beforeEach(function () {
- sinon.stub(controller, 'rebalanceSingleComponentHosts', Em.K);
- });
- afterEach(function () {
- controller.rebalanceSingleComponentHosts.restore();
- });
- it('SECONDARY_NAMENODE is absent, reassign component is NAMENODE', function () {
- controller.set('content.reassign.component_name', 'NAMENODE');
- controller.set('content.masterComponentHosts', []);
- controller.loadStep();
- expect(controller.get('showCurrentHost')).to.be.false;
- expect(controller.get('componentToRebalance')).to.equal('NAMENODE');
- expect(controller.get('rebalanceComponentHostsCounter')).to.equal(1);
- });
- it('SECONDARY_NAMENODE is present, reassign component is NAMENODE', function () {
- controller.set('content.reassign.component_name', 'NAMENODE');
- controller.set('content.masterComponentHosts', [
- {
- component: 'SECONDARY_NAMENODE'
- }
- ]);
- controller.loadStep();
- expect(controller.get('showCurrentHost')).to.be.true;
- expect(controller.rebalanceSingleComponentHosts.calledWith('NAMENODE'));
- });
- it('SECONDARY_NAMENODE is absent, reassign component is not NAMENODE', function () {
- controller.set('content.reassign.component_name', 'COMP');
- controller.set('content.masterComponentHosts', []);
- controller.loadStep();
- expect(controller.get('showCurrentHost')).to.be.true;
- expect(controller.rebalanceSingleComponentHosts.calledWith('COMP'));
- });
- it('if HA is enabled then multipleComponents should contain NAMENODE', function () {
- sinon.stub(App,'get', function() {
- return true;
- });
- controller.loadStep();
- expect(controller.get('multipleComponents')).to.eql(['NAMENODE']);
- App.get.restore();
- });
- });
- describe('#loadComponents', function () {
- it('masterComponentHosts is empty', function () {
- controller.set('content.masterComponentHosts', []);
- controller.set('content.reassign.host_id', 1);
- expect(controller.loadComponents()).to.be.empty;
- expect(controller.get('currentHostId')).to.equal(1);
- });
- it('masterComponentHosts does not contain reassign component', function () {
- sinon.stub(App.HostComponent, 'find', function () {
- return [Em.Object.create({
- componentName: 'COMP1',
- serviceName: 'SERVICE'
- })];
- });
- controller.set('content.masterComponentHosts', [{
- component: 'COMP1',
- hostName: 'host1'
- }]);
- controller.set('content.reassign.host_id', 1);
- controller.set('content.reassign.component_name', 'COMP2');
- expect(controller.loadComponents()).to.eql([
- {
- "component_name": "COMP1",
- "display_name": "Comp1",
- "selectedHost": "host1",
- "isInstalled": true,
- "serviceId": "SERVICE",
- "isServiceCoHost": false,
- "color": "grey"
- }
- ]);
- expect(controller.get('currentHostId')).to.equal(1);
- App.HostComponent.find.restore();
- });
- it('masterComponentHosts contains reassign component', function () {
- sinon.stub(App.HostComponent, 'find', function () {
- return [Em.Object.create({
- componentName: 'COMP1',
- serviceName: 'SERVICE'
- })];
- });
- controller.set('content.masterComponentHosts', [{
- component: 'COMP1',
- hostName: 'host1'
- }]);
- controller.set('content.reassign.host_id', 1);
- controller.set('content.reassign.component_name', 'COMP1');
- expect(controller.loadComponents()).to.eql([
- {
- "component_name": "COMP1",
- "display_name": "Comp1",
- "selectedHost": "host1",
- "isInstalled": true,
- "serviceId": "SERVICE",
- "isServiceCoHost": false,
- "color": "green"
- }
- ]);
- expect(controller.get('currentHostId')).to.equal(1);
- App.HostComponent.find.restore();
- });
- });
- describe('#rebalanceSingleComponentHosts', function () {
- it('hosts is empty', function () {
- controller.set('hosts', []);
- expect(controller.rebalanceSingleComponentHosts()).to.be.false;
- });
- it('currentHostId matches one available host', function () {
- controller.set('hosts', [Em.Object.create({
- host_name: 'host1'
- })]);
- controller.set('currentHostId', 'host1');
- expect(controller.rebalanceSingleComponentHosts()).to.be.false;
- });
- var testCases = [
- {
- title: 'selectedHost = currentHostId and component_name = content.reassign.component_name',
- arguments: {
- selectedHost: 'host1',
- reassignComponentName: 'COMP1'
- },
- result: 'host3'
- },
- {
- title: 'selectedHost not equal to currentHostId and component_name = content.reassign.component_name',
- arguments: {
- selectedHost: 'host2',
- reassignComponentName: 'COMP1'
- },
- result: 'host2'
- },
- {
- title: 'selectedHost = currentHostId and component_name not equal to content.reassign.component_name',
- arguments: {
- selectedHost: 'host1',
- reassignComponentName: 'COMP2'
- },
- result: 'host1'
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.set('hosts', [
- Em.Object.create({
- host_name: 'host3'
- }),
- Em.Object.create({
- host_name: 'host2'
- })
- ]);
- controller.set('currentHostId', 'host1');
- controller.set('content.reassign.component_name', test.arguments.reassignComponentName);
- controller.set('selectedServicesMasters', [Em.Object.create({
- component_name: 'COMP1',
- selectedHost: test.arguments.selectedHost
- })]);
- expect(controller.rebalanceSingleComponentHosts('COMP1')).to.be.true;
- expect(controller.get('selectedServicesMasters')[0].get('selectedHost')).to.equal(test.result);
- expect(controller.get('selectedServicesMasters')[0].get('availableHosts').mapProperty('host_name')).to.eql(['host2', 'host3']);
- });
- });
- });
- describe('#getIsSubmitDisabled', function () {
- var hostComponents = [];
- var isSubmitDisabled = false;
- beforeEach(function () {
- sinon.stub(App.HostComponent, 'find', function () {
- return hostComponents;
- });
- sinon.stub(controller, '_super', function() {
- return isSubmitDisabled;
- });
- });
- afterEach(function () {
- App.HostComponent.find.restore();
- controller._super.restore();
- });
- it('No host-components, reassigned equal 0', function () {
- expect(controller.getIsSubmitDisabled()).to.be.true;
- expect(controller.get('submitDisabled')).to.be.true;
- });
- it('Reassign component match existed components, reassigned equal 0', function () {
- controller.set('content.reassign.component_name', 'COMP1');
- hostComponents = [Em.Object.create({
- componentName: 'COMP1',
- hostName: 'host1'
- })];
- controller.set('servicesMasters', [{
- selectedHost: 'host1'
- }]);
- expect(controller.getIsSubmitDisabled()).to.be.true;
- expect(controller.get('submitDisabled')).to.be.true;
- });
- it('Reassign component do not match existed components, reassigned equal 1', function () {
- controller.set('content.reassign.component_name', 'COMP1');
- hostComponents = [Em.Object.create({
- componentName: 'COMP1',
- hostName: 'host1'
- })];
- controller.set('servicesMasters', []);
- expect(controller.getIsSubmitDisabled()).to.be.false;
- expect(controller.get('submitDisabled')).to.be.false;
- });
- it('Reassign component do not match existed components, reassigned equal 2', function () {
- controller.set('content.reassign.component_name', 'COMP1');
- hostComponents = [
- Em.Object.create({
- componentName: 'COMP1',
- hostName: 'host1'
- }),
- Em.Object.create({
- componentName: 'COMP1',
- hostName: 'host2'
- })
- ];
- controller.set('servicesMasters', []);
- expect(controller.getIsSubmitDisabled()).to.be.true;
- expect(controller.get('submitDisabled')).to.be.true;
- });
- it('submitDisabled is already true', function () {
- isSubmitDisabled = true;
- expect(controller.getIsSubmitDisabled()).to.be.true;
- expect(controller.get('submitDisabled')).to.be.true;
- });
- });
- });
|