123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /**
- * 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'
- },
- healthCases = [
- {
- status: 'STARTED',
- health: 'green'
- },
- {
- status: 'STARTING',
- health: 'green-blinking'
- },
- {
- status: 'INSTALLED',
- health: 'red'
- },
- {
- status: 'STOPPING',
- health: 'red-blinking'
- },
- {
- status: 'UNKNOWN',
- health: 'yellow'
- },
- {
- status: 'ANOTHER',
- health: 'yellow'
- }
- ],
- statusPropertiesCases = [
- {
- status: 'INSTALLED',
- property: 'isStopped'
- },
- {
- status: 'STARTED',
- property: 'isStarted'
- }
- ],
- services = [
- {
- name: 'HDFS',
- configurable: true
- },
- {
- name: 'YARN',
- configurable: true
- },
- {
- name: 'MAPREDUCE2',
- configurable: true
- },
- {
- name:'TEZ',
- clientOnly: true,
- configurable: true
- },
- {
- name: 'HBASE',
- configurable: true
- },
- {
- name: 'HIVE',
- configurable: true
- },
- {
- name: 'FLUME',
- configurable: true
- },
- {
- name: 'FALCON',
- configurable: true
- },
- {
- name: 'STORM',
- configurable: true
- },
- {
- name: 'OOZIE',
- configurable: true
- },
- {
- name: 'GANGLIA',
- configurable: true
- },
- {
- name: 'ZOOKEEPER',
- configurable: true
- },
- {
- name: 'PIG',
- configurable: true,
- clientOnly: true
- },
- {
- name: 'SQOOP',
- clientOnly: true
- },
- {
- name: 'HUE',
- configurable: true
- }
- ],
- clientsOnly = services.filterProperty('clientOnly').mapProperty('name'),
- configurable = services.filterProperty('configurable').mapProperty('name'),
- 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']
- };
- 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;
- });
- });
- describe('#healthStatus', function () {
- healthCases.forEach(function (item) {
- it('should be ' + item.health, function () {
- service.set('workStatus', item.status);
- expect(service.get('healthStatus')).to.equal(item.health);
- });
- });
- });
- 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 () {
- var mockHostComponentModel = function (mock) {
- sinon.stub(App.HostComponent, 'find', function () {
- return mock;
- });
- }
- beforeEach(function () {
- service.reopen({
- serviceName: 'HDFS'
- });
- });
- afterEach(function () {
- App.HostComponent.find.restore();
- });
- hostComponentsDataFalse.forEach(function (item) {
- it('should be false', function () {
- mockHostComponentModel(item);
- expect(service.get('isRestartRequired')).to.be.false;
- });
- });
- hostComponentsDataTrue.forEach(function (item) {
- it('should be true', function () {
- mockHostComponentModel(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);
- });
- });
- });
- });
|