123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- /**
- * 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 validator = require('utils/validator');
- require('utils/component');
- require('utils/batch_scheduled_requests');
- require('controllers/main/host');
- describe('MainHostController', function () {
- var hostController;
- describe('#bulkOperation', function() {
- beforeEach(function() {
- hostController = App.MainHostController.create({
- bulkOperationForHostsRestart: function(){},
- bulkOperationForHosts: function(){},
- bulkOperationForHostComponentsRestart: function(){},
- bulkOperationForHostComponentsDecommission: function(){},
- bulkOperationForHostComponents: function(){},
- bulkOperationForHostComponentsPassiveState: function(){},
- bulkOperationForHostsPassiveState: function(){}
- });
- sinon.spy(hostController, 'bulkOperationForHostsRestart');
- sinon.spy(hostController, 'bulkOperationForHosts');
- sinon.spy(hostController, 'bulkOperationForHostComponentsRestart');
- sinon.spy(hostController, 'bulkOperationForHostComponentsDecommission');
- sinon.spy(hostController, 'bulkOperationForHostComponents');
- sinon.spy(hostController, 'bulkOperationForHostComponentsPassiveState');
- sinon.spy(hostController, 'bulkOperationForHostsPassiveState');
- });
- afterEach(function() {
- hostController.bulkOperationForHosts.restore();
- hostController.bulkOperationForHostsRestart.restore();
- hostController.bulkOperationForHostComponentsRestart.restore();
- hostController.bulkOperationForHostComponentsDecommission.restore();
- hostController.bulkOperationForHostComponents.restore();
- hostController.bulkOperationForHostComponentsPassiveState.restore();
- hostController.bulkOperationForHostsPassiveState.restore();
- });
- it('RESTART for hosts', function() {
- var operationData = {
- action: 'RESTART'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostsRestart.calledOnce).to.equal(true);
- });
- it('START for hosts', function() {
- var operationData = {
- action: 'STARTED'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
- });
- it('STOP for hosts', function() {
- var operationData = {
- action: 'INSTALLED'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
- });
- it('PASSIVE_STATE for hosts', function() {
- var operationData = {
- action: 'PASSIVE_STATE'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostsPassiveState.calledOnce).to.equal(true);
- });
- it('RESTART for hostComponents', function() {
- var operationData = {
- action: 'RESTART',
- componentNameFormatted: 'DataNodes'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostComponentsRestart.calledOnce).to.equal(true);
- });
- it('START for hostComponents', function() {
- var operationData = {
- action: 'STARTED',
- componentNameFormatted: 'DataNodes'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
- });
- it('STOP for hostComponents', function() {
- var operationData = {
- action: 'INSTALLED',
- componentNameFormatted: 'DataNodes'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
- });
- it('DECOMMISSION for hostComponents', function() {
- var operationData = {
- action: 'DECOMMISSION',
- componentNameFormatted: 'DataNodes'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
- });
- it('RECOMMISSION for hostComponents', function() {
- var operationData = {
- action: 'DECOMMISSION_OFF',
- componentNameFormatted: 'DataNodes'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
- });
- it('PASSIVE_STATE for hostComponents', function() {
- var operationData = {
- action: 'PASSIVE_STATE',
- componentNameFormatted: 'DataNodes'
- };
- hostController.bulkOperation(operationData, []);
- expect(hostController.bulkOperationForHostComponentsPassiveState.calledOnce).to.equal(true);
- });
- });
- describe('#bulkOperationForHosts', function() {
- beforeEach(function(){
- hostController = App.MainHostController.create({});
- sinon.spy($, 'ajax');
- });
- afterEach(function() {
- $.ajax.restore();
- });
- var tests = [
- {
- operationData: {},
- hosts: [],
- m: 'no hosts',
- e: false
- },
- {
- operationData: {
- actionToCheck: 'STARTED'
- },
- hosts: [
- Em.Object.create({
- hostComponents: Em.A([
- Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'NAMENODE'}),
- Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE'})
- ])
- })
- ],
- m: '1 host. components are in proper state',
- e: true
- },
- {
- operationData: {
- actionToCheck: 'INSTALLED'
- },
- hosts: [
- Em.Object.create({
- hostComponents: Em.A([
- Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'NAMENODE'}),
- Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE'})
- ])
- })
- ],
- m: '1 host. components are not in proper state',
- e: false
- },
- {
- operationData: {
- actionToCheck: 'INSTALLED'
- },
- hosts: [
- Em.Object.create({
- hostComponents: Em.A([
- Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'INSTALLED', componentName: 'NAMENODE'}),
- Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE'})
- ])
- })
- ],
- m: '1 host. some components are in proper state',
- e: true
- }
- ];
- tests.forEach(function(test) {
- it(test.m, function() {
- hostController.bulkOperationForHosts(test.operationData, test.hosts);
- expect($.ajax.called).to.equal(test.e);
- });
- });
- });
- describe('#bulkOperationForHostsRestart', function() {
- beforeEach(function(){
- hostController = App.MainHostController.create({});
- sinon.spy($, 'ajax');
- });
- afterEach(function() {
- $.ajax.restore();
- });
- var tests = [
- {
- hosts: Em.A([]),
- m: 'No hosts',
- e: false
- },
- {
- hosts: Em.A([
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({}), Em.Object.create({})])
- })
- ]),
- m: 'One host',
- e: true
- }
- ];
- tests.forEach(function(test) {
- it(test.m, function() {
- hostController.bulkOperationForHostsRestart({}, test.hosts);
- expect($.ajax.calledOnce).to.equal(test.e)
- });
- });
- });
- describe('#bulkOperationForHostsPassiveState', function() {
- beforeEach(function(){
- hostController = App.MainHostController.create({});
- sinon.spy($, 'ajax');
- });
- afterEach(function() {
- $.ajax.restore();
- });
- var tests = [
- {
- hosts: Em.A([]),
- operationData: {},
- m: 'No hosts',
- e: false
- },
- {
- hosts: Em.A([
- Em.Object.create({
- passiveState: 'ACTIVE'
- })
- ]),
- operationData: {
- state: 'ACTIVE'
- },
- m: 'One host, but in state that should get',
- e: false
- },
- {
- hosts: Em.A([
- Em.Object.create({
- passiveState: 'ACTIVE'
- })
- ]),
- operationData: {
- state: 'PASSIVE'
- },
- m: 'One host with proper state',
- e: true
- }
- ];
- tests.forEach(function(test) {
- it(test.m, function() {
- hostController.bulkOperationForHostsPassiveState(test.operationData, test.hosts);
- expect($.ajax.calledOnce).to.equal(test.e)
- });
- });
- });
- describe('#bulkOperationForHostComponentsPassiveState', function() {
- beforeEach(function(){
- hostController = App.MainHostController.create({});
- sinon.spy($, 'ajax');
- });
- afterEach(function() {
- $.ajax.restore();
- });
- var tests = [
- {
- hosts: Em.A([]),
- operationData: {},
- m: 'No hosts',
- e: false
- },
- {
- hosts: Em.A([
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'ACTIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- }),
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'ACTIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- })
- ]),
- operationData: {
- componentName: 'CN',
- state: 'ACTIVE'
- },
- m: 'Two hosts with components in state that they should get',
- e: false
- },
- {
- hosts: Em.A([
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'ACTIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- }),
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'PASSIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- })
- ]),
- operationData: {
- componentName: 'CN',
- state: 'PASSIVE'
- },
- m: 'One host with component in proper state (ACTIVE)',
- e: true
- },
- {
- hosts: Em.A([
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'ACTIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- }),
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'PASSIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- })
- ]),
- operationData: {
- componentName: 'CN',
- state: 'PASSIVE'
- },
- m: 'One host with component in proper state (PASSIVE)',
- e: true
- },
- {
- hosts: Em.A([
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'ACTIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- }),
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'IMPLIED'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- })
- ]),
- operationData: {
- componentName: 'CN',
- state: 'PASSIVE'
- },
- m: 'One host with component in proper state (ACTIVE)',
- e: true
- },
- {
- hosts: Em.A([
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'ACTIVE'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- }),
- Em.Object.create({
- hostComponents: Em.A([Em.Object.create({componentName:'CN',passiveState:'IMPLIED'}), Em.Object.create({componentName:'ACN',passiveState:'ACTIVE'})])
- })
- ]),
- operationData: {
- componentName: 'CN',
- state: 'ACTIVE'
- },
- m: 'One host with component in proper state (PASSIVE)',
- e: true
- }
- ];
- tests.forEach(function(test) {
- it(test.m, function() {
- hostController.bulkOperationForHostComponentsPassiveState(test.operationData, test.hosts);
- expect($.ajax.calledOnce).to.equal(test.e)
- });
- });
- });
- });
|