123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- /**
- * 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 modelSetup = require('test/init_model_test');
- require('models/service');
- var service,
- serviceData = {
- id: 'service'
- },
- statusPropertiesCases = [
- {
- status: 'INSTALLED',
- property: 'isStopped'
- },
- {
- status: 'STARTED',
- property: 'isStarted'
- }
- ],
- hostComponentsDataFalse = [
- [],
- [
- {
- staleConfigs: false
- }
- ],
- [
- {
- service: {
- serviceName: 'HIVE'
- },
- staleConfigs: false
- }
- ]
- ],
- hostComponentsDataTrue = [
- [
- Em.Object.create({
- service: {
- serviceName: 'HDFS'
- },
- staleConfigs: true,
- displayName: 'service0'
- })
- ],
- [
- Em.Object.create({
- host: {
- publicHostName: 'host0'
- },
- service: {
- serviceName: 'HDFS'
- },
- staleConfigs: true,
- displayName: 'service1'
- })
- ]
- ],
- restartData = {
- host0: ['service0', 'service1']
- };
- function getModel() {
- return App.Service.createRecord(serviceData);
- }
- describe('App.Service', function () {
- beforeEach(function () {
- service = App.Service.createRecord(serviceData);
- });
- afterEach(function () {
- modelSetup.deleteRecord(service);
- });
- describe('#isInPassive', function () {
- it('should be true', function () {
- service.set('passiveState', 'ON');
- expect(service.get('isInPassive')).to.be.true;
- });
- it('should be false', function () {
- service.set('passiveState', 'OFF');
- expect(service.get('isInPassive')).to.be.false;
- });
- });
- App.TestAliases.testAsComputedGetByKey(getModel(), 'healthStatus', 'healthStatusMap', 'workStatus', {defaultValue: 'yellow', map: {
- STARTED: 'green',
- STARTING: 'green-blinking',
- INSTALLED: 'red',
- STOPPING: 'red-blinking',
- UNKNOWN: 'yellow'
- }});
- statusPropertiesCases.forEach(function (item) {
- var status = item.status,
- property = item.property;
- describe('#' + property, function () {
- it('status ' + status + ' is for ' + property, function () {
- service.set('workStatus', status);
- expect(service.get(property)).to.be.true;
- var falseStates = statusPropertiesCases.mapProperty('property').without(property);
- var falseStatuses = [];
- falseStates.forEach(function (state) {
- falseStatuses.push(service.get(state));
- });
- expect(falseStatuses).to.eql([false]);
- });
- });
- });
- describe('#isRestartRequired', function () {
- beforeEach(function () {
- service.reopen({
- serviceName: 'HDFS',
- hostComponents: []
- });
- });
- hostComponentsDataFalse.forEach(function (item) {
- it('should be false', function () {
- service.set('hostComponents', item);
- expect(service.get('isRestartRequired')).to.be.false;
- });
- });
- hostComponentsDataTrue.forEach(function (item) {
- it('should be true', function () {
- service.set('hostComponents', item);
- expect(service.get('isRestartRequired')).to.be.true;
- });
- });
- });
- describe('#restartRequiredMessage', function () {
- it('should form message for 2 services on 1 host', function () {
- service.set('restartRequiredHostsAndComponents', restartData);
- expect(service.get('restartRequiredMessage')).to.contain('host0');
- expect(service.get('restartRequiredMessage')).to.contain('service0');
- expect(service.get('restartRequiredMessage')).to.contain('service1');
- });
- });
- describe('#serviceTypes', function () {
- var testCases = [
- {
- serviceName: 'PIG',
- result: []
- },
- {
- serviceName: 'GANGLIA',
- result: ['MONITORING']
- },
- {
- serviceName: 'HDFS',
- result: ['HA_MODE']
- },
- {
- serviceName: 'YARN',
- result: ['HA_MODE']
- }
- ];
- testCases.forEach(function (test) {
- it('service name - ' + test.serviceName, function () {
- service.set('serviceName', test.serviceName);
- service.propertyDidChange('serviceTypes');
- expect(service.get('serviceTypes')).to.eql(test.result);
- });
- });
- });
- describe('#allowToDelete', function () {
- beforeEach(function () {
- this.stub = sinon.stub(service, 'get');
- });
- afterEach(function () {
- this.stub.restore();
- });
- Em.A([
- {
- m: 'may be deleted (1)',
- slaveComponents: [{allowToDelete: true}],
- masterComponents: [{allowToDelete: true}],
- workStatus: 'INIT',
- e: true
- },
- {
- m: 'may be deleted (2)',
- slaveComponents: [{allowToDelete: true}],
- masterComponents: [{allowToDelete: true}],
- workStatus: 'INSTALL_FAILED',
- e: true
- },
- {
- m: 'may be deleted (3)',
- slaveComponents: [{allowToDelete: true}],
- masterComponents: [{allowToDelete: true}],
- workStatus: 'INSTALLED',
- e: true
- },
- {
- m: 'may be deleted (4)',
- slaveComponents: [{allowToDelete: true}],
- masterComponents: [{allowToDelete: true}],
- workStatus: 'UNKNOWN',
- e: true
- },
- {
- m: 'deleting is not allowed (1)',
- slaveComponents: [{allowToDelete: false}],
- masterComponents: [{allowToDelete: true}],
- workStatus: 'UNKNOWN',
- e: false
- },
- {
- m: 'deleting is not allowed (2)',
- slaveComponents: [{allowToDelete: false}],
- masterComponents: [{allowToDelete: false}],
- workStatus: 'UNKNOWN',
- e: false
- },
- {
- m: 'deleting is not allowed (3)',
- slaveComponents: [{allowToDelete: true}],
- masterComponents: [{allowToDelete: false}],
- workStatus: 'UNKNOWN',
- e: false
- },
- {
- m: 'deleting is not allowed (4)',
- slaveComponents: [{allowToDelete: true}],
- masterComponents: [{allowToDelete: true}],
- workStatus: 'STARTED',
- e: false
- }
- ]).forEach(function (test) {
- it(test.m, function () {
- this.stub.withArgs('workStatus').returns(test.workStatus);
- this.stub.withArgs('slaveComponents').returns(test.slaveComponents);
- this.stub.withArgs('masterComponents').returns(test.masterComponents);
- expect(Em.get(service, 'allowToDelete')).to.be.equal(test.e);
- });
- });
- });
- });
|