123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696 |
- /**
- * 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 Ember = require('ember');
- var App = require('app');
- require('utils/helper');
- require('controllers/wizard/slave_component_groups_controller');
- var controller;
- describe('App.SlaveComponentGroupsController', function () {
- beforeEach(function () {
- controller = App.SlaveComponentGroupsController.create({
- content: {},
- selectedSlaveComponent: null
- });
- });
- describe('#getHostsByGroup', function () {
- it('should return empty array', function () {
- controller.set('hosts', undefined);
- expect(controller.getHostsByGroup()).to.eql([]);
- });
- it('should return g1 hosts', function () {
- var hosts = Em.A([
- Em.Object.create({
- group: 'g1',
- name: 'h1'
- }),
- Em.Object.create({
- group: 'g2',
- name: 'h2'
- }),
- Em.Object.create({
- group: 'g1',
- name: 'h3'
- })
- ]);
- var group = {
- name: 'g1'
- };
- var selectedSlaveComponent = Em.Object.create({
- hosts: hosts
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- var expected = [
- {
- "group": "g1",
- "name": "h1"
- },
- {
- "group": "g1",
- "name": "h3"
- }
- ];
-
- expect(JSON.parse(JSON.stringify(controller.getHostsByGroup(group)))).to.eql(expected);
- });
- });
- describe('#changeSlaveGroupName', function () {
- it('should return true if group is exist', function () {
- var selectedSlaveComponent = Em.Object.create({
- groups: Em.A([
- Em.Object.create({
- name: 'g1'
- })
- ])
- });
- var group = {};
- controller.set('selectedSlaveComponent',selectedSlaveComponent);
- expect(controller.changeSlaveGroupName(group, 'g1')).to.be.true;
- });
- it('should return false if group is not exist', function () {
- var hosts = Em.A([
- Em.Object.create({
- group: 'g1',
- name: 'h1'
- }),
- Em.Object.create({
- group: 'g2',
- name: 'h2'
- }),
- Em.Object.create({
- group: 'g1',
- name: 'h3'
- })
- ]);
- var selectedSlaveComponent = Em.Object.create({
- hosts: hosts,
- groups: Em.A([
- Em.Object.create({
- name: 'g1'
- })
- ])
- });
- var group = {
- name: 'g2'
- };
- controller.set('selectedSlaveComponent',selectedSlaveComponent);
- expect(controller.changeSlaveGroupName(group, 'g2')).to.be.false;
- });
- });
- describe('#loadStep', function () {
- beforeEach(function () {
- sinon.stub(App.SlaveConfigs, 'create').returns(Em.Object.create({
- groups: false,
- componentName: '',
- displayName: ''
- }));
- sinon.stub(App.config, 'get').returns(Em.A([
- Em.Object.create({
- category: 'HBASE',
- serviceName: 'HBASE',
- configs: Em.A([Em.Object.create({})])
- })
- ]));
- sinon.stub(App.ServiceConfigProperty, 'create').returns(Em.Object.create({
- name: 'dfs_data_dir',
- initialValue: Em.K
- })
- );
- });
- afterEach(function () {
- App.SlaveConfigs.create.restore();
- App.ServiceConfigProperty.create.restore();
- App.config.get.restore();
- });
- it('should add groups to stepConfgig', function () {
- var stepConfigs = Em.A([
- Em.Object.create({
- serviceName: 'HBASE',
- configCategories: Em.A([
- Em.Object.create({
- isForSlaveComponent: true,
- primaryName: 'sl1',
- slaveConfigs: Em.A([])
- })
- ])
- })
- ]);
- var content = Em.A([
- Em.Object.create({
- componentName: 'sl1',
- displayName: 'd1'
- })
- ]);
- controller.set('content',content);
- controller.set('stepConfigs',stepConfigs);
- controller.loadStep();
- var expected = [
- {
- "serviceName": "HBASE",
- "configCategories": [
- {
- "isForSlaveComponent": true,
- "primaryName": "sl1",
- "slaveConfigs": {
- "groups": [
- {
- "name": "Default",
- "index":
- "default",
- "type": "default",
- "active": true,
- "properties": []
- }
- ],
- "componentName": "sl1",
- "displayName": "d1"
- }
- }
- ]
- }
- ];
- var result = JSON.parse(JSON.stringify(controller.get('stepConfigs')));
- expect(result).to.be.eql(expected);
- });
- });
- describe('#componentProperties', function () {
- beforeEach(function () {
- sinon.stub(App.config, 'get').returns(Em.A([
- Em.Object.create({
- category: 'RegionServer',
- serviceName: 'HBASE',
- configs: Em.A([
- Em.Object.create({
- category: 'RegionServer'
- }),
- Em.Object.create({
- next: true,
- category: 'RegionServer'
- })
- ])
- })
- ]));
- sinon.stub(App.ServiceConfigProperty, 'create', function(value) {
- if (value && value.next) {
- return Em.Object.create({
- name: 'dfs_data_dir',
- initialValue: Em.K,
- validate: Em.K
- });
- } else {
- return Em.Object.create({
- name: 'mapred_local_dir',
- initialValue: Em.K,
- validate: Em.K
- });
- }
- });
- });
- afterEach(function () {
- App.ServiceConfigProperty.create.restore();
- App.config.get.restore();
- });
- it('should return created config', function () {
- var res = JSON.parse(JSON.stringify(controller.componentProperties('HBASE')));
- var expected = [
- {
- "name": "mapred_local_dir"
- },
- {
- "name": "dfs_data_dir"
- }
- ];
- expect(res).to.be.eql(expected);
- });
- });
- describe('#selectedComponentName', function () {
- afterEach(function () {
- App.router.get.restore();
- });
- it('should return selected component name HDFS', function () {
- sinon.stub(App.router, 'get').returns('HDFS');
- expect(controller.get('selectedComponentName')).to.be.eql({
- name: 'DATANODE',
- displayName: 'DataNode'
- });
- });
- it('should return selected component name HBASE', function () {
- sinon.stub(App.router, 'get').returns('HBASE');
- expect(controller.get('selectedComponentName')).to.be.eql({
- name: 'HBASE_REGIONSERVER',
- displayName: 'RegionServer'
- });
- });
- it('should return null', function () {
- sinon.stub(App.router, 'get').returns('undefined');
- expect(controller.get('selectedComponentName')).to.be.null;
- });
- });
- describe('#selectedSlaveComponent', function () {
- beforeEach(function () {
- sinon.stub(App.router, 'get').returns(Em.A([
- Em.Object.create({
- serviceName: 'HDFS',
- configCategories: Em.A([
- Em.Object.create({
- isForSlaveComponent: true,
- primaryName: 'sl1',
- slaveConfigs: Em.A([]),
- name: 'name'
- })
- ])
- })
- ]));
- });
- afterEach(function () {
- App.router.get.restore();
- });
- it('should return selected component name', function () {
- var controller = App.SlaveComponentGroupsController.create({
- content: {}
- });
- controller.set('selectedComponentName', Em.Object.create({
- displayName: 'name'
- }));
- controller.set('selectedComponentName', 'value')
- expect(controller.get('selectedSlaveComponent')).to.be.null;
- });
- });
- describe('#removeSlaveComponentGroup', function () {
- beforeEach(function() {
- sinon.stub(controller, 'componentProperties').returns(Em.A([]));
- });
- afterEach(function() {
- controller.componentProperties.restore();
- });
- it('should return empty selected component', function () {
- var selectedSlaveComponent = Em.Object.create({
- newGroupIndex: 0,
- hosts: Em.A([]),
- groups: Em.A([
- Em.Object.create({
- active: true,
- name: 'New Group',
- type: 'new'
- })
- ])
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- var ev = Em.Object.create({
- context: selectedSlaveComponent.groups[0]
- });
- controller.removeSlaveComponentGroup(ev);
- var expected = {
- "newGroupIndex": 0,
- "hosts": [],
- "groups": []
- };
- var res = JSON.parse(JSON.stringify(controller.get('selectedSlaveComponent')));
- expect(res).to.be.eql(expected);
- });
- });
- describe('#showSlaveComponentGroup', function () {
- it('should make all groups active', function () {
- var selectedSlaveComponent = Em.Object.create({
- newGroupIndex: 0,
- hosts: Em.A([]),
- groups: Em.A([
- Em.Object.create({
- active: false,
- name: 'New Group',
- type: 'new'
- })
- ])
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- var ev = Em.Object.create({
- context: selectedSlaveComponent.groups[0]
- });
- controller.showSlaveComponentGroup(ev);
- var expected = {
- "newGroupIndex": 0,
- "hosts": [],
- "groups": [
- {
- "active": true,
- "name": "New Group",
- "type": "new"
- }
- ]
- };
- var res = JSON.parse(JSON.stringify(controller.get('selectedSlaveComponent')));
- expect(res).to.be.eql(expected);
- });
- });
- describe('#selectedComponentDisplayName', function () {
- beforeEach(function () {
- sinon.stub(App.format, 'role').returns('name')
- });
- afterEach(function () {
- App.format.role.restore();
- });
- it('should return selected component name', function () {
- expect(controller.get('selectedComponentDisplayName')).to.be.equal('name');
- });
- });
- describe('#hosts', function () {
- it('should return hosts', function () {
- var selectedSlaveComponent = Em.Object.create({
- newGroupIndex: 0,
- hosts: Em.A([{name: 'h1'}]),
- groups: Em.A([
- Em.Object.create({
- active: false,
- name: 'New Group',
- type: 'new'
- })
- ])
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- expect(controller.get('hosts')).to.be.eql(Em.A([{name: 'h1'}]));
- });
- });
- describe('#componentGroups', function () {
- it('should return groups', function () {
- var selectedSlaveComponent = Em.Object.create({
- newGroupIndex: 0,
- hosts: Em.A([{name: 'h1', group: 'one'}, {name: 'h2', group: 'one'}]),
- groups: Em.A([
- Em.Object.create({
- active: false,
- name: 'New Group',
- type: 'new'
- })
- ])
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- expect(controller.get('componentGroups')).to.be.eql(Em.A([
- Em.Object.create({
- active: false,
- name: 'New Group',
- type: 'new'
- })
- ]));
- });
- });
- describe('#activeGroup', function () {
- it('should return active group', function () {
- var selectedSlaveComponent = Em.Object.create({
- newGroupIndex: 0,
- hosts: Em.A([{name: 'h1', group: 'one'}, {name: 'h2', group: 'one'}]),
- groups: Em.A([
- Em.Object.create({
- active: false,
- name: 'New Group',
- type: 'new'
- }),
- Em.Object.create({
- active: true,
- name: 'New Group',
- type: 'new'
- })
- ])
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- expect(controller.get('activeGroup')).to.be.eql(Em.Object.create({
- active: true,
- name: 'New Group',
- type: 'new'
- }));
- });
- });
- describe('#groups', function () {
- it('should return uniq groups names', function () {
- var selectedSlaveComponent = Em.Object.create({
- newGroupIndex: 0,
- hosts: Em.A([{name: 'h1', group: 'one'}, {name: 'h2', group: 'one'}]),
- groups: Em.A([
- Em.Object.create({
- active: false,
- name: 'New Group',
- type: 'new'
- })
- ])
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- expect(controller.get('groups')).to.be.eql(['one']);
- });
- });
- describe('#addSlaveComponentGroup', function () {
- beforeEach(function() {
- sinon.stub(controller, 'componentProperties').returns(Em.A([]));
- });
- afterEach(function() {
- controller.componentProperties.restore();
- });
- it('should return selected component name', function () {
- var selectedSlaveComponent = Em.Object.create({
- newGroupIndex: 0,
- groups: Em.A([
- Em.Object.create({
- active: true,
- name: 'New Group'
- })
- ])
- });
- controller.set('selectedSlaveComponent', selectedSlaveComponent);
- controller.addSlaveComponentGroup();
- var expected = {
- "newGroupIndex": 1,
- "groups": [
- {
- "active": false,
- "name": "New Group"
- },
- {
- "name": "New Group 1",
- "index": 1,
- "type": "new",
- "active": true,
- "properties": []
- }
- ]
- };
- var res = JSON.parse(JSON.stringify(controller.get('selectedSlaveComponent')));
- expect(res).to.be.eql(expected);
- });
- });
- describe('#checkGroupName', function () {
- it('should make equal to 2', function () {
- var selectedSlaveComponent = Em.Object.create({
- groups: Em.A([
- Em.Object.create({
- name: 'New Group 1'
- })
- ]),
- newGroupIndex: 0
- });
- var group = {};
- controller.set('selectedSlaveComponent',selectedSlaveComponent);
- controller.checkGroupName();
- expect(controller.get('selectedSlaveComponent').newGroupIndex).to.be.equal(2);
- });
- });
- describe('#changeHostGroup', function () {
- it('should push 1 host group', function () {
- var selectedSlaveComponent = Em.Object.create({
- tempSelectedGroups: undefined
- });
- var host = Em.Object.create({
- hostName: 'h1'
- });
- controller.set('selectedSlaveComponent',selectedSlaveComponent);
- controller.changeHostGroup(host, 'g1');
- var expected = [
- {
- "hostName": "h1",
- "groupName": "g1"
- }
- ];
- var result = JSON.parse(JSON.stringify(controller.get('selectedSlaveComponent').tempSelectedGroups));
- expect(result).to.be.eql(expected);
- });
- it('should push change host group name', function () {
- var selectedSlaveComponent = Em.Object.create({
- tempSelectedGroups: [
- Em.Object.create({
- hostName: 'h1',
- groupName: ''
- })
- ]
- });
- var host = Em.Object.create({
- hostName: 'h1'
- });
- controller.set('selectedSlaveComponent',selectedSlaveComponent);
- controller.changeHostGroup(host, 'g1');
- var expected = [
- Em.Object.create({
- "hostName": "h1",
- "groupName": "g1"
- })
- ]
- expect(controller.get('selectedSlaveComponent').tempSelectedGroups).to.be.eql(expected);
- });
- });
- describe('#loadGroups', function () {
- beforeEach(function () {
- sinon.stub(App.SlaveConfigs, 'create').returns(Em.Object.create({
- groups: false,
- componentName: '',
- displayName: ''
- }));
- sinon.stub(App.config, 'get').returns(Em.A([
- Em.Object.create({
- category: 'HDFS',
- serviceName: 'HDFS',
- configs: Em.A([])
- })
- ]));
- });
- afterEach(function () {
- App.SlaveConfigs.create.restore();
- App.config.get.restore();
- });
- it('should modefie step confgigs', function () {
- var stepConfigs = Em.A([
- Em.Object.create({
- serviceName: 'HDFS',
- configCategories: Em.A([
- Em.Object.create({
- isForSlaveComponent: true,
- primaryName: 'sl1',
- slaveConfigs: Em.A([])
- })
- ])
- })
- ]);
- var content = Em.A([
- Em.Object.create({
- componentName: 'sl1',
- displayName: 'd1',
- groups: Em.A([
- Em.Object.create({
- name: 'g1'
- })
- ])
- })
- ]);
- controller.set('content',content);
- controller.set('stepConfigs',stepConfigs);
- controller.loadGroups();
- var expected = [
- {
- "serviceName": "HDFS",
- "configCategories": [
- {
- "isForSlaveComponent": true,
- "primaryName": "sl1",
- "slaveConfigs": {
- "groups": [
- {
- "name": "g1"
- }
- ],
- "componentName": "sl1",
- "displayName": "d1"
- }
- }
- ]
- }
- ];
- var result = JSON.parse(JSON.stringify(controller.get('stepConfigs')));
- expect(result).to.be.eql(expected);
- });
- it('should add groups to stepConfgig', function () {
- var stepConfigs = Em.A([
- Em.Object.create({
- serviceName: 'HDFS',
- configCategories: Em.A([
- Em.Object.create({
- isForSlaveComponent: true,
- primaryName: 'sl1',
- slaveConfigs: Em.A([])
- })
- ])
- })
- ]);
- var content = Em.A([
- Em.Object.create({
- componentName: 'sl1',
- displayName: 'd1'
- })
- ]);
- controller.set('content',content);
- controller.set('stepConfigs',stepConfigs);
- controller.loadGroups();
- var expected = [
- {
- "serviceName": "HDFS",
- "configCategories": [
- {
- "isForSlaveComponent": true,
- "primaryName": "sl1",
- "slaveConfigs": {
- "groups": [
- {
- "name": "Default",
- "index":
- "default",
- "type": "default",
- "active": true,
- "properties": []
- }
- ],
- "componentName": "sl1",
- "displayName": "d1"
- }
- }
- ]
- }
- ];
- var result = JSON.parse(JSON.stringify(controller.get('stepConfigs')))
- expect(result).to.be.eql(expected);
- });
- });
- });
|