123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- /**
- * 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 blueprintUtils = require('utils/blueprint');
- describe('utils/blueprint', function() {
- var masterBlueprint = {
- blueprint: {
- host_groups: [
- {
- name: "host-group-1",
- components: [
- { name: "ZOOKEEPER_SERVER" },
- { name: "NAMENODE" },
- { name: "HBASE_MASTER" }
- ]
- },
- {
- name: "host-group-2",
- components: [
- { name: "SECONDARY_NAMENODE" }
- ]
- }
- ]
- },
- blueprint_cluster_binding: {
- host_groups: [
- {
- name: "host-group-1",
- hosts: [
- { fqdn: "host1" },
- { fqdn: "host2" }
- ]
- },
- {
- name: "host-group-2",
- hosts: [
- { fqdn: "host3" }
- ]
- }
- ]
- }
- };
- var slaveBlueprint = {
- blueprint: {
- host_groups: [
- {
- name: "host-group-1",
- components: [
- { name: "DATANODE" }
- ]
- },
- {
- name: "host-group-2",
- components: [
- { name: "DATANODE" },
- { name: "HDFS_CLIENT" },
- { name: "ZOOKEEPER_CLIENT" }
- ]
- }
- ]
- },
- blueprint_cluster_binding: {
- host_groups: [
- {
- name: "host-group-1",
- hosts: [
- { fqdn: "host3" }
- ]
- },
- {
- name: "host-group-2",
- hosts: [
- { fqdn: "host4" },
- { fqdn: "host5" }
- ]
- }
- ]
- }
- };
- describe('#matchGroups', function() {
- it('should compose same host group into pairs', function() {
- expect(blueprintUtils.matchGroups(masterBlueprint, slaveBlueprint)).to.deep.equal([
- { g1: "host-group-1" },
- { g1: "host-group-2", g2: "host-group-1" },
- { g2: "host-group-2" }
- ]);
- });
- });
- describe('#filterByComponents', function() {
- it('should remove all components except', function() {
- expect(blueprintUtils.filterByComponents(masterBlueprint, ["NAMENODE"])).to.deep.equal({
- blueprint: {
- host_groups: [
- {
- name: "host-group-1",
- components: [
- { name: "NAMENODE" }
- ]
- }
- ]
- },
- blueprint_cluster_binding: {
- host_groups: [
- {
- name: "host-group-1",
- hosts: [
- { fqdn: "host1" },
- { fqdn: "host2" }
- ]
- }
- ]
- }
- });
- });
- });
- describe('#addComponentsToBlueprint', function() {
- it('should add components to blueprint', function() {
- var components = ["FLUME_HANDLER", "HCAT"];
- expect(blueprintUtils.addComponentsToBlueprint(masterBlueprint, components)).to.deep.equal({
- blueprint: {
- host_groups: [
- {
- name: "host-group-1",
- components: [
- { name: "ZOOKEEPER_SERVER" },
- { name: "NAMENODE" },
- { name: "HBASE_MASTER" },
- { name: "FLUME_HANDLER" },
- { name: "HCAT" }
- ]
- },
- {
- name: "host-group-2",
- components: [
- { name: "SECONDARY_NAMENODE" },
- { name: "FLUME_HANDLER" },
- { name: "HCAT" }
- ]
- }
- ]
- },
- blueprint_cluster_binding: {
- host_groups: [
- {
- name: "host-group-1",
- hosts: [
- { fqdn: "host1" },
- { fqdn: "host2" }
- ]
- },
- {
- name: "host-group-2",
- hosts: [
- { fqdn: "host3" }
- ]
- }
- ]
- }
- });
- });
- });
- describe('#mergeBlueprints', function() {
- it('should merge components', function() {
- expect(blueprintUtils.mergeBlueprints(masterBlueprint, slaveBlueprint)).to.deep.equal(
- {
- blueprint: {
- host_groups: [
- {
- name: "host-group-1",
- components: [
- { name: "ZOOKEEPER_SERVER" },
- { name: "NAMENODE" },
- { name: "HBASE_MASTER" }
- ]
- },
- {
- name: "host-group-2",
- components: [
- { name: "SECONDARY_NAMENODE" },
- { name: "DATANODE" }
- ]
- },
- {
- name: "host-group-3",
- components: [
- { name: "DATANODE" },
- { name: "HDFS_CLIENT" },
- { name: "ZOOKEEPER_CLIENT" }
- ]
- }
- ]
- },
- blueprint_cluster_binding: {
- host_groups: [
- {
- name: "host-group-1",
- hosts: [
- { fqdn: "host1" },
- { fqdn: "host2" }
- ]
- },
- {
- name: "host-group-2",
- hosts: [
- { fqdn: "host3" }
- ]
- },
- {
- name: "host-group-3",
- hosts: [
- { fqdn: "host4" },
- { fqdn: "host5" }
- ]
- }
- ]
- }
- }
- );
- });
- });
- describe('#buildConfigsJSON', function () {
- var tests = [
- {
- "stepConfigs": [
- Em.Object.create({
- serviceName: "YARN",
- configs: [
- Em.Object.create({
- name: "p1",
- value: "v1",
- filename: "yarn-site.xml",
- isRequiredByAgent: true
- }),
- Em.Object.create({
- name: "p2",
- value: "v2",
- filename: "yarn-site.xml",
- isRequiredByAgent: true
- }),
- Em.Object.create({
- name: "p3",
- value: "v3",
- filename: "yarn-env.xml",
- isRequiredByAgent: true
- })
- ]
- }),
- Em.Object.create({
- serviceName: "MISC",
- configs: [
- Em.Object.create({
- name: "user",
- value: "yarn",
- filename: "yarn-env.xml",
- isRequiredByAgent: true
- })
- ]
- })
- ],
- "configurations": {
- "yarn-site": {
- "properties": {
- "p1": "v1",
- "p2": "v2"
- }
- },
- "yarn-env": {
- "properties": {
- "p3": "v3",
- "user": "yarn"
- }
- }
- }
- }
- ];
- tests.forEach(function (test) {
- it("generate configs for request (use in validation)", function () {
- expect(blueprintUtils.buildConfigsJSON(test.stepConfigs)).to.eql(test.configurations);
- });
- });
- });
- describe('#generateHostGroups()', function () {
- beforeEach(function() {
- sinon.stub(blueprintUtils, 'getComponentForHosts').returns({
- "host1": ["C1", "C2"],
- "host2": ["C1", "C3"]
- });
- });
- afterEach(function() {
- blueprintUtils.getComponentForHosts.restore();
- });
- var tests = [
- {
- "hostNames": ["host1", "host2"],
- "hostComponents": [
- Em.Object.create({
- componentName: "C1",
- hostName: "host1"
- }),
- Em.Object.create({
- componentName: "C2",
- hostName: "host1"
- }),
- Em.Object.create({
- componentName: "C1",
- hostName: "host2"
- }),
- Em.Object.create({
- componentName: "C3",
- hostName: "host2"
- })
- ],
- result: {
- blueprint: {
- host_groups: [
- {
- name: "host-group-1",
- "components": [
- {
- "name": "C1"
- },
- {
- "name": "C2"
- }
- ]
- },
- {
- name: "host-group-2",
- "components": [
- {
- "name": "C1"
- },
- {
- "name": "C3"
- }
- ]
- }
- ]
- },
- blueprint_cluster_binding: {
- host_groups: [
- {
- "name": "host-group-1",
- "hosts": [
- {
- "fqdn": "host1"
- }
- ]
- },
- {
- "name": "host-group-2",
- "hosts": [
- {
- "fqdn": "host2"
- }
- ]
- }
- ]
- }
- }
- }
- ];
- tests.forEach(function (test) {
- it("generate host groups", function () {
- expect(blueprintUtils.generateHostGroups(test.hostNames)).to.eql(test.result);
- });
- });
- });
- describe("#getComponentForHosts()", function() {
- var res;
- beforeEach(function() {
- sinon.stub(App.ClientComponent, 'find').returns([
- Em.Object.create({
- componentName: "C1",
- hostNames: ["host1", "host2"]
- })
- ]);
- sinon.stub(App.SlaveComponent, 'find').returns([
- Em.Object.create({
- componentName: "C2",
- hostNames: ["host2", "host3"]
- })
- ]);
- sinon.stub(App.MasterComponent, 'find').returns([
- Em.Object.create({
- componentName: "C3",
- hostNames: ["host3"]
- })
- ]);
- res = blueprintUtils.getComponentForHosts();
- });
- afterEach(function() {
- App.ClientComponent.find.restore();
- App.SlaveComponent.find.restore();
- App.MasterComponent.find.restore();
- });
- it('map for 3 items is created', function () {
- expect(Object.keys(res)).to.have.property('length').equal(3);
- });
- it("host1 map is valid", function() {
- expect(res.host1.toArray()).to.eql(['C1']);
- });
- it("host2 map is valid", function() {
- expect(res.host2.toArray()).to.eql(['C1', 'C2']);
- });
- it("host3 map is valid", function() {
- expect(res.host3.toArray()).to.eql(['C2', 'C3']);
- });
- });
- describe('#_generateHostMap', function() {
- it('generate map', function() {
- var map = blueprintUtils._generateHostMap({}, ['h1','h2', 'h1'],'c1');
- expect(map['h1'][0]).to.eql('c1');
- expect(map['h2'][0]).to.eql('c1');
- });
- it('skip generations as hosts is empty', function() {
- expect(blueprintUtils._generateHostMap({}, [],'c1')).to.eql({});
- });
- it('skip throws error when data is wrong (should assert error if no data returned from server)', function() {
- expect(function () {
- blueprintUtils._generateHostMap();
- }).to.throw(Error);
- });
- });
- });
|