1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318 |
- /**
- * 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');
- require('controllers/main/service/info/configs');
- var batchUtils = require('utils/batch_scheduled_requests');
- var mainServiceInfoConfigsController = null;
- describe("App.MainServiceInfoConfigsController", function () {
- beforeEach(function () {
- sinon.stub(App.config, 'loadConfigTheme').returns($.Deferred().resolve().promise());
- sinon.stub(App.themesMapper, 'generateAdvancedTabs').returns(Em.K);
- mainServiceInfoConfigsController = App.MainServiceInfoConfigsController.create({
- loadDependentConfigs: function () {
- return {done: Em.K}
- }
- });
- });
- afterEach(function() {
- App.config.loadConfigTheme.restore();
- App.themesMapper.generateAdvancedTabs.restore();
- });
- describe("#showSavePopup", function () {
- var tests = [
- {
- path: false,
- callback: null,
- action: "onSave",
- m: "save configs without path/callback",
- results: [
- {
- method: "restartServicePopup",
- called: true
- }
- ]
- },
- {
- path: true,
- callback: true,
- action: "onSave",
- m: "save configs with path/callback",
- results: [
- {
- method: "restartServicePopup",
- called: true
- }
- ]
- },
- {
- path: false,
- callback: false,
- action: "onDiscard",
- m: "discard changes without path/callback",
- results: [
- {
- method: "restartServicePopup",
- called: false
- }
- ]
- },
- {
- path: false,
- callback: true,
- action: "onDiscard",
- m: "discard changes with callback",
- results: [
- {
- method: "restartServicePopup",
- called: false
- },
- {
- method: "callback",
- called: true
- },
- {
- field: "hash",
- value: "hash"
- }
- ]
- },
- {
- path: true,
- callback: null,
- action: "onDiscard",
- m: "discard changes with path",
- results: [
- {
- method: "restartServicePopup",
- called: false
- },
- {
- field: "forceTransition",
- value: true
- }
- ]
- }
- ];
- beforeEach(function () {
- sinon.stub(mainServiceInfoConfigsController, "restartServicePopup", Em.K);
- sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
- return "hash"
- });
- App.router.route = Em.K;
- });
- afterEach(function () {
- mainServiceInfoConfigsController.restartServicePopup.restore();
- mainServiceInfoConfigsController.getHash.restore();
- });
- tests.forEach(function (t) {
- t.results.forEach(function (r) {
- it(t.m + " " + r.method + " " + r.field, function () {
- if (t.callback) {
- t.callback = sinon.stub();
- }
- mainServiceInfoConfigsController.showSavePopup(t.path, t.callback)[t.action]();
- if (r.method) {
- if (r.method === 'callback') {
- expect(t.callback.calledOnce).to.equal(r.called);
- } else {
- expect(mainServiceInfoConfigsController[r.method].calledOnce).to.equal(r.called);
- }
- } else if (r.field) {
- expect(mainServiceInfoConfigsController.get(r.field)).to.equal(r.value);
- }
- }, this);
- });
- }, this);
- });
- describe("#hasUnsavedChanges", function () {
- beforeEach(function () {
- sinon.stub(mainServiceInfoConfigsController, "getHash", function () {
- return "hash"
- });
- });
- afterEach(function () {
- mainServiceInfoConfigsController.getHash.restore();
- });
- it("with unsaved", function () {
- mainServiceInfoConfigsController.set("hash", "hash1");
- expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(true);
- });
- it("without unsaved", function () {
- mainServiceInfoConfigsController.set("hash", "hash");
- expect(mainServiceInfoConfigsController.hasUnsavedChanges()).to.equal(false);
- });
- });
- describe("#manageConfigurationGroup", function () {
- beforeEach(function () {
- sinon.stub(mainServiceInfoConfigsController, "manageConfigurationGroups", Em.K);
- });
- afterEach(function () {
- mainServiceInfoConfigsController.manageConfigurationGroups.restore();
- });
- it("run manageConfigurationGroups", function () {
- mainServiceInfoConfigsController.manageConfigurationGroup();
- expect(mainServiceInfoConfigsController.manageConfigurationGroups.calledOnce).to.equal(true);
- });
- });
- describe("#addOverrideProperty", function () {
- var serviceConfigProperty = Em.Object.create({
- overrides: []
- });
- var group = {};
- var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
- newSCP.set('value', '');
- newSCP.set('isOriginalSCP', false);
- newSCP.set('parentSCP', serviceConfigProperty);
- newSCP.set('isEditable', true);
- newSCP.set('group', group);
- it("add new overridden property", function () {
- mainServiceInfoConfigsController.addOverrideProperty(serviceConfigProperty, group);
- expect(serviceConfigProperty.get("overrides")[0]).to.eql(newSCP);
- });
- });
- describe("#showComponentsShouldBeRestarted", function () {
- var tests = [
- {
- input: {
- context: {
- 'publicHostName1': ['TaskTracker'],
- 'publicHostName2': ['JobTracker', 'TaskTracker']
- }
- },
- components: "2 TaskTrackers, 1 JobTracker",
- text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.components'))
- },
- {
- input: {
- context: {
- 'publicHostName1': ['TaskTracker']
- }
- },
- components: "1 TaskTracker",
- text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.component'))
- }
- ];
- beforeEach(function () {
- sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
- });
- afterEach(function () {
- mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
- });
- tests.forEach(function (t) {
- it("trigger showItemsShouldBeRestarted popup with components", function () {
- mainServiceInfoConfigsController.showComponentsShouldBeRestarted(t.input);
- expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.components, t.text)).to.equal(true);
- });
- });
- });
- describe("#showHostsShouldBeRestarted", function () {
- var tests = [
- {
- input: {
- context: {
- 'publicHostName1': ['TaskTracker'],
- 'publicHostName2': ['JobTracker', 'TaskTracker']
- }
- },
- hosts: "publicHostName1, publicHostName2",
- text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.hosts'))
- },
- {
- input: {
- context: {
- 'publicHostName1': ['TaskTracker']
- }
- },
- hosts: "publicHostName1",
- text: Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(Em.I18n.t('common.host'))
- }
- ];
- beforeEach(function () {
- sinon.stub(mainServiceInfoConfigsController, "showItemsShouldBeRestarted", Em.K);
- });
- afterEach(function () {
- mainServiceInfoConfigsController.showItemsShouldBeRestarted.restore();
- });
- tests.forEach(function (t) {
- it("trigger showItemsShouldBeRestarted popup with hosts", function () {
- mainServiceInfoConfigsController.showHostsShouldBeRestarted(t.input);
- expect(mainServiceInfoConfigsController.showItemsShouldBeRestarted.calledWith(t.hosts, t.text)).to.equal(true);
- });
- });
- });
- describe("#rollingRestartStaleConfigSlaveComponents", function () {
- var tests = [
- {
- componentName: {
- context: "ComponentName"
- },
- displayName: "displayName",
- passiveState: "ON"
- },
- {
- componentName: {
- context: "ComponentName1"
- },
- displayName: "displayName1",
- passiveState: "OFF"
- }
- ];
- beforeEach(function () {
- mainServiceInfoConfigsController.set("content", {displayName: "", passiveState: ""});
- sinon.stub(batchUtils, "launchHostComponentRollingRestart", Em.K);
- });
- afterEach(function () {
- batchUtils.launchHostComponentRollingRestart.restore();
- });
- tests.forEach(function (t) {
- it("trigger rollingRestartStaleConfigSlaveComponents", function () {
- mainServiceInfoConfigsController.set("content.displayName", t.displayName);
- mainServiceInfoConfigsController.set("content.passiveState", t.passiveState);
- mainServiceInfoConfigsController.rollingRestartStaleConfigSlaveComponents(t.componentName);
- expect(batchUtils.launchHostComponentRollingRestart.calledWith(t.componentName.context, t.displayName, t.passiveState == "ON", true)).to.equal(true);
- });
- });
- });
- describe("#restartAllStaleConfigComponents", function () {
- beforeEach(function () {
- sinon.stub(batchUtils, "restartAllServiceHostComponents", Em.K);
- });
- afterEach(function () {
- batchUtils.restartAllServiceHostComponents.restore();
- });
- it("trigger restartAllServiceHostComponents", function () {
- mainServiceInfoConfigsController.restartAllStaleConfigComponents().onPrimary();
- expect(batchUtils.restartAllServiceHostComponents.calledOnce).to.equal(true);
- });
- });
- describe("#doCancel", function () {
- beforeEach(function () {
- sinon.stub(Em.run, 'once', Em.K);
- });
- afterEach(function () {
- Em.run.once.restore();
- });
- it("trigger onConfigGroupChange", function () {
- mainServiceInfoConfigsController.doCancel();
- expect(Em.run.once.calledWith(mainServiceInfoConfigsController, "onConfigGroupChange")).to.equal(true);
- });
- });
- describe("#getCurrentServiceComponents", function () {
- var t = Em.Object.create({
- content: Em.Object.create({
- hostComponents: [
- Em.Object.create({
- componentName: "componentName1",
- displayName: "displayName1"
- }),
- Em.Object.create({
- componentName: "componentName2",
- displayName: "displayName2"
- })
- ]
- }),
- validComponents: Em.A([
- Em.Object.create({
- componentName: "componentName1",
- displayName: "displayName1",
- selected: false
- }),
- Em.Object.create({
- componentName: "componentName2",
- displayName: "displayName2",
- selected: false
- })
- ])
- });
- beforeEach(function () {
- mainServiceInfoConfigsController.set("content", { hostComponents: Em.A([])});
- });
- it("get current service components", function () {
- mainServiceInfoConfigsController.get("content.hostComponents").push(t.content.hostComponents[0]);
- var com = mainServiceInfoConfigsController.get("getCurrentServiceComponents");
- expect(com[0]).to.eql(t.validComponents[0]);
- });
- });
- describe("#getMasterComponentHostValue", function () {
- var tests = [
- {
- content: {
- hostComponents: [
- Em.Object.create({
- componentName: "componentName1",
- hostName: "hostName"
- })
- ]
- },
- result: "hostName",
- multiple: false,
- m: "returns hostname"
- },
- {
- content: {
- hostComponents: [
- Em.Object.create({
- componentName: "componentName2",
- hostName: "hostName1"
- }),
- Em.Object.create({
- componentName: "componentName2",
- hostName: "hostName2"
- })
- ]
- },
- result: ["hostName1","hostName2"],
- multiple: true,
- m: "returns hostnames"
- }
- ];
- tests.forEach(function(t){
- beforeEach(function () {
- mainServiceInfoConfigsController.set("content", { hostComponents: []});
- });
- it(t.m, function () {
- mainServiceInfoConfigsController.set("content.hostComponents", t.content.hostComponents);
- expect(mainServiceInfoConfigsController.getMasterComponentHostValue(t.content.hostComponents[0].componentName, t.multiple)).to.eql(t.result);
- });
- });
- });
- describe("#setServerConfigValue", function () {
- it("parsing storm.zookeeper.servers property in non standart method", function () {
- expect(mainServiceInfoConfigsController.setServerConfigValue("storm.zookeeper.servers", ["a", "b"])).to.equal('[\'a\',\'b\']');
- });
- it("parsing default properties", function () {
- expect(mainServiceInfoConfigsController.setServerConfigValue("any.other.property", "value")).to.equal("value");
- });
- });
- describe("#createSiteObj", function () {
- var tests = [
- {
- siteName: "hdfs-site",
- tagName: "version1",
- siteObj: Em.A([
- {
- name: "property1",
- value: "value1"
- },
- {
- name: "property2",
- value: "value2<"
- },
- {
- name: "property_heapsize",
- value: "value3"
- },
- {
- name: "property_permsize",
- value: "value4m"
- }
- ]),
- result: {
- "type": "hdfs-site",
- "tag": "version1",
- "properties": {
- "property1": "value1",
- "property2": "value2<",
- "property_heapsize": "value3m",
- "property_permsize": "value4m"
- }
- },
- m: "default"
- },
- {
- siteName: "falcon-startup.properties",
- tagName: "version1",
- siteObj: Em.A([
- {
- name: "property1",
- value: "value1"
- },
- {
- name: "property2",
- value: "value2<"
- }
- ]),
- result: {
- "type": "falcon-startup.properties",
- "tag": "version1",
- "properties": {
- "property1": "value1",
- "property2": "value2<"
- }
- },
- m: "for falcon-startup.properties"
- }
- ];
- tests.forEach(function (t) {
- it("create site object " + t.m, function () {
- expect(mainServiceInfoConfigsController.createSiteObj(t.siteName, t.tagName, t.siteObj)).to.deep.eql(t.result)
- });
- });
- });
- describe("#createCoreSiteObj", function () {
- var tests = [
- {
- tagName: "version1",
- uiConfigs: Em.A([
- Em.Object.create({
- name: "property1",
- value: "value1",
- filename: "core-site.xml"
- }),
- Em.Object.create({
- name: "property2",
- value: "value2<",
- filename: "core-site.xml"
- })
- ]),
- result: {
- "type": "core-site",
- "tag": "version1",
- "properties": {
- "property1": "value1",
- "property2": "value2<"
- }
- }
- }
- ];
- tests.forEach(function (t) {
- it("create core object", function () {
- mainServiceInfoConfigsController.set("uiConfigs", t.uiConfigs);
- expect(mainServiceInfoConfigsController.createCoreSiteObj(t.tagName)).to.deep.eql(t.result);
- });
- });
- });
- describe("#doPUTClusterConfigurationSites", function () {
- var sc = [
- Em.Object.create({
- configs: [
- Em.Object.create({
- name: '_heapsize',
- value: '1024m'
- }),
- Em.Object.create({
- name: '_newsize',
- value: '1024m'
- }),
- Em.Object.create({
- name: '_maxnewsize',
- value: '1024m'
- })
- ]
- })
- ],
- scExc = [
- Em.Object.create({
- configs: [
- Em.Object.create({
- name: 'hadoop_heapsize',
- value: '1024m'
- }),
- Em.Object.create({
- name: 'yarn_heapsize',
- value: '1024m'
- }),
- Em.Object.create({
- name: 'nodemanager_heapsize',
- value: '1024m'
- }),
- Em.Object.create({
- name: 'resourcemanager_heapsize',
- value: '1024m'
- }),
- Em.Object.create({
- name: 'apptimelineserver_heapsize',
- value: '1024m'
- }),
- Em.Object.create({
- name: 'jobhistory_heapsize',
- value: '1024m'
- })
- ]
- })
- ];
- beforeEach(function () {
- sinon.stub(App.router, 'getClusterName', function() {
- return 'clName';
- });
- sinon.stub(App.ajax, "send", Em.K);
- });
- afterEach(function () {
- App.ajax.send.restore();
- App.router.getClusterName.restore();
- });
- it("ajax request to put clsuter cfg", function () {
- mainServiceInfoConfigsController.set('stepConfigs', sc);
- expect(mainServiceInfoConfigsController.doPUTClusterConfigurationSites([])).to.equal(mainServiceInfoConfigsController.get("doPUTClusterConfigurationSiteResult"));
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- it('values should be parsed', function () {
- mainServiceInfoConfigsController.set('stepConfigs', sc);
- mainServiceInfoConfigsController.doPUTClusterConfigurationSites([]);
- expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
- });
- it('values should not be parsed', function () {
- mainServiceInfoConfigsController.set('stepConfigs', scExc);
- mainServiceInfoConfigsController.doPUTClusterConfigurationSites([]);
- expect(mainServiceInfoConfigsController.get('stepConfigs')[0].get('configs').mapProperty('value').uniq()).to.eql(['1024m']);
- });
- });
- describe("#isConfigChanged", function () {
- var tests = [
- {
- loadedConfig: {
- apptimelineserver_heapsize: "1024",
- hbase_log_dir: "/var/log/hbase",
- lzo_enabled: "true"
- },
- savingConfig: {
- apptimelineserver_heapsize: "1024",
- hbase_log_dir: "/var/log/hbase",
- lzo_enabled: "true"
- },
- m: "configs doesn't changed",
- res: false
- },
- {
- loadedConfig: {
- apptimelineserver_heapsize: "1024",
- hbase_log_dir: "/var/log/hbase",
- lzo_enabled: "true"
- },
- savingConfig: {
- apptimelineserver_heapsize: "1024",
- hbase_log_dir: "/var/log/hbase",
- lzo_enabled: "false"
- },
- m: "configs changed",
- res: true
- },
- {
- loadedConfig: {
- apptimelineserver_heapsize: "1024",
- hbase_log_dir: "/var/log/hbase"
- },
- savingConfig: {
- apptimelineserver_heapsize: "1024",
- hbase_log_dir: "/var/log/hbase",
- lzo_enabled: "false"
- },
- m: "add new config",
- res: true
- }
- ];
- tests.forEach(function(t){
- it(t.m, function () {
- expect(mainServiceInfoConfigsController.isConfigChanged(t.loadedConfig, t.savingConfig)).to.equal(t.res);
- });
- });
- });
- describe("#isDirChanged", function() {
- describe("when service name is HDFS", function() {
- beforeEach(function() {
- mainServiceInfoConfigsController.set('content', Ember.Object.create ({ serviceName: 'HDFS' }));
- });
- describe("for hadoop 2", function() {
- var tests = [
- {
- it: "should set dirChanged to false if none of the properties exist",
- expect: false,
- config: Ember.Object.create ({})
- },
- {
- it: "should set dirChanged to true if dfs.namenode.name.dir is not default",
- expect: true,
- config: Ember.Object.create ({
- name: 'dfs.namenode.name.dir',
- isNotDefaultValue: true
- })
- },
- {
- it: "should set dirChanged to false if dfs.namenode.name.dir is default",
- expect: false,
- config: Ember.Object.create ({
- name: 'dfs.namenode.name.dir',
- isNotDefaultValue: false
- })
- },
- {
- it: "should set dirChanged to true if dfs.namenode.checkpoint.dir is not default",
- expect: true,
- config: Ember.Object.create ({
- name: 'dfs.namenode.checkpoint.dir',
- isNotDefaultValue: true
- })
- },
- {
- it: "should set dirChanged to false if dfs.namenode.checkpoint.dir is default",
- expect: false,
- config: Ember.Object.create ({
- name: 'dfs.namenode.checkpoint.dir',
- isNotDefaultValue: false
- })
- },
- {
- it: "should set dirChanged to true if dfs.datanode.data.dir is not default",
- expect: true,
- config: Ember.Object.create ({
- name: 'dfs.datanode.data.dir',
- isNotDefaultValue: true
- })
- },
- {
- it: "should set dirChanged to false if dfs.datanode.data.dir is default",
- expect: false,
- config: Ember.Object.create ({
- name: 'dfs.datanode.data.dir',
- isNotDefaultValue: false
- })
- }
- ];
- beforeEach(function() {
- sinon.stub(App, 'get').returns(true);
- });
- afterEach(function() {
- App.get.restore();
- });
- tests.forEach(function(test) {
- it(test.it, function() {
- mainServiceInfoConfigsController.set('stepConfigs', [Ember.Object.create ({ configs: [test.config], serviceName: 'HDFS' })]);
- expect(mainServiceInfoConfigsController.isDirChanged()).to.equal(test.expect);
- })
- });
- });
- });
- });
- describe("#addDynamicProperties", function() {
- var tests = [
- {
- stepConfigs: [Em.Object.create({
- serviceName: "HIVE",
- configs: []
- })],
- content: Em.Object.create({
- serviceName: "HIVE"
- }),
- m: "add dynamic property",
- addDynamic: true
- },
- {
- stepConfigs: [Em.Object.create({
- serviceName: "HIVE",
- configs: [
- Em.Object.create({
- name: "templeton.hive.properties"
- })
- ]
- })],
- content: Em.Object.create({
- serviceName: "HIVE"
- }),
- m: "don't add dynamic property (already included)",
- addDynamic: false
- },
- {
- stepConfigs: [Em.Object.create({
- serviceName: "HDFS",
- configs: []
- })],
- content: Em.Object.create({
- serviceName: "HDFS"
- }),
- m: "don't add dynamic property (wrong service)",
- addDynamic: false
- }
- ];
- var dynamicProperty = {
- "name": "templeton.hive.properties",
- "templateName": ["hive.metastore.uris"],
- "foreignKey": null,
- "value": "hive.metastore.local=false,hive.metastore.uris=<templateName[0]>,hive.metastore.sasl.enabled=yes,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse",
- "filename": "webhcat-site.xml"
- };
- tests.forEach(function(t) {
- it(t.m, function() {
- mainServiceInfoConfigsController.set("content", t.content);
- mainServiceInfoConfigsController.set("stepConfigs", t.stepConfigs);
- var configs = [];
- mainServiceInfoConfigsController.addDynamicProperties(configs);
- if (t.addDynamic){
- expect(configs.findProperty("name","templeton.hive.properties")).to.deep.eql(dynamicProperty);
- }
- });
- });
- });
- describe("#loadUiSideConfigs", function () {
- var t = {
- configMapping: [
- {
- foreignKey: null,
- templateName: "",
- value: "default",
- name: "name1",
- filename: "filename1"
- },
- {
- foreignKey: "notNull",
- templateName: "",
- value: "default2",
- name: "name2",
- filename: "filename2"
- }
- ],
- configMappingf: [
- {
- foreignKey: null,
- templateName: "",
- value: "default",
- name: "name1",
- filename: "filename1"
- }
- ],
- valueWithOverrides: {
- "value": "default",
- "overrides": {
- "value1": "value1",
- "value2": "value2"
- }
- },
- uiConfigs: [
- {
- "id": "site property",
- "name": "name1",
- "value": "default",
- "filename": "filename1",
- "overrides": {
- "value1": "value1",
- "value2": "value2"
- }
- }
- ]
- };
- beforeEach(function(){
- sinon.stub(mainServiceInfoConfigsController, "addDynamicProperties", Em.K);
- sinon.stub(mainServiceInfoConfigsController, "getGlobConfigValueWithOverrides", function () {
- return t.valueWithOverrides
- });
- });
- afterEach(function(){
- mainServiceInfoConfigsController.addDynamicProperties.restore();
- mainServiceInfoConfigsController.getGlobConfigValueWithOverrides.restore();
- });
- it("load ui config", function() {
- expect(mainServiceInfoConfigsController.loadUiSideConfigs(t.configMapping)[0]).to.deep.equal(t.uiConfigs[0]);
- expect(mainServiceInfoConfigsController.addDynamicProperties.calledWith(t.configMappingf)).to.equal(true);
- expect(mainServiceInfoConfigsController.getGlobConfigValueWithOverrides.calledWith(t.configMapping[0].templateName, t.configMapping[0].value, t.configMapping[0].name)).to.equal(true);
- });
- });
- describe("#formatConfigValues", function () {
- var t = {
- configs: [
- Em.Object.create({ name: "p1", value: " v1 v1 ", displayType: "" }),
- Em.Object.create({ name: "p2", value: true, displayType: "" }),
- Em.Object.create({ name: "p3", value: " d1 ", displayType: "directory" }),
- Em.Object.create({ name: "p4", value: " d1 d2 d3 ", displayType: "directories" }),
- Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
- Em.Object.create({ name: "p6", value: " v ", displayType: "host" }),
- Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1 ", displayType: "advanced" }),
- Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1 ", displayType: "advanced" })
- ],
- result: [
- Em.Object.create({ name: "p1", value: " v1 v1", displayType: "" }),
- Em.Object.create({ name: "p2", value: "true", displayType: "" }),
- Em.Object.create({ name: "p3", value: "d1", displayType: "directory" }),
- Em.Object.create({ name: "p4", value: "d1,d2,d3", displayType: "directories" }),
- Em.Object.create({ name: "p5", value: " v1 ", displayType: "password" }),
- Em.Object.create({ name: "p6", value: "v", displayType: "host" }),
- Em.Object.create({ name: "javax.jdo.option.ConnectionURL", value: " v1", displayType: "advanced" }),
- Em.Object.create({ name: "oozie.service.JPAService.jdbc.url", value: " v1", displayType: "advanced" })
- ]
- };
- it("format config values", function () {
- mainServiceInfoConfigsController.formatConfigValues(t.configs);
- expect(t.configs).to.deep.equal(t.result);
- });
- });
- describe("#createConfigObject", function() {
- var tests = [
- {
- siteName: "core-site",
- serviceName: "HDFS",
- method: "createCoreSiteObj"
- },
- {
- siteName: "core-site",
- serviceName: "ANY",
- method: false
- },
- {
- siteName: "any",
- method: "createSiteObj"
- },
- {
- siteName: "mapred-queue-acls",
- method: false
- }
- ];
- beforeEach(function() {
- sinon.stub(mainServiceInfoConfigsController, "createCoreSiteObj", Em.K);
- sinon.stub(mainServiceInfoConfigsController, "createSiteObj", Em.K);
- mainServiceInfoConfigsController.set("content", {});
- });
- afterEach(function() {
- mainServiceInfoConfigsController.createCoreSiteObj.restore();
- mainServiceInfoConfigsController.createSiteObj.restore();
- });
- tests.forEach(function(t) {
- it("create object for " + t.siteName + " run method " + t.method, function() {
- mainServiceInfoConfigsController.set("content.serviceName", t.serviceName);
- mainServiceInfoConfigsController.createConfigObject(t.siteName, "versrion1");
- if (t.method) {
- expect(mainServiceInfoConfigsController[t.method].calledOnce).to.equal(true);
- } else {
- expect(mainServiceInfoConfigsController["createCoreSiteObj"].calledOnce).to.equal(false);
- expect(mainServiceInfoConfigsController["createSiteObj"].calledOnce).to.equal(false);
- }
- });
- });
- });
- describe("#putConfigGroupChanges", function() {
- var t = {
- data: {
- ConfigGroup: {
- id: "id"
- }
- },
- request: [{
- ConfigGroup: {
- id: "id"
- }
- }]
- };
- beforeEach(function() {
- sinon.spy($,"ajax");
- });
- afterEach(function() {
- $.ajax.restore();
- });
- it("updates configs groups", function() {
- mainServiceInfoConfigsController.putConfigGroupChanges(t.data);
- expect(JSON.parse($.ajax.args[0][0].data)).to.deep.equal(t.request);
- });
- });
- describe("#setEditability", function () {
- var tests = [
- {
- isAdmin: true,
- isHostsConfigsPage: false,
- defaultGroupSelected: true,
- isReconfigurable: true,
- isEditable: true,
- m: ""
- },
- {
- isAdmin: false,
- isHostsConfigsPage: false,
- defaultGroupSelected: true,
- isReconfigurable: true,
- isEditable: false,
- m: "(non admin)"
- },
- {
- isAdmin: true,
- isHostsConfigsPage: true,
- defaultGroupSelected: true,
- isReconfigurable: true,
- isEditable: false,
- m: "(isHostsConfigsPage)"
- },
- {
- isAdmin: true,
- isHostsConfigsPage: false,
- defaultGroupSelected: false,
- isReconfigurable: true,
- isEditable: false,
- m: "(defaultGroupSelected is false)"
- },
- {
- isAdmin: true,
- isHostsConfigsPage: false,
- defaultGroupSelected: true,
- isReconfigurable: false,
- isEditable: false,
- m: "(isReconfigurable is false)"
- }
- ];
- beforeEach(function(){
- this.mock = sinon.stub(App, 'isAccessible');
- });
- afterEach(function () {
- this.mock.restore();
- });
- tests.forEach(function(t) {
- it("set isEditable " + t.isEditable + t.m, function(){
- this.mock.returns(t.isAdmin);
- mainServiceInfoConfigsController.set("isHostsConfigsPage", t.isHostsConfigsPage);
- var serviceConfigProperty = Em.Object.create({
- isReconfigurable: t.isReconfigurable
- });
- mainServiceInfoConfigsController.setEditability(serviceConfigProperty, t.defaultGroupSelected);
- expect(serviceConfigProperty.get("isEditable")).to.equal(t.isEditable);
- });
- });
- });
- describe("#checkOverrideProperty", function () {
- var tests = [{
- overrideToAdd: {
- name: "name1",
- filename: "filename1"
- },
- componentConfig: {
- configs: [
- {
- name: "name1",
- filename: "filename2"
- },
- {
- name: "name1",
- filename: "filename1"
- }
- ]
- },
- add: true,
- m: "add property"
- },
- {
- overrideToAdd: {
- name: "name1"
- },
- componentConfig: {
- configs: [
- {
- name: "name2"
- }
- ]
- },
- add: false,
- m: "don't add property, different names"
- },
- {
- overrideToAdd: {
- name: "name1",
- filename: "filename1"
- },
- componentConfig: {
- configs: [
- {
- name: "name1",
- filename: "filename2"
- }
- ]
- },
- add: false,
- m: "don't add property, different filenames"
- },
- {
- overrideToAdd: null,
- componentConfig: {},
- add: false,
- m: "don't add property, overrideToAdd is null"
- }];
- beforeEach(function() {
- sinon.stub(mainServiceInfoConfigsController,"addOverrideProperty", Em.K)
- });
- afterEach(function() {
- mainServiceInfoConfigsController.addOverrideProperty.restore();
- });
- tests.forEach(function(t) {
- it(t.m, function() {
- mainServiceInfoConfigsController.set("overrideToAdd", t.overrideToAdd);
- mainServiceInfoConfigsController.checkOverrideProperty(t.componentConfig);
- if(t.add) {
- expect(mainServiceInfoConfigsController.addOverrideProperty.calledWith(t.overrideToAdd)).to.equal(true);
- expect(mainServiceInfoConfigsController.get("overrideToAdd")).to.equal(null);
- } else {
- expect(mainServiceInfoConfigsController.addOverrideProperty.calledOnce).to.equal(false);
- }
- });
- });
- });
- describe("#trackRequest()", function () {
- after(function(){
- mainServiceInfoConfigsController.set('requestInProgress', null);
- });
- it("should set requestInProgress", function () {
- mainServiceInfoConfigsController.trackRequest({'request': {}});
- expect(mainServiceInfoConfigsController.get('requestInProgress')).to.eql({'request': {}});
- });
- });
- describe("#setValuesForOverrides", function() {
- var tests = [
- {
- overrides: [
- {name: "override1"},
- {name: "override2"}
- ],
- _serviceConfigProperty: {},
- serviceConfigProperty: Em.Object.create({overrides: Em.A([])}),
- defaultGroupSelected: true
- }
- ];
- beforeEach(function() {
- sinon.stub(mainServiceInfoConfigsController, "createNewSCP", function(override) {return {name: override.name}})
- });
- afterEach(function() {
- mainServiceInfoConfigsController.createNewSCP.restore();
- });
- tests.forEach(function(t) {
- it("set values for overrides. use createNewSCP method to do this", function() {
- var serviceConfigProperty = t.serviceConfigProperty;
- mainServiceInfoConfigsController.setValuesForOverrides(t.overrides, serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
- expect(serviceConfigProperty.get("overrides")[0]).to.eql(t.overrides[0]);
- expect(serviceConfigProperty.get("overrides")[1]).to.eql(t.overrides[1]);
- });
- });
- });
- describe("#createConfigProperty", function() {
- var tests = [
- {
- _serviceConfigProperty: {
- overrides: {
- }
- },
- defaultGroupSelected: true,
- restartData: {},
- serviceConfigsData: {},
- serviceConfigProperty: {
- overrides: null,
- isOverridable: true
- }
- }];
- beforeEach(function() {
- sinon.stub(mainServiceInfoConfigsController, "setValuesForOverrides", Em.K);
- sinon.stub(mainServiceInfoConfigsController, "setEditability", Em.K);
- });
- afterEach(function() {
- mainServiceInfoConfigsController.setValuesForOverrides.restore();
- mainServiceInfoConfigsController.setEditability.restore();
- });
- tests.forEach(function(t) {
- it("create service config. run methods to correctly set object fileds", function() {
- var result = mainServiceInfoConfigsController.createConfigProperty(t._serviceConfigProperty, t.defaultGroupSelected, t.restartData, t.serviceConfigsData);
- expect(mainServiceInfoConfigsController.setValuesForOverrides.calledWith(t._serviceConfigProperty.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected));
- expect(result.getProperties('overrides','isOverridable')).to.eql(t.serviceConfigProperty);
- });
- });
- });
- describe("#createNewSCP", function() {
- var tests = [
- {
- overrides: {
- value: "value",
- group: {
- value: "group1"
- }
- },
- _serviceConfigProperty: {},
- serviceConfigProperty: Em.Object.create({
- value: "parentSCP",
- supportsFinal: true
- }),
- defaultGroupSelected: true,
- newSCP: {
- value: "value",
- isOriginalSCP: false,
- parentSCP:Em.Object.create({
- value: "parentSCP",
- supportsFinal: true
- }),
- group: {
- value: "group1"
- },
- isEditable: false
- }
- }
- ];
- tests.forEach(function(t) {
- it("", function() {
- var newSCP = mainServiceInfoConfigsController.createNewSCP(t.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected);
- expect(newSCP.getProperties("value", "isOriginalSCP", "parentSCP", "group", "isEditable")).to.eql(t.newSCP);
- });
- });
- });
- describe("#setCompareDefaultGroupConfig", function() {
- beforeEach(function() {
- sinon.stub(mainServiceInfoConfigsController, "getComparisonConfig").returns("compConfig");
- sinon.stub(mainServiceInfoConfigsController, "getMockComparisonConfig").returns("mockConfig");
- sinon.stub(mainServiceInfoConfigsController, "hasCompareDiffs").returns(true);
- });
- afterEach(function() {
- mainServiceInfoConfigsController.getComparisonConfig.restore();
- mainServiceInfoConfigsController.getMockComparisonConfig.restore();
- mainServiceInfoConfigsController.hasCompareDiffs.restore();
- });
- it("expect that setCompareDefaultGroupConfig will not run anything", function() {
- expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({}).compareConfigs.length).to.equal(0);
- });
- it("expect that setCompareDefaultGroupConfig will not run anything", function() {
- expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({},{}).compareConfigs.length).to.equal(0);
- });
- it("expect that serviceConfig.compareConfigs will be getMockComparisonConfig", function() {
- expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, null)).to.eql({compareConfigs: ["mockConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
- });
- it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
- expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isUserProperty: true}, {})).to.eql({compareConfigs: ["compConfig"], isUserProperty: true, isComparison: true, hasCompareDiffs: true});
- });
- it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
- expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isComparison: true, hasCompareDiffs: true});
- });
- it("expect that serviceConfig.compareConfigs will be getComparisonConfig", function() {
- expect(mainServiceInfoConfigsController.setCompareDefaultGroupConfig({isReconfigurable: true, isMock: true}, {})).to.eql({compareConfigs: ["compConfig"], isReconfigurable: true, isMock: true, isComparison: true, hasCompareDiffs: true});
- });
- });
- describe('#showSaveConfigsPopup', function () {
- var bodyView;
- describe('#bodyClass', function () {
- beforeEach(function() {
- sinon.stub(App.ajax, 'send', Em.K);
- // default implementation
- bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup().get('bodyClass').create({
- parentView: Em.View.create()
- });
- });
- afterEach(function() {
- App.ajax.send.restore();
- });
- describe('#componentsFilterSuccessCallback', function () {
- it('check components with unknown state', function () {
- bodyView = mainServiceInfoConfigsController.showSaveConfigsPopup('', true, '', {}, '', 'unknown', '').get('bodyClass').create({
- parentView: Em.View.create()
- });
- bodyView.componentsFilterSuccessCallback({
- items: [
- {
- ServiceComponentInfo: {
- total_count: 4,
- started_count: 2,
- installed_count: 1,
- component_name: 'c1'
- },
- host_components: [
- {HostRoles: {host_name: 'h1'}}
- ]
- }
- ]
- });
- var unknownHosts = bodyView.get('unknownHosts');
- expect(unknownHosts.length).to.equal(1);
- expect(unknownHosts[0]).to.eql({name: 'h1', components: 'C1'});
- });
- });
- });
- });
- });
|